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

The following are Jave code examples for showing how to use getTitle() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MySmashCouch   File: CustomNavigationListener.java   View Source Code Vote up 7 votes
/**
 * Metodo encargado de la navegacion. Usa item.getTitle para manejar el caso de intentar
 * navegar hacia la tab en la que ya estamos
 * @param item
 * @return true si se marca la tab, false si no
 */
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment newFragment = null;
    if(!(tabActualTitle == item.getTitle())){
        tabActualTitle = item.getTitle();
        switch (item.getItemId()) {
            case R.id.action_sofa:
                newFragment = Sofa.newInstance();
                break;
            case R.id.action_torneo:
                newFragment = Torneo.newInstance();
                break;
            case R.id.action_mapas:
                newFragment = Mapas.newInstance();
                break;
        }
        FragmentTransaction transaction = context.getFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();
        return true;
    }else{
        return false;
    }
}
 
Example 2
Project: Quran   File: AyahToolBar.java   View Source Code Vote up 5 votes
@Override
public boolean onLongClick(View v) {
  MenuItem item = menu.findItem(v.getId());
  if (item != null && item.getTitle() != null) {
    Toast.makeText(context, item.getTitle(), Toast.LENGTH_SHORT).show();
    return true;
  }
  return false;
}
 
Example 3
Project: easyfilemanager   File: FabSpeedDial.java   View Source Code Vote up 5 votes
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 4
Project: MKAPP   File: ActivityMain.java   View Source Code Vote up 5 votes
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 5
Project: MKAPP   File: AdapterRule.java   View Source Code Vote up 5 votes
private void markPro(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 6
Project: CodeMineProject1   File: ComputerPartActivity.java   View Source Code Vote up 5 votes
public void swapMenuItemTitle(MenuItem item) {
    if (item.getTitle() == null) {
        //IMPORTANT this prevents crashes when onOptionsItemSelected() is called from
        //the user pressing the back button or the info dialog.
        //if this is removed the other checks throw nullpointers, so keep it here.
    }
    else if(item.getTitle().toString().contains("Ascending")){
        item.setTitle(item.getTitle().toString().replace("Ascending", "Descending"));
    }
    else if (item.getTitle().toString().contains("Descending")){//the filter items will contain neither.
        item.setTitle(item.getTitle().toString().replace("Descending", "Ascending"));
    }
}
 
Example 7
Project: FireFiles   File: FabSpeedDial.java   View Source Code Vote up 5 votes
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 8
Project: QuickActionView   File: QuickActionView.java   View Source Code Vote up 5 votes
/**
 * Add actions to the QuickActionView from the given menu resource id.
 *
 * @param menuId menu resource id
 * @return the QuickActionView
 */
public QuickActionView addActions(@MenuRes int menuId) {
    Menu menu = new MenuBuilder(mContext);
    new MenuInflater(mContext).inflate(menuId, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Action action = new Action(item.getItemId(), item.getIcon(), item.getTitle());
        addAction(action);
    }
    return this;
}
 
Example 9
Project: simple-share-android   File: FabSpeedDial.java   View Source Code Vote up 5 votes
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
Project: Camera-Roll-Android-App   File: ItemActivity.java   View Source Code Vote up 5 votes
@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 11
Project: Cook-It-Android-XML-Template   File: Main.java   View Source Code Vote up 4 votes
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 12
Project: MaterialOCR   File: FabSpeedDial.java   View Source Code Vote up 4 votes
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 13
Project: JinsMemeBRIDGE-Android   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
  CharSequence cs = item.getTitle();

  if (cs == null) {
    Log.d("DEBUG", "press actionbar back!");
    return true;
  }

  String itemTitle = item.getTitle().toString();

  Log.d("DEBUG", "item id = " + item.getItemId() + " " + itemTitle);

  if (itemTitle.equals(getString(R.string.basic_conf))) {
    Log.d("DEBUG", "tap basic setting");

    transitToFragment(basicConfigFragment);

    return true;
  } else if (itemTitle.equals(getString(R.string.spotify_conf))) {
    Log.d("DEBUG", "tap spotify setting");

    transitToFragment(spotifyConfigFragment);

    return true;
  } else if (itemTitle.equals(getString(R.string.hue_conf))) {
    Log.d("DEBUG", "tap hue setting");

    transitToFragment(hueConfigFragment);

    return true;
  } else if (itemTitle.equals(getString(R.string.remo_conf))) {
    Log.d("DEBUG", "tap remo setting");

    transitToFragment(remoConfigFragment);

    return true;
  } else if (itemTitle.contains(getString(R.string.osc_conf))) {
    Log.d("DEBUG", "tap osc setting");

    transitToFragment(oscConfigFragment);

    return true;
  } else if (itemTitle.contains(getString(R.string.midi_conf))) {
    Log.d("DEBUG", "tap midi setting");

    transitToFragment(midiConfigFragment);

    return true;
  }
  /*
   * MODIFY YOURSELF
   * Add your implemented function's configuration
   *
   */
  /*
  else if (itemTitle.equals(getString(R.string.***_config) {
    Log.d("DEBUG", "tap *** setting");

    transittToConfig(***ConfigFragment);

    return true;
  }
   */
  else if (itemTitle.equals(getString(R.string.about))) {
    Log.d("DEBUG", "tap about");

    transitToFragment(aboutFragment);

    return true;
  } else if (itemTitle.equals(getString(R.string.exit_app))) {
    finishAndRemoveTask();
  }

  return super.onOptionsItemSelected(item);
}
 
Example 14
Project: login   File: BottomSheetAdapterBuilder.java   View Source Code Vote up 4 votes
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 15
Project: BottomSheetMenu   File: BottomSheetUtils.java   View Source Code Vote up 4 votes
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);
}