use of com.google.android.material.badge.BadgeDrawable in project ods-android by Orange-OpenSource.
the class BottomNavigationDemoFragment method updateBadgeGravity.
private void updateBadgeGravity(@BadgeGravity int badgeGravity) {
for (BottomNavigationView bn : bottomNavigationViews) {
for (int i = 0; i < MAX_BOTTOM_NAV_CHILDREN; i++) {
// Update the badge gravity on all the menu items.
MenuItem menuItem = bn.getMenu().getItem(i);
int menuItemId = menuItem.getItemId();
BadgeDrawable badgeDrawable = bn.getBadge(menuItemId);
if (badgeDrawable != null) {
badgeDrawable.setBadgeGravity(badgeGravity);
}
}
}
}
use of com.google.android.material.badge.BadgeDrawable in project portals-ecommerce-demo by ionic-team.
the class ProductFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_product, container, false);
context.setSelectedProduct(product);
context.getSupportActionBar().setHomeButtonEnabled(true);
context.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Load product image
final ImageView productImage = root.findViewById(R.id.product_image);
String imageResourceName = product.image.substring(0, product.image.lastIndexOf(".")).replaceAll("-", "_");
final int resourceId = getResources().getIdentifier(imageResourceName, "drawable", getContext().getPackageName());
productImage.setImageResource(resourceId);
// Load product text data
final TextView productTitle = root.findViewById(R.id.product_page_title);
productTitle.setText(product.title);
final TextView productPrice = root.findViewById(R.id.product_page_price);
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMaximumFractionDigits(0);
format.setCurrency(Currency.getInstance("USD"));
productPrice.setText(format.format(product.price));
final TextView productDescription = root.findViewById(R.id.product_page_description);
productDescription.setText(product.description);
// Setup add to cart functionality
final Button addToCartButton = root.findViewById(R.id.add_cart_button);
addToCartButton.setOnClickListener(v -> {
EcommerceApp.getInstance().getShoppingCart().addItem(product);
// Increment badge number on the bottom nav
TabLayout tabs = getActivity().findViewById(R.id.tab_layout);
BadgeDrawable badge = tabs.getTabAt(1).getOrCreateBadge();
badge.setVisible(true);
badge.setNumber(EcommerceApp.getInstance().getShoppingCart().getTotalItemCount());
});
return root;
}
use of com.google.android.material.badge.BadgeDrawable in project portals-ecommerce-demo by ionic-team.
the class CartFragment method updateCartView.
private void updateCartView(View root) {
cartAdapter = new CartAdapter(CartFragment.this.getActivity(), v -> updateCartView(root));
recyclerView.setLayoutManager(new LinearLayoutManager(CartFragment.this.getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(cartAdapter);
TextView subtotalTextView = root.findViewById(R.id.text_view_subtotal_value);
TextView estimatedTotalTextView = root.findViewById(R.id.text_view_total_value);
TextView shippingTextView = root.findViewById(R.id.text_view_shipping_value);
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
format.setCurrency(Currency.getInstance("USD"));
String price = format.format(cartViewModel.getShoppingCart().getValue().getTotalPriceOfProductsInCart());
subtotalTextView.setText(price);
estimatedTotalTextView.setText(String.format("%s + Tax", price));
shippingTextView.setText(R.string.standard_shipping);
// Show/Hide if empty cart
TabLayout navView = getActivity().findViewById(R.id.tab_layout);
BadgeDrawable badge = navView.getTabAt(1).getOrCreateBadge();
int itemCount = EcommerceApp.getInstance().getShoppingCart().getTotalItemCount();
if (itemCount == 0) {
showEmptyCartViews(root);
badge.setVisible(false);
} else {
badge.setVisible(true);
badge.setNumber(EcommerceApp.getInstance().getShoppingCart().getTotalItemCount());
showNonEmptyCartViews(root);
}
}
use of com.google.android.material.badge.BadgeDrawable in project ScoreCounter by n-apps.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isKeepScreenOn = LocalSettings.isKeepScreenOnEnabled();
if (savedInstanceState != null) {
currentDiceRoll = savedInstanceState.getInt(STATE_CURRENT_DICE_ROLL);
previousDiceRoll = savedInstanceState.getInt(STATE_PREVIOUS_DICE_ROLL);
}
boolean isLightTheme = LocalSettings.isLightTheme();
// If android Q override night mode settings from system default
if (Utilities.hasQ()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
LocalSettings.saveDarkTheme((currentNightMode == Configuration.UI_MODE_NIGHT_YES));
} else {
AppCompatDelegate.setDefaultNightMode(isLightTheme ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES);
}
setContentView(R.layout.activity_main);
rateMyAppDialog = new RateMyAppDialog(this);
manager = getSupportFragmentManager();
bottomNavigationBar = findViewById(R.id.bottom_navigation);
bottomNavigationBar.setSelectedItemId(R.id.counters);
bottomNavigationBar.setOnItemSelectedListener(item -> {
switch(item.getItemId()) {
case R.id.counters:
switchFragment(TAGS[0]);
if (currentDiceRoll > 0) {
BadgeDrawable badge = bottomNavigationBar.getOrCreateBadge(R.id.dices);
badge.setVisible(true);
int primary = ContextCompat.getColor(this, R.color.colorSecondary);
badge.setBackgroundColor(primary);
badge.setNumber(currentDiceRoll);
} else {
hideDiceBadge();
}
bottomNavigationBar.setElevation(0);
break;
case R.id.dices:
switchFragment(TAGS[1]);
hideDiceBadge();
bottomNavigationBar.setElevation(0);
break;
case R.id.more:
switchFragment(TAGS[2]);
hideDiceBadge();
bottomNavigationBar.setElevation(20);
break;
}
return true;
});
bottomNavigationBar.setOnItemReselectedListener(item -> {
if (item.getItemId() == R.id.counters) {
if (currentFragment instanceof CountersFragment) {
((CountersFragment) currentFragment).scrollToTop();
}
}
});
switchFragment(TAGS[0]);
if (isLightTheme) {
ViewUtil.setLightStatusBar(this);
} else {
ViewUtil.clearLightStatusBar(this);
}
ViewUtil.setNavBarColor(this, isLightTheme);
applyKeepScreenOnIfNeeded();
}
use of com.google.android.material.badge.BadgeDrawable in project browser by scoute-dich.
the class BrowserActivity method updateOmniBox.
@SuppressLint({ "UnsafeOptInUsageError" })
private void updateOmniBox() {
BadgeDrawable badge = bottom_navigation.getOrCreateBadge(R.id.page_0);
badge.setVisible(true);
badge.setNumber(BrowserContainer.size());
badge.setBackgroundColor(colorSecondary);
badgeDrawable.setNumber(BrowserContainer.size());
BadgeUtils.attachBadgeDrawable(badgeDrawable, omniBox_tab, findViewById(R.id.layout));
omniBox_text.clearFocus();
ninjaWebView = (NinjaWebView) currentAlbumController;
String url = ninjaWebView.getUrl();
if (url != null) {
progressBar.setVisibility(View.GONE);
ninjaWebView.setProfileIcon(omniBox_tab);
ninjaWebView.initCookieManager(url);
listTrusted = new List_trusted(context);
if (Objects.requireNonNull(ninjaWebView.getTitle()).isEmpty())
omniBox_text.setText(url);
else
omniBox_text.setText(ninjaWebView.getTitle());
if (url.startsWith("https://") || url.contains("about:blank") || listTrusted.isWhite(url))
omniBox_tab.setOnClickListener(v -> showTabView());
else if (url.isEmpty()) {
omniBox_tab.setOnClickListener(v -> showTabView());
omniBox_text.setText("");
} else {
omniBox_tab.setImageResource(R.drawable.icon_alert);
omniBox_tab.setOnClickListener(v -> {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
builder.setIcon(R.drawable.icon_alert);
builder.setTitle(R.string.app_warning);
builder.setMessage(R.string.toast_unsecured);
builder.setPositiveButton(R.string.app_ok, (dialog, whichButton) -> ninjaWebView.loadUrl(url.replace("http://", "https://")));
builder.setNegativeButton(R.string.app_cancel, (dialog, whichButton) -> {
dialog.cancel();
omniBox_tab.setOnClickListener(v2 -> showTabView());
});
AlertDialog dialog = builder.create();
dialog.show();
HelperUnit.setupDialog(context, dialog);
});
}
}
}
Aggregations