Example usage for android.view MenuItem setTitle

List of usage examples for android.view MenuItem setTitle

Introduction

In this page you can find the example usage for android.view MenuItem setTitle.

Prototype


public MenuItem setTitle(@StringRes int title);

Source Link

Document

Change the title associated with this item.

Usage

From source file:paulscode.android.mupen64plusae.game.GameActivity.java

@Override
public void onGameSidebarAction(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.menuItem_exit:
        mWaitingOnConfirmation = true;/*from www  . j a  v  a  2 s. c  o  m*/
        CoreInterface.exit();
        break;
    case R.id.menuItem_toggle_speed:
        CoreInterface.toggleSpeed();

        //Reload the menu with the new speed
        final MenuItem toggleSpeedItem = mGameSidebar.getMenu().findItem(R.id.menuItem_toggle_speed);
        toggleSpeedItem.setTitle(this.getString(R.string.menuItem_toggleSpeed, NativeExports.emuGetSpeed()));
        mGameSidebar.reload();
        break;
    case R.id.menuItem_set_speed:
        CoreInterface.setCustomSpeedFromPrompt(this);
        break;
    case R.id.menuItem_screenshot:
        CoreInterface.screenshot();
        break;
    case R.id.menuItem_set_slot:
        CoreInterface.setSlotFromPrompt(this);
        break;
    case R.id.menuItem_slot_load:
        CoreInterface.loadSlot(this);
        break;
    case R.id.menuItem_slot_save:
        CoreInterface.saveSlot(this);
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
        }
        break;
    case R.id.menuItem_file_load:
        CoreInterface.loadFileFromPrompt(this);
        break;
    case R.id.menuItem_file_save:
        CoreInterface.saveFileFromPrompt();
        break;
    case R.id.menuItem_file_load_auto_save:
        CoreInterface.loadAutoSaveFromPrompt(this);
        break;
    case R.id.menuItem_disable_frame_limiter:
        CoreInterface.toggleFramelimiter();

        final int resId = NativeExports.emuGetFramelimiter() ? R.string.menuItem_enableFramelimiter
                : R.string.menuItem_disableFramelimiter;

        //Reload the menu with the new speed
        final MenuItem frameLimiterItem = mGameSidebar.getMenu().findItem(R.id.menuItem_disable_frame_limiter);
        frameLimiterItem.setTitle(this.getString(resId));
        mGameSidebar.reload();
        break;
    case R.id.menuItem_player_one:
        setPakTypeFromPrompt(1);
        break;
    case R.id.menuItem_player_two:
        setPakTypeFromPrompt(2);
        break;
    case R.id.menuItem_player_three:
        setPakTypeFromPrompt(3);
        break;
    case R.id.menuItem_player_four:
        setPakTypeFromPrompt(4);
        break;
    case R.id.menuItem_setIme:
        final InputMethodManager imeManager = (InputMethodManager) this
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imeManager != null)
            imeManager.showInputMethodPicker();
        break;
    case R.id.menuItem_reset:
        mWaitingOnConfirmation = true;
        CoreInterface.restart();
        break;
    default:
    }
}

From source file:com.google.android.cameraview.demo.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.aspect_ratio:
        if (mCameraView != null) {
            final Set<AspectRatio> ratios = mCameraView.getSupportedAspectRatios();
            final AspectRatio currentRatio = mCameraView.getAspectRatio();
            AspectRatioFragment.newInstance(ratios, currentRatio).show(getSupportFragmentManager(),
                    FRAGMENT_DIALOG);//  w w w .  ja  v a  2s  .  c  o m
        }
        break;
    case R.id.switch_flash:
        if (mCameraView != null) {
            mCurrentFlash = (mCurrentFlash + 1) % FLASH_OPTIONS.length;
            item.setTitle(FLASH_TITLES[mCurrentFlash]);
            item.setIcon(FLASH_ICONS[mCurrentFlash]);
            mCameraView.setFlash(FLASH_OPTIONS[mCurrentFlash]);
        }
        break;
    case R.id.switch_camera:
        if (mCameraView != null) {
            int facing = mCameraView.getFacing();
            mCameraView.setFacing(
                    facing == CameraView.FACING_FRONT ? CameraView.FACING_BACK : CameraView.FACING_FRONT);
        }
        break;
    }
    return false;
}

