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

The following are Jave code examples for showing how to use setTitle() 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: RetroMusicPlayer   File: LibraryFragment.java   View Source Code Vote up 6 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_main, menu);
    if (isPlaylistPage()) {
        menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
    }
    Fragment currentFragment = getCurrentFragment();
    if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
        AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;

        MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
        if (Util.isLandscape(getResources())) {
            gridSizeItem.setTitle(R.string.action_grid_size_land);
        }
        setUpGridSizeMenu(absLibraryRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());

        menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
        menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
    } else {
        menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
        menu.removeItem(R.id.action_grid_size);
        menu.removeItem(R.id.action_colored_footers);
    }
    colorToolbar();
}
 
Example 2
Project: Android-opencv-native-samples   File: FdActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
    if (item == mItemFace50)
        setMinFaceSize(0.5f);
    else if (item == mItemFace40)
        setMinFaceSize(0.4f);
    else if (item == mItemFace30)
        setMinFaceSize(0.3f);
    else if (item == mItemFace20)
        setMinFaceSize(0.2f);
    else if (item == mItemType) {
        int tmpDetectorType = (mDetectorType + 1) % mDetectorName.length;
        item.setTitle(mDetectorName[tmpDetectorType]);
        setDetectorType(tmpDetectorType);
    }
    return true;
}
 
Example 3
Project: OpenHub   File: IssueDetailActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mPresenter.getIssue() != null) {
        getMenuInflater().inflate(R.menu.menu_issue_detail, menu);
        boolean isCanToggle = AppData.INSTANCE.getLoggedUser().getLogin()
                .equals(mPresenter.getIssue().getUser().getLogin()) ||
                AppData.INSTANCE.getLoggedUser().getLogin()
                        .equals(mPresenter.getIssue().getRepoAuthorName());
        boolean isOpen = mPresenter.getIssue().getState().equals(Issue.IssueState.open);
        if (isCanToggle) {
            MenuItem item = menu.findItem(R.id.action_issue_toggle);
            item.setTitle(isOpen ? R.string.close : R.string.reopen);
        } else {
            menu.removeItem(R.id.action_issue_toggle);
        }
    }
    return true;
}
 
Example 4
Project: referendum_1o_android   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_main, menu);

    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        switch (menuItem.getItemId()) {
            case R.id.action_share:
                menuItem.setTitle(StringsManager.getString("menu_share_app"));
                break;
            case R.id.action_language:
                menuItem.setTitle(StringsManager.getString("menu_language"));
                break;
        }
    }

    if (mFragment instanceof ShareFragment) {
        menu.findItem(R.id.action_share).setVisible(true);
        menu.findItem(R.id.action_language).setVisible(false);
    } else {
        menu.findItem(R.id.action_share).setVisible(false);
        menu.findItem(R.id.action_language).setVisible(true);
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 5
Project: foco   File: EditDocActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.action_music:
            MusicDialog dialog = MusicDialog.newInstance();
            dialog.show(getSupportFragmentManager(), "MusicDialogFragment");
            return true;
        case R.id.action_preview:
            if (mTextLoaded) {
                if (!mPreviewMode) {
                    showPreviewMode();
                    item.setIcon(R.drawable.ic_edit);
                    item.setTitle(R.string.action_edit);
                } else {
                    showEditMode();
                    item.setIcon(R.drawable.ic_preview);
                    item.setTitle(R.string.action_preview);
                }
            } else {
                Toast.makeText(this, R.string.preview_error_msg, Toast.LENGTH_LONG).show();
            }
            return true;
        case R.id.action_save:
            saveDocument(new Callbacks.FinishCallback<Void>() {
                @Override
                public void onFinish(Void result) {
                    Toast.makeText(EditDocActivity.this, R.string.save_success_msg, Toast.LENGTH_LONG).show();
                }
            });
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 6
Project: boohee_v5.6   File: CollectionActivity.java   View Source Code Vote up 5 votes
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case 1:
            if (getString(R.string.g6).equals(item.getTitle())) {
                item.setTitle(R.string.g7);
                this.mAdapter.setEdit(true);
                this.rippleLayout.setVisibility(8);
                this.viewOperate.setVisibility(0);
                this.viewOperate.startAnimation(AnimationUtils.loadAnimation(this, R.anim.o));
                return true;
            }
            item.setTitle(R.string.g6);
            this.mAdapter.setEdit(false);
            this.viewOperate.animate().alphaBy(1.0f).alpha(0.0f).setDuration(300).setListener
                    (new AnimatorListenerAdapter() {
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    CollectionActivity.this.viewOperate.setVisibility(8);
                    CollectionActivity.this.rippleLayout.setVisibility(0);
                    CollectionActivity.this.viewOperate.setAlpha(1.0f);
                }
            }).start();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 7
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 8
Project: AndroidProgramming3e   File: CrimeListFragment.java   View Source Code Vote up 5 votes
@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
Project: Android-Programming-BigNerd   File: CrimeListFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_crime_list, menu);

    MenuItem subtitle = menu.findItem(R.id.show_subtitle);
    if (mSubtitleVisible) {
        subtitle.setTitle(R.string.hide_subtitle);
    } else {
        subtitle.setTitle(R.string.show_subtitle);
    }
}
 
