Skip to content

Instantly share code, notes, and snippets.

@jmartinesp
Created March 26, 2014 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmartinesp/9788601 to your computer and use it in GitHub Desktop.
Save jmartinesp/9788601 to your computer and use it in GitHub Desktop.
Tried to fix an AsyncTask so it loads a Bitmap from an ArrayList to a ImageView every second
class GetImagesTask extends AsyncTask<Long, Bitmap, Void>{
@Override
protected ArrayList<Bitmap> doInBackground(Long... id) {
long projectId = id[0];
Project project = getProject(projectId);
ArrayList<Bitmap> i = new ArrayList<Bitmap>();
File[] files = MediaHelper.getProjectFilenames(project.getImagePath());
if(files != null && files.length > 0){
for(File aFile : files){
Bitmap bitmap = MediaHelper.getScaledImage(aFile, screenSize.y / 2, screenSize.x / 2);
i.add(bitmap);
Log.d(TAG, "image added...size = " + bitmap.getByteCount());
}
}
for (Bitmap b : i) {
publishProgress(b);
try{
Thread.sleep(1000);
}catch (InterruptedException e){
Log.d(TAG, "Thread interrupted unexpectedly.");
}
}
return i;
}
protected void onProgressUpdate(Bitmap... bitmaps) {
Bitmap b = bitmaps[0];
ivSlide.setImageBitmap(b);
Log.d(TAG, "Setting ImageView image");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment