Last active
September 9, 2016 06:44
-
-
Save jsaund/f4473ca3ddc4c51b2bef0eb6c508ddd9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ImageFetcherAltActivity extends AppCompactActivity { | |
| class WorkerThread extends Thread { | |
| void fetchImage(String url) { | |
| handler.sendEmptyMessage(MSG_SHOW_LOADER); | |
| // network call to load image | |
| handler.obtainMessage(MSG_SHOW_IMAGE, imageBitmap).sendToTarget(); | |
| } | |
| } | |
| class UIHandler extends Handler { | |
| @Override | |
| public void handleMessage(Message msg) { | |
| switch (msg.what) { | |
| case MSG_SHOW_LOADER: { | |
| progressIndicator.setVisibility(View.VISIBLE); | |
| break; | |
| } | |
| case MSG_HIDE_LOADER: { | |
| progressIndicator.setVisibility(View.GONE); | |
| break; | |
| } | |
| case MSG_SHOW_IMAGE: { | |
| progressIndicator.setVisibility(View.GONE); | |
| imageView.setImageBitmap((Bitmap) msg.obj); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| @Override | |
| protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| // prepare the view, maybe setContentView, etc | |
| new WorkerThread().fetchImage(imageUrl); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment