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