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

The following examples show how to use android.view.MenuItem#setTitle() . These examples are extracted from open source projects. 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
private void setupUserInfoNavigationDrawer() {
    // https://code.google.com/p/android/issues/detail?id=190226
    View header = mNavigationView.getHeaderView(0);

    ((TextView) header.findViewById(R.id.profile_email_text)).setText(AptoideUtils.getSharedPreferences().getString(Configs.LOGIN_USER_LOGIN, ""));
    ((TextView) header.findViewById(R.id.profile_name_text)).setText(AptoideUtils.getSharedPreferences().getString(Constants.USER_NAME, ""));

    ImageView profileImage = (ImageView) header.findViewById(R.id.profile_image);
    String userProfilePicPath = AptoideUtils.getSharedPreferences().getString(Constants.USER_AVATAR, "");
    if (AptoideUtils.AccountUtils.isLoggedIn(MainActivity.this)) {
        Glide.with(this).load(userProfilePicPath).transform(new CircleTransform(this)).into(profileImage);
    } else {
        profileImage.setImageResource(R.drawable.user_account_white);
    }

    MenuItem item = mNavigationView.getMenu().getItem(0);
    if (AptoideUtils.AccountUtils.isLoggedIn(MainActivity.this)) {
        item.setTitle(R.string.my_account);
        item.setIcon(R.drawable.ic_action_accounts);
    } else {
        item.setIcon(R.drawable.user_account_grey);
        item.setTitle(R.string.navigation_drawer_signup_login);
    }
}
 
Example 2
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem pauseMenu = menu.findItem(R.id.action_list_grid);
    if (viewIsList) {
        pauseMenu.setIcon(R.drawable.ic_view_grid_black_24dp);
        pauseMenu.setTitle(R.string.action_grid);
    } else {
        pauseMenu.setIcon(R.drawable.ic_view_list_black_24dp);
        pauseMenu.setTitle(R.string.action_list);
    }
    AppCompat.setTint(pauseMenu, getResources().getColor(R.color.colorMenuText));
    return super.onPrepareOptionsMenu(menu);
}
 
Example 3
Source Project: WeGit   File: RepoActivity.java    License: Apache License 2.0 5 votes vote down vote up
public void updateStarMenuItem() {
    MenuItem starItem = menu.findItem(R.id.action_star);

    switch (starState) {
        case STARRED:
            starItem.setTitle("UNSTAR");
            break;
        case UNSTARRED:
            starItem.setTitle("STAR");
            break;
        default:
            break;
    }
}
 
Example 4
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_refresh_account_saved_thing_activity:
            if (mMenu != null) {
                mMenu.findItem(R.id.action_lazy_mode_account_saved_thing_activity).setTitle(R.string.action_start_lazy_mode);
            }
            sectionsPagerAdapter.refresh();
            return true;
        case R.id.action_lazy_mode_account_saved_thing_activity:
            MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_account_saved_thing_activity);
            if (isInLazyMode) {
                isInLazyMode = false;
                sectionsPagerAdapter.stopLazyMode();
                lazyModeItem.setTitle(R.string.action_start_lazy_mode);
                params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
                collapsingToolbarLayout.setLayoutParams(params);
            } else {
                isInLazyMode = true;
                if (sectionsPagerAdapter.startLazyMode()) {
                    lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
                    appBarLayout.setExpanded(false);
                    params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
                    collapsingToolbarLayout.setLayoutParams(params);
                } else {
                    isInLazyMode = false;
                }
            }
            return true;
    }
    return false;
}
 
Example 5
Source Project: weex   File: EncodeActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater menuInflater = getMenuInflater();
  menuInflater.inflate(R.menu.encode, menu);
  boolean useVcard = qrCodeEncoder != null && qrCodeEncoder.isUseVCard();
  int encodeNameResource = useVcard ? R.string.menu_encode_mecard : R.string.menu_encode_vcard;
  MenuItem encodeItem = menu.findItem(R.id.menu_encode);
  encodeItem.setTitle(encodeNameResource);
  Intent intent = getIntent();
  if (intent != null) {
    String type = intent.getStringExtra(Intents.Encode.TYPE);
    encodeItem.setVisible(Contents.Type.CONTACT.equals(type));
  }
  return super.onCreateOptionsMenu(menu);
}
 
Example 6
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_crime_list, menu);

    MenuItem subtitleItem = menu.findItem(R.id.show_subtitle);
    if (mSubtitleVisible) {
        subtitleItem.setTitle(R.string.hide_subtitle);
    } else {
        subtitleItem.setTitle(R.string.show_subtitle);
    }
}
 
