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:com.joravasal.comicagg.ComicListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_log_out:
        Intent intent = new Intent(this, LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("DeleteToken", true);
        startActivity(intent);// w  w w .j  av  a 2  s  . c o  m
        finish();
        break;
    case R.id.menu_refresh:
        ((ComicListFragment) getSupportFragmentManager().findFragmentById(R.id.comic_list)).loadList(true,
                showUnread, 0);
        break;
    case R.id.menu_show_all:
        if (!isOnline()) {
            Toast.makeText(getApplicationContext(), getString(R.string.toast_need_internet), Toast.LENGTH_LONG)
                    .show();
            break;
        }
        if (showUnread) {
            showUnread = false;
            item.setTitle(R.string.menu_show_unread);
        } else {
            showUnread = true;
            item.setTitle(R.string.menu_show_all);
        }
        ((ComicListFragment) getSupportFragmentManager().findFragmentById(R.id.comic_list)).loadList(true,
                showUnread, 0);
        // TODO: mantener igual entre sesiones?
        break;
    case R.id.menu_about:
        // TODO: create and open a new window with about info
    case R.id.menu_edit_account:
        // TODO: create and open edit account for user window
    case R.id.menu_mark_all_read:
        // TODO: sent to the server the order of mark all as read (ask for
        // confirmation depends on options)
    case R.id.menu_options:
        // TODO: create and open options window
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:gov.wa.wsdot.android.wsdot.ui.TrafficMapActivity.java

private void toggleCameras(MenuItem item) {
    if (showCameras) {
        AnalyticsUtils.getInstance(this).trackPageView("/Traffic Map/Hide Cameras");

        for (Entry<Marker, String> entry : markers.entrySet()) {
            Marker key = entry.getKey();
            String value = entry.getValue();

            if (value.equalsIgnoreCase("camera")) {
                key.setVisible(false);//w ww . j  a v a  2s  .c o  m
            }
        }

        item.setTitle("Show Cameras");
        showCameras = false;
    } else {
        AnalyticsUtils.getInstance(this).trackPageView("/Traffic Map/Show Cameras");

        for (Entry<Marker, String> entry : markers.entrySet()) {
            Marker key = entry.getKey();
            String value = entry.getValue();

            if (value.equalsIgnoreCase("camera")) {
                key.setVisible(true);
            }
        }

        item.setTitle("Hide Cameras");
        showCameras = true;
    }

    // Save camera display preference
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean("KEY_SHOW_CAMERAS", showCameras);
    editor.commit();
}

From source file:net.reichholf.dreamdroid.fragment.ServiceListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (getMultiPaneHandler().isDrawerOpen())
        return;/*  w ww  . j  av  a2  s  .  com*/

    MenuItem setDefault = menu.findItem(R.id.menu_default);
    String defaultReference = DreamDroid.getCurrentProfile().getDefaultRef();
    setDefault.setVisible(true);
    if (defaultReference != null) {
        if (defaultReference.equals(mDetailReference)) {
            setDefault.setIcon(R.drawable.ic_action_fav);
            setDefault.setTitle(R.string.reset_default);
        } else {
            setDefault.setIcon(R.drawable.ic_action_nofav);
            setDefault.setTitle(R.string.set_default);
        }
    }
}

From source file:net.news.inrss.fragment.EntryFragment.java

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

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;/*from w  ww  .  j ava 2 s .c  om*/

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

            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;
        }
        case R.id.menu_open_in_browser: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                    startActivity(browserIntent);
                }
            }
            break;
        }
        case R.id.menu_switch_full_original: {
            if (mPreferFullText) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mPreferFullText = false;
                        Log.d(TAG, "run: manual call of displayEntry(), fullText=false");
                        mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                    }
                });
            } else {
                Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
                final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

                if (alreadyMobilized) {
                    Log.d(TAG, "onOptionsItemSelected: alreadyMobilized");
                    mPreferFullText = true;
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(TAG, "run: manual call of displayEntry(), fullText=true");
                            mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                        }
                    });
                } else if (!isRefreshing()) {
                    Log.d(TAG, "onOptionsItemSelected: about to load article...");
                    mPreferFullText = false;
                    ConnectivityManager connectivityManager = (ConnectivityManager) activity
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

                    // since we have acquired the networkInfo, we use it for basic checks
                    if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                        FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] });
                        activity.startService(new Intent(activity, FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
                    } else {
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                        Log.d(TAG, "onOptionsItemSelected: cannot load article. no internet connection.");
                    }
                } else {
                    Log.d(TAG, "onOptionsItemSelected: refreshing already in progress");
                }
            }
            mShowFullContentItem.setChecked(mPreferFullText);
            break;
        }
        default:
            break;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.sj.android.appusage.activities.UsageListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.filter_menu:
        if (UsageSharedPrefernceHelper.isFilterMode(mActivity)) {
            UsageSharedPrefernceHelper.setFilterMode(mActivity, false);
            item.setIcon(R.drawable.ic_filter_list_white_24dp);
            item.setTitle(R.string.string_filter);
            mIsFilteredMap = false;//  w w  w.j av  a2s .com
            setmUsageAppData(mUsageAppData);
        } else {
            if (UsageSharedPrefernceHelper.getSelectedApplicationForFiltering(mActivity) == null
                    || UsageSharedPrefernceHelper.getSelectedApplicationForFiltering(mActivity).size() == 0) {
                Toast.makeText(mActivity, R.string.string_filter_menu_enable_message, Toast.LENGTH_LONG).show();
            } else {
                UsageSharedPrefernceHelper.setFilterMode(mActivity, true);
                item.setIcon(R.drawable.ic_select_all_white_24dp);
                item.setTitle(R.string.string_all);
                mIsFilteredMap = true;
                setmUsageAppData(mUsageAppData);
            }
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

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

@Override
public void onPromptFinished() {
    //In here we only reload things that are updated through prompts

    //reload menu item with new slot
    final MenuItem slotItem = mGameSidebar.getMenu().findItem(R.id.menuItem_set_slot);
    slotItem.setTitle(this.getString(R.string.menuItem_setSlot, mCoreFragment.getSlot()));

    //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, mCoreFragment.getCurrentSpeed()));

    mGameSidebar.reload();/*ww w.j  a v  a  2s.  c  o  m*/
}

From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java

public void openMenu(View view, ParcelableStatus status) {
    mPopupMenu = PopupMenu.getInstance(getActivity(), view);
    mPopupMenu.inflate(R.menu.action_status);
    final int activated_color = getResources().getColor(R.color.holo_blue_bright);
    final boolean click_to_open_menu = mPreferences.getBoolean(PREFERENCE_KEY_CLICK_TO_OPEN_MENU, false);
    final String buffer_authorised = mPreferences.getString(PREFERENCE_KEY_BUFFERAPP_ACCESS_TOKEN, null);
    final Menu menu = mPopupMenu.getMenu();
    final MenuItem itemView = menu.findItem(MENU_VIEW);
    if (itemView != null) {
        itemView.setVisible(click_to_open_menu);
    }// www.ja  va  2  s  .com
    final MenuItem direct_retweet = menu.findItem(MENU_RETWEET);
    if (direct_retweet != null) {
        final Drawable icon = direct_retweet.getIcon().mutate();
        direct_retweet.setVisible(
                (!status.is_protected && status.account_id != status.user_id) || isMyRetweet(status));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, PorterDuff.Mode.MULTIPLY);
            direct_retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            direct_retweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem bufferView = menu.findItem(MENU_ADD_TO_BUFFER);
    if (bufferView != null) {
        if (buffer_authorised != null && !buffer_authorised.equals("")) {
            bufferView.setVisible(true);
        } else {
            bufferView.setVisible(false);
        }
    }
    setMenuForStatus(getActivity(), menu, status);
    mPopupMenu.setOnMenuItemClickListener(this);
    mPopupMenu.show();
}

From source file:org.creativecommons.thelist.misc.MainActivity.java

private void updateMenuTitles() {
    MenuItem switchAccounts = menu.findItem(R.id.switch_accounts);

    if (mCurrentUser.getAccountCount() > 0) {
        switchAccounts.setVisible(false);
        //TODO: uncomment when Switch Accounts works
        //switchAccounts.setTitle("Switch Accounts");
    } else {//from   ww w .j a va 2  s .  co  m
        switchAccounts.setTitle("Add Account");
    }
}

From source file:com.ksharkapps.musicnow.ui.activities.ProfileActivity.java

/**
 * {@inheritDoc}/* w  ww .j a va2s.  co m*/
 */
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    // Theme the add to home screen icon
    // Set the shuffle all title to "play all" if a playlist.
    final MenuItem shuffle = menu.findItem(R.id.menu_shuffle);
    String title = null;
    if (isFavorites() || isLastAdded() || isPlaylist()) {
        title = getString(R.string.menu_play_all);
    } else {
        title = getString(R.string.menu_shuffle);
    }
    shuffle.setTitle(title);
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem drawerMenuItem = menu.findItem(R.id.menu_open_close_drawer);
    if (drawerMenuItem != null) {
        drawerMenuItem.setTitle(drawerLayout.isDrawerOpen(DRAWER_GRAVITY) ? R.string.menu_close_drawer
                : R.string.menu_open_drawer);
    }/*from   www .  ja v  a2s .c  o  m*/
    MenuItem favoritesMenuItem = menu.findItem(R.id.menu_favorites);
    if (favoritesMenuItem != null && tabsAdapter != null && tabsAdapter.getSelectedItem() >= 0) {
        TabModel tab = tabsAdapter.getItem(tabsAdapter.getSelectedItem());
        favoritesMenuItem
                .setTitle(isFavorite(tab) ? R.string.menu_remove_favorites : R.string.menu_add_favorites);
    }
    MenuItem preferencesMenuItem = menu.findItem(R.id.menu_settings);
    MenuItem preferencesSubMenuItem = menu.findItem(R.id.menu_sub_settings);
    try {
        if (MainApplication.getInstance().settings.preferencesSubmenu()) {
            preferencesSubMenuItem.setVisible(true);
            preferencesMenuItem.setVisible(false);
            Menu subMenu = preferencesSubMenuItem.getSubMenu();
            subMenu.findItem(R.id.menu_sub_settings_suspend)
                    .setVisible(MainApplication.getInstance().settings.isAutoupdateEnabled());
            subMenu.findItem(R.id.menu_sub_settings_autoupdate)
                    .setChecked(MainApplication.getInstance().settings.isAutoupdateEnabled());
            subMenu.findItem(R.id.menu_sub_settings_maskpictures)
                    .setChecked(MainApplication.getInstance().settings.maskPictures());
        } else {
            preferencesMenuItem.setVisible(true);
            preferencesSubMenuItem.setVisible(false);
        }
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    return super.onPrepareOptionsMenu(menu);
}