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:com.grarak.kerneladiutor.activities.NavigationActivity.java

private void appendFragments(boolean setShortcuts) {
    sActualFragments.clear();//from  www.ja  v  a 2 s  . c o  m
    Menu menu = mNavigationView.getMenu();
    menu.clear();

    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;

        Drawable drawable = ContextCompat.getDrawable(this,
                Utils.DONATED && Prefs.getBoolean("section_icons", false, this)
                        && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable
                                : R.drawable.ic_blank);

        if (fragment == null) {
            lastSubMenu = menu.addSubMenu(id);
            sActualFragments.put(id, null);
        } else if (Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) : lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(drawable);
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            sActualFragments.put(id, fragment);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();

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

    // Share button support
    MenuItem share = menu.findItem(R.id.shareButton);

    boolean visible = false;
    if (chat != null) {
        final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()).getMultiJaxmpp()
                .get(chat.getSessionObject());
        try {/*  w  ww .ja v a 2 s  .c  o  m*/
            JID jid = chat.getJid();

            if (jid.getResource() == null) {
                jid = FileTransferUtility.getBestJidForFeatures(jaxmpp, jid.getBareJid(),
                        FileTransferUtility.FEATURES);
            }

            if (jid != null) {
                visible = FileTransferUtility.resourceContainsFeatures(jaxmpp, jid,
                        FileTransferUtility.FEATURES);
            }
        } catch (XMLException e) {
        }
    } else {
        Log.v(TAG, "no chat for fragment");
    }
    share.setVisible(visible);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.mifos.mifosxdroid.online.clientdetails.ClientDetailsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    if (isClientActive) {
        menu.add(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_CLIENTS_NAME);
        menu.add(Menu.NONE, MENU_ITEM_PIN_POINT, Menu.NONE, getString(R.string.pinpoint));
        menu.add(Menu.NONE, MENU_ITEM_CLIENT_CHARGES, Menu.NONE, getString(R.string.charges));
        menu.add(Menu.NONE, MENU_ITEM_ADD_SAVINGS_ACCOUNT, Menu.NONE, getString(R.string.savings_account));
        menu.add(Menu.NONE, MENU_ITEM_ADD_LOAN_ACCOUNT, Menu.NONE, getString(R.string.add_loan));
        menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getString(R.string.documents));
        menu.add(Menu.NONE, MENU_ITEM_IDENTIFIERS, Menu.NONE, getString(R.string.identifiers));
        menu.add(Menu.NONE, MENU_ITEM_SURVEYS, Menu.NONE, getString(R.string.survey));
    }//  w w  w . j a  v a  2  s . c om
    super.onPrepareOptionsMenu(menu);
}

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

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    getMenuInflater().inflate(R.menu.traffic, menu);

    if (showCameras) {
        menu.getItem(0).setTitle("Hide Cameras");
    } else {//from  w  w  w.  ja  va 2  s.c  om
        menu.getItem(0).setTitle("Show Cameras");
    }

    /**
     * Check if current location is within a lat/lon bounding box surrounding
     * the greater Seattle area.
     */
    try {
        LatLng center = map.getCameraPosition().target;

        if (inPolygon(seattleArea, center.latitude, center.longitude)) {
            MenuItem menuItem_Alerts = menu.add(0, MENU_ITEM_SEATTLE_ALERTS, menu.size(), "Seattle Alerts")
                    .setIcon(R.drawable.ic_menu_alerts);

            MenuItemCompat.setShowAsAction(menuItem_Alerts,
                    MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);

            MenuItem menuItem_Lanes = menu.add(0, MENU_ITEM_EXPRESS_LANES, menu.size(), "Express Lanes");
            MenuItemCompat.setShowAsAction(menuItem_Lanes, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        }

    } catch (NullPointerException e) {
        Log.e(TAG, "Error getting LatLng center");
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();

    if (showOperationsMenu) {
        MenuItem mi = menu.add(Menu.NONE, R.id.menu_notifications, Menu.FIRST, R.string.notifications);
        mi.setIcon(R.drawable.ic_events_dark);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }/* w  w w.ja  v  a2 s.  c o  m*/
}

From source file:com.activiti.android.ui.fragments.task.form.TaskFormFoundationFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (getVersionNumber() >= ActivitiVersionNumber.VERSION_1_2_2 && !isEnded) {
        if (!DisplayUtils.hasCentralPane(getActivity())) {
            menu.clear();
            inflater.inflate(R.menu.task_form, menu);
        } else {/* w  ww  . java2 s .co  m*/
            getToolbar().getMenu().clear();
            getToolbar().inflateMenu(R.menu.task_form);
            // Set an OnMenuItemClickListener to handle menu item clicks
            getToolbar().setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    return onOptionsItemSelected(item);
                }
            });

        }
    }
}

