Skip to content

Instantly share code, notes, and snippets.

@jsaund
Last active September 29, 2016 10:31
Show Gist options
  • Save jsaund/4aa2099cd0910ef059a1e9c5c114b408 to your computer and use it in GitHub Desktop.
Save jsaund/4aa2099cd0910ef059a1e9c5c114b408 to your computer and use it in GitHub Desktop.
static class UIHandler extends Handler {
private final WeakReference<ImageFetcherActivity> mActivityRef;
UIHandler(ImageFetcherActivity activity) {
mActivityRef = new WeakReference(activity);
}
@Override
public void handleMessage(Message msg) {
final ImageFetcherActivity activity = mActivityRef.get();
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
removeCallbacksAndMessages(null);
return
}
switch (msg.what) {
case MSG_SHOW_LOADER: {
activity.progressIndicator.setVisibility(View.VISIBLE);
break;
}
case MSG_HIDE_LOADER: {
activity.progressIndicator.setVisibility(View.GONE);
break;
}
case MSG_SHOW_IMAGE: {
activity.progressIndicator.setVisibility(View.GONE);
activity.imageView.setImageBitmap((Bitmap) msg.obj);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment