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
public class ImageDownloaderTask extends AsyncTask<String, Void, Bitmap> { | |
private static final String TAG = "ImageDownloaderTask"; | |
private final OnImageDownloadedListener mListener; | |
public ImageDownloaderTask(OnImageDownloadedListener listener) { | |
mListener = listener; | |
} | |
@Override | |
protected Bitmap doInBackground(String... params) { |
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
public class MainActivity extends AppCompatActivity { | |
final String IMAGE_URL = "https://pixabay.com/static/uploads/photo/2014/12/22/00/05/spindle-576757_960_720.png"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final ImageView imageView = (ImageView) findViewById(R.id.headerimage); | |
new ImageDownloaderTask(new ImageDownloaderTask.OnImageDownloadedListener() { |
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
public class ImageUtil { | |
private static final String TAG = "ImageUtil"; | |
public static Bitmap getImage(String urlSpec) { | |
Bitmap result = null; | |
try { | |
byte[] posterBytes = getBytes(urlSpec); | |
result = BitmapFactory.decodeByteArray(posterBytes, 0, posterBytes.length); | |
} catch (IOException e) { | |
Log.e(TAG, "getImage: ", e); |
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
/** | |
* A helper view class useful in playing animation in a more memory efficient way, since Bitmaps | |
* are preloaded on a background handlerThread and reused, while the main thread "plays" the frames. | |
* To specify which animation frames should be played you need to provide an implementation of | |
* FramesDataSource. | |
*/ | |
public class FrameAnimationView extends FrameLayout { | |
private static final String TAG = FrameAnimationView.class.getSimpleName(); | |
private final ImageView imageView; | |
private final Handler animationHandler; |