Example 7
Source Project: NClientV2   File: GalleryActivity.java    License: Apache License 2.0 5 votes vote down vote up
public void initFavoriteIcon(Menu menu){
    boolean onlineFavorite=!isLocal&&((Gallery)gallery).isOnlineFavorite();
    boolean unknown=getIntent().getBooleanExtra(getPackageName()+ ".UNKNOWN",false);
    MenuItem item=menu.findItem(R.id.add_online_gallery);

    item.setIcon(onlineFavorite?R.drawable.ic_star:R.drawable.ic_star_border);

    if(unknown)item.setTitle(R.string.toggle_online_favorite);
    else if(onlineFavorite)item.setTitle(R.string.remove_from_online_favorites);
    else item.setTitle(R.string.add_to_online_favorite);
}
 
Example 8
Source Project: NClientV2   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showLanguageIcon(MenuItem item) {
    switch (Global.getOnlyLanguage()){
        case JAPANESE:item.setTitle(R.string.only_japanese);item.setIcon(R.drawable.ic_jpbw);break;
        case CHINESE:item.setTitle(R.string.only_chinese);item.setIcon(R.drawable.ic_cnbw);break;
        case ENGLISH:item.setTitle(R.string.only_english);item.setIcon(R.drawable.ic_gbbw);break;
        case ALL:item.setTitle(R.string.all_languages);item.setIcon(R.drawable.ic_world);break;
    }
    Global.setTint(item.getIcon());
}
 
Example 9
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 10
Source Project: android-CardReader   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 11
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 12
Source Project: FaceT   File: ProfileActivity.java    License: 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 13
private void populateTabs() {
	drawerList.getMenu().clear();
	drawerList.inflateMenu(R.menu.drawer_navigation);

	SharedPreferences prefs = Util.getPreferences(this);
	boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
	boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canBookmark(this);
	boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this);

	MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline);
	if(Util.isOffline(this)) {
		setDrawerItemVisible(R.id.drawer_home, false);

		if(lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_home) {
			String newFragment = Util.openToTab(this);
			if(newFragment == null || "Home".equals(newFragment)) {
				newFragment = "Artist";
			}

			lastSelectedPosition = getDrawerItemId(newFragment);
			drawerItemSelected(newFragment);
		}

		offlineMenuItem.setTitle(R.string.main_online);
	} else {
		offlineMenuItem.setTitle(R.string.main_offline);
	}

	if(!podcastsEnabled) {
		setDrawerItemVisible(R.id.drawer_podcasts, false);
	}
	if(!bookmarksEnabled) {
		setDrawerItemVisible(R.id.drawer_bookmarks, false);
	}
	if(!adminEnabled) {
		setDrawerItemVisible(R.id.drawer_admin, false);
	}

	if(lastSelectedPosition != 0) {
		MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
		if(item != null) {
			item.setChecked(true);
		}
	}
	drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark);

	showingTabs = true;
}
 
Example 14
Source Project: NClientV2   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void popularItemDispay(MenuItem item) {
    item.setTitle(getString(R.string.sort_type_title_format,getString(Global.getSortType().getNameId())));
    Global.setTint(item.getIcon());
}
 
Example 15
Source Project: Cook-It-Android-XML-Template   File: Main.java    License: 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 16
private void updateLockIcon(@NonNull MenuItem menuItem) {
    if (getView() == null) return;
    boolean isEnabled = ViewCompat.isNestedScrollingEnabled(getView());
    menuItem.setTitle(isEnabled ? UNLOCK : LOCK);
    menuItem.setIcon(isEnabled ? mUnlockDrawable : mLockDrawable);
}
 
