List of usage examples for android.support.v4.view ViewPager SCROLL_STATE_IDLE
int SCROLL_STATE_IDLE
To view the source code for android.support.v4.view ViewPager SCROLL_STATE_IDLE.
Click Source Link
From source file:com.granita.tasks.TaskListActivity.java
@SuppressLint("NewApi") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/* w ww.ja va 2 s.c o m*/ protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate called again"); super.onCreate(savedInstanceState); // check for single pane activity change mTwoPane = getResources().getBoolean(R.bool.has_two_panes); resolveIntentAction(getIntent()); //custom start Tracker t = ((com.granita.tasks.Tasks) getApplication()) .getTracker(com.granita.tasks.Tasks.TrackerName.APP_TRACKER); t.setScreenName("Tasks: List activity"); t.send(new HitBuilders.AppViewBuilder().build()); //check if sync for icloud calendar exists String packageName = "com.granita.caldavsync"; Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName); if (intent == null) { /* bring user to the market or let them choose an app? */ intent = new Intent(this, installicloud.class); startActivity(intent); } try { //Start premium features String base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvczcgR9FJqJ/LK94t4VcmdfVizoy66QWJRxF+o0ZZbFeMi1jQ6kBcYb1kogQnLLBeS+Q0DtRjsxap9Z6B8yP5rcZxIs51yF2LKy9+nmcLeJF0wPU2cvIjZLf7dD7Umh/LMi88VHSLExwkDMb2vBpcROz7DwjhgF5fzXHWh986ZxWmJiMiYLX1cg5toWaOPYgxcSELyCsfkvfmtX8ctJ+QcovWXevSBJsOQCLNkmKdBd5biExy96WicjVUZ/e31/CCjb8xYcMJnMaBGXEBDdtJFMFAczpdrB+Zyw6gEr1ZUH1U7trsbTrC2TvOa1MTcwXHE2JwqjU2eke4FLYIcAdbwIDAQAB"; mHelper = new IabHelper(this, base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { Log.d(TAG, "In-app Billing setup failed: " + result); } else { mHelper.queryInventoryAsync(mGotInventoryListener); Log.d(TAG, "In-app Billing is set up OK"); } } }); //End premium features } catch (Exception e) { } //custom end if (mSelectedTaskUri != null) { if (mShouldShowDetails && mShouldSwitchToDetail) { Intent viewTaskIntent = new Intent(Intent.ACTION_VIEW); viewTaskIntent.setData(mSelectedTaskUri); startActivity(viewTaskIntent); mSwitchedToDetail = true; mShouldSwitchToDetail = false; mTransientState = true; } } else { mShouldShowDetails = false; } setContentView(R.layout.activity_task_list); //custom start mAuthority = getString(R.string.org_dmfs_tasks_authority); //custom end mSearchHistoryHelper = new SearchHistoryHelper(this); if (findViewById(R.id.task_detail_container) != null) { // In two-pane mode, list items should be given the // 'activated' state when touched. // get list fragment // mTaskListFrag = (TaskListFragment) getSupportFragmentManager().findFragmentById(R.id.task_list); // mTaskListFrag.setListViewScrollbarPositionLeft(true); // mTaskListFrag.setActivateOnItemClick(true); /* * Create a detail fragment, but don't load any URL yet, we do that later when the fragment gets attached */ mTaskDetailFrag = ViewTaskFragment.newInstance(mSelectedTaskUri); getSupportFragmentManager().beginTransaction() .replace(R.id.task_detail_container, mTaskDetailFrag, DETAIL_FRAGMENT_TAG).commit(); } else { FragmentManager fragmentManager = getSupportFragmentManager(); Fragment detailFragment = fragmentManager.findFragmentByTag(DETAIL_FRAGMENT_TAG); if (detailFragment != null) { fragmentManager.beginTransaction().remove(detailFragment).commit(); } } mGroupingFactories = new AbstractGroupingFactory[] { new ByList(mAuthority), new ByDueDate(mAuthority), new ByStartDate(mAuthority), new ByPriority(mAuthority), new ByProgress(mAuthority), new BySearch(mAuthority, mSearchHistoryHelper) }; // set up pager adapter try { mPagerAdapter = new TaskGroupPagerAdapter(getSupportFragmentManager(), mGroupingFactories, this, R.xml.listview_tabs); } catch (XmlPullParserException e) { // TODO Automatisch generierter Erfassungsblock e.printStackTrace(); } catch (IOException e) { // TODO Automatisch generierter Erfassungsblock e.printStackTrace(); } catch (XmlObjectPullParserException e) { // TODO Automatisch generierter Erfassungsblock e.printStackTrace(); } // Setup ViewPager mPagerAdapter.setTwoPaneLayout(mTwoPane); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); int currentPageIndex = mPagerAdapter.getPagePosition(mCurrentPageId); if (currentPageIndex >= 0) { mCurrentPagePosition = currentPageIndex; mViewPager.setCurrentItem(currentPageIndex); if (VERSION.SDK_INT >= 14 && mCurrentPageId == R.id.task_group_search) { if (mSearchItem != null) { // that's actually quite impossible to happen MenuItemCompat.expandActionView(mSearchItem); } else { mAutoExpandSearchView = true; } } } updateTitle(currentPageIndex); // Bind the tabs to the ViewPager mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); mTabs.setViewPager(mViewPager); mTabs.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int position) { mSelectedTaskUri = null; mCurrentPagePosition = position; int newPageId = mPagerAdapter.getPageId(position); if (newPageId == R.id.task_group_search) { int oldPageId = mCurrentPageId; mCurrentPageId = newPageId; // store the page position we're coming from mPreviousPagePosition = mPagerAdapter.getPagePosition(oldPageId); } else if (mCurrentPageId == R.id.task_group_search) { // we've been on the search page before, so commit the search and close the search view mSearchHistoryHelper.commitSearch(); mHandler.post(mSearchUpdater); mCurrentPageId = newPageId; hideSearchActionView(); } mCurrentPageId = newPageId; updateTitle(mCurrentPageId); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE && mCurrentPageId == R.id.task_group_search) { // the search page is selected now, expand the search view mHandler.post(new Runnable() { @Override public void run() { MenuItemCompat.expandActionView(mSearchItem); } }); } } }); // make sure the status bar color is set properly on Android 5+ devices if (VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDarker)); } }
From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java
@Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE) this.mCurrentPage = mPager.getCurrentItem(); }
From source file:cpi.suhaib.extendedcirclepagerindicator.CirclePageIndicator.java
@Override public void onPageSelected(int position) { if (mSnap || mScrollState == ViewPager.SCROLL_STATE_IDLE) { mCurrentPage = position;/* ww w. j av a 2s . co m*/ invalidate(); } if (mIsMaxIndicatorsEnabled && position > mLastPage && position - mOffset > mMaxIndicators - 1) { mOffset++; } else if (mIsMaxIndicatorsEnabled && position < mLastPage && position - mOffset < 0) { mOffset--; } if (mListener != null) { mListener.onPageSelected(position); } mLastPage = position; }
From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java
@Override public void onPageSelected(int position) { if (mSnap || mScrollState == ViewPager.SCROLL_STATE_IDLE) { mCurrentPage = position;/*from w ww. j a v a 2s. c om*/ mSnapPage = position; invalidate(); } if (pageChangeListener != null) { pageChangeListener.onPageSelected(position); } }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;// www. ja v a2s. co m if (!mIsViewPagerMode) break; // Detect if we touch down on tab, later to move mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If tab touched, so move if (mIsTabActionDown) { mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set tab index relative to current coordinate if (mIsActionDown) setTabIndex((int) (event.getX() / mTabSize)); case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsTabActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java
private boolean onFixedTouchEvent(MotionEvent event) { if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: return true; case MotionEvent.ACTION_UP: if (bounds != null && !bounds.isEmpty()) { RectF curPageBound = bounds.get(mCurrentPage); if (curPageBound != null) { float left = event.getX(); final int width = getWidth(); final int count = mViewPager.getAdapter().getCount(); final float UnitWidth = width / (count > 3 ? 4f : count); final int clickMultiple = (int) (left / UnitWidth); final int curMultiple = (int) (curPageBound.left / UnitWidth); final int postion = mCurrentPage - curMultiple + clickMultiple; if (postion >= 0 && postion != mCurrentPage && postion < count) mViewPager.setCurrentItem(postion); return true; }/*from w ww. ja v a 2s . com*/ } } } return super.onTouchEvent(event); }
From source file:com.home.library.vpi.TitlePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* ww w . java2s .c om*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // mCurrentPage is -1 on first start and after orientation changed. If so, retrieve the correct index from viewpager. if (mCurrentPage == -1 && mViewPager != null) { mCurrentPage = mViewPager.getCurrentItem(); } //Calculate views bounds ArrayList<Rect> bounds = calculateAllBounds(mPaintText); final int boundsSize = bounds.size(); //Make sure we're on a page that still exists if (mCurrentPage >= boundsSize) { setCurrentItem(boundsSize - 1); return; } setBackGroundColor(canvas); final int countMinusOne = count - 1; final float halfWidth = getWidth() / 2f; final int left = getLeft(); final float leftClip = left + mClipPadding; final int width = getWidth(); int height = getHeight(); final int right = left + width; final float rightClip = right - mClipPadding; int page = mCurrentPage; float offsetPercent; if (mPageOffset <= 0.5) { offsetPercent = mPageOffset; } else { page += 1; offsetPercent = 1 - mPageOffset; } final boolean currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE); final boolean currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE); final float selectedPercent = (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE; //Verify if the current view must be clipped to the screen Rect curPageBound = bounds.get(mCurrentPage); float curPageWidth = curPageBound.right - curPageBound.left; if (curPageBound.left < leftClip) { //Try to clip to the screen (left side) clipViewOnTheLeft(curPageBound, curPageWidth, left); } if (curPageBound.right > rightClip) { //Try to clip to the screen (right side) clipViewOnTheRight(curPageBound, curPageWidth, right); } //Left views starting from the current position if (mCurrentPage > 0) { for (int i = mCurrentPage - 1; i >= 0; i--) { Rect bound = bounds.get(i); //Is left side is outside the screen if (bound.left < leftClip) { int w = bound.right - bound.left; //Try to clip to the screen (left side) clipViewOnTheLeft(bound, w, left); //Except if there's an intersection with the right view Rect rightBound = bounds.get(i + 1); //Intersection if (bound.right + mTitlePadding > rightBound.left) { bound.left = (int) (rightBound.left - w - mTitlePadding); bound.right = bound.left + w; } } } } //Right views starting from the current position if (mCurrentPage < countMinusOne) { for (int i = mCurrentPage + 1; i < count; i++) { Rect bound = bounds.get(i); //If right side is outside the screen if (bound.right > rightClip) { int w = bound.right - bound.left; //Try to clip to the screen (right side) clipViewOnTheRight(bound, w, right); //Except if there's an intersection with the left view Rect leftBound = bounds.get(i - 1); //Intersection if (bound.left - mTitlePadding < leftBound.right) { bound.left = (int) (leftBound.right + mTitlePadding); bound.right = bound.left + w; } } } } //Now draw views int colorTextAlpha = mColorText >>> 24; for (int i = 0; i < count; i++) { //Get the title Rect bound = bounds.get(i); //Only if one side is visible if ((bound.left > left && bound.left < right) || (bound.right > left && bound.right < right)) { final boolean currentPage = (i == page); final CharSequence pageTitle = getTitle(i); //Only set bold if we are within bounds mPaintText.setFakeBoldText(currentPage && currentBold && mBoldText); //Draw text as unselected if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mPaintText.setColor(mColorText); } if (currentPage && currentSelected && mScrollState != ViewPager.SCROLL_STATE_IDLE) { //Fade out/in unselected text as the selected text fades in/out mPaintText.setAlpha(colorTextAlpha - (int) (colorTextAlpha * selectedPercent)); } //Except if there's an intersection with the right view if (i < boundsSize - 1) { Rect rightBound = bounds.get(i + 1); //Intersection if (bound.right + mTitlePadding > rightBound.left) { int w = bound.right - bound.left; bound.left = (int) (rightBound.left - w - mTitlePadding); bound.right = bound.left + w; } } canvas.drawText(pageTitle, 0, pageTitle.length(), bound.left, bound.bottom + mTopPadding, mPaintText); //If we are within the selected bounds draw the selected text if (currentPage && currentSelected) { //mScrollState != ViewPager.SCROLL_STATE_IDLE if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mPaintText.setColor(mColorSelected); mPaintText.setAlpha((int) ((mColorSelected >>> 24) * selectedPercent)); } canvas.drawText(pageTitle, 0, pageTitle.length(), bound.left, bound.bottom + mTopPadding, mPaintText); } } } //If we want the line on the top change height to zero and invert the line height to trick the drawing code float footerLineHeight = mFooterLineHeight; float footerIndicatorLineHeight = mFooterIndicatorHeight; if (mLinePosition == LinePosition.Top) { height = 0; footerLineHeight = -footerLineHeight; footerIndicatorLineHeight = -footerIndicatorLineHeight; } //Draw the footer line mPath.reset(); mPath.moveTo(0, height - footerLineHeight / 2f); mPath.lineTo(width, height - footerLineHeight / 2f); mPath.close(); if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mPaintFooterLine.setColor(mFooterColor); } canvas.drawPath(mPath, mPaintFooterLine); float heightMinusLine = height - footerLineHeight; switch (mFooterIndicatorStyle) { case Triangle: mPath.reset(); mPath.moveTo(halfWidth, heightMinusLine - footerIndicatorLineHeight); mPath.lineTo(halfWidth + footerIndicatorLineHeight, heightMinusLine); mPath.lineTo(halfWidth - footerIndicatorLineHeight, heightMinusLine); mPath.close(); canvas.drawPath(mPath, mPaintFooterIndicator); break; case Underline: if (!currentSelected || page >= boundsSize) { break; } Rect underlineBounds = bounds.get(page); final float rightPlusPadding = underlineBounds.right + mFooterIndicatorUnderlinePadding; final float leftMinusPadding = underlineBounds.left - mFooterIndicatorUnderlinePadding; final float heightMinusLineMinusIndicator = heightMinusLine - footerIndicatorLineHeight; mPath.reset(); mPath.moveTo(leftMinusPadding, heightMinusLine); mPath.lineTo(rightPlusPadding, heightMinusLine); mPath.lineTo(rightPlusPadding, heightMinusLineMinusIndicator); mPath.lineTo(leftMinusPadding, heightMinusLineMinusIndicator); mPath.close(); if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mPaintFooterIndicator.setAlpha((int) (0xFF * selectedPercent)); } canvas.drawPath(mPath, mPaintFooterIndicator); if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mPaintFooterIndicator.setAlpha(0xFF); } break; } }
From source file:com.gigamole.library.NavigationTabBar.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;// w w w. jav a 2 s . c o m if (!mIsViewPagerMode) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; else mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); else mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { if (mIsHorizontalOrientation) setModelIndex((int) (event.getX() / mModelSize)); else setModelIndex((int) (event.getY() / mModelSize)); } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:talex.zsw.baselibrary.widget.NavigationTabBar.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;/*www . ja v a2s . c o m*/ if (!mIsViewPagerMode) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) { mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; } else { mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; } break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) { mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); } else { mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); } break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { if (mIsHorizontalOrientation) { setModelIndex((int) (event.getX() / mModelSize)); } else { setModelIndex((int) (event.getY() / mModelSize)); } } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
@Override public void onPageSelected(final int position) { // If VP idle, so update if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { mIsResizeIn = position < mIndex; mLastIndex = mIndex;/*from w w w .j a v a 2s.c om*/ mIndex = position; postInvalidate(); } }