Java Code Examples for android.view.MenuItem#getTitle()

The following examples show how to use android.view.MenuItem#getTitle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (theme.isBaseLight()) {
        int black = ContextCompat.getColor(this, R.color.black);
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            SpannableString s = new SpannableString(item.getTitle());
            s.setSpan(new ForegroundColorSpan(black), 0, s.length(), 0);
            item.setTitle(s);
        }
    }
    return super.onPrepareOptionsMenu(menu);
}
 
Example 2
Source File: HTMLActivity.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getTitle() == null){
        finish();
        return true;
    }
    return false;
}
 
Example 3
Source File: BottomNavigationView.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public Item(MenuItem menuItem) {
    id = menuItem.getItemId();
    try {   // breaks preview
        this.icon = menuItem.getIcon();
    } catch (Exception e) {
    }
    this.text = menuItem.getTitle();
    iconTint = MenuItemCompat.getIconTintList(menuItem);
}
 
Example 4
Source File: ThemePreferencesManager.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RestrictTo")
public void showChooseThemePopup(View anchor) {
  PopupMenu popupMenu = new PopupMenu(context, anchor);
  popupMenu.inflate(R.menu.mtrl_choose_theme_menu);
  if (popupMenu.getMenu() instanceof MenuBuilder) {
    MenuBuilder menuBuilder = (MenuBuilder) popupMenu.getMenu();

    menuBuilder.setOptionalIconsVisible(true);

    ColorStateList defaultColor =
        AppCompatResources.getColorStateList(
            context, R.color.material_on_surface_emphasis_medium);
    int selectedColor = MaterialColors.getColor(anchor, resourceProvider.getPrimaryColor());
    int currentThemeId = getCurrentThemeId();
    for (int i = 0; i < menuBuilder.size(); i++) {
      MenuItem item = menuBuilder.getItem(i);
      if (item.getItemId() == currentThemeId) {
        DrawableCompat.setTint(item.getIcon(), selectedColor);

        SpannableString s = new SpannableString(item.getTitle());
        s.setSpan(new ForegroundColorSpan(selectedColor), 0, s.length(), 0);
        item.setTitle(s);
      } else {
        DrawableCompat.setTintList(item.getIcon(), defaultColor);
      }
    }
  }
  popupMenu.setOnMenuItemClickListener(
      item -> {
        saveAndApplyTheme(item.getItemId());
        return false;
      });
  popupMenu.show();
}
 
Example 5
Source File: CommentListingFragment.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

	if(item.getTitle() != null
			&& item.getTitle().equals(getActivity().getString(R.string.action_reply))) {

		onParentReply();
		return true;
	}

	return false;
}
 
Example 6
Source File: MainActivity.java    From science-journal with Apache License 2.0 5 votes vote down vote up
private CharSequence getTitleToRestore(MenuItem menuItem) {
  if (menuItem.getItemId() == R.id.navigation_item_experiments) {
    return getResources().getString(R.string.app_name);
  } else {
    return menuItem.getTitle();
  }
}
 
Example 7
Source File: ViewClickProbe.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void trackMenuItem(Object object, MenuItem menuItem, boolean hasTrackClickAnn,long currentTime) {
    try {
        if (isTrackClickSwitchClose()) {
            return;
        }

        Object pageObj = null;
        if (!AllegroUtils.isPage(object)) {
            pageObj = AllegroUtils.getPageObjFromView(null);
        }

        if (!checkTrackClickEnable(pageObj, menuItem, hasTrackClickAnn)) {
            return;
        }

        Map<String, Object> elementInfo = new HashMap<>();
        elementInfo.put(Constants.ELEMENT_TYPE, "MenuItem");
        CharSequence title = menuItem.getTitle();
        if (!TextUtils.isEmpty(title)) {
            elementInfo.put(Constants.ELEMENT_CONTENT, title);
        }
        String idName = AllegroUtils.getIdResourceName(menuItem.getItemId());
        if (!TextUtils.isEmpty(idName)) {
            elementInfo.put(Constants.ELEMENT_ID, idName);
        }
        autoTrackClick(pageObj, elementInfo, hasTrackClickAnn,currentTime);
    } catch (Throwable ignore) {
        ExceptionUtil.exceptionThrow(ignore);
    }
}
 
