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();
}
});
}
}
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);
}
}
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);
}
}
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());
}
});
}
}
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;
}
Aggregations