Example 10
Project: boohee_v5.6   File: DownloadManageActivity.java   View Source Code Vote up 5 votes
private void changeEditMode(MenuItem item) {
    if (this.tvDelete.getVisibility() == 0) {
        this.mAdapter.setShowSelect(false);
        this.tvDelete.setVisibility(8);
        this.selectLine.setVisibility(4);
        item.setTitle(getString(R.string.jk));
    } else if (this.tvDelete.getVisibility() == 8) {
        this.mAdapter.setShowSelect(true);
        this.tvDelete.setVisibility(0);
        this.selectLine.setVisibility(0);
        item.setTitle(getString(R.string.jl));
    }
}
 
Example 11
Project: dab-iot   File: MainActivity.java   View Source Code Vote up 5 votes
@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
Project: android-study   File: RecyclerViewSnapUI.java   View Source Code Vote up 5 votes
@Override public boolean onMenuItemClick(MenuItem item) {
  if (item.getItemId() == R.id.layoutType) {
    mHorizontal = !mHorizontal;
    setupAdapter();
    item.setTitle(mHorizontal ? "Vertical" : "Horizontal");
  }
  return false;
}
 
Example 13
Project: UbiBike-client   File: Friends.java   View Source Code Vote up 5 votes
/**
 * Update user information in drawer
 */
private void updateDrawerUserInformation() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_drawer);
    Menu menu = navigationView.getMenu();
    MenuItem userName = menu.findItem(R.id.nav_user_name);
    userName.setTitle(SharedPrefClass.getFirstName(this) + " " + SharedPrefClass.getLastName(this));
    MenuItem userEmail = menu.findItem(R.id.nav_user_email);
    userEmail.setTitle(SharedPrefClass.getEmail(this));
    MenuItem userPoints = menu.findItem(R.id.nav_user_points);
    userPoints.setTitle(Integer.toString(SharedPrefClass.getPoints(this)) + " points");
}
 
Example 14
Project: boohee_v5.6   File: WeightRecordActivity.java   View Source Code Vote up 5 votes
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.p, menu);
    MenuItem item = menu.findItem(R.id.action_record);
    item.setTitle("");
    item.setIcon(0);
    return true;
}
 
Example 15
Project: RoadLab-Pro   File: NewTagFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (menu != null) {
        MenuItem item = menu.findItem(R.id.action_bar_save);
        if (updateMode && item != null) {
            item.setTitle(R.string.update_hint);
        }
    }
}
 
