/** * Called before a slide change happens. By returning false, one can disallow the slide change. * * @return true, if the slide change should be allowed, else false */ private boolean handleBeforeSlideChanged() { Fragment currentFragment = mPagerAdapter.getItem(pager.getCurrentItem()); LogHelper.d( TAG, String.format( "User wants to move away from slide: %s. Checking if this should be allowed...", currentFragment)); // Check if the current fragment implements ISlidePolicy, else a change is always allowed if (currentFragment instanceof ISlidePolicy) { ISlidePolicy slide = (ISlidePolicy) currentFragment; LogHelper.d(TAG, "Current fragment implements ISlidePolicy."); // Check if policy is fulfilled if (!slide.isPolicyRespected()) { LogHelper.d(TAG, "Slide policy not respected, denying change request."); return false; } } LogHelper.d(TAG, "Change request will be allowed."); return true; }
private void handleIllegalSlideChangeAttempt() { Fragment currentFragment = mPagerAdapter.getItem(pager.getCurrentItem()); if (currentFragment != null && currentFragment instanceof ISlidePolicy) { ISlidePolicy slide = (ISlidePolicy) currentFragment; if (!slide.isPolicyRespected()) { slide.onUserIllegallyRequestedNextPage(); } } }