Example 8
Source File: NavigationView.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public Item(MenuItem item) {
    id = item.getItemId();
    icon = item.getIcon();
    tint = MenuItemCompat.getIconTintList(item);
    groupId = item.getGroupId();
    title = item.getTitle();
}
 
Example 9
Source File: FabSpeedDial.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
            .inflate(getMenuItemLayoutId(), this, false);

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    FrameLayout cardView = (FrameLayout) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        //cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);
    if (Utils.hasLollipop()) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}
 
Example 10
Source File: AdapterRule.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
private void markPro(Context context, MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
Example 11
Source File: AdapterRule.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
private void markPro(Context context, MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
Example 12
Source File: ActivityMain.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
private void markPro(MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, this)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
Example 13
Source File: FloatingActionMenu.java    From Carbon with Apache License 2.0 4 votes vote down vote up
public Item(MenuItem item) {
    icon = item.getIcon();
    tint = MenuItemCompat.getIconTintList(item);
    enabled = item.isEnabled();
    title = item.getTitle();
}
 
Example 14
Source File: Main.java    From Cook-It-Android-XML-Template with MIT License 4 votes vote down vote up
private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/SourceSansPro-Semibold.otf");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(),  Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
Example 15
Source File: BottomSheetUtils.java    From BottomSheetMenu with Apache License 2.0 4 votes vote down vote up
public static void setMenuItemTextColor(MenuItem menuItem, @ColorInt int textColor) {
    SpannableString s = new SpannableString(menuItem.getTitle());
    s.setSpan(new ForegroundColorSpan(textColor), 0, s.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    menuItem.setTitle(s);
}
 
Example 16
Source File: BottomSheetAdapterBuilder.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
                                                 int itemTextColor, int itemBackground,
                                                 int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();
    mTitles = 0;

    boolean addedSubMenu = false;

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);

        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                SubMenu subMenu = item.getSubMenu();

                if (i != 0 && addedSubMenu) {
                    if (mMode == BottomSheetBuilder.MODE_GRID) {
                        throw new IllegalArgumentException("MODE_GRID can't have submenus." +
                                " Use MODE_LIST instead");
                    }
                    items.add(new BottomSheetDivider(dividerBackground));
                }

                CharSequence title = item.getTitle();
                if (title != null && !title.equals("")) {
                    items.add(new BottomSheetHeader(title.toString(), titleTextColor));
                    mTitles++;
                }

                for (int j = 0; j < subMenu.size(); j++) {
                    MenuItem subItem = subMenu.getItem(j);
                    if (subItem.isVisible()) {
                        items.add(new BottomSheetMenuItem(subItem, itemTextColor,
                                itemBackground, tintColor));
                        addedSubMenu = true;
                    }
                }
            } else {
                items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
            }
        }
    }

    return items;
}
 
Example 17
Source File: ShopListActivity.java    From FaceT with Mozilla Public License 2.0 4 votes vote down vote up
private void applyFontToMenuItem(MenuItem mi) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypeFaceSpan("", fontType), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
Example 18
Source File: FabSpeedDial.java    From fab-speed-dial with Apache License 2.0 4 votes vote down vote up
private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
            .inflate(getMenuItemLayoutId(), this, false);

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(ContextCompat.getColorStateList(getContext(),
                miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}
 
Example 19
Source File: MainActivity.java    From FaceT with Mozilla Public License 2.0 4 votes vote down vote up
private void applyFontToMenuItem(MenuItem mi) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypeFaceSpan("", fontType), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
Example 20
Source File: MainActivity.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new RobotoLightTypefaceSpan("", font), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}