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