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

The following examples show how to use android.view.MenuItem#setTitle() . 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: MainActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RepoActivity.java    From WeGit with 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 3
Source File: MainActivity.java    From android-RecyclerView with 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 4
Source File: MainActivity.java    From android-CardReader with 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 5
Source File: MainActivity.java    From android-SwipeRefreshLayoutBasic with 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 6
Source File: MainActivity.java    From NClientV2 with 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 7
Source File: GalleryActivity.java    From NClientV2 with 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 File: CrimeListFragment.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: EncodeActivity.java    From weex with 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 10
Source File: AccountSavedThingActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 11
Source File: MainActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: ConsoleFragment.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
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 13
Source File: AppListFragment.java    From MaxLock with GNU General Public License v3.0 4 votes vote down vote up
@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 14
Source File: MainActivity.java    From FwdPortForwardingApp with GNU General Public License v3.0 4 votes vote down vote up
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 15
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 16
Source File: MainActivity.java    From NClientV2 with 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 17
Source File: OverlayContentLayout.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
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 18
Source File: SubsonicActivity.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: ProfileActivity.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: TagFilterActivity.java    From NClientV2 with 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());
}