Created
March 26, 2014 17:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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