Last active
January 18, 2016 02:32
-
-
Save ColeMurray/3db2285e7ead0f29a053 to your computer and use it in GitHub Desktop.
scheduleVisibilityCheck - A method to place a runnable on a handlers message queue
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 VisibilityTracker { | |
| private static final long VISIBILITY_CHECK_DELAY_MILLIS = 100; | |
| private WeakHashMap<View, TrackingInfo> mTrackedViews = new WeakHashMap<>(); | |
| private ViewTreeObserver.OnPreDrawListener mOnPreDrawListener; | |
| private VisibilityTrackerListener mVisibilityTrackerListener; | |
| private boolean mIsVisibilityCheckedScheduled; | |
| private Handler mVisibilityHandler; | |
| private VisibilityChecker mVisibilityChecker; | |
| private Runnable mVisibilityRunnable; | |
| public VisibilityTracker(Activity activity) { | |
| View rootView = activity.getWindow().getDecorView(); | |
| mVisibilityHandler = new Handler(); | |
| mVisibilityChecker = new VisibilityChecker(); | |
| mVisibilityRunnable = new VisibilityRunnable(); | |
| // ........ | |
| private void scheduleVisibilityCheck() { | |
| if (mIsVisibilityCheckedScheduled) { | |
| return; | |
| } | |
| mIsVisibilityCheckedScheduled = true; | |
| mVisibilityHandler.postDelayed(mVisibilityRunnable, VISIBILITY_CHECK_DELAY_MILLIS); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment