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:net.reichholf.dreamdroid.fragment.ServiceListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (getMultiPaneHandler().isDrawerOpen())
        return;//from w w  w  .  j a va 2s  .  c  o m

    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:com.acrylicgoat.scrumnotes.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();//  w ww  .ja v  a2  s  .c  o  m
    getMenuInflater().inflate(R.menu.activity_main, menu);
    readDB();
    if (devs != null && devs.size() > 0) {
        for (int i = 0; i < devs.size(); i++) {
            Developer dev = (Developer) devs.get(i);
            menu.add(0, MENUITEM, 0, dev.getName());

        }
    }
    boolean drawerOpen = drawerLayout.isDrawerOpen(drawerList);
    menu.findItem(R.id.save).setVisible(!drawerOpen);
    return true;
}

From source file:com.nadmm.airports.DownloadActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.menu_download).setEnabled(false);
    Cursor c = mDbManager.getCurrentFromCatalog();
    boolean enabled = c.moveToFirst();
    c.close();/*from   w  ww  .j a v a  2s  .c om*/
    menu.findItem(R.id.menu_search).setEnabled(enabled);

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.android.contacts.activities.ContactDetailActivity.java

public void setAssociationMenu(Menu menu, boolean fromOptionsMenu) {
    if (fromOptionsMenu) {
        MenuItem associationMenuItem = menu.findItem(R.id.menu_association_sim);
        if (associationMenuItem != null) {
            /*//from  w  w w . j a v  a2 s  .  c o m
             * Bug Fix by Mediatek Begin.
             *   Original Android's code:
             *     if (isHasPhoneItem()) { 
             *   CR ID: ALPS00116397
             */
            if (SlotUtils.isGeminiEnabled() && isHasPhoneItem() && !isMe()) {
                /*
                 * Bug Fix by Mediatek End.
                 */
                int simInfoSize = SIMInfoWrapper.getDefault().getInsertedSimCount();

                associationMenuItem.setVisible(!this.mContactData.isDirectoryEntry());
                associationMenuItem.setEnabled(simInfoSize > 0);
            } else {
                associationMenuItem.setVisible(false);
            }
        }

    }
}

From source file:com.android.contacts.activities.ContactDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem starredMenuItem = menu.findItem(R.id.menu_star);
    /*//from  w w  w .  j  av  a  2s. com
     * Bug Fix by Mediatek Begin.
     *   Original Android's code:
            
    starredMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
        // Toggle "starred" state
        // Make sure there is a contact
        if (mLookupUri != null) {
            // Read the current starred value from the UI instead of using the last
            // loaded state. This allows rapid tapping without writing the same
            // value several times
            final boolean isStarred = starredMenuItem.isChecked();
            
            // To improve responsiveness, swap out the picture (and tag) in the UI already
            ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
                    mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
                    !isStarred);
            
            // Now perform the real save
            Intent intent = ContactSaveService.createSetStarredIntent(
                    ContactDetailActivity.this, mLookupUri, !isStarred);
            ContactDetailActivity.this.startService(intent);
        }
        return true;
    }
    });
    // If there is contact data, update the starred state
    if (mContactData != null) {
    ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
            mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
            mContactData.getStarred());
    }
     *   CR ID: ALPS00115684
     */
    if (this.mContactData != null && this.mContactData.getIndicate() < 0) {

        starredMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // Toggle "starred" state
                // Make sure there is a contact
                if (mLookupUri != null) {
                    // Read the current starred value from the UI instead of using the last
                    // loaded state. This allows rapid tapping without writing the same
                    // value several times
                    final boolean isStarred = starredMenuItem.isChecked();

                    // To improve responsiveness, swap out the picture (and tag) in the UI already
                    ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
                            mContactData.isDirectoryEntry(), mContactData.isUserProfile(), !isStarred);

                    // Now perform the real save
                    Intent intent = ContactSaveService.createSetStarredIntent(ContactDetailActivity.this,
                            mLookupUri, !isStarred);
                    ContactDetailActivity.this.startService(intent);
                }
                return true;
            }
        });
        ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(),
                mContactData.isUserProfile(), mContactData.getStarred());
    } else {
        Log.i(TAG, "it is sim contact");
        starredMenuItem.setVisible(false);
    }
    /*
     * Bug Fix by Mediatek End.
     */

    /*
     * New Feature by Mediatek Begin. set this if show new association menu
     */
    setAssociationMenu(menu, true);
    /*
     * New Feature by Mediatek End.
     */

    return true;
}

From source file:cgeo.geocaching.cgeocaches.java

private static void setVisible(final Menu menu, final int itemId, final boolean visible) {
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        item.setVisible(visible);//from w  w w. j a  v  a  2  s .c o m
    }
}

