Created
April 4, 2019 09:24
-
-
Save FrannyZhao/f3b11e70eac2ded0e0b290bed658c544 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
private final UIHandler uiHandler = new UIHandler(this); | |
static class UIHandler extends Handler { | |
private final WeakReference<DashboardFragment> mFragment; | |
private static final int MSG_SHOW_MASK = 1; | |
private static final int MSG_HIDE_MASK = 2; | |
private UIHandler(DashboardFragment fragment) { | |
mFragment = new WeakReference<>(fragment); | |
} | |
@Override | |
public void handleMessage(Message msg) { | |
if (mFragment.get() == null) { | |
return; | |
} | |
DashboardFragment fragment = mFragment.get(); | |
switch (msg.what) { | |
case MSG_SHOW_MASK: | |
fragment.mMask.setVisibility(View.VISIBLE); | |
break; | |
case MSG_HIDE_MASK: | |
fragment.mMask.setVisibility(View.GONE); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
uiHandler.removeCallbacksAndMessages(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment