Last active
September 29, 2016 10:31
-
-
Save jsaund/4aa2099cd0910ef059a1e9c5c114b408 to your computer and use it in GitHub Desktop.
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
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