Search in sources :

Example 1 with OnTabSelectedListener

use of com.google.android.material.tabs.TabLayout.OnTabSelectedListener in project ods-android by Orange-OpenSource.

the class TabsControllableDemoFragment method setAllTabLayoutBadges.

private void setAllTabLayoutBadges() {
    for (TabLayout tabLayout : tabLayouts) {
        setupBadging(tabLayout);
        tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {

            @Override
            public void onTabSelected(Tab tab) {
                tab.removeBadge();
            }

            @Override
            public void onTabUnselected(Tab tab) {
            }

            @Override
            public void onTabReselected(Tab tab) {
                tab.removeBadge();
            }
        });
    }
}
Also used : Tab(com.google.android.material.tabs.TabLayout.Tab) TabLayout(com.google.android.material.tabs.TabLayout) OnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)

Example 2 with OnTabSelectedListener

use of com.google.android.material.tabs.TabLayout.OnTabSelectedListener in project Osmand by osmandapp.

the class ConfigureWidgetsFragment method setupTabLayout.

private void setupTabLayout() {
    widgetsTabAdapter = new WidgetsTabAdapter(this);
    viewPager.setAdapter(widgetsTabAdapter);
    viewPager.registerOnPageChangeCallback(new OnPageChangeCallback() {

        @Override
        public void onPageSelected(int position) {
            selectedPanel = WidgetsPanel.values()[position];
        }
    });
    TabLayoutMediator mediator = new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
    });
    mediator.attach();
    int profileColor = selectedAppMode.getProfileColor(nightMode);
    int defaultIconColor = ColorUtilities.getDefaultIconColor(app, nightMode);
    tabLayout.setSelectedTabIndicatorColor(profileColor);
    tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {

        @Override
        public void onTabSelected(Tab tab) {
            setupTabIconColor(tab, profileColor);
        }

        @Override
        public void onTabUnselected(Tab tab) {
            setupTabIconColor(tab, defaultIconColor);
        }

        @Override
        public void onTabReselected(Tab tab) {
        }
    });
    List<WidgetsPanel> panels = Arrays.asList(WidgetsPanel.values());
    for (int i = 0; i < tabLayout.getTabCount(); i++) {
        Tab tab = tabLayout.getTabAt(i);
        WidgetsPanel panel = panels.get(i);
        if (tab != null) {
            tab.setTag(panel);
            tab.setIcon(panel.getIconId(AndroidUtils.isLayoutRtl(app)));
        }
    }
    int position = panels.indexOf(selectedPanel);
    viewPager.setCurrentItem(position, false);
    if (position == 0) {
        Tab tab = tabLayout.getTabAt(position);
        setupTabIconColor(tab, profileColor);
    }
}
Also used : Tab(com.google.android.material.tabs.TabLayout.Tab) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) OnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) OnPageChangeCallback(androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback)

Example 3 with OnTabSelectedListener

use of com.google.android.material.tabs.TabLayout.OnTabSelectedListener in project OsmAnd by osmandapp.

the class ConfigureWidgetsFragment method setupTabLayout.

private void setupTabLayout() {
    widgetsTabAdapter = new WidgetsTabAdapter(this);
    viewPager.setAdapter(widgetsTabAdapter);
    viewPager.registerOnPageChangeCallback(new OnPageChangeCallback() {

        @Override
        public void onPageSelected(int position) {
            selectedPanel = WidgetsPanel.values()[position];
        }
    });
    TabLayoutMediator mediator = new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
    });
    mediator.attach();
    int profileColor = selectedAppMode.getProfileColor(nightMode);
    int defaultIconColor = ColorUtilities.getDefaultIconColor(app, nightMode);
    tabLayout.setSelectedTabIndicatorColor(profileColor);
    tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {

        @Override
        public void onTabSelected(Tab tab) {
            setupTabIconColor(tab, profileColor);
        }

        @Override
        public void onTabUnselected(Tab tab) {
            setupTabIconColor(tab, defaultIconColor);
        }

        @Override
        public void onTabReselected(Tab tab) {
        }
    });
    List<WidgetsPanel> panels = Arrays.asList(WidgetsPanel.values());
    for (int i = 0; i < tabLayout.getTabCount(); i++) {
        Tab tab = tabLayout.getTabAt(i);
        WidgetsPanel panel = panels.get(i);
        if (tab != null) {
            tab.setTag(panel);
            tab.setIcon(panel.getIconId(AndroidUtils.isLayoutRtl(app)));
        }
    }
    int position = panels.indexOf(selectedPanel);
    viewPager.setCurrentItem(position, false);
    if (position == 0) {
        Tab tab = tabLayout.getTabAt(position);
        setupTabIconColor(tab, profileColor);
    }
}
Also used : Tab(com.google.android.material.tabs.TabLayout.Tab) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) OnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) OnPageChangeCallback(androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback)

Example 4 with OnTabSelectedListener

use of com.google.android.material.tabs.TabLayout.OnTabSelectedListener in project ods-android by Orange-OpenSource.

the class TabsMainDemoFragment method setupBadging.

private void setupBadging() {
    for (TabLayout tabLayout : tabLayouts) {
        // An icon only badge will be displayed.
        BadgeDrawable badgeDrawable = tabLayout.getTabAt(0).getOrCreateBadge();
        badgeDrawable.setVisible(true);
        // A badge with the text "99" will be displayed.
        badgeDrawable = tabLayout.getTabAt(1).getOrCreateBadge();
        badgeDrawable.setVisible(true);
        badgeDrawable.setNumber(99);
        // A badge with the text "999+" will be displayed.
        badgeDrawable = tabLayout.getTabAt(2).getOrCreateBadge();
        badgeDrawable.setVisible(true);
        badgeDrawable.setNumber(9999);
        tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {

            @Override
            public void onTabSelected(Tab tab) {
                clearAndHideBadge(tab.getPosition());
            }

            @Override
            public void onTabUnselected(Tab tab) {
            }

            @Override
            public void onTabReselected(Tab tab) {
                clearAndHideBadge(tab.getPosition());
            }
        });
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) Tab(com.google.android.material.tabs.TabLayout.Tab) TabLayout(com.google.android.material.tabs.TabLayout) OnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)

Aggregations

OnTabSelectedListener (com.google.android.material.tabs.TabLayout.OnTabSelectedListener)4 Tab (com.google.android.material.tabs.TabLayout.Tab)4 OnPageChangeCallback (androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback)2 TabLayout (com.google.android.material.tabs.TabLayout)2 TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)2 WidgetsPanel (net.osmand.plus.views.mapwidgets.WidgetsPanel)2 BadgeDrawable (com.google.android.material.badge.BadgeDrawable)1