Search in sources :

Example 1 with Tab

use of com.google.android.material.tabs.TabLayout.Tab 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 Tab

use of com.google.android.material.tabs.TabLayout.Tab 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 Tab

use of com.google.android.material.tabs.TabLayout.Tab 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 Tab

use of com.google.android.material.tabs.TabLayout.Tab 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)

Example 5 with Tab

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

the class TabsScrollableDemoFragment method onCreateDemoView.

@Nullable
@Override
public View onCreateDemoView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
    // return layoutInflater.inflate(getTabsContent(), viewGroup, false /* attachToRoot */);
    View view = layoutInflater.inflate(R.layout.cat_tabs_scrollable_fragment, viewGroup, false);
    ViewGroup content = view.findViewById(R.id.content);
    View tabsContent = layoutInflater.inflate(getTabsContent(), content, false);
    content.addView(tabsContent, 0);
    scrollableTabLayout = tabsContent.findViewById(R.id.scrollable_tab_layout);
    RadioButton tabGravityStartButton = view.findViewById(R.id.tabs_gravity_start_button);
    tabGravityStartButton.setOnClickListener(v -> scrollableTabLayout.setTabGravity(TabLayout.GRAVITY_START));
    RadioButton tabGravityCenterButton = view.findViewById(R.id.tabs_gravity_center_button);
    tabGravityCenterButton.setOnClickListener(v -> scrollableTabLayout.setTabGravity(TabLayout.GRAVITY_CENTER));
    if (bundle != null) {
        scrollableTabLayout.removeAllTabs();
        scrollableTabLayout.setTabGravity(bundle.getInt(KEY_TAB_GRAVITY));
        // Restore saved tabs
        String[] tabLabels = bundle.getStringArray(KEY_TABS);
        for (String label : tabLabels) {
            scrollableTabLayout.addTab(scrollableTabLayout.newTab().setText(label));
        }
    }
    numTabs = scrollableTabLayout.getTabCount();
    tabTitles = getContext().getResources().getStringArray(R.array.cat_tabs_titles);
    Button addButton = view.findViewById(R.id.add_tab_button);
    addButton.setOnClickListener(v -> {
        scrollableTabLayout.addTab(scrollableTabLayout.newTab().setText(tabTitles[numTabs % tabTitles.length]));
        numTabs++;
    });
    Button removeButton = view.findViewById(R.id.remove_tab_button);
    removeButton.setOnClickListener(v -> {
        Tab tab = scrollableTabLayout.getTabAt(scrollableTabLayout.getTabCount() - 1);
        if (tab != null) {
            scrollableTabLayout.removeTab(tab);
        }
        numTabs = Math.max(0, numTabs - 1);
    });
    return view;
}
Also used : Tab(com.google.android.material.tabs.TabLayout.Tab) RadioButton(android.widget.RadioButton) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) RadioButton(android.widget.RadioButton) View(android.view.View) Nullable(androidx.annotation.Nullable)

Aggregations

Tab (com.google.android.material.tabs.TabLayout.Tab)6 OnTabSelectedListener (com.google.android.material.tabs.TabLayout.OnTabSelectedListener)4 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Button (android.widget.Button)2 Nullable (androidx.annotation.Nullable)2 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 RadioButton (android.widget.RadioButton)1 BadgeDrawable (com.google.android.material.badge.BadgeDrawable)1