1010import android .content .Intent ;
1111import android .content .SharedPreferences ;
1212import android .content .pm .PackageManager ;
13+ import android .graphics .Bitmap ;
14+ import android .graphics .drawable .Drawable ;
1315import android .net .ConnectivityManager ;
1416import android .net .NetworkInfo ;
1517import android .net .Uri ;
2931import android .widget .ImageView ;
3032import android .widget .ProgressBar ;
3133import android .widget .Toast ;
32-
3334import com .bumptech .glide .Glide ;
3435import com .bumptech .glide .load .resource .drawable .GlideDrawable ;
3536import com .bumptech .glide .request .RequestListener ;
36- import com .bumptech .glide .request .target . GlideDrawableImageViewTarget ;
37- import com .bumptech .glide .request .target .Target ;
37+ import com .bumptech .glide .request .animation . GlideAnimation ;
38+ import com .bumptech .glide .request .target .SimpleTarget ;
3839import com .zulip .android .R ;
3940import com .zulip .android .util .ZLog ;
40-
4141import java .io .BufferedInputStream ;
4242import java .io .File ;
4343import java .io .FileOutputStream ;
4747import java .net .MalformedURLException ;
4848import java .net .URL ;
4949import java .net .URLConnection ;
50+ import uk .co .senab .photoview .PhotoView ;
5051
5152
5253public class PhotoViewActivity extends AppCompatActivity implements ActivityCompat .OnRequestPermissionsResultCallback {
@@ -55,7 +56,7 @@ public class PhotoViewActivity extends AppCompatActivity implements ActivityComp
5556 private static final int EXTERNAL_STORAGE_PERMISSION_CONSTANT = 100 ;
5657 private static final int REQUEST_PERMISSION_SETTING = 101 ;
5758 int id = 1 ;
58- private ImageView linkImage ;
59+ private PhotoView linkImage ;
5960 private ProgressBar progressBar ;
6061 private NotificationManager mNotifyManager ;
6162 private NotificationCompat .Builder mBuilder ;
@@ -74,31 +75,26 @@ protected void onCreate(Bundle savedInstanceState) {
7475 final Intent intent = getIntent ();
7576 String url = intent .getStringExtra (Intent .EXTRA_TEXT );
7677 getSupportActionBar ().setTitle (url );
77- linkImage = (ImageView ) findViewById (R .id .linkImageView );
78+ linkImage = (PhotoView ) findViewById (R .id .linkImageView );
7879 progressBar = (ProgressBar ) findViewById (R .id .progress );
79- GlideDrawableImageViewTarget imageViewPreview = new GlideDrawableImageViewTarget (linkImage );
80- Glide
81- .with (this )
82- .load (url )
83- .listener (new RequestListener <String , GlideDrawable >() {
84- @ Override
85- public boolean onException (Exception e , String model , Target <GlideDrawable > target , boolean isFirstResource ) {
86- progressBar .setVisibility (View .GONE );
87- if (!isNetworkAvailable ()) {
88- Toast .makeText (getApplicationContext (), R .string .toast_no_internet_connection , Toast .LENGTH_SHORT ).show ();
89- } else {
90- Toast .makeText (getApplicationContext (), R .string .toast_unable_to_load_image , Toast .LENGTH_SHORT ).show ();
91- }
92- return false ;
93- }
94-
95- @ Override
96- public boolean onResourceReady (GlideDrawable resource , String model , Target <GlideDrawable > target , boolean isFromMemoryCache , boolean isFirstResource ) {
97- progressBar .setVisibility (View .GONE );
98- return false ;
99- }
100- })
101- .into (imageViewPreview );
80+ Glide .with (this ).load (url ).asBitmap ().into (new SimpleTarget <Bitmap >() {
81+ @ Override
82+ public void onResourceReady (Bitmap resource , GlideAnimation <? super Bitmap > glideAnimation ) {
83+ progressBar .setVisibility (View .GONE );
84+ linkImage .setImageBitmap (resource );
85+ }
86+
87+ @ Override
88+ public void onLoadFailed (Exception e , Drawable errorDrawable ) {
89+ super .onLoadFailed (e , errorDrawable );
90+ progressBar .setVisibility (View .GONE );
91+ if (!isNetworkAvailable ()) {
92+ Toast .makeText (getApplicationContext (), R .string .toast_no_internet_connection , Toast .LENGTH_SHORT ).show ();
93+ } else {
94+ Toast .makeText (getApplicationContext (), R .string .toast_unable_to_load_image , Toast .LENGTH_SHORT ).show ();
95+ }
96+ }
97+ });
10298 }
10399
104100 private boolean isNetworkAvailable () {
0 commit comments