Java Code Examples for android.support.v4.view.ViewPager#getCurrentItem()
The following examples show how to use
android.support.v4.view.ViewPager#getCurrentItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackHandlerHelper.java From FragmentBackHandler with Apache License 2.0 | 6 votes |
/** * 将back事件分发给ViewPager中的Fragment,{@link #handleBackPress(FragmentManager)} 已经实现了对ViewPager的支持,所以自行决定是否使用该方法 * * @return 如果处理了back键则返回 <b>true</b> * @see #handleBackPress(FragmentManager) * @see #handleBackPress(Fragment) * @see #handleBackPress(FragmentActivity) */ public static boolean handleBackPress(ViewPager viewPager) { if (viewPager == null) return false; PagerAdapter adapter = viewPager.getAdapter(); if (adapter == null) return false; int currentItem = viewPager.getCurrentItem(); Fragment fragment; if (adapter instanceof FragmentPagerAdapter) { fragment = ((FragmentPagerAdapter) adapter).getItem(currentItem); } else if (adapter instanceof FragmentStatePagerAdapter) { fragment = ((FragmentStatePagerAdapter) adapter).getItem(currentItem); } else { fragment = null; } return isFragmentBackHandled(fragment); }
Example 2
Source File: AppIntroBase.java From GithubApp with Apache License 2.0 | 6 votes |
@Override public boolean onKeyDown(int code, KeyEvent event) { if (code == KeyEvent.KEYCODE_ENTER || code == KeyEvent.KEYCODE_BUTTON_A || code == KeyEvent.KEYCODE_DPAD_CENTER) { ViewPager vp = (ViewPager) this.findViewById(R.id.view_pager); if (vp.getCurrentItem() == vp.getAdapter().getCount() - 1) { onDonePressed(fragments.get(vp.getCurrentItem())); } else { vp.setCurrentItem(vp.getCurrentItem() + 1); } return false; } return super.onKeyDown(code, event); }
Example 3
Source File: ScenePageAdapter.java From scene with Apache License 2.0 | 6 votes |
private void configSceneUserVisibleHint(ViewPager viewPager, UserVisibleHintGroupScene scene, int position) { if (mCurrentScene == null) { int currentItem = viewPager.getCurrentItem(); if (currentItem == position) { mCurrentScene = scene; } } boolean visible = scene == mCurrentScene; if (visible) { if (scene.getUserVisibleHint()) { //to ensure that the behavior will be consistent with FragmentPagerAdapter scene.setUserVisibleHint(false); } scene.setUserVisibleHint(true); } else { if (scene.getUserVisibleHint()) { scene.setUserVisibleHint(false); } } }
Example 4
Source File: CardEditActivity.java From CreditCardView with Apache License 2.0 | 6 votes |
public void showNext() { final ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager); CardFragmentAdapter adapter = (CardFragmentAdapter) pager.getAdapter(); int max = adapter.getCount(); int currentIndex = pager.getCurrentItem(); if (currentIndex + 1 < max) { pager.setCurrentItem(currentIndex + 1); } else { // completed the card entry. setKeyboardVisibility(false); } refreshNextButton(); }
Example 5
Source File: BallTabLayout.java From nono-android with GNU General Public License v3.0 | 6 votes |
public void setupWithViewPager(@NonNull ViewPager viewPager){ final PagerAdapter adapter = viewPager.getAdapter(); mViewPagerAdapterWrapper = new WeakReference<PagerAdapter>(adapter); if (adapter == null) { throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set"); } // First we'll add Tabs, using the adapter's page titles setTabsFromPagerAdapter(adapter); // Now we'll add our page change listener to the ViewPager viewPager.addOnPageChangeListener(new BallTabLayoutOnPageChangeListener(this)); // Now we'll add a tab selected listener to set ViewPager's current item setOnTabSelectedListener(new ViewPagerOnBallTabSelectedListener(viewPager)); // Make sure we reflect the currently set ViewPager item if (adapter.getCount() > 0) { final int curItem = viewPager.getCurrentItem(); if (getSelectedTabPosition() != curItem) { selectTab(getTabAt(curItem)); } } }
Example 6
Source File: CardEditActivity.java From CreditCardView with Apache License 2.0 | 5 votes |
public void showPrevious() { final ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager); int currentIndex = pager.getCurrentItem(); if (currentIndex == 0) { setResult(RESULT_CANCELED); finish(); } if (currentIndex - 1 >= 0) { pager.setCurrentItem(currentIndex - 1); } refreshNextButton(); }
Example 7
Source File: SlideLayout.java From SlideActivity with MIT License | 5 votes |
private boolean canViewPagerScroll(ViewPager p, int dx) { if (dx == 0) return false; final int index = p.getCurrentItem(); return !(dx > 0 && index <= 0 || dx < 0 && index >= p.getAdapter().getCount() - 1); }
Example 8
Source File: EasySlidingTabs.java From EasySlidingTabs with Apache License 2.0 | 5 votes |
/** * Set the view pager * * @param pager pager */ public void setViewPager(ViewPager pager) { // TODO tmp strategy if (pager == null || pager.getAdapter() == null) { return; } this.pager = pager; this.selectedPosition = pager.getCurrentItem(); if (pager.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } pager.addOnPageChangeListener(pageListener); this.notifyDataSetChanged(); this.setTabsValue(); }
Example 9
Source File: y.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public boolean canScrollHorizontal(View view, int i) { ViewPager viewpager = (ViewPager)view; PagerAdapter pageradapter = viewpager.getAdapter(); if (pageradapter != null && pageradapter.getCount() != 0) { int j = viewpager.getCurrentItem(); if (i < 0 && j < -1 + pageradapter.getCount() || i > 0 && j > 0) { return true; } } return false; }
Example 10
Source File: Intro.java From CumulusTV with MIT License | 5 votes |
@Override public boolean onKeyDown(int code, KeyEvent kvent) { if(code == KeyEvent.KEYCODE_DPAD_CENTER) { ViewPager vp = (ViewPager)this.findViewById(com.github.paolorotolo.appintro.R.id.view_pager); if(vp.getCurrentItem() == vp.getAdapter().getCount()-1) { onDonePressed(); } else { vp.setCurrentItem(vp.getCurrentItem()+1); } return false; } return super.onKeyDown(code, kvent); }
Example 11
Source File: PullToRefreshViewPager.java From ONE-Unofficial with Apache License 2.0 | 5 votes |
@Override protected boolean isReadyForPullEnd() { ViewPager refreshableView = getRefreshableView(); PagerAdapter adapter = refreshableView.getAdapter(); if (null != adapter) { return refreshableView.getCurrentItem() == adapter.getCount() - 1; } return false; }
Example 12
Source File: PagerIndicator.java From oneHookLibraryAndroid with Apache License 2.0 | 5 votes |
public void setViewPager(final ViewPager viewPager) { if (viewPager != null) { viewPager.addOnPageChangeListener(this); if (viewPager.getAdapter() == null) { throw new RuntimeException("Set View pager's adapter before you call setViewPager"); } final PagerAdapter adapter = viewPager.getAdapter(); if (adapter instanceof InfinitePagerAdapter<?>) { mRealItemCount = ((InfinitePagerAdapter<?>) adapter).getWrappedPagerAdapter().getCount(); } else { mRealItemCount = adapter.getCount(); } final int itemCount = mRealItemCount; mDotDrawables = new DotDrawable[itemCount]; mDots = new View[itemCount]; for (int i = 0; i < itemCount; i++) { final View view = new View(getContext()); mDotDrawables[i] = new DotDrawable(i == viewPager.getCurrentItem() ? mSelectedDotColor : mDefaultDotColor); mDots[i] = view; if (Build.VERSION.SDK_INT <= 15) { view.setBackgroundDrawable(mDotDrawables[i]); } else { view.setBackground(mDotDrawables[i]); } view.setLayoutParams(obtainLayoutParams()); addView(view); } } }
Example 13
Source File: PlayViewHandler.java From MousePaint with MIT License | 5 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case 0x123: final int count = msg.arg1; playingDirection = msg.arg2; final ViewPager viewPager = (ViewPager) msg.obj; int i = viewPager.getCurrentItem(); if (playingDirection == 0) { if (i == count - 1) { playingDirection = -1; i--; } else { i++; } } else { if (i == count-1) { playingDirection = 1; i=0; } else { i++; } } viewPager.setCurrentItem(i, false); if (play) { postDelayed(new Runnable() { @Override public void run() { slidingPlayView(viewPager, count, playingDirection); } }, DEFAULT_TIME); } break; } super.handleMessage(msg); }
Example 14
Source File: BubbleTab.java From BubbleTab with Apache License 2.0 | 5 votes |
public void setupWithViewPager(final ViewPager viewPager) { this.viewPager = viewPager; viewPager.addOnPageChangeListener(pageChangeListener); final int currentItem = viewPager.getCurrentItem(); for (int i = 0; i < icons.size(); i++) { icons.get(i).setSelected(i == currentItem); } circle.setTranslationX(tabWidth * currentItem); postInvalidate(); }
Example 15
Source File: PullToRefreshViewPager.java From AndroidBase with Apache License 2.0 | 5 votes |
@Override protected boolean isReadyForPullStart() { ViewPager refreshableView = getRefreshableView(); PagerAdapter adapter = refreshableView.getAdapter(); if (null != adapter) { return refreshableView.getCurrentItem() == 0; } return false; }
Example 16
Source File: MainActivity.java From tapchat-android with Apache License 2.0 | 5 votes |
private int getCurrentIndex() { ViewPager view = (ViewPager) findViewById(R.id.pager); if (view != null) { return view.getCurrentItem(); } else { return -1; } }
Example 17
Source File: BezierBannerView.java From ZoomPreviewPicture with Apache License 2.0 | 5 votes |
/** * 绑定viewpager * @param viewPager viewPager */ public void attachToViewpager(ViewPager viewPager) { viewPager.addOnPageChangeListener(this); count = viewPager.getAdapter().getCount(); mSelectedIndex=viewPager.getCurrentItem(); moveToNext(); mDrection=DIRECTION_RIGHT; invalidate(); }
Example 18
Source File: ImageMediaCenterUtil.java From ImageLoader with Apache License 2.0 | 5 votes |
private static void showFileInfo(ViewPager viewPager, List<String> urls, final Context context) { int position = viewPager.getCurrentItem(); String url = urls.get(position); ImageLoader.getActualLoader().getFileFromDiskCache(url, new FileGetter() { @Override public void onSuccess(File file, int width, int height) { String text = file.getAbsolutePath(); text += "\n" + MyUtil.formatFileSize(file.length()); text += "\nw"+ width+"x"+height +"\n"; text += MyUtil.printExif(file.getAbsolutePath()); View view = View.inflate(context,R.layout.html,null); TextView textView = view.findViewById(R.id.tv_html); textView.setText(text); new AlertDialog.Builder(context) .setView(view) .create().show(); } @Override public void onFail(Throwable e) { e.printStackTrace(); } }); }
Example 19
Source File: SlidingLayout.java From UltimateAndroid with Apache License 2.0 | 4 votes |
boolean canViewPagerScrollHorizontally(ViewPager p, int dx) { return !(dx < 0 && p.getCurrentItem() <= 0 || 0 < dx && p.getAdapter().getCount() - 1 <= p.getCurrentItem()); }
Example 20
Source File: CardEditActivity.java From CreditCardView with Apache License 2.0 | 3 votes |
public void refreshNextButton() { ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager); int max = pager.getAdapter().getCount(); int text = R.string.next; if (pager.getCurrentItem() == max - 1) { text = R.string.done; } ((TextView) findViewById(R.id.next)).setText(text); }