Search in sources :

Example 6 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project AppManager by MuntashirAkon.

the class ReflowMenuView method getOrCreateBadge.

/**
 * Creates an instance of {@link BadgeDrawable} if none exists. Initializes (if needed) and
 * returns the associated instance of {@link BadgeDrawable}.
 *
 * @param menuItemId Id of the menu item.
 * @return an instance of BadgeDrawable associated with {@code menuItemId}.
 */
BadgeDrawable getOrCreateBadge(int menuItemId) {
    validateMenuItemId(menuItemId);
    BadgeDrawable badgeDrawable = badgeDrawables.get(menuItemId);
    // Create an instance of BadgeDrawable if none were already initialized for this menu item.
    if (badgeDrawable == null) {
        badgeDrawable = BadgeDrawable.create(getContext());
        badgeDrawables.put(menuItemId, badgeDrawable);
    }
    ReflowMenuItemView itemView = findItemView(menuItemId);
    if (itemView != null) {
        itemView.setBadge(badgeDrawable);
    }
    return badgeDrawable;
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable)

Example 7 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project AppManager by MuntashirAkon.

the class ReflowMenuView method setBadgeIfNeeded.

private void setBadgeIfNeeded(@NonNull ReflowMenuItemView child) {
    int childId = child.getId();
    if (!isValidId(childId)) {
        // Child doesn't have a valid id, do not set any BadgeDrawable on the view.
        return;
    }
    BadgeDrawable badgeDrawable = badgeDrawables.get(childId);
    if (badgeDrawable != null) {
        child.setBadge(badgeDrawable);
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) SuppressLint(android.annotation.SuppressLint)

Example 8 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project TCSS450-Mobile-App by TCSS450-Team7-MobileApp.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMainActivity = this;
    MainActivityArgs args = MainActivityArgs.fromBundle(getIntent().getExtras());
    // Import com.auth0.android.jwt.JWT
    JWT jwt = new JWT(args.getJwt());
    // created on the web service.
    if (!jwt.isExpired(0)) {
        jwt = new JWT(args.getJwt());
    }
    new ViewModelProvider(this, new UserInfoViewModel.UserInfoViewModelFactory(args.getEmail(), jwt.toString(), args.getFirst(), args.getLast(), args.getNick(), args.getId())).get(UserInfoViewModel.class);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    // Make sure the new statements go BELOW setContentView
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_message, R.id.navigation_home, R.id.navigation_weather).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
    mNewMessageModel = new ViewModelProvider(this).get(NewMessageCountViewModel.class);
    navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
        if (destination.getId() == R.id.navigation_message) {
            // When the user navigates to the chats page, reset the new message count.
            // This will need some extra logic for your project as it should have
            // multiple chat rooms.
            mNewMessageModel.reset();
        }
    });
    mNewMessageModel.addMessageCountObserver(this, count -> {
        BadgeDrawable badge = binding.navView.getOrCreateBadge(R.id.navigation_message);
        badge.setMaxCharacterCount(2);
        if (count > 0) {
            // new messages! update and show the notification badge.
            badge.setNumber(count);
            badge.setVisible(true);
        } else {
            // user did some action to clear the new messages, remove the badge
            badge.clearNumber();
            badge.setVisible(false);
        }
    });
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) NewMessageCountViewModel(edu.uw.tcss450.blynch99.tcss450mobileapp.model.NewMessageCountViewModel) JWT(com.auth0.android.jwt.JWT) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 9 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project sesl by OneUIProject.

the class NavigationBarMenuView method removeBadge.

void removeBadge(int menuItemId) {
    validateMenuItemId(menuItemId);
    BadgeDrawable badgeDrawable = badgeDrawables.get(menuItemId);
    NavigationBarItemView itemView = findItemView(menuItemId);
    if (itemView != null) {
        itemView.removeBadge();
    }
    if (badgeDrawable != null) {
        badgeDrawables.remove(menuItemId);
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable)

Example 10 with BadgeDrawable

use of com.google.android.material.badge.BadgeDrawable in project sesl by OneUIProject.

the class NavigationBarMenuView method getOrCreateBadge.

/**
 * Creates an instance of {@link BadgeDrawable} if none exists. Initializes (if needed) and
 * returns the associated instance of {@link BadgeDrawable}.
 *
 * @param menuItemId Id of the menu item.
 * @return an instance of BadgeDrawable associated with {@code menuItemId}.
 */
BadgeDrawable getOrCreateBadge(int menuItemId) {
    validateMenuItemId(menuItemId);
    BadgeDrawable badgeDrawable = badgeDrawables.get(menuItemId);
    // Create an instance of BadgeDrawable if none were already initialized for this menu item.
    if (badgeDrawable == null) {
        badgeDrawable = BadgeDrawable.create(getContext());
        badgeDrawables.put(menuItemId, badgeDrawable);
    }
    NavigationBarItemView itemView = findItemView(menuItemId);
    if (itemView != null) {
        itemView.setBadge(badgeDrawable);
    }
    return badgeDrawable;
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable)

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