Example 16
Project: Musicoco   File: LeftNavigationController.java   View Source Code Vote up 5 votes
private void updateSwitchMenuIconAndText() {
    MenuItem item;
    Menu menu = navigationView.getMenu();
    if (menu != null) {
        item = menu.findItem(R.id.setting_night_mode);
        if (item == null) {
            return;
        }
    } else {
        return;
    }

    ThemeEnum theme = appPreference.getTheme();

    Drawable icon;
    String title;

    if (theme == ThemeEnum.WHITE || theme == ThemeEnum.VARYING) { // 白天模式
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            icon = activity.getDrawable(R.drawable.ic_night);
        } else {
            icon = activity.getResources().getDrawable(R.drawable.ic_night);
        }
        title = activity.getString(R.string.setting_night_mode);
    } else { // 切换到 白天模式

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            icon = activity.getDrawable(R.drawable.ic_daytime);
        } else { // 切换到 白天模式
            icon = activity.getResources().getDrawable(R.drawable.ic_daytime);
        }
        title = activity.getString(R.string.setting_daytime_mode);
    }

    item.setIcon(icon);
    item.setTitle(title);

}
 
Example 17
Project: SmART-Form   File: TestListFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	super.onCreateOptionsMenu(menu, inflater);
	inflater.inflate(edu.osu.siyang.smartform.R.menu.fragment_test_list, menu);
	MenuItem showSubtitle = menu.findItem(edu.osu.siyang.smartform.R.id.menu_item_show_hint);
	showSubtitle.setTitle(edu.osu.siyang.smartform.R.string.show_subtitle);
}
 
Example 18
Project: tiny   File: BitmapCompressTestActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    mOriginImg.setImageBitmap(null);
    mCompressImg.setImageBitmap(null);
    switch (id) {
        case R.id.action_config:
            if (mConfig == Bitmap.Config.ARGB_8888) {
                item.setTitle("RGB_565");
                mConfig = Bitmap.Config.RGB_565;
            } else if (mConfig == Bitmap.Config.RGB_565) {
                item.setTitle("ARGB_8888");
                mConfig = Bitmap.Config.ARGB_8888;
            }

            break;
        case R.id.action_bytes:
            //free memory for test
            gcAndFinalize();
            testBytes();
            break;
        case R.id.action_file:
            gcAndFinalize();
            testFile();
            break;
        case R.id.action_bitmap:
            gcAndFinalize();
            testBitmap();
            break;
        case R.id.action_stream:
            gcAndFinalize();
            testStream();
            break;
        case R.id.action_res:
            gcAndFinalize();
            testResource();
            break;
        case R.id.action_uri:
            gcAndFinalize();
            testUri();
            break;
        default:
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 19
Project: referendum_1o_android   File: MainActivity.java   View Source Code Vote up 4 votes
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    getWindow().setBackgroundDrawableResource(R.color.white);
    setStatusBarColor(R.color.colorPrimaryDark);

    mNavigationView = findViewById(R.id.navigation);
    mNavigationView.setOnNavigationItemSelectedListener(this);

    for (int i = 0; i < mNavigationView.getMenu().size(); i++) {
        MenuItem menuItem = mNavigationView.getMenu().getItem(i);
        switch (menuItem.getItemId()) {
            case R.id.navigation_informat:
                menuItem.setTitle(StringsManager.getString("menu_info"));
                break;
            case R.id.navigation_web:
                menuItem.setTitle(StringsManager.getString("menu_web"));
                break;
            case R.id.navigation_vota:
                menuItem.setTitle(StringsManager.getString("menu_vote"));
                break;
            case R.id.navigation_results:
                menuItem.setTitle(StringsManager.getString("menu_results"));
                break;
            case R.id.navigation_comparteix:
                menuItem.setTitle(StringsManager.getString("menu_share_tab"));
                break;
        }
    }

    if (savedInstanceState == null) {
        showFirstFragment();
        SharedPreferencesUtils.setInt(SharedPreferencesUtils.NUMBER_OF_EXECUTIONS, SharedPreferencesUtils.getInt(SharedPreferencesUtils.NUMBER_OF_EXECUTIONS, 0) + 1);
        if (!SharedPreferencesUtils.getBoolean(SharedPreferencesUtils.HAS_RATED, false)) {
            int numberOfExecutions = SharedPreferencesUtils.getInt(SharedPreferencesUtils.NUMBER_OF_EXECUTIONS, 0);
            if (numberOfExecutions == 2 || numberOfExecutions % 8 == 0) {
                showRatingDialog();
            }
        }
    } else {
        mCurrentScreen = savedInstanceState.getString("currentScreen", TAB_INFO);
        switch (mCurrentScreen) {
            case TAB_INFO:
                getSupportActionBar().setTitle(StringsManager.getString("title_twitter"));
                mFragment = getSupportFragmentManager().findFragmentByTag(InfoFragment.TAG);
                mNavigationView.getMenu().getItem(INFO_FRAGMENT).setChecked(true);
                break;
            case TAB_WEB:
                getSupportActionBar().setTitle(StringsManager.getString("title_web"));
                mFragment = getSupportFragmentManager().findFragmentByTag(WebFragment.TAG);
                mNavigationView.getMenu().getItem(WEB_FRAGMENT).setChecked(true);
                break;
            case TAB_VOTE:
                getSupportActionBar().setTitle(StringsManager.getString("title_vote"));
                mFragment = getSupportFragmentManager().findFragmentByTag(VoteFragment.TAG);
                mNavigationView.getMenu().getItem(VOTA_FRAGMENT).setChecked(true);
                break;
            case TAB_RESULTS:
                getSupportActionBar().setTitle(StringsManager.getString("title_results"));
                mFragment = getSupportFragmentManager().findFragmentByTag(ResultsFragment.TAG);
                mNavigationView.getMenu().getItem(RESULTS_FRAGMENT).setChecked(true);
                break;
            case TAB_SHARE:
                getSupportActionBar().setTitle(StringsManager.getString("title_share"));
                mFragment = getSupportFragmentManager().findFragmentByTag(ShareFragment.TAG);
                mNavigationView.getMenu().getItem(SHARE_FRAGMENT).setChecked(true);
                break;
        }
        supportInvalidateOptionsMenu();
    }

    fetchRemoteConfig();
}
 
