Java Code Examples for androidx.viewpager.widget.ViewPager#addOnPageChangeListener()
The following examples show how to use
androidx.viewpager.widget.ViewPager#addOnPageChangeListener() .
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: ViewsActivity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_views); mFragments.add(new CircleMenuFragment()); tabs.add("环形菜单"); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(mViewPager); tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); }
Example 2
Source File: CrashReporterActivity.java From loco-answers with GNU General Public License v3.0 | 6 votes |
private void setupViewPager(ViewPager viewPager) { String[] titles = {getString(R.string.crashes), getString(R.string.exceptions)}; mainPagerAdapter = new MainPagerAdapter(getSupportFragmentManager(), titles); viewPager.setAdapter(mainPagerAdapter); viewPager.addOnPageChangeListener(new SimplePageChangeListener() { @Override public void onPageSelected(int position) { selectedTabPosition = position; } }); Intent intent = getIntent(); if (intent != null && !intent.getBooleanExtra(Constants.LANDING, false)) { selectedTabPosition = 1; } viewPager.setCurrentItem(selectedTabPosition); }
Example 3
Source File: MultiFragmentsActivity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_multi_fragments); 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); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); tabLayout.setupWithViewPager(mViewPager); }
Example 4
Source File: ScreenSlideActivity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen_slide); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When changing pages, reset the action bar actions since they are dependent // on which page is currently active. An alternative approach is to have each // fragment expose actions itself (rather than the activity exposing actions), // but for simplicity, the activity provides the actions in this sample. invalidateOptionsMenu(); } }); }
Example 5
Source File: UserActivity.java From intra42 with Apache License 2.0 | 5 votes |
@Override public void setupViewPager(ViewPager viewPager) { final ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(UserOverviewFragment.newInstance(), getString(R.string.title_tab_user_overview)); adapter.addFragment(UserQuestsFragment.newInstance(), getString(R.string.title_tab_user_quests)); adapter.addFragment(UserProjectsFragment.newInstance(), getString(R.string.title_tab_user_projects)); // adapter.addFragment(UserMarksFragment.newInstance(), getString(R.string.tab_user_marks)); // adapter.addFragment(UserProjectsDoingFragment.newInstance(), getString(R.string.tab_user_projects)); adapter.addFragment(UserExpertisesFragment.newInstance(), getString(R.string.title_tab_user_expertises)); adapter.addFragment(UserAchievementsFragment.newInstance(), getString(R.string.title_tab_user_achievements)); adapter.addFragment(UserSkillsFragment.newInstance(), getString(R.string.title_tab_user_skills)); adapter.addFragment(UserPartnershipsFragment.newInstance(), getString(R.string.title_tab_user_partnerships)); adapter.addFragment(UserPatronagesFragment.newInstance(), getString(R.string.title_tab_user_patronages)); if (AppSettings.Advanced.getAllowAdvancedData(this)) { adapter.addFragment(UserAppsFragment.newInstance(), getString(R.string.title_tab_user_apps)); } viewPager.setAdapter(adapter); ((CustomViewPager) viewPager).disableSwiping(getString(R.string.title_tab_user_projects)); viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { selectedTab = position; app.mFirebaseAnalytics.setCurrentScreen(UserActivity.this, "User Profile -> " + adapter.getItem(position).getClass().getSimpleName(), null /* class override */); } }); app.mFirebaseAnalytics.setCurrentScreen(UserActivity.this, "User Profile -> " + UserOverviewFragment.class.getSimpleName(), null /* class override */); }
Example 6
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 7
Source File: PagerSlidingTabStrip.java From EmojiChat with Apache License 2.0 | 5 votes |
public void setViewPager(ViewPager pager) { this.pager = pager; if (pager.getAdapter() == null) { throw new IllegalStateException( "ViewPager does not have adapter instance."); } pager.addOnPageChangeListener(pageListener); notifyDataSetChanged(); }
Example 8
Source File: SmileyView.java From Ruisi with Apache License 2.0 | 5 votes |
private void init(Context context) { this.context = context; setElevation(DimenUtils.dip2px(context, 4)); size8 = DimenUtils.dip2px(context, 8); setOrientation(VERTICAL); colorTab = ContextCompat.getColor(context, R.color.bg_primary); colorTabSize = ContextCompat.getColor(context, R.color.bg_secondary); viewPager = new ViewPager(context); viewPager.setLayoutParams(new LayoutParams(LMP, LWC, 1)); viewPager.addOnPageChangeListener(this); dotImageResourseId = R.drawable.dot_bg; addView(viewPager); dotContainer = new LinearLayout(context); dotContainer.setOrientation(LinearLayout.HORIZONTAL); dotContainer.setLayoutParams(new LayoutParams(LMP, DimenUtils.dip2px(context, 16))); dotContainer.setGravity(Gravity.CENTER_HORIZONTAL); addView(dotContainer); tabContainer = new LinearLayout(context); tabContainer.setOrientation(LinearLayout.HORIZONTAL); tabContainer.setGravity(Gravity.CENTER_VERTICAL); tabContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.bg_primary)); tabContainer.setLayoutParams(new LayoutParams(LMP, DimenUtils.dip2px(context, 36))); addView(tabContainer); }
Example 9
Source File: InkPageIndicator.java From material-intro with MIT License | 5 votes |
public void setViewPager(ViewPager viewPager) { this.viewPager = viewPager; viewPager.addOnPageChangeListener(this); setPageCount(viewPager.getAdapter().getCount()); viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { setPageCount(InkPageIndicator.this.viewPager.getAdapter().getCount()); invalidate(); } }); }
Example 10
Source File: ViewPagerPageManager.java From Paginize with MIT License | 5 votes |
private void initViewPager(Context context) { mViewPager = new ViewPager(context); mViewPager.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mPagerAdapter = new InnerPagePagerAdapter(); mViewPager.setAdapter(mPagerAdapter); mViewPager.addOnPageChangeListener(new InnerPageChangeListener()); getContainerView().addView(mViewPager); }
Example 11
Source File: DynamicPageIndicator.java From dynamic-support with Apache License 2.0 | 5 votes |
public void setViewPager(ViewPager viewPager) { this.viewPager = viewPager; viewPager.addOnPageChangeListener(this); setPageCount(viewPager.getAdapter().getCount()); viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { setPageCount(DynamicPageIndicator.this.viewPager.getAdapter().getCount()); } }); setCurrentPageImmediate(); }
Example 12
Source File: FeaturePagerActivity.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_featurepager); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Bundle extras = getIntent().getExtras(); featuresList = extras.getParcelableArrayList(FeatureUtilities.KEY_FEATURESLIST); isReadOnly = extras.getBoolean(FeatureUtilities.KEY_READONLY); selectedFeature = featuresList.get(0); PagerAdapter featureAdapter = new FeaturePageAdapter(this, featuresList, isReadOnly, getSupportFragmentManager()); ViewPager featuresPager = findViewById(R.id.featurePager); // ViewPager viewPager = new ViewPager(this); featuresPager.setAdapter(featureAdapter); featuresPager.addOnPageChangeListener(this); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); tableNameView = findViewById(R.id.tableNameView); dbNameView = findViewById(R.id.databaseNameView); featureCounterView = findViewById(R.id.featureCounterView); onPageSelected(0); }
Example 13
Source File: AdvancedContentFragment.java From YcShareElement with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mViewPager = (ViewPager) view; mAdapter = new BasePagerAdapter(); mViewPager.addOnPageChangeListener(this); initCells(); YcShareElement.postStartTransition(getActivity()); }
Example 14
Source File: TabLayoutHelper.java From android-tablayouthelper with Apache License 2.0 | 5 votes |
protected void setupWithViewPager(@NonNull TabLayout tabLayout, @NonNull ViewPager viewPager) { final PagerAdapter adapter = viewPager.getAdapter(); if (adapter == null) { throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set"); } setTabsFromPagerAdapter(tabLayout, adapter, viewPager.getCurrentItem()); viewPager.getAdapter().registerDataSetObserver(mInternalDataSetObserver); viewPager.addOnPageChangeListener(mInternalTabLayoutOnPageChangeListener); viewPager.addOnAdapterChangeListener(mInternalOnAdapterChangeListener); tabLayout.addOnTabSelectedListener(mInternalOnTabSelectedListener); }
Example 15
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 16
Source File: DeviceDetailFragment.java From arcusandroid with Apache License 2.0 | 5 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(inflater, container, savedInstanceState); viewPager = (ViewPager) (view != null ? view.findViewById(R.id.fragment_device_detail_child_view_pager) : null); if (viewPager != null) { viewPager.setOffscreenPageLimit(1); } populate(); viewPager.removeOnPageChangeListener(onPageChangeListener); viewPager.addOnPageChangeListener(onPageChangeListener); return view; }
Example 17
Source File: MainActivity.java From flashy-tabbar-android with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFragmentList.add(new TabFragment(titles[0])); mFragmentList.add(new TabFragment(titles[1])); mFragmentList.add(new TabFragment(titles[2])); mFragmentList.add(new TabFragment(titles[3])); ViewPager viewPager = findViewById(R.id.view_pager); 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); tabFlashyAnimator = new TabFlashyAnimator(tabLayout); tabFlashyAnimator.addTabItem(titles[0], R.drawable.ic_events); tabFlashyAnimator.addTabItem(titles[1], R.drawable.ic_highlights); tabFlashyAnimator.addTabItem(titles[2], R.drawable.ic_search); tabFlashyAnimator.addTabItem(titles[3], R.drawable.ic_settings, R.color.colorAccent, getResources().getDimension(R.dimen.big_text)); tabFlashyAnimator.highLightTab(0); viewPager.addOnPageChangeListener(tabFlashyAnimator); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { tabFlashyAnimator.setBadge(1, 2); } }, 1000); handler.postDelayed(new Runnable() { @Override public void run() { tabFlashyAnimator.setBadge(20, 2); } }, 2000); handler.postDelayed(new Runnable() { @Override public void run() { tabFlashyAnimator.setBadge(200, 2); } }, 3000); }
Example 18
Source File: MainActivity.java From SSLSocks with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. ViewPager mViewPager = findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); mViewPager.addOnPageChangeListener(onPageChangeListener); fabAdd = findViewById(R.id.fab); fabAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, KeyEditActivity.class); startActivityForResult(intent, KEY_EDIT_REQUEST); } }); // attempt extraction in activity, to make service start faster StunnelProcessManager.checkAndExtract(this); StunnelProcessManager.setupConfig(this); // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.notification_channel); String description = getString(R.string.notification_desc); int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance // or other notification behaviors after this NotificationManager notificationManager = getSystemService(NotificationManager.class); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); } } }
Example 19
Source File: AppcompatActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_actionbar); //turn on up button getSupportActionBar().setDisplayHomeAsUpEnabled(true); FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { one = (PageFragment) fragmentManager.getFragment(savedInstanceState, "ONE"); two = (PageFragment) fragmentManager.getFragment(savedInstanceState, "TWO"); three = (PageFragment) fragmentManager.getFragment(savedInstanceState, "THREE"); four = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FOUR"); five = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FIVE"); //since survived, need to clean up or I can't add them to the pagers adapter again. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(one); remove.remove(two); remove.remove(three); remove.remove(four); remove.remove(five); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { one = PageFragment.create(1); two = PageFragment.create(2); three = PageFragment.create(3); four = PageFragment.create(4); five = PageFragment.create(5); } viewPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new myFragmentPagerAdapter(5); viewPager.setAdapter(mPagerAdapter); //viewPager.setCurrentItem(2); //we need to know when a page has changed, so we can change/fix the next/previous/finish buttons viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { supportInvalidateOptionsMenu(); } }); }
Example 20
Source File: EmojiView.java From Emoji with Apache License 2.0 | 4 votes |
@SuppressWarnings("PMD.CyclomaticComplexity") public EmojiView(final Context context, final OnEmojiClickListener onEmojiClickListener, final OnEmojiLongClickListener onEmojiLongClickListener, @NonNull final EmojiPopup.Builder builder) { super(context); View.inflate(context, R.layout.emoji_view, this); setOrientation(VERTICAL); setBackgroundColor(builder.backgroundColor != 0 ? builder.backgroundColor : Utils.resolveColor(context, R.attr.emojiBackground, R.color.emoji_background)); themeIconColor = builder.iconColor != 0 ? builder.iconColor : Utils.resolveColor(context, R.attr.emojiIcons, R.color.emoji_icons); final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorAccent, value, true); themeAccentColor = builder.selectedIconColor != 0 ? builder.selectedIconColor : value.data; final ViewPager emojisPager = findViewById(R.id.emojiViewPager); final View emojiDivider = findViewById(R.id.emojiViewDivider); emojiDivider.setBackgroundColor(builder.dividerColor != 0 ? builder.dividerColor : Utils.resolveColor(context, R.attr.emojiDivider, R.color.emoji_divider)); if (builder.pageTransformer != null) { emojisPager.setPageTransformer(true, builder.pageTransformer); } final LinearLayout emojisTab = findViewById(R.id.emojiViewTab); emojisPager.addOnPageChangeListener(this); final EmojiCategory[] categories = EmojiManager.getInstance().getCategories(); emojiTabs = new ImageButton[categories.length + 2]; emojiTabs[0] = inflateButton(context, R.drawable.emoji_recent, R.string.emoji_category_recent, emojisTab); for (int i = 0; i < categories.length; i++) { emojiTabs[i + 1] = inflateButton(context, categories[i].getIcon(), categories[i].getCategoryName(), emojisTab); } emojiTabs[emojiTabs.length - 1] = inflateButton(context, R.drawable.emoji_backspace, R.string.emoji_backspace, emojisTab); handleOnClicks(emojisPager); emojiPagerAdapter = new EmojiPagerAdapter(onEmojiClickListener, onEmojiLongClickListener, builder.recentEmoji, builder.variantEmoji); emojisPager.setAdapter(emojiPagerAdapter); final int startIndex = emojiPagerAdapter.numberOfRecentEmojis() > 0 ? 0 : 1; emojisPager.setCurrentItem(startIndex); onPageSelected(startIndex); }