Code example for List

Methods: getindexOfsize

0
	 *  
	 * @param whichActivity 
	 *            the index of Activity 
	 */ 
	private void launchActivity(int whichActivity) {
		launchActivity(mActivities.get(whichActivity));
		maybeShowToast(whichActivity);
		maybeShowAnimation(whichActivity);
	} 
 
	/** 
	 * Add Activity NOTE: 添加的顺序很重要 
	 *  
	 * @param cls 
	 *            class of activity 
	 */ 
	public void addActivity(Class<?> cls) {
		mActivities.add(cls);
	} 
 
	/** 
	 * Get index of the Activity 
	 *  
	 * @param cls 
	 *            class of activity 
	 * @return 
	 */ 
	private int getIndexOf(Class<?> cls) {
		int index = mActivities.indexOf(cls);
		if (-1 == index) {
			Log.e(TAG, "No such activity: " + cls.getName());
		} 
		return index;
	} 
 
	@SuppressWarnings("unused") 
	private Class<?> getActivityAt(int index) {
		if (index > 0 && index < mActivities.size()) {
			return mActivities.get(index);
		} 
		return null; 
	} 
 
	/** 
	 * Show next activity(already setCurrentActivity) 
	 */ 
	@Override 
	public void showNext() { 
		mDirection = SHOW_NEXT;
		setDisplayedActivity(mWhichActivity + 1, true);
	} 
 
	/** 
	 * Show next activity of 
	 *  
	 * @param cls 
	 *            class of activity 
	 */ 
	public void showNextOf(Class<?> cls) {
		setCurrentActivity(cls);
		showNext(); 
	} 
 
	/** 
	 * Show next activity(use current context as a activity) 
	 */ 
	public void autoShowNext() { 
		showNextOf(mActivity.getClass());
	} 
 
	/** 
	 * Show previous activity(already setCurrentActivity) 
	 */ 
	@Override 
	public void showPrevious() { 
		mDirection = SHOW_PROVIOUS;
		setDisplayedActivity(mWhichActivity - 1, true);
	} 
 
	/** 
	 * Show previous activity of 
	 *  
	 * @param cls 
	 *            class of activity 
	 */ 
	public void showPreviousOf(Class<?> cls) {
		setCurrentActivity(cls);
		showPrevious(); 
	} 
 
	/** 
	 * Show previous activity(use current context as a activity) 
	 */ 
	public void autoShowPrevious() { 
		showPreviousOf(mActivity.getClass());
	} 
 
	/** 
	 * Sets which child view will be displayed 
	 *  
	 * @param whichActivity 
	 *            the index of the child view to display 
	 * @param display 
	 *            display immediately 
	 */ 
	public void setDisplayedActivity(int whichActivity, boolean display) {
		mWhichActivity = whichActivity;
		if (whichActivity >= getCount()) {
			mWhichActivity = 0;
		} else if (whichActivity < 0) {
			mWhichActivity = getCount() - 1;
		} 
 
		if (display) {
			launchActivity(mWhichActivity);
		} 
	} 
 
	/** 
	 * Set current Activity 
	 *  
	 * @param cls 
	 *            class of activity 
	 */ 
	public void setCurrentActivity(Class<?> cls) {
		setDisplayedActivity(getIndexOf(cls), false);
	} 
 
	public void setInAnimation(int resourceId) {
		setEnableAnimation(true); 
		mNextInAnimation = resourceId;
	} 
 
	public void setOutAnimation(int resourceId) {
		setEnableAnimation(true); 
		mNextOutAnimation = resourceId;
	} 
 
	public void setPreviousInAnimation(int resourceId) {
		mPreviousInAnimation = resourceId;
	} 
 
	public void setPreviousOutAnimation(int resourceId) {
		mPreviousOutAnimation = resourceId;
	} 
 
	public void setEnableAnimation(boolean enable) {
		mAnimationEnabled = enable;
	} 
 
	/** 
	 * Count activities 
	 *  
	 * @return the number of activities 
	 */ 
	public int getCount() { 
		return mActivities.size();
	} 
} 
Experience pair programming with AI  Get Codota for Java