From source file:org.kde.kdeconnect.UserInterface.DeviceFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    //Log.e("DeviceFragment", "onPrepareOptionsMenu");

    super.onPrepareOptionsMenu(menu);
    menu.clear();

    if (device == null) {
        return;// ww  w  .j a  va 2 s . co m
    }

    //Plugins button list
    final Collection<Plugin> plugins = device.getLoadedPlugins().values();
    for (final Plugin p : plugins) {
        if (!p.displayInContextMenu()) {
            continue;
        }
        menu.add(p.getActionName()).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                p.startMainActivity(mActivity);
                return true;
            }
        });
    }

    menu.add(R.string.device_menu_plugins).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Intent intent = new Intent(mActivity, SettingsActivity.class);
            intent.putExtra("deviceId", mDeviceId);
            startActivity(intent);
            return true;
        }
    });

    if (device.isPaired() && device.isReachable()) {

        menu.add(R.string.encryption_info_title)
                .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        Context context = mActivity;
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setTitle(context.getResources().getString(R.string.encryption_info_title));
                        builder.setPositiveButton(context.getResources().getString(R.string.ok),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.dismiss();
                                    }
                                });

                        if (device.certificate == null) {
                            builder.setMessage(R.string.encryption_info_msg_no_ssl);
                        } else {
                            builder.setMessage(context.getResources().getString(R.string.my_device_fingerprint)
                                    + "\n" + SslHelper.getCertificateHash(SslHelper.certificate) + "\n\n"
                                    + context.getResources().getString(R.string.remote_device_fingerprint)
                                    + "\n" + SslHelper.getCertificateHash(device.certificate));
                        }
                        builder.create().show();
                        return true;
                    }
                });
    }

    if (device.isPaired()) {

        menu.add(R.string.device_menu_unpair)
                .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        //Remove listener so buttons don't show for a while before changing the view
                        device.removePluginsChangedListener(pluginsChangedListener);
                        device.removePairingCallback(pairingCallback);
                        device.unpair();
                        mActivity.onDeviceSelected(null);
                        return true;
                    }
                });
    }

}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.track.TrackListingFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    /*//from   w  w w.  j  a  v  a2s.  c  o m
     * menu.clear(); MenuItem item = menu.add(Menu.CATEGORY_SYSTEM,
     * R.id.map_view, Menu.NONE, R.string.map_view);
     * item.setIcon(R.drawable.ic_map);
     * item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
     */
    menu.clear();
    getActivity().getMenuInflater().inflate(R.menu.list_menu, menu);

    if (category == null) {
        category = (getArguments() != null) ? getArguments().getString(SearchFragment.ARG_CATEGORY) : null;
    }

    super.onPrepareOptionsMenu(menu);
}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.info.InfoListingFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    /*/*from   ww w .j  ava  2  s.  c  o m*/
     * menu.clear(); MenuItem item = menu.add(Menu.CATEGORY_SYSTEM,
     * R.id.map_view, Menu.NONE, R.string.map_view);
     * item.setIcon(R.drawable.ic_map);
     * item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
     */
    menu.clear();
    getActivity().getMenuInflater().inflate(R.menu.list_menu, menu);
    menu.getItem(0).setVisible(false);// hide show on map
    if (category == null) {
        category = (getArguments() != null) ? getArguments().getString(SearchFragment.ARG_CATEGORY) : null;
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:com.facebook.samples.rps.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // only add the menu when the selection fragment is showing
    if (fragments[RPS].isVisible()) {
        if (menu.size() == 0) {
            share = menu.add(R.string.share_on_facebook);
            message = menu.add(R.string.send_with_messenger);
            friends = menu.add(R.string.see_friends);
            settings = menu.add(R.string.check_settings);
        }/*from  w w w .  j ava2  s . c  om*/
        return true;
    } else {
        menu.clear();
        settings = null;
    }
    return false;
}