Skip to content

Commit ba91f9e

Browse files
committed
Try switching to Picasso for images to see if it improves memory usage. #296. #194
1 parent 106a759 commit ba91f9e

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

main/src/main/java/com/librelio/view/ImageLayout.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import com.librelio.utils.SystemHelper;
2424
import com.niveales.wind.R;
25+
import com.squareup.picasso.Callback;
26+
import com.squareup.picasso.Picasso;
2527

2628
import org.apache.commons.io.FilenameUtils;
2729

@@ -185,6 +187,7 @@ private void setCurrentImageViewPosition(int position) {
185187
currentImageViewPosition = position;
186188
int actualPosition = slidesInfo.count - position;
187189
String path = slidesInfo.getFullPathToImage(actualPosition);
190+
// TODO replace with Picasso image loading
188191
new GetBitmapAsyncTask(false) {
189192
@Override
190193
protected void onPostExecute(Bitmap bmp) {
@@ -210,23 +213,19 @@ private void initSingleImage() {
210213
final ImageView imageView = (ImageView) view
211214
.findViewById(R.id.slideshow_item_image);
212215
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() {
214218
@Override
215-
protected void onPostExecute(Bitmap bmp) {
216-
if (isCancelled()) {
217-
return;
218-
}
219+
public void onSuccess() {
219220
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);
228222
}
229-
}.execute(slidesInfo.getFullPathToImage(1));
223+
224+
@Override
225+
public void onError() {
226+
imageView.setVisibility(View.GONE);
227+
}
228+
});
230229
}
231230

232231
@Override
@@ -257,7 +256,7 @@ public SlidesInfo(String basePath) {
257256
this.suffix = fileName.split("_")[1].split("\\.")[1];
258257
this.count = Integer
259258
.valueOf(fileName.split("_")[1].split("\\.")[0]);
260-
for (int i = 1; i < count; i++) {
259+
for (int i = 1; i <= count; i++) {
261260
images.add(this.assetDir + "/" + this.preffix + "_"
262261
+ String.valueOf(i) + "." + this.suffix);
263262
}
@@ -279,12 +278,12 @@ public String toString() {
279278
}
280279

281280
private class GetBitmapAsyncTask extends AsyncTask<String, Void, Bitmap> {
282-
281+
283282
private boolean showProgressBar = false;
284283

285284
public GetBitmapAsyncTask(boolean showProgressBar) {
286285
this.showProgressBar = showProgressBar;
287-
286+
288287
}
289288
@Override
290289
protected void onPreExecute() {
@@ -350,22 +349,18 @@ public View instantiateItem(ViewGroup container, int position) {
350349
final FrameLayout background = (FrameLayout) view
351350
.findViewById(R.id.slide_show_frame);
352351
background.setBackgroundColor(backgroundColor);
353-
new GetBitmapAsyncTask(true) {
352+
Picasso.with(context).load(new File(path))
353+
.fit().centerInside().into(img, new Callback() {
354354
@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+
367357
}
368-
}.execute(path);
358+
359+
@Override
360+
public void onError() {
361+
img.setVisibility(View.GONE);
362+
}
363+
});
369364
container.addView(view);
370365
return view;
371366
}

0 commit comments

Comments
 (0)