From source file:com.odoo.addons.sale.SalesDetail.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_sale_detail, menu);
    OField name = (OField) mForm.findViewById(R.id.fname);
    name.setEditable(false);/*from  w w  w  .j a va  2  s .com*/
    if (extra != null && !extra.getString("type").equals(Type.SaleOrder.toString())) {
        // Operation on Sale Order
    } else {
        menu.findItem(R.id.menu_sale_save).setVisible(false);
        menu.findItem(R.id.menu_sale_confirm_sale).setVisible(false);
    }
    if (extra != null && record != null && record.getString("state").equals("cancel")) {
        menu.findItem(R.id.menu_sale_save).setVisible(true).setTitle("Copy Quotation");
        menu.findItem(R.id.menu_sale_detail_more).setVisible(false);
        mForm.setEditable(true);
    } else {
        menu.findItem(R.id.menu_sale_detail_more).setVisible(false);
        menu.findItem(R.id.menu_sale_new_copy_of_quotation).setVisible(false);
    }
    if (extra == null || !extra.containsKey(OColumn.ROW_ID)) {
        menu.findItem(R.id.menu_sale_save).setVisible(true);
        menu.findItem(R.id.menu_sale_detail_more).setVisible(false);
    }
    return true;
}

From source file:br.com.bioscada.apps.biotracks.TrackListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.track_list, menu);

    menu.findItem(R.id.track_list_help_feedback).setTitle(
            ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable() ? R.string.menu_help_feedback
                    : R.string.menu_help);

    searchMenuItem = menu.findItem(R.id.track_list_search);
    ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem, trackController);

    startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
    playMultipleItem = menu.findItem(R.id.track_list_play_mutliple);
    syncNowMenuItem = menu.findItem(R.id.track_list_sync_now);
    aggregatedStatisticsMenuItem = menu.findItem(R.id.track_list_aggregated_statistics);
    exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
    importAllMenuItem = menu.findItem(R.id.track_list_import_all);
    deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.android.contacts.activities.ContactSelectionActivity.java

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

    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_menu, menu);

    final MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchItem.setVisible(!mIsSearchMode && mIsSearchSupported);

    final Drawable searchIcon = searchItem.getIcon();
    if (searchIcon != null) {
        searchIcon.mutate().setColorFilter(ContextCompat.getColor(this, R.color.actionbar_icon_color),
                PorterDuff.Mode.SRC_ATOP);
    }//from   w  ww  .j  a  va2  s  .  c  o  m
    return true;
}

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

public void configureToolbar() {
    mToolbar.setOnMenuItemClickListener(this);
    Menu menu = mToolbar.getMenu();
    // Switch on or off rebuild/empty/custom study depending on whether or not filtered deck
    if (getCol().getDecks().isDyn(getCol().getDecks().selected())) {
        menu.findItem(R.id.action_rebuild).setVisible(true);
        menu.findItem(R.id.action_empty).setVisible(true);
        menu.findItem(R.id.action_custom_study).setVisible(false);
    } else {/*w  w  w .j av  a 2  s  . c  o  m*/
        menu.findItem(R.id.action_rebuild).setVisible(false);
        menu.findItem(R.id.action_empty).setVisible(false);
        menu.findItem(R.id.action_custom_study).setVisible(true);
    }
    // Don't show custom study icon if congrats shown
    if (mCurrentContentView == CONTENT_CONGRATS) {
        menu.findItem(R.id.action_custom_study).setVisible(false);
    }
    // Switch on rename / delete / export if tablet layout
    if (mFragmented) {
        menu.findItem(R.id.action_rename).setVisible(true);
        menu.findItem(R.id.action_delete).setVisible(true);
        menu.findItem(R.id.action_export).setVisible(true);
    } else {
        menu.findItem(R.id.action_rename).setVisible(false);
        menu.findItem(R.id.action_delete).setVisible(false);
        menu.findItem(R.id.action_export).setVisible(false);
    }
    // Switch on or off unbury depending on if there are cards to unbury
    menu.findItem(R.id.action_unbury).setVisible(getCol().getSched().haveBuried());
    // Switch on or off undo depending on whether undo is available
    if (!getCol().undoAvailable()) {
        menu.findItem(R.id.action_undo).setVisible(false);
    } else {
        menu.findItem(R.id.action_undo).setVisible(true);
        Resources res = AnkiDroidApp.getAppResources();
        menu.findItem(R.id.action_undo)
                .setTitle(res.getString(R.string.studyoptions_congrats_undo, getCol().undoName(res)));
    }
    // Set the back button listener
    if (!mFragmented) {
        mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((AnkiActivity) getActivity()).finishWithAnimation(ActivityTransitionAnimation.RIGHT);
            }
        });
    }
}