Example 20
Project: keepass2android   File: FragmentFiles.java   View Source Code Vote up 4 votes
@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "onPrepareOptionsMenu()");

    /*
     * Some bugs? This method seems to be called even after `onDestroy()`...
     */
    if (getActivity() == null)
        return;

    /*
     * Sorting.
     */

    final boolean sortAscending = DisplayPrefs
            .isSortAscending(getActivity());
    MenuItem miSort = menu.findItem(R.id.afc_menuitem_sort);

    switch (DisplayPrefs.getSortType(getActivity())) {
    case BaseFile.SORT_BY_NAME:
        miSort.setIcon(Ui.resolveAttribute(getActivity(),
                sortAscending ? R.attr.afc_ic_menu_sort_by_name_asc
                        : R.attr.afc_ic_menu_sort_by_name_desc));
        break;
    case BaseFile.SORT_BY_SIZE:
        miSort.setIcon(Ui.resolveAttribute(getActivity(),
                sortAscending ? R.attr.afc_ic_menu_sort_by_size_asc
                        : R.attr.afc_ic_menu_sort_by_size_desc));
        break;
    case BaseFile.SORT_BY_MODIFICATION_TIME:
        miSort.setIcon(Ui.resolveAttribute(getActivity(),
                sortAscending ? R.attr.afc_ic_menu_sort_by_date_asc
                        : R.attr.afc_ic_menu_sort_by_date_desc));
        break;
    }

    /*
     * View type.
     */

    MenuItem menuItem = menu.findItem(R.id.afc_menuitem_switch_viewmode);
    switch (DisplayPrefs.getViewType(getActivity())) {
    case GRID:
        menuItem.setIcon(Ui.resolveAttribute(getActivity(),
                R.attr.afc_ic_menu_listview));
        menuItem.setTitle(R.string.afc_cmd_list_view);
        break;
    case LIST:
        menuItem.setIcon(Ui.resolveAttribute(getActivity(),
                R.attr.afc_ic_menu_gridview));
        menuItem.setTitle(R.string.afc_cmd_grid_view);
        break;
    }

    /*
     * New folder.
     */

    menu.findItem(R.id.afc_menuitem_new_folder).setEnabled(!mLoading);
}