Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

In this page you can find the example usage for android.view Menu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:jmri.enginedriver.threaded_application.java

public void displayPowerStateMenuButton2(Menu menu) {
    if (prefs.getBoolean("show_layout_power_button_preference", false)) {
        menu.findItem(R.id.power_layout_button).setVisible(true);
    } else {/*from   w  w  w  . j  av  a 2 s .  c o  m*/
        menu.findItem(R.id.power_layout_button).setVisible(false);
    }
}

From source file:jmri.enginedriver.threaded_application.java

public void displayEStop(Menu menu) {
    if (prefs.getBoolean("show_emergency_stop_menu_preference", false)) {
        menu.findItem(R.id.EmerStop).setVisible(true);
    } else {//from  w  w  w .j  a  va  2s. c  o  m
        menu.findItem(R.id.EmerStop).setVisible(false);
    }

}

From source file:biz.bokhorst.xprivacy.ActivityApp.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    boolean accountsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cAccounts,
            null).restricted;/* ww w  .  ja  v a 2  s. co  m*/
    boolean appsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cSystem,
            null).restricted;
    boolean contactsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cContacts,
            null).restricted;

    menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this));
    menu.findItem(R.id.menu_export).setEnabled(mounted);
    menu.findItem(R.id.menu_import).setEnabled(mounted);
    menu.findItem(R.id.menu_accounts).setEnabled(accountsRestricted);
    menu.findItem(R.id.menu_applications).setEnabled(appsRestricted);
    menu.findItem(R.id.menu_contacts).setEnabled(contactsRestricted);

    return super.onPrepareOptionsMenu(menu);
}

From source file:jmri.enginedriver.threaded_application.java

public void displayPowerStateMenuButton(Menu menu) {
    if (prefs.getBoolean("show_layout_power_button_preference", false) && (power_state != null)) {
        menu.findItem(R.id.power_layout_button).setVisible(true);
    } else {//  w  w w  .jav a2 s  .c o  m
        menu.findItem(R.id.power_layout_button).setVisible(false);
    }
}

From source file:jmri.enginedriver.threaded_application.java

public void setPowerStateButton(Menu menu) {
    if (menu != null) {
        if ((power_state == null) || (power_state.equals("2"))) {
            menu.findItem(R.id.power_layout_button).setIcon(R.drawable.power_yellow);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                menu.findItem(R.id.power_layout_button).setTitle("Layout Power is UnKnown");
            }/*from w w w  .  j  a v a2  s. c om*/
        } else if (power_state.equals("1")) {
            menu.findItem(R.id.power_layout_button).setIcon(R.drawable.power_green);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                menu.findItem(R.id.power_layout_button).setTitle("Layout Power is ON");
            }
        } else {
            menu.findItem(R.id.power_layout_button).setIcon(R.drawable.power_red);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                menu.findItem(R.id.power_layout_button).setTitle("Layout Power is Off");
            }
        }
    }
}

