androidx.viewpager.widget.ViewPager Java Examples
The following examples show how to use
androidx.viewpager.widget.ViewPager.
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: DynamicMotionLayout.java From dynamic-motion with Apache License 2.0 | 7 votes |
/** * Set the page count for the view pager. * * @param pageCount The page count to be set. * @param onPageChangeListener The page change listener to receive page change events. */ public void setPageCount(int pageCount, @Nullable ViewPager.OnPageChangeListener onPageChangeListener) { this.mPageCount = pageCount; if (mViewPager == null) { addView(LayoutInflater.from(getContext()).inflate( R.layout.adm_view_pager, this, false)); mViewPager = findViewById(R.id.adm_view_pager); } mViewPager.setAdapter(new ViewPagerAdapter(pageCount)); mViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { super.onPageScrolled(position, positionOffset, positionOffsetPixels); setProgress((position + positionOffset) / (mPageCount - 1)); } }); if (mViewPager.getAdapter() != null) { mViewPager.getAdapter().notifyDataSetChanged(); } }
Example #2
Source File: GiphyActivity.java From mollyim-android with GNU General Public License v3.0 | 7 votes |
private void initializeResources() { ViewPager viewPager = ViewUtil.findById(this, R.id.giphy_pager); TabLayout tabLayout = ViewUtil.findById(this, R.id.tab_layout); this.gifFragment = new GiphyGifFragment(); this.stickerFragment = new GiphyStickerFragment(); this.forMms = getIntent().getBooleanExtra(EXTRA_IS_MMS, false); gifFragment.setClickListener(this); stickerFragment.setClickListener(this); viewPager.setAdapter(new GiphyFragmentPagerAdapter(this, getSupportFragmentManager(), gifFragment, stickerFragment)); tabLayout.setupWithViewPager(viewPager); tabLayout.setBackgroundColor(getConversationColor()); }
Example #3
Source File: UnderlinePageIndicator.java From arcusandroid with Apache License 2.0 | 6 votes |
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mCurrentPage = position; mPositionOffset = positionOffset; if (mFades) { if (positionOffsetPixels > 0) { removeCallbacks(mFadeRunnable); mPaint.setAlpha(0xFF); } else if (mScrollState != ViewPager.SCROLL_STATE_DRAGGING) { postDelayed(mFadeRunnable, mFadeDelay); } } invalidate(); if (mListener != null) { mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } }
Example #4
Source File: HideActivity.java From PagerBottomTabStrip with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hide); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); PageNavigationView pageBottomTabLayout = findViewById(tab); mNavigationController = pageBottomTabLayout.material() .addItem(R.drawable.ic_restore_teal_24dp, "Recents") .addItem(R.drawable.ic_favorite_teal_24dp, "Favorites") .addItem(R.drawable.ic_nearby_teal_24dp, "Nearby") .build(); ViewPager viewPager = findViewById(R.id.viewPager); viewPager.setAdapter(new TestViewPagerAdapter(getSupportFragmentManager())); mNavigationController.setupWithViewPager(viewPager); }
Example #5
Source File: MainActivity.java From ui with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); //mViewPager.setCurrentItem(7);// set to a specific page in the pager. }
Example #6
Source File: FragmentPageCalcultor.java From sa-sdk-android with Apache License 2.0 | 6 votes |
/** * 收集 frg 页面 */ private void collectFrgs(View childView) { if (childView.getTag(R.id.fragment_root_view) != null) { Object fragment = childView.getTag(R.id.fragment_root_view); if (FrgUtil.isVisible(fragment)) { int position = -1; if (childView.getParent() != null && childView.getParent() instanceof ViewPager) { ViewPager viewPager = (ViewPager) childView.getParent(); position = viewPager.getCurrentItem(); } int hashCode = fragment.hashCode(); // 加上 frg 在 ViewPager 中的位置 hashCode = hashCode + position; // 把当前页面中 frg 的 hashcode 存起来 currentFrgs.append(hashCode, fragment); Log.i("yyyy", " 遍历到了一个 fragment 页面:(" + hashCode + ")" + fragment.getClass().getSimpleName()); } } }
Example #7
Source File: DynamicScrollUtils.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Initialize view pager fields so that we can access them via reflection. */ private static void initializeViewPagerFields() { if (F_VIEW_PAGER_EDGE_GLOW_LEFT != null && F_VIEW_PAGER_EDGE_GLOW_RIGHT != null) { F_VIEW_PAGER_EDGE_GLOW_LEFT.setAccessible(true); F_VIEW_PAGER_EDGE_GLOW_RIGHT.setAccessible(true); return; } Class<?> clazz = ViewPager.class; for (Field field : clazz.getDeclaredFields()) { switch (field.getName()) { case "mLeftEdge": field.setAccessible(true); F_VIEW_PAGER_EDGE_GLOW_LEFT = field; break; case "mRightEdge": field.setAccessible(true); F_VIEW_PAGER_EDGE_GLOW_RIGHT = field; break; } } }
Example #8
Source File: LinkingHelpActivity.java From DeviceConnect-Android with MIT License | 6 votes |
private void set() { Button nextBtn = findViewById(R.id.fragment_linking_help_next); Button preBtn = findViewById(R.id.fragment_linking_help_pre); ViewPager viewPager = findViewById(R.id.viewPager); if (viewPager != null && nextBtn != null && preBtn != null) { int position = viewPager.getCurrentItem(); if (position == 0) { preBtn.setVisibility(View.GONE); } else { preBtn.setVisibility(View.VISIBLE); } if (position == HELP_RES_ID[mScreenId].length - 1) { nextBtn.setVisibility(View.GONE); } else { nextBtn.setVisibility(View.VISIBLE); } } }
Example #9
Source File: ViewPagerNestedActivity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_pager_nested); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
Example #10
Source File: AccountSavedThingActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
private void initializeViewPager() { sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(2); tabLayout.setupWithViewPager(viewPager); viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (isInLazyMode) { if (viewPager.getCurrentItem() == 0) { sectionsPagerAdapter.resumeLazyMode(); } else { sectionsPagerAdapter.pauseLazyMode(); } } if (position == 0) { unlockSwipeRightToGoBack(); } else { lockSwipeRightToGoBack(); } } }); }
Example #11
Source File: MainActivity.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
private void setupTabs() { ViewPager viewPager = findViewById(R.id.pager); TabLayout normalTabs = findViewById(R.id.tabs_normal); normalTabs.setupWithViewPager(viewPager, true); TabLayout compactTabs = findViewById(R.id.tabs_compact); compactTabs.setupWithViewPager(viewPager, true); Toolbar toolbar = findViewById(R.id.toolbar); if (SP.getBoolean("short_tabtitles", false)) { normalTabs.setVisibility(View.GONE); compactTabs.setVisibility(View.VISIBLE); toolbar.setLayoutParams(new LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.compact_height))); } else { normalTabs.setVisibility(View.VISIBLE); compactTabs.setVisibility(View.GONE); TypedValue typedValue = new TypedValue(); if (getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) { toolbar.setLayoutParams(new LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics()))); } } }
Example #12
Source File: StatisticsFragment.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_statistics, container, false); ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (actionBar != null) { //actionBar.setSubtitle(R.string.action_main); actionBar.setDisplayHomeAsUpEnabled(true); } container.removeAllViews(); ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager); setupViewPager(viewPager); TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); setHasOptionsMenu(true); return view; }
Example #13
Source File: VPAppFrgActivity.java From sa-sdk-android with Apache License 2.0 | 6 votes |
private void initViewPager() { listPagerViews = new ArrayList<>(); listPagerViews.add(new Frg_app_1()); listPagerViews.add(new Frg_app_2()); listPagerViews.add(new Frg_app_3()); ViewPager viewPager = findViewById(R.id.vp_app_frg); pagerAdapter = new FragmentPagerAdapter(getFragmentManager()) { @Override public int getCount() { return listPagerViews.size(); } @Override public Fragment getItem(int i) { return listPagerViews.get(i); } }; viewPager.setAdapter(pagerAdapter); }
Example #14
Source File: EndLessActivity.java From android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_end_less); mFragmentList.add(new LinearLayoutFragment()); mFragmentList.add(new LinearLayoutFragment()); tableLayout = (TabLayout) findViewById(R.id.tableLayout); viewPager = (ViewPager) findViewById(R.id.viewPager); mAdapter = new FragmentAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); tableLayout.setupWithViewPager(viewPager); tableLayout.setTabMode(TabLayout.MODE_FIXED); }
Example #15
Source File: MaterialUpConceptActivity.java From CoordinatorExamples with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_material_up_concept); TabLayout tabLayout = (TabLayout) findViewById(R.id.materialup_tabs); ViewPager viewPager = (ViewPager) findViewById(R.id.materialup_viewpager); AppBarLayout appbarLayout = (AppBarLayout) findViewById(R.id.materialup_appbar); mProfileImage = (ImageView) findViewById(R.id.materialup_profile_image); Toolbar toolbar = (Toolbar) findViewById(R.id.materialup_toolbar); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); appbarLayout.addOnOffsetChangedListener(this); mMaxScrollSize = appbarLayout.getTotalScrollRange(); viewPager.setAdapter(new TabsAdapter(getSupportFragmentManager())); tabLayout.setupWithViewPager(viewPager); }
Example #16
Source File: SimpleMainActivity.java From a with GNU General Public License v3.0 | 5 votes |
/** * 控件绑定 */ @Override protected void bindView() { mFragmentList = createTabFragments(); mainFragmentPageAdapter = new MainFragmentPageAdapter(getSupportFragmentManager()); mHomeViewPager.setAdapter(mainFragmentPageAdapter); mHomeViewPager.setOffscreenPageLimit(3); mHomeViewPager.addOnPageChangeListener((ViewPager.OnPageChangeListener)this); mHomeViewPager.setCurrentItem(0, false); sivBookshelf.setChecked(true); }
Example #17
Source File: DemoFragmentActivity.java From ActivityTaskView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo_fragment); setTitle(getClass().getSimpleName()); setActionBarBack(); for(int i = 0; i < 3; i++){ fragmentList.add(DemoFragment.newInstance(i)); } ViewPager vp = (ViewPager) findViewById(R.id.vp); vp.setOffscreenPageLimit(1); vp.setAdapter(new DemoAdapter(getSupportFragmentManager())); }
Example #18
Source File: TabLayout.java From a with GNU General Public License v3.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mViewPager == null) { // If we don't have a ViewPager already, check if our parent is a ViewPager to // setup with it automatically final ViewParent vp = getParent(); if (vp instanceof ViewPager) { // If we have a ViewPager parent and we've been added as part of its decor, let's // assume that we should automatically setup to display any titles setupWithViewPager((ViewPager) vp, true, true); } } }
Example #19
Source File: ChannelActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_streamer_info); // Get the various handles of view and layouts that is part of this view streamerImage = (ImageView) findViewById(R.id.profileImageView); additionalInfoLayout = (LinearLayout) findViewById(R.id.additional_info_wrapper); streamerInfoName = (TextView) findViewById(R.id.twitch_name); streamerViewers = (TextView) findViewById(R.id.txt_viewers); streamerFollowers = (TextView) findViewById(R.id.txt_followers); toolbar = (Toolbar) findViewById(R.id.StreamerInfo_Toolbar); additionalToolbar = (Toolbar) findViewById(R.id.additional_toolbar); mViewPager = (ViewPager) findViewById(R.id.container); mTabs = (TabLayout) findViewById(R.id.tabs); mAppBar = (AppBarLayout) findViewById(R.id.appbar); mFab = (FloatingActionButton) findViewById(R.id.fab); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } // Get the StreamerInfo object sent with the intent to open this activity Intent intent = getIntent(); info = intent.getParcelableExtra(getResources().getString(R.string.channel_info_intent_object)); streamerInfoName .setText(info.getDisplayName()); streamerFollowers .setText(getReadableInt(info.getFollowers())); streamerViewers .setText(getReadableInt(info.getViews())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { streamerImage.setTransitionName(getString(R.string.streamerInfo_transition)); } setUpTabs(); initStreamerImageAndColors(); initiateFAB(); }
Example #20
Source File: MainActivity.java From GooglePlayCloned with Apache License 2.0 | 5 votes |
private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new HomeFragment(), "Home"); adapter.addFragment(new HomeFragment(), "Games"); adapter.addFragment(new HomeFragment(), "Movies"); adapter.addFragment(new HomeFragment(), "Books"); adapter.addFragment(new HomeFragment(), "Music"); viewPager.setAdapter(adapter); }
Example #21
Source File: PageIndicatorView.java From Alarmio with Apache License 2.0 | 5 votes |
/** * You must call this AFTER setting the Adapter for the ViewPager, or it won't display the right amount of points. * * @param viewPager */ public void setViewPager(ViewPager viewPager) { this.viewPager = viewPager; viewPager.addOnPageChangeListener(this); size = viewPager.getAdapter().getCount(); invalidate(); }
Example #22
Source File: MainActivity.java From bubble-icon-tabbar-android with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFragmentList.add(new TabFragment(titles[0], colors[0])); mFragmentList.add(new TabFragment(titles[1], colors[1])); mFragmentList.add(new TabFragment(titles[2], colors[2])); mFragmentList.add(new TabFragment(titles[3], colors[3])); ViewPager viewPager = findViewById(R.id.viewPager); FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return mFragmentList.get(position); } @Override public int getCount() { return mFragmentList.size(); } }; viewPager.setAdapter(adapter); TabLayout tabLayout = findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(viewPager); tabBubbleAnimator = new TabBubbleAnimator(tabLayout); tabBubbleAnimator.addTabItem(titles[0], R.drawable.ic_grid, colors[0]); tabBubbleAnimator.addTabItem(titles[1], R.drawable.ic_clock,colors[1]); tabBubbleAnimator.addTabItem(titles[2], R.drawable.ic_folder, colors[2]); tabBubbleAnimator.addTabItem(titles[3], R.drawable.ic_menu, colors[3]); tabBubbleAnimator.setUnselectedColorId(Color.BLACK); tabBubbleAnimator.highLightTab(0); viewPager.addOnPageChangeListener(tabBubbleAnimator); }
Example #23
Source File: CirclePageIndicator.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 5 votes |
@Override public void setViewPager(ViewPager view) { if (mViewPager == view) { return; } if (mViewPager != null) { mViewPager.removeOnPageChangeListener(this); } if (view.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } mViewPager = view; mViewPager.addOnPageChangeListener(this); invalidate(); }
Example #24
Source File: ViewUserDetailActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
private void initializeViewPager() { sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(2); tabLayout.setupWithViewPager(viewPager); viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (isInLazyMode) { if (viewPager.getCurrentItem() == 0) { sectionsPagerAdapter.resumeLazyMode(); } else { sectionsPagerAdapter.pauseLazyMode(); } } if (position == 0) { unlockSwipeRightToGoBack(); } else { lockSwipeRightToGoBack(); } sectionsPagerAdapter.displaySortTypeInToolbar(); } }); if (mAccessToken != null && mMessageFullname != null) { ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { mMessageFullname = null; } @Override public void readFailed() { } }); } }
Example #25
Source File: CirclePageIndicator.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override public void onPageSelected(int position) { if (mSnap || mScrollState == ViewPager.SCROLL_STATE_IDLE) { mCurrentPage = position; mSnapPage = position; invalidate(); } if (mListener != null) { mListener.onPageSelected(position); } }
Example #26
Source File: MapInPagerDemoActivity.java From android-samples with Apache License 2.0 | 5 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_in_pager_demo); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); // This is required to avoid a black flash when the map is loaded. The flash is due // to the use of a SurfaceView as the underlying view of the map. mPager.requestTransparentRegion(mPager); }
Example #27
Source File: TabStripHelper.java From ProjectX with Apache License 2.0 | 5 votes |
@Override public void onPageSelected(int position) { if (mView instanceof TabStripView) ((TabStripView) mView).onViewPagerItemSelected(position); else if (mView instanceof TabStripViewGroup) ((TabStripViewGroup) mView).onViewPagerItemSelected(position); if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { mPosition = position; updateView(false); } }
Example #28
Source File: PagerSlidingTabStrip.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { scrollToChild(pager.getCurrentItem(), 0); } if (delegatePageListener != null) { delegatePageListener.onPageScrollStateChanged(state); } }
Example #29
Source File: CirclePageIndicator.java From SmartFlasher with GNU General Public License v3.0 | 5 votes |
@Override public void onPageSelected(int position) { if (mSnap || mScrollState == ViewPager.SCROLL_STATE_IDLE) { mCurrentPage = position; mSnapPage = position; invalidate(); } if (mListener != null) { mListener.onPageSelected(position); } }
Example #30
Source File: CourseTabsDashboardFragmentTest.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Testing initialization */ @Test public void initializeTest() { CourseTabsDashboardFragment fragment = CourseTabsDashboardFragment.newInstance(getCourseData(), "testsCourseId", Screen.COURSE_DASHBOARD); SupportFragmentTestUtil.startVisibleFragment(fragment, RoboFragmentActivity.class, android.R.id.content); View view = fragment.getView(); assertNotNull(view); View viewPager = view.findViewById(R.id.viewPager); assertNotNull(viewPager); assertThat(viewPager).isInstanceOf(ViewPager.class); }