Skip to content

Instantly share code, notes, and snippets.

@jsaund
Created September 11, 2016 00:11
Show Gist options
  • Save jsaund/a76da153c582db92471f35f9d0ad2f84 to your computer and use it in GitHub Desktop.
Save jsaund/a76da153c582db92471f35f9d0ad2f84 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) {
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