Search in sources :

Example 16 with BadgeDrawable

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);
            }
        }
    }
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) MenuItem(android.view.MenuItem)

Example 17 with BadgeDrawable

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;
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) Button(android.widget.Button) TabLayout(com.google.android.material.tabs.TabLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) NumberFormat(java.text.NumberFormat)

Example 18 with BadgeDrawable

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);
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) EcommerceApp(io.ionic.demo.ecommerce.EcommerceApp) R(io.ionic.demo.ecommerce.R) Currency(java.util.Currency) ViewGroup(android.view.ViewGroup) NumberFormat(java.text.NumberFormat) BadgeDrawable(com.google.android.material.badge.BadgeDrawable) TextView(android.widget.TextView) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) BadgeDrawable(com.google.android.material.badge.BadgeDrawable) TabLayout(com.google.android.material.tabs.TabLayout) TextView(android.widget.TextView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NumberFormat(java.text.NumberFormat)

Example 19 with BadgeDrawable

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();
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) CountersFragment(ua.napps.scorekeeper.counters.CountersFragment) RateMyAppDialog(ua.napps.scorekeeper.utils.RateMyAppDialog)

Example 20 with BadgeDrawable

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);
            });
        }
    }
}
Also used : Chip(com.google.android.material.chip.Chip) Arrays(java.util.Arrays) Bundle(android.os.Bundle) PrintManager(android.print.PrintManager) List_trusted(de.baumann.browser.browser.List_trusted) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) PrintAttributes(android.print.PrintAttributes) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) BadgeDrawable(com.google.android.material.badge.BadgeDrawable) AdapterRecord(de.baumann.browser.view.AdapterRecord) Manifest(android.Manifest) SRC_ANCHOR_TYPE(android.webkit.WebView.HitTestResult.SRC_ANCHOR_TYPE) Handler(android.os.Handler) ClipboardManager(android.content.ClipboardManager) DataURIParser(de.baumann.browser.browser.DataURIParser) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) HelperUnit(de.baumann.browser.unit.HelperUnit) CardView(androidx.cardview.widget.CardView) GridAdapter(de.baumann.browser.view.GridAdapter) BottomAppBar(com.google.android.material.bottomappbar.BottomAppBar) IMAGE_TYPE(android.webkit.WebView.HitTestResult.IMAGE_TYPE) LinearProgressIndicator(com.google.android.material.progressindicator.LinearProgressIndicator) IntentFilter(android.content.IntentFilter) WindowInsetsController(android.view.WindowInsetsController) FaviconHelper(de.baumann.browser.database.FaviconHelper) Message(android.os.Message) PrintDocumentAdapter(android.print.PrintDocumentAdapter) TextWatcher(android.text.TextWatcher) MaterialCardView(com.google.android.material.card.MaterialCardView) TextInputLayout(com.google.android.material.textfield.TextInputLayout) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Toast(android.widget.Toast) BrowserUnit(de.baumann.browser.unit.BrowserUnit) Record(de.baumann.browser.database.Record) TAG(android.content.ContentValues.TAG) WebChromeClient(android.webkit.WebChromeClient) ValueCallback(android.webkit.ValueCallback) KeyListener(android.text.method.KeyListener) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Configuration(android.content.res.Configuration) PreferenceManager(androidx.preference.PreferenceManager) RecordUnit(de.baumann.browser.unit.RecordUnit) EditText(android.widget.EditText) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) GridView(android.widget.GridView) PackageManager(android.content.pm.PackageManager) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WindowManager(android.view.WindowManager) BrowserController(de.baumann.browser.browser.BrowserController) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) WebBackForwardList(android.webkit.WebBackForwardList) Button(android.widget.Button) STARTSITE_ITEM(de.baumann.browser.database.RecordAction.STARTSITE_ITEM) WebView(android.webkit.WebView) GridItem(de.baumann.browser.view.GridItem) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NotificationManager(android.app.NotificationManager) SRC_IMAGE_ANCHOR_TYPE(android.webkit.WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) ObjectAnimator(android.animation.ObjectAnimator) R(de.baumann.browser.R) List_protected(de.baumann.browser.browser.List_protected) WebStorage(android.webkit.WebStorage) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) DownloadManager(android.app.DownloadManager) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) RelativeLayout(android.widget.RelativeLayout) BOOKMARK_ITEM(de.baumann.browser.database.RecordAction.BOOKMARK_ITEM) ListView(android.widget.ListView) OrientationEventListener(android.view.OrientationEventListener) BrowserContainer(de.baumann.browser.browser.BrowserContainer) SearchManager(android.app.SearchManager) Window(android.view.Window) Context(android.content.Context) ContextMenu(android.view.ContextMenu) TextInputEditText(com.google.android.material.textfield.TextInputEditText) List_standard(de.baumann.browser.browser.List_standard) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) NinjaWebView(de.baumann.browser.view.NinjaWebView) Intent(android.content.Intent) MediaPlayer(android.media.MediaPlayer) NinjaToast(de.baumann.browser.view.NinjaToast) NavigationBarView(com.google.android.material.navigation.NavigationBarView) ClipData(android.content.ClipData) RecordAction(de.baumann.browser.database.RecordAction) SuppressLint(android.annotation.SuppressLint) SwipeTouchListener(de.baumann.browser.view.SwipeTouchListener) Build(android.os.Build) LinkedList(java.util.LinkedList) VideoView(android.widget.VideoView) BadgeUtils(com.google.android.material.badge.BadgeUtils) ActivityCompat(androidx.core.app.ActivityCompat) AlbumController(de.baumann.browser.browser.AlbumController) PopupMenu(androidx.appcompat.widget.PopupMenu) HandlerThread(android.os.HandlerThread) Bitmap(android.graphics.Bitmap) AdapterSearch(de.baumann.browser.view.AdapterSearch) Activity(android.app.Activity) Resources(android.content.res.Resources) AlertDialog(androidx.appcompat.app.AlertDialog) BadgeDrawable(com.google.android.material.badge.BadgeDrawable) List_trusted(de.baumann.browser.browser.List_trusted) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) SuppressLint(android.annotation.SuppressLint)

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