22
22
23
23
import com .librelio .utils .SystemHelper ;
24
24
import com .niveales .wind .R ;
25
+ import com .squareup .picasso .Callback ;
26
+ import com .squareup .picasso .Picasso ;
25
27
26
28
import org .apache .commons .io .FilenameUtils ;
27
29
@@ -185,6 +187,7 @@ private void setCurrentImageViewPosition(int position) {
185
187
currentImageViewPosition = position ;
186
188
int actualPosition = slidesInfo .count - position ;
187
189
String path = slidesInfo .getFullPathToImage (actualPosition );
190
+ // TODO replace with Picasso image loading
188
191
new GetBitmapAsyncTask (false ) {
189
192
@ Override
190
193
protected void onPostExecute (Bitmap bmp ) {
@@ -210,23 +213,19 @@ private void initSingleImage() {
210
213
final ImageView imageView = (ImageView ) view
211
214
.findViewById (R .id .slideshow_item_image );
212
215
final TextView text = (TextView ) view .findViewById (R .id .slideshow_item_text );
213
- new GetBitmapAsyncTask (true ) {
216
+ Picasso .with (context ).load (new File (slidesInfo .getFullPathToImage (1 )))
217
+ .fit ().centerInside ().into (imageView , new Callback () {
214
218
@ Override
215
- protected void onPostExecute (Bitmap bmp ) {
216
- if (isCancelled ()) {
217
- return ;
218
- }
219
+ public void onSuccess () {
219
220
view .setBackgroundColor (backgroundColor );
220
- if (bmp == null ) {
221
- Log .w ("ImageLayout" , "Single Image Bitmap null" );
222
- imageView .setVisibility (View .GONE );
223
- text .setVisibility (View .VISIBLE );
224
- } else {
225
- imageView .setImageBitmap (bmp );
226
- }
227
- super .onPostExecute (bmp );
221
+ text .setVisibility (View .VISIBLE );
228
222
}
229
- }.execute (slidesInfo .getFullPathToImage (1 ));
223
+
224
+ @ Override
225
+ public void onError () {
226
+ imageView .setVisibility (View .GONE );
227
+ }
228
+ });
230
229
}
231
230
232
231
@ Override
@@ -257,7 +256,7 @@ public SlidesInfo(String basePath) {
257
256
this .suffix = fileName .split ("_" )[1 ].split ("\\ ." )[1 ];
258
257
this .count = Integer
259
258
.valueOf (fileName .split ("_" )[1 ].split ("\\ ." )[0 ]);
260
- for (int i = 1 ; i < count ; i ++) {
259
+ for (int i = 1 ; i <= count ; i ++) {
261
260
images .add (this .assetDir + "/" + this .preffix + "_"
262
261
+ String .valueOf (i ) + "." + this .suffix );
263
262
}
@@ -279,12 +278,12 @@ public String toString() {
279
278
}
280
279
281
280
private class GetBitmapAsyncTask extends AsyncTask <String , Void , Bitmap > {
282
-
281
+
283
282
private boolean showProgressBar = false ;
284
283
285
284
public GetBitmapAsyncTask (boolean showProgressBar ) {
286
285
this .showProgressBar = showProgressBar ;
287
-
286
+
288
287
}
289
288
@ Override
290
289
protected void onPreExecute () {
@@ -350,22 +349,18 @@ public View instantiateItem(ViewGroup container, int position) {
350
349
final FrameLayout background = (FrameLayout ) view
351
350
.findViewById (R .id .slide_show_frame );
352
351
background .setBackgroundColor (backgroundColor );
353
- new GetBitmapAsyncTask (true ) {
352
+ Picasso .with (context ).load (new File (path ))
353
+ .fit ().centerInside ().into (img , new Callback () {
354
354
@ Override
355
- protected void onPostExecute (Bitmap bmp ) {
356
- if (isCancelled ()) {
357
- return ;
358
- }
359
- if (bmp == null ) {
360
- Log .w ("ImageLayout" , "ViewPager Image Bitmap null" );
361
- img .setVisibility (View .GONE );
362
- text .setVisibility (View .VISIBLE );
363
- } else {
364
- img .setImageBitmap (bmp );
365
- }
366
- super .onPostExecute (bmp );
355
+ public void onSuccess () {
356
+
367
357
}
368
- }.execute (path );
358
+
359
+ @ Override
360
+ public void onError () {
361
+ img .setVisibility (View .GONE );
362
+ }
363
+ });
369
364
container .addView (view );
370
365
return view ;
371
366
}
0 commit comments