From source file:com.flym.dennikn.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//  w  w w . j  a v a  2 s  . c  om

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    String title = cursor.getString(mTitlePos);
                    startActivity(Intent.createChooser(
                            new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                    .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                            getString(R.string.menu_share)));
                }
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:com.carlrice.reader.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//from  w ww.j  av  a 2 s  .co  m

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = Application.context().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    String title = cursor.getString(mTitlePos);
                    startActivity(Intent.createChooser(
                            new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                    .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                            getString(R.string.menu_share)));
                }
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = Application.context().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:de.schildbach.wallet.ui.WalletActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final Resources res = getResources();
    final String externalStorageState = Environment.getExternalStorageState();

    menu.findItem(R.id.wallet_options_exchange_rates)
            .setVisible(Constants.ENABLE_EXCHANGE_RATES && res.getBoolean(R.bool.show_exchange_rates_option));
    menu.findItem(R.id.wallet_options_sweep_wallet).setVisible(Constants.ENABLE_SWEEP_WALLET);
    menu.findItem(R.id.wallet_options_restore_wallet)
            .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState)
                    || Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState));
    menu.findItem(R.id.wallet_options_backup_wallet)
            .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState));
    final MenuItem encryptKeysOption = menu.findItem(R.id.wallet_options_encrypt_keys);
    encryptKeysOption.setTitle(wallet.isEncrypted() ? R.string.wallet_options_encrypt_keys_change
            : R.string.wallet_options_encrypt_keys_set);

    return true;//w  w  w .  ja  v a  2s.co m
}

From source file:com.cforlando.streetartandroid.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_licenses) {
        Intent intent = new Intent(this, LicenseActivity.class);
        startActivity(intent);//from w ww  .j  a  va2s  .  c o m
    } else if (id == R.id.action_logout) {
        if (ParseUser.getCurrentUser() == null) {
            loadSignIn();
        } else {
            ParseUser.logOut();
            Snackbar.make(mCoordinatorLayout, R.string.signed_out_message, Snackbar.LENGTH_SHORT).show();
            item.setTitle(R.string.sign_in);
        }

        //            Intent intent = new Intent(MainActivity.this,
        //                    LoginActivity.class);
        //            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
        //                    | Intent.FLAG_ACTIVITY_NEW_TASK);
        //            startActivity(intent);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.ubergeek42.WeechatAndroid.WeechatActivity.java

@MainThread
@Cat("Menu")//from w  w  w. j a  va  2s  .  c  o  m
private void makeMenuReflectConnectionStatus() {
    if (uiMenu == null)
        return;
    MenuItem connectionStatus = uiMenu.findItem(R.id.menu_connection_state);
    String msg;

    if (state.contains(AUTHENTICATED))
        msg = getString(R.string.disconnect);
    else if (state.contains(STARTED))
        msg = getString(R.string.stop_connecting);
    else
        msg = getString(R.string.connect);
    connectionStatus.setTitle(msg);

    final View menuHotlist = uiMenu.findItem(R.id.menu_hotlist).getActionView();
    ImageView bellImage = menuHotlist.findViewById(R.id.hotlist_bell);
    bellImage.setImageResource(P.optimizeTraffic ? R.drawable.ic_bell_cracked : R.drawable.ic_bell);
}

From source file:com.elixsr.portforwarder.ui.MainActivity.java

private void handleForwardingButton(MenuItem item) {

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

        Snackbar.make(this.coordinatorLayout, "Port Forwarding Started", Snackbar.LENGTH_LONG)
                .setAction("Stop", null).show();

        fab.hide();//from   www  .  j ava  2s.  c om

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

        Snackbar.make(this.coordinatorLayout, "Port Forwarding Stopped", Snackbar.LENGTH_LONG).show();

        stopService(forwardingServiceIntent);
    }

    Log.i(TAG, "Forwarding Enabled: " + forwardingManager.isEnabled());
    item.setTitle(generateForwardingActionMenuText(forwardingManager.isEnabled()));
}

From source file:com.golfwallet.main.MainActivity.java

/**   
 *  \brief/*from   w w  w .j  a v a  2 s. c o  m*/
 *    Method called when the user click on a menu item.
 *    \param item An item of the menu
 *    \return Say if the action of selection is made correctly or not
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Toast.makeText(MainActivity.this, "Settings clicked", Toast.LENGTH_SHORT).show();
        Intent apiTestIntent = new Intent(MainActivity.this, APITest.class);
        MainActivity.this.startActivity(apiTestIntent);
        return true;
    } else if (id == R.id.action_logout) {
        if (ReadWriteData.getConnectionState(context)) {
            Toast.makeText(MainActivity.this, "Bye bye !", Toast.LENGTH_SHORT).show();

            item.setTitle("Login");
            setConnected(false);
        } else {
            item.setTitle("Logout");
            Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(loginIntent);
            finish();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.technoxist.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//  w ww  .ja  v a 2  s  .  c  o m

            if (mFavorite) {
                item.setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            if (link != null) {
                String title = cursor.getString(mTitlePos);
                startActivity(Intent.createChooser(
                        new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                        getString(R.string.menu_share)));
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}