Example 17
@SuppressLint("ApplySharedPref")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            appListModel.getAdapter().getFilter().filter("");
            return Util.hideKeyboardFromWindow(getActivity(), getView());
        case R.id.toolbar_filter_activated:
            String appListFilter = prefs.getString("app_list_filter", "");
            switch (appListFilter) {
                case "@*activated*":
                    prefs.edit().putString("app_list_filter", "@*deactivated*").apply();
                    break;
                case "@*deactivated*":
                    prefs.edit().remove("app_list_filter").apply();
                    break;
                default:
                    prefs.edit().putString("app_list_filter", "@*activated*").apply();
                    break;
            }
            filterIcon(item);
            appListModel.getAdapter().getFilter().filter("");
            return true;
        case R.id.toolbar_backup_list:
            if (prefs.getBoolean(Common.ENABLE_PRO, false)) {
                Util.checkForStoragePermission(this, BACKUP_STORAGE_PERMISSION_REQUEST_CODE, R.string.dialog_storage_permission_backup_restore);
            } else {
                Toast.makeText(getActivity(), R.string.toast_pro_required, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.toolbar_restore_list:
            if (prefs.getBoolean(Common.ENABLE_PRO, false)) {
                Util.checkForStoragePermission(this, RESTORE_STORAGE_PERMISSION_REQUEST_CODE, R.string.dialog_storage_permission_backup_restore);
            } else {
                Toast.makeText(getActivity(), R.string.toast_pro_required, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.toolbar_clear_list:
            MLPreferences.getPrefsApps(getActivity()).edit().clear().commit();
            MLPreferences.getPreferencesKeysPerApp(getActivity()).edit().clear().commit();
            ((SettingsActivity) getActivity()).restart();
            return true;
        case R.id.toolbar_load_all:
            appListModel.setLoadAll(!appListModel.getLoadAll());
            item.setTitle(appListModel.getLoadAll() ? R.string.menu_only_openable : R.string.menu_all_apps);
            // Load new data with animation
            rootView.findViewById(android.R.id.progress).setVisibility(View.VISIBLE);
            appListModel.loadData();
            return true;
        default:
            return false;
    }
}
 
Example 18
private void handleForwardingButton(MenuItem item) {


        if (!forwardingManager.isEnabled()) {
            // startPortForwarding();

            Snackbar.make(this.coordinatorLayout, R.string.snackbar_port_forwarding_started_text, Snackbar.LENGTH_LONG)
                    .setAction("Stop", null).show();

            fab.hide();

            startService(forwardingServiceIntent);
        } else {
            // Stop forwarding
            fab.show();

            Snackbar.make(this.coordinatorLayout, R.string.snackbar_port_forwarding_stopped_text, Snackbar.LENGTH_LONG).show();

            stopService(forwardingServiceIntent);
        }

        Log.i(TAG, "Forwarding Enabled: " + forwardingManager.isEnabled());
        item.setTitle(generateForwardingActionMenuText(forwardingManager.isEnabled()));
    }
 
Example 19
private void refreshToolbar(Menu menu) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    menu.findItem(R.id.resync_action).setVisible(getLyrics().isLRC());
    menu.findItem(R.id.convert_action).setVisible(getLyrics().isLRC());
    menu.findItem(R.id.save_action).setVisible(!sharedPreferences.getBoolean("pref_auto_save", true));
    menu.findItem(R.id.action_vote).setVisible("user-submission".equals(getLyrics().getSource()));
    MenuItem romanizeMenuItem = menu.findItem(R.id.romanize_action); // .setVisible(RomanizeUtil.detectIdeographic(getLyrics().getText()));

    if (romanizeMenuItem != null && getLyrics() != null && getLyrics().getText() != null && getLyrics().getFlag() == Lyrics.POSITIVE_RESULT) {
        boolean isIdeographic = RomanizeUtil.detectIdeographic(getLyrics().getText());
        Lyrics storedLyrics = null;
        if (!isIdeographic) {
            storedLyrics = getLyrics() == null ? null :
                    DatabaseHelper.getInstance(getContext()).get(new String[]{
                            getLyrics().getArtist(),
                            getLyrics().getTitle(),
                            getLyrics().getOriginalArtist(),
                            getLyrics().getOriginalTitle()});
        }
        romanizeMenuItem.setVisible(isIdeographic ||
                (storedLyrics != null && RomanizeUtil.detectIdeographic(storedLyrics.getText())));
        romanizeMenuItem.setTitle(isIdeographic ? R.string.romanize : R.string.reset);

        if (getLyrics().getFlag() == Lyrics.POSITIVE_RESULT
                && sharedPreferences.getBoolean("pref_auto_save", true)) {
            if (storedLyrics == null || (getLyrics().isLRC() && !getLyrics().isLRC())) {
                lyricsPresentInDB = true;
                new WriteToDatabaseTask().execute(this, menu.findItem(R.id.save_action), getLyrics());
            }
            menu.findItem(R.id.save_action).setVisible(false);
        }
    } else {
        romanizeMenuItem.setVisible(false);
    }

    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View toolbarChild = toolbar.getChildAt(i);
        if (toolbarChild instanceof ActionMenuView) {
            ViewGroup actionBarContainer = (ViewGroup) toolbarChild;
            for (int j = 0; j < actionBarContainer.getChildCount(); j++) {
                View v = actionBarContainer.getChildAt(j);
                v.setOnLongClickListener(menuItemLongClickListener);
            }
            break;
        }
    }
}
 
Example 20
Source Project: NClientV2   File: TagFilterActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void updateSortItem(MenuItem item){
    item.setIcon(TagV2.isSortedByName()?R.drawable.ic_sort_by_alpha:R.drawable.ic_sort);
    item.setTitle(TagV2.isSortedByName()?R.string.sort_by_title:R.string.sort_by_popular);
    Global.setTint(item.getIcon());
}