10
10
import android .content .Intent ;
11
11
import android .content .SharedPreferences ;
12
12
import android .content .pm .PackageManager ;
13
+ import android .graphics .Bitmap ;
14
+ import android .graphics .drawable .Drawable ;
13
15
import android .net .ConnectivityManager ;
14
16
import android .net .NetworkInfo ;
15
17
import android .net .Uri ;
29
31
import android .widget .ImageView ;
30
32
import android .widget .ProgressBar ;
31
33
import android .widget .Toast ;
32
-
33
34
import com .bumptech .glide .Glide ;
34
35
import com .bumptech .glide .load .resource .drawable .GlideDrawable ;
35
36
import 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 ;
38
39
import com .zulip .android .R ;
39
40
import com .zulip .android .util .ZLog ;
40
-
41
41
import java .io .BufferedInputStream ;
42
42
import java .io .File ;
43
43
import java .io .FileOutputStream ;
47
47
import java .net .MalformedURLException ;
48
48
import java .net .URL ;
49
49
import java .net .URLConnection ;
50
+ import uk .co .senab .photoview .PhotoView ;
50
51
51
52
52
53
public class PhotoViewActivity extends AppCompatActivity implements ActivityCompat .OnRequestPermissionsResultCallback {
@@ -55,7 +56,7 @@ public class PhotoViewActivity extends AppCompatActivity implements ActivityComp
55
56
private static final int EXTERNAL_STORAGE_PERMISSION_CONSTANT = 100 ;
56
57
private static final int REQUEST_PERMISSION_SETTING = 101 ;
57
58
int id = 1 ;
58
- private ImageView linkImage ;
59
+ private PhotoView linkImage ;
59
60
private ProgressBar progressBar ;
60
61
private NotificationManager mNotifyManager ;
61
62
private NotificationCompat .Builder mBuilder ;
@@ -74,31 +75,26 @@ protected void onCreate(Bundle savedInstanceState) {
74
75
final Intent intent = getIntent ();
75
76
String url = intent .getStringExtra (Intent .EXTRA_TEXT );
76
77
getSupportActionBar ().setTitle (url );
77
- linkImage = (ImageView ) findViewById (R .id .linkImageView );
78
+ linkImage = (PhotoView ) findViewById (R .id .linkImageView );
78
79
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
+ });
102
98
}
103
99
104
100
private boolean isNetworkAvailable () {
0 commit comments