Search in sources :

Example 31 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project ods-android by Orange-OpenSource.

the class NavigationRailDemoFragment method updateBadgeGravity.

private void updateBadgeGravity(@BadgeGravity int badgeGravity) {
    for (int i = 0; i < navigationRailView.getMenu().size(); i++) {
        // Update the badge gravity on all the menu items.
        MenuItem menuItem = navigationRailView.getMenu().getItem(i);
        int menuItemId = menuItem.getItemId();
        BadgeDrawable badgeDrawable = navigationRailView.getBadge(menuItemId);
        if (badgeDrawable != null) {
            badgeDrawable.setBadgeGravity(badgeGravity);
        }
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) MenuItem(android.view.MenuItem)

Example 32 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project ods-android by Orange-OpenSource.

the class NavigationRailDemoFragment method clearAndHideBadge.

private void clearAndHideBadge(int menuItemId) {
    MenuItem menuItem = navigationRailView.getMenu().getItem(0);
    if (menuItem.getItemId() == menuItemId) {
        // Hide instead of removing the badge associated with the first menu item because the user
        // can trigger it to be displayed again.
        BadgeDrawable badgeDrawable = navigationRailView.getBadge(menuItemId);
        if (badgeDrawable != null) {
            badgeDrawable.setVisible(false);
            badgeDrawable.clearNumber();
        }
    } else {
        // Remove the badge associated with this menu item because cannot be displayed again.
        navigationRailView.removeBadge(menuItemId);
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) MenuItem(android.view.MenuItem)

Example 33 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project ods-android by Orange-OpenSource.

the class BottomNavigationDemoFragment method clearAndHideBadge.

private void clearAndHideBadge(int menuItemId) {
    for (BottomNavigationView bn : bottomNavigationViews) {
        MenuItem menuItem = bn.getMenu().getItem(0);
        if (menuItem.getItemId() == menuItemId) {
            // Hide instead of removing the badge associated with the first menu item because the user
            // can trigger it to be displayed again.
            BadgeDrawable badgeDrawable = bn.getBadge(menuItemId);
            if (badgeDrawable != null) {
                badgeDrawable.setVisible(false);
                badgeDrawable.clearNumber();
            }
        } else {
            // Remove the badge associated with this menu item because cannot be displayed again.
            bn.removeBadge(menuItemId);
        }
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) MenuItem(android.view.MenuItem)

Example 34 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project ods-android by Orange-OpenSource.

the class BottomNavigationDemoFragment method setupBadging.

private void setupBadging() {
    for (BottomNavigationView bn : bottomNavigationViews) {
        int menuItemId = bn.getMenu().getItem(0).getItemId();
        // An icon only badge will be displayed.
        BadgeDrawable badge = bn.getOrCreateBadge(menuItemId);
        badge.setVisible(true);
        menuItemId = bn.getMenu().getItem(1).getItemId();
        // A badge with the text "99" will be displayed.
        badge = bn.getOrCreateBadge(menuItemId);
        badge.setVisible(true);
        badge.setNumber(99);
        menuItemId = bn.getMenu().getItem(2).getItemId();
        // A badge with the text "999+" will be displayed.
        badge = bn.getOrCreateBadge(menuItemId);
        badge.setVisible(true);
        badge.setNumber(9999);
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView)

Aggregations

BadgeDrawable (com.google.android.material.badge.BadgeDrawable)34 MenuItem (android.view.MenuItem)7 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)7 SuppressLint (android.annotation.SuppressLint)5 TabLayout (com.google.android.material.tabs.TabLayout)5 View (android.view.View)4 TextView (android.widget.TextView)4 Bundle (android.os.Bundle)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 NonNull (androidx.annotation.NonNull)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 Handler (android.os.Handler)2 Message (android.os.Message)2 TextUtils (android.text.TextUtils)2 KeyEvent (android.view.KeyEvent)2 WindowManager (android.view.WindowManager)2