Skip to content

Instantly share code, notes, and snippets.

View FlaviusPopescu's full-sized avatar

Flavius Popescu FlaviusPopescu

View GitHub Profile
* 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;
FlaviusPopescu /
Created April 28, 2016 23:55
Internet and Background Threads
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);
FlaviusPopescu /
Created April 28, 2016 23:51
Internet and Background Tasks
public class MainActivity extends AppCompatActivity {
final String IMAGE_URL = "";
protected void onCreate(Bundle savedInstanceState) {
final ImageView imageView = (ImageView) findViewById(;
new ImageDownloaderTask(new ImageDownloaderTask.OnImageDownloadedListener() {
FlaviusPopescu /
Last active April 28, 2016 23:21
Internet and Background Threads
public class ImageDownloaderTask extends AsyncTask<String, Void, Bitmap> {
private static final String TAG = "ImageDownloaderTask";
private final OnImageDownloadedListener mListener;
public ImageDownloaderTask(OnImageDownloadedListener listener) {
mListener = listener;
protected Bitmap doInBackground(String... params) {