Example usage for android.view Menu clear

List of usage examples for android.view Menu clear

Introduction

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

Prototype

public void clear();

Source Link

Document

Remove all existing items from the menu, leaving it empty as if it had just been created.

Usage

From source file:org.tigase.mobile.TigaseMobileMessengerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (getCurrentPage() == 0 || getCurrentPage() == 1 || helper.isXLarge()) {
        MenuInflater inflater = getMenuInflater();
        Log.v(TAG, "current page " + getCurrentPage());
        Log.v(TAG, "xlarge = " + helper.isXLarge());
        final boolean serviceActive = JaxmppService.isServiceActive();

        menu.clear();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            inflater.inflate(R.menu.main_menu_old, menu);
        } else {// ww  w.j  a va 2 s . c  o  m
            inflater.inflate(R.menu.main_menu, menu);
        }

        MenuItem con = menu.findItem(R.id.connectButton);
        con.setVisible(!serviceActive);

        MenuItem dcon = menu.findItem(R.id.disconnectButton);
        dcon.setVisible(serviceActive);

        MenuItem showOffline = menu.findItem(R.id.showHideOffline);
        showOffline.setCheckable(true);
        showOffline.setChecked(mPreferences.getBoolean(Preferences.SHOW_OFFLINE, Boolean.TRUE));

        MenuItem add = menu.findItem(R.id.contactAdd);
        helper.setShowAsAction(add, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        add.setVisible(serviceActive);

        MenuItem bookmarks = menu.findItem(R.id.bookmarksShow);
        if (bookmarks != null) {
            bookmarks.setVisible(serviceActive);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.tingtingapps.securesms.ConversationActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = this.getMenuInflater();
    menu.clear();

    if (isSingleConversation() && isEncryptedConversation) {
        inflater.inflate(R.menu.conversation_secure_identity, menu);
        inflater.inflate(R.menu.conversation_secure_sms, menu.findItem(R.id.menu_security).getSubMenu());
    } else if (isSingleConversation()) {
        inflater.inflate(R.menu.conversation_insecure, menu);
    }//from  w  ww. j  a  va  2s  . c om

    if (isSingleConversation()) {
        inflater.inflate(R.menu.conversation_callable, menu);
    } else if (isGroupConversation()) {
        inflater.inflate(R.menu.conversation_group_options, menu);

        if (!isPushGroupConversation()) {
            inflater.inflate(R.menu.conversation_mms_group_options, menu);
            if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
                menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
            } else {
                menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
            }
        } else if (isActiveGroup()) {
            inflater.inflate(R.menu.conversation_push_group_options, menu);
        }
    }

    inflater.inflate(R.menu.conversation, menu);

    if (recipients != null && recipients.isMuted())
        inflater.inflate(R.menu.conversation_muted, menu);
    else
        inflater.inflate(R.menu.conversation_unmuted, menu);

    if (isSingleConversation() && getRecipients().getPrimaryRecipient().getContactUri() == null) {
        inflater.inflate(R.menu.conversation_add_to_contacts, menu);
    }

    super.onPrepareOptionsMenu(menu);
    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.node.browser.DocumentFolderBrowserFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (!MenuFragmentHelper.canDisplayFragmentMenu(getActivity())) {
        return;//from   w  ww . j a  v a  2s.c  o m
    }
    menu.clear();
    getMenu(menu);
}

From source file:org.smssecure.smssecure.ConversationActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = this.getMenuInflater();
    menu.clear();

    if (isSingleConversation() && isEncryptedConversation) {
        inflater.inflate(R.menu.conversation_secure_identity, menu);
        inflater.inflate(R.menu.conversation_secure_sms, menu.findItem(R.id.menu_security).getSubMenu());
    } else if (isSingleConversation()) {
        inflater.inflate(R.menu.conversation_insecure_no_push, menu);
        inflater.inflate(R.menu.conversation_insecure, menu);
    }/*from   w w  w .jav a2s  .  c o m*/

    if (isSingleConversation()) {
        inflater.inflate(R.menu.conversation_callable, menu);
    } else if (isGroupConversation()) {
        inflater.inflate(R.menu.conversation_group_options, menu);

        if (!isPushGroupConversation()) {
            inflater.inflate(R.menu.conversation_mms_group_options, menu);
            if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
                menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
            } else {
                menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
            }
        }
    }

    inflater.inflate(R.menu.conversation, menu);

    if (recipients != null && recipients.isMuted())
        inflater.inflate(R.menu.conversation_muted, menu);
    else
        inflater.inflate(R.menu.conversation_unmuted, menu);

    if (isSingleConversation() && getRecipients().getPrimaryRecipient().getContactUri() == null) {
        inflater.inflate(R.menu.conversation_add_to_contacts, menu);
    }

    if (archived)
        menu.findItem(R.id.menu_archive_conversation)
                .setTitle(R.string.conversation__menu_unarchive_conversation);

    super.onPrepareOptionsMenu(menu);
    return true;
}

From source file:org.fdroid.fdroid.AppDetails.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.clear();
    if (app == null) {
        return true;
    }// w w w  .jav a 2s. co  m

    if (packageManager.getLaunchIntentForPackage(app.packageName) != null && app.canAndWantToUpdate()) {
        MenuItemCompat.setShowAsAction(
                menu.add(Menu.NONE, LAUNCH, 1, R.string.menu_launch).setIcon(R.drawable.ic_play_arrow_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    if (app.isInstalled()) {
        MenuItemCompat.setShowAsAction(
                menu.add(Menu.NONE, UNINSTALL, 1, R.string.menu_uninstall).setIcon(R.drawable.ic_delete_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    MenuItemCompat.setShowAsAction(
            menu.add(Menu.NONE, SHARE, 1, R.string.menu_share).setIcon(R.drawable.ic_share_white),
            MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all).setIcon(R.drawable.ic_do_not_disturb_white)
            .setCheckable(true).setChecked(app.ignoreAllUpdates);

    if (app.hasUpdates()) {
        menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this)
                .setIcon(R.drawable.ic_do_not_disturb_white).setCheckable(true)
                .setChecked(app.ignoreThisUpdate >= app.suggestedVersionCode);
    }

    // Ignore on devices without Bluetooth
    if (app.isInstalled() && fdroidApp.bluetoothAdapter != null) {
        menu.add(Menu.NONE, SEND_VIA_BLUETOOTH, 3, R.string.send_via_bluetooth)
                .setIcon(R.drawable.ic_bluetooth_white);
    }
    return true;
}

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

/**
 * Set up the App bar menu//from  w  ww.  j  a  v a 2  s  .  c o m
 *
 * Loop through all menu items, checking ID for set up.
 * We do it this way because item indices aren't set since the menu is dynamic.
 * (ex. travel charts may be added to the start)
 *
 * @param menu
 * @return
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    getMenuInflater().inflate(R.menu.traffic, menu);

    if (bestTimesAvailable) {
        menu.add(0, R.id.best_times_to_travel, 0, "Best Times to Travel").setIcon(R.drawable.ic_menu_chart)
                .setActionView(R.layout.action_bar_notification_icon)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        final MenuItem chartMenuItem = menu.findItem(R.id.best_times_to_travel);
        // Since we added an action view, need to hook up the onclick ourselves.
        chartMenuItem.getActionView()
                .setOnClickListener(v -> TrafficMapActivity.this.onMenuItemSelected(0, chartMenuItem));
        menu_item_refresh = 2;
    } else {
        menu_item_refresh = 1;
    }

    for (int i = 0; i < menu.size(); i++) {
        switch (menu.getItem(i).getItemId()) {
        case R.id.toggle_cameras:
            if (showCameras) {
                menu.getItem(i).setTitle("Hide Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam);
            } else {
                menu.getItem(i).setTitle("Show Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam_off);
            }
            break;
        default:
            break;
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.jtechme.apphub.AppDetailsData.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.clear();
    if (app == null)
        return true;

    if (mPm.getLaunchIntentForPackage(app.packageName) != null && app.canAndWantToUpdate()) {
        MenuItemCompat.setShowAsAction(/* ww w.jav  a  2  s  .com*/
                menu.add(Menu.NONE, LAUNCH, 1, R.string.menu_launch).setIcon(R.drawable.ic_play_arrow_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    if (app.isInstalled()) {
        MenuItemCompat.setShowAsAction(
                menu.add(Menu.NONE, UNINSTALL, 1, R.string.menu_uninstall).setIcon(R.drawable.ic_delete_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    MenuItemCompat.setShowAsAction(
            menu.add(Menu.NONE, SHARE, 1, R.string.menu_share).setIcon(R.drawable.ic_share_white),
            MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all).setIcon(R.drawable.ic_do_not_disturb_white)
            .setCheckable(true).setChecked(app.ignoreAllUpdates);

    if (app.hasUpdates()) {
        menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this)
                .setIcon(R.drawable.ic_do_not_disturb_white).setCheckable(true)
                .setChecked(app.ignoreThisUpdate >= app.suggestedVercode);
    }

    // Ignore on devices without Bluetooth
    if (app.isInstalled() && fdroidApp.bluetoothAdapter != null) {
        menu.add(Menu.NONE, SEND_VIA_BLUETOOTH, 3, R.string.send_via_bluetooth)
                .setIcon(R.drawable.ic_bluetooth_white);
    }
    return true;
}

From source file:org.cobaltians.cobalt.activities.CobaltActivity.java

private void setupOptionsMenu(Menu menu, String color, JSONArray actions) {
    ActionBar actionBar = getSupportActionBar();
    // TODO: use LinearLayout for bottomBar instead to handle groups
    //LinearLayout bottomBar = (LinearLayout) findViewById(getBottomBarId());
    BottomBar bottomBar = (BottomBar) findViewById(getBottomBarId());

    // TODO: make bars more flexible
    if (actionBar == null || bottomBar == null) {
        if (Cobalt.DEBUG) {
            Log.w(Cobalt.TAG, TAG/*from  w  w w.jav  a  2s.c o m*/
                    + " - setupOptionsMenu: activity does not have an action bar and/or does not contain a bottom bar.");
        }
        return;
    }

    Menu bottomMenu = bottomBar.getMenu();

    menu.clear();
    bottomMenu.clear();

    int actionId = 0;
    int menuItemsAddedToTop = 0;
    int menuItemsAddedToOverflow = 0;
    int menuItemsAddedToBottom = 0;

    int length = actions.length();
    for (int i = 0; i < length; i++) {
        try {
            JSONObject action = actions.getJSONObject(i);
            String position = action.getString(Cobalt.kActionPosition); // must be "top", "bottom", "overflow"
            JSONArray groupActions = action.optJSONArray(Cobalt.kActionActions);

            Menu addToMenu = menu;
            int order;

            switch (position) {
            case Cobalt.kPositionTop:
                order = menuItemsAddedToTop++;
                break;
            case Cobalt.kPositionOverflow:
                order = menuItemsAddedToOverflow++;
                break;
            case Cobalt.kPositionBottom:
                order = menuItemsAddedToBottom++;
                addToMenu = bottomMenu;
                // TODO find a way to add same space between each actionViewItem
                /*MenuItem spaceMenuItem = addToMenu.add(Menu.NONE, Menu.NONE, order++, "");
                MenuItemCompat.setShowAsAction(spaceMenuItem, MenuItem.SHOW_AS_ACTION_ALWAYS);
                spaceMenuItem.setVisible(true);
                spaceMenuItem.setEnabled(false);*/
                break;
            default:
                throw new JSONException("androidPosition attribute must be top, overflow or bottom.");
            }

            if (groupActions != null) {
                addGroup(addToMenu, order, groupActions, actionId, position, color);
            } else {
                addMenuItem(addToMenu, order, action, actionId++, position, color);
            }
        } catch (JSONException exception) {
            if (Cobalt.DEBUG) {
                Log.w(Cobalt.TAG, TAG + " - setupOptionsMenu: action " + i
                        + " of actions array below is not an object, does not contain a position field or its value is not top, overflow or bottom.\n"
                        + actions.toString());
            }

            exception.printStackTrace();
        }
    }
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    menu.clear();
    if (mIsPickAutoUploadDirectoryMode || mIsPickShareWithDirectoryMode) {
        if (!mPathTracker.isAtRoot()) {
            inflater.inflate(R.menu.options_menu_pick_auto_upload, menu);
        } else {//from  ww  w  . j a va 2  s  . com
            Toast.makeText(this, "Select a folder first.", Toast.LENGTH_SHORT).show();
        }
    } else {
        inflater.inflate(R.menu.options_menu_dashboard, menu);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:org.numixproject.hermes.activity.ConversationActivity.java

/**
 * On options menu requested/*from   ww  w  .ja va2 s  .co m*/
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.clear();

    // Check the menu to display (Server or Conversation)
    if (conversationLayout.getVisibility() == LinearLayout.INVISIBLE) {
        if (server.getStatus() == Status.CONNECTED) {
            // inflate Server options from xml
            MenuInflater inflater = new MenuInflater(this);
            inflater.inflate(R.menu.room_activity, menu);
        } else {
            // inflate Server options from xml
            MenuInflater inflater = new MenuInflater(this);
            inflater.inflate(R.menu.room_activity_disconnected, menu);
        }
    } else {
        // inflate Conversation options from xml
        MenuInflater inflater = new MenuInflater(this);
        inflater.inflate(R.menu.conversations, menu);
    }

    return super.onPrepareOptionsMenu(menu);
}