Code example for ViewPager

Methods: setOnPageChangeListener

0
	 *  
	 * @param context The Activity context. 
	 * @param attrs Attributes to apply to this view. 
	 */ 
	public BlockingViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
		 
		init(); 
	} 
	 
	/** 
	 * Checks whether or not backward navigation is being blocked or allowed. 
	 *  
	 * @return Returns <code>true</code> if backward navigation is not permitted, 
	 * or <code>false</code> if there is no restriction about it. 
	 */ 
	public boolean isBlockPrevious() { 
		return blockPrevious;
	} 
 
	/** 
	 * Establish whether or not backward navigation will be blocked or allowed. 
	 *  
	 * @param blockPrevious Set <code>true</code> to disallow backward navigation, 
	 * or set <code>false</code> to remove any restriction about it. 
	 */ 
	public void setBlockPrevious(boolean blockPrevious) {
		this.blockPrevious = blockPrevious;
	} 
 
	/** 
	 * Checks whether or not forward navigation is being blocked or allowed. 
	 *  
	 * @return Returns <code>true</code> if forward navigation is not permitted, 
	 * or <code>false</code> if there is no restriction about it. 
	 */ 
	public boolean isBlockNext() { 
		return blockNext;
	} 
 
	/** 
	 * Establish whether or not forward navigation will be blocked or allowed. 
	 *  
	 * @param blockNext Set <code>true</code> to disallow forward navigation, 
	 * or set <code>false</code> to remove any restriction about it. 
	 */ 
	public void setBlockNext(boolean blockNext) {
		this.blockNext = blockNext;
	} 
 
	/** 
	 * <p>Obtain the lowest page index to where the user has permission to navigate to.</p> 
	 * <p>If there is not such limit, a value of {@link #RELEASE_BLOCKING} will be 
	 * returned.</p> 
	 *  
	 * @return The index of the lowest page where the user can navigate, or 
	 * {@link #RELEASE_BLOCKING} if there is not such limit. 
	 */ 
	public int getMin() { 
		return min;
	} 
 
	/** 
	 * <p>Establish the lowest page index to where the user will have permission to 
	 * navigate to.</p> 
	 * <p>Send a value of {@link #RELEASE_BLOCKING} to remove any limitation about it.</p> 
	 *  
	 * @param min The lowest index of the page that the user will be able to navigate to, or 
	 * {@link #RELEASE_BLOCKING} if there shouldn't be any limit. 
	 */ 
	public void setMin(int min) {
		 
		this.min = min;
		 
		if(this.min < 0)
			this.min = RELEASE_BLOCKING;
		if(getAdapter() != null && this.min >= getAdapter().getCount())
			this.min = RELEASE_BLOCKING;
		mBlockingPageChangeListener.reset(getCurrentItem());
	} 
 
	/** 
	 * <p>Obtain the highest page index to where the user has permission to navigate to.</p> 
	 * <p>If there is not such limit, a value of {@link #RELEASE_BLOCKING} will be 
	 * returned.</p> 
	 *  
	 * @return The index of the highest page where the user can navigate, or 
	 * {@link #RELEASE_BLOCKING} if there is not such limit. 
	 */ 
	public int getMax() { 
		return max;
	} 
 
	/** 
	 * <p>Establish the highest page index to where the user will have permission to 
	 * navigate to.</p> 
	 * <p>Send a value of {@link #RELEASE_BLOCKING} to remove any limitation about it.</p> 
	 *  
	 * @param min The highest index of the page that the user will be able to navigate to, or 
	 * {@link #RELEASE_BLOCKING} if there shouldn't be any limit. 
	 */ 
	public void setMax(int max) {
		 
		this.max = max;
		 
		if(this.max < 0)
			this.max = RELEASE_BLOCKING;
		if(getAdapter() != null && this.max >= getAdapter().getCount())
			this.max = RELEASE_BLOCKING;
		mBlockingPageChangeListener.reset(getCurrentItem());
	} 
	 
	/** 
	 * <p>Set a custom {@link OnPageBlockedListener} to this view. This is specially useful if you 
	 * need to get a feedback when a navigation denial occurs.</p> 
	 * <p>The default implementation assigns an empty listener, and setting the parameter to 
	 * <code>null</code> will revert to that.</p> 
	 *   
	 * @param listener Your custom implementation of the listener to assign, or <code>null</code> to 
	 * revert to the empty implementation. 
	 */ 
	public void setOnPageBlockedListener(OnPageBlockedListener listener) {
	 
		if(listener == null)
			listener = new EmptyPageBlockedListener();
		 
		mPageBlockedListener = listener;
	} 
 
	/** 
	 * <p>Set a custom {@link OnBlockingPageChangeListener} to this view. The default implementation 
	 * endows this instance with a base implementation, so you probably won't need to assign 
	 * any other at all.</p> 
	 * <p>Assigning <code>null</code> will revert to the base implementation of the listener (without 
	 * losing any permissions already assigned)</p> 
	 *  
	 * @param listener Your custom implementation of the listener to assign, or <code>null</code> to 
	 * revert to the base implementation. 
	 */ 
	public void setOnBlockingPageChangeListener(OnBlockingPageChangeListener listener) {
		 
		if(listener == null)
			listener = new BaseBlockingPageChangeListener();
		 
		mBlockingPageChangeListener = listener;
		super.setOnPageChangeListener(mBlockingPageChangeListener);
	} 
	 
	/** 
	 * Initialize the view. 
	 */