From source file:com.ichi2.anki.DeckPicker.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Null check to prevent crash on API23 when we don't have required permission to access db
    if (getCol() == null) {
        return false;
    }/*from  w ww.  ja v a2  s .  c  o m*/
    // Show / hide undo
    if (mFragmented || !getCol().undoAvailable()) {
        menu.findItem(R.id.action_undo).setVisible(false);
    } else {
        Resources res = getResources();
        menu.findItem(R.id.action_undo).setVisible(true);
        String undo = res.getString(R.string.studyoptions_congrats_undo, getCol().undoName(res));
        menu.findItem(R.id.action_undo).setTitle(undo);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (fileOpened && searchResult != null) {
        MenuItem imReplace = menu.findItem(R.id.im_replace);
        MenuItem imReplaceAll = menu.findItem(R.id.im_replace_all);
        MenuItem imPrev = menu.findItem(R.id.im_previous_item);
        MenuItem imNext = menu.findItem(R.id.im_next_item);

        if (imReplace != null)
            imReplace.setVisible(searchResult.canReplaceSomething());

        if (imReplaceAll != null)
            imReplaceAll.setVisible(searchResult.canReplaceSomething());

        if (imPrev != null)
            imPrev.setVisible(searchResult.hasPrevious());

        if (imNext != null)
            imNext.setVisible(searchResult.hasNext());

    } else if (fileOpened) {
        MenuItem imSave = menu.findItem(R.id.im_save);
        MenuItem imUndo = menu.findItem(R.id.im_undo);
        MenuItem imRedo = menu.findItem(R.id.im_redo);

        if (mEditor != null) {
            if (imSave != null)
                imSave.setVisible(mEditor.canSaveFile());
            if (imUndo != null)
                imUndo.setVisible(mEditor.getCanUndo());
            if (imRedo != null)
                imRedo.setVisible(mEditor.getCanRedo());
        } else {//w ww. j a  va2s  .  c  om
            imSave.setVisible(false);
            imUndo.setVisible(false);
            imRedo.setVisible(false);
        }

        MenuItem imMarkdown = menu.findItem(R.id.im_view_markdown);
        boolean isMarkdown = Arrays.asList(MimeTypes.MIME_MARKDOWN)
                .contains(FilenameUtils.getExtension(greatUri.getFileName()));
        if (imMarkdown != null)
            imMarkdown.setVisible(isMarkdown);

        MenuItem imShare = menu.findItem(R.id.im_share);
        if (imMarkdown != null) {
            ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(imShare);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, greatUri.getUri());
            shareIntent.setType("text/plain");
            shareAction.setShareIntent(shareIntent);
        }
    }

    return true;
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // This happens when the user begins to hold down the menu key, so
    // allow them to chord to get a shortcut.
    mCanChord = true;/*from  ww w. j  av a2s .  c  o m*/

    super.onPrepareOptionsMenu(menu);

    MenuItem src, dest;

    menu.findItem(R.id.find_next_menu_id)
            .setVisible(last_search_string != null && last_search_string.length() > 0);

    // Login/Logout
    if (mSettings.isLoggedIn()) {
        menu.findItem(R.id.login_menu_id).setVisible(false);
        menu.findItem(R.id.inbox_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setTitle(
                String.format(getResources().getString(R.string.user_profile), mSettings.getUsername()));
        menu.findItem(R.id.logout_menu_id).setVisible(true);
        menu.findItem(R.id.logout_menu_id)
                .setTitle(String.format(getResources().getString(R.string.logout), mSettings.getUsername()));
    } else {
        menu.findItem(R.id.login_menu_id).setVisible(true);
        menu.findItem(R.id.inbox_menu_id).setVisible(false);
        menu.findItem(R.id.user_profile_menu_id).setVisible(false);
        menu.findItem(R.id.logout_menu_id).setVisible(false);
    }

    // Edit and delete
    if (getOpThingInfo() != null) {
        if (mSettings.getUsername() != null
                && mSettings.getUsername().equalsIgnoreCase(getOpThingInfo().getAuthor())) {
            if (getOpThingInfo().isIs_self())
                menu.findItem(R.id.op_edit_menu_id).setVisible(true);
            else
                menu.findItem(R.id.op_edit_menu_id).setVisible(false);
            menu.findItem(R.id.op_delete_menu_id).setVisible(true);
        } else {
            menu.findItem(R.id.op_edit_menu_id).setVisible(false);
            menu.findItem(R.id.op_delete_menu_id).setVisible(false);
        }
    }

    // Theme: Light/Dark
    src = Util.isLightTheme(mSettings.getTheme()) ? menu.findItem(R.id.dark_menu_id)
            : menu.findItem(R.id.light_menu_id);
    dest = menu.findItem(R.id.light_dark_menu_id);
    dest.setTitle(src.getTitle());

    // Sort
    if (Constants.CommentsSort.SORT_BY_BEST_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_best_menu_id);
    else if (Constants.CommentsSort.SORT_BY_HOT_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_hot_menu_id);
    else if (Constants.CommentsSort.SORT_BY_NEW_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_new_menu_id);
    else if (Constants.CommentsSort.SORT_BY_CONTROVERSIAL_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_controversial_menu_id);
    else if (Constants.CommentsSort.SORT_BY_TOP_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_top_menu_id);
    else if (Constants.CommentsSort.SORT_BY_OLD_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_old_menu_id);
    dest = menu.findItem(R.id.sort_by_menu_id);
    dest.setTitle(src.getTitle());

    return true;
}

From source file:com.dycody.android.idealnote.DetailFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    // Closes search view if left open in List fragment
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    if (searchMenuItem != null) {
        MenuItemCompat.collapseActionView(searchMenuItem);
    }//w w  w.j  a  v  a2 s.  co  m

    boolean newNote = noteTmp.get_id() == null;

    menu.findItem(R.id.menu_checklist_on).setVisible(!noteTmp.isChecklist());
    menu.findItem(R.id.menu_checklist_off).setVisible(noteTmp.isChecklist());
    menu.findItem(R.id.menu_lock).setVisible(!noteTmp.isLocked());
    menu.findItem(R.id.menu_unlock).setVisible(noteTmp.isLocked());
    // If note is trashed only this options will be available from menu
    if (noteTmp.isTrashed()) {
        menu.findItem(R.id.menu_untrash).setVisible(true);
        menu.findItem(R.id.menu_delete).setVisible(true);
        // Otherwise all other actions will be available
    } else {
        menu.findItem(R.id.menu_add_shortcut).setVisible(!newNote);
        menu.findItem(R.id.menu_archive).setVisible(!newNote && !noteTmp.isArchived());
        menu.findItem(R.id.menu_unarchive).setVisible(!newNote && noteTmp.isArchived());
        menu.findItem(R.id.menu_trash).setVisible(!newNote);
    }
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

protected void setupMenuNavigationButtons(MenuInflater inflater, Menu menu, String frameId, boolean edited) {
    inflater.inflate(R.menu.previous_frame, menu);
    inflater.inflate(R.menu.next_frame, menu);
    // we should have already got focus by the time this is called, so can try to disable invalid buttons
    if (frameId != null) {
        NavigationMode navigationAllowed = FrameItem.getNavigationAllowed(getContentResolver(), frameId);
        if (navigationAllowed == NavigationMode.PREVIOUS || navigationAllowed == NavigationMode.NONE) {
            menu.findItem(R.id.menu_next_frame).setEnabled(false);
        }/*from www.j  ava2  s .  c  o m*/
        if (navigationAllowed == NavigationMode.NEXT || navigationAllowed == NavigationMode.NONE) {
            menu.findItem(R.id.menu_previous_frame).setEnabled(false);
        }
    }
    inflater.inflate(R.menu.add_frame, menu);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (edited) {
            inflater.inflate(R.menu.finished_editing, menu);
        } else {
            inflater.inflate(R.menu.back_without_editing, menu);
        }
    }
}