Skip to content

Instantly share code, notes, and snippets.

@ColeMurray
Last active January 18, 2016 20:36
Show Gist options
  • Select an option

  • Save ColeMurray/0372bfeb357dceae5fee to your computer and use it in GitHub Desktop.

Select an option

Save ColeMurray/0372bfeb357dceae5fee to your computer and use it in GitHub Desktop.
VisibilityRunnable - A runnable that calls a listener with visible and invisibleViews
class VisibilityRunnable implements Runnable {
private final List<View> mVisibleViews;
private final List<View> mInvisibleViews;
private VisibilityChecker mVisibilityChecker;
VisibilityRunnable() {
mVisibleViews = new ArrayList<>();
mInvisibleViews = new ArrayList<>();
}
@Override
public void run() {
mIsVisibilityCheckedScheduled = false;
for (final Map.Entry<View, TrackingInfo> entry : mTrackedViews.entrySet()) {
final View view = entry.getKey();
final int minPercentageViewed = entry.getValue().mMinVisiblePercent;
if (mVisibilityChecker.isVisible(view, minPercentageViewed)) {
mVisibleViews.add(view);
} else
mInvisibleViews.add(view);
}
if (mVisibilityTrackerListener != null) {
mVisibilityTrackerListener.onVisibilityChanged(mVisibleViews, mInvisibleViews);
}
mVisibleViews.clear();
mInvisibleViews.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment