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.chuhan.privatecalc.fragment.os.FragmentActivity.java

/**
 * Dispatch onPrepareOptionsMenu() to fragments.
 *//*from  ww w . ja  v  a  2 s  .  c  om*/
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
        if (mOptionsMenuInvalidated) {
            mOptionsMenuInvalidated = false;
            menu.clear();
            onCreatePanelMenu(featureId, menu);
        }
        boolean goforit = super.onPreparePanel(featureId, view, menu);
        goforit |= mFragments.dispatchPrepareOptionsMenu(menu);
        return goforit && menu.hasVisibleItems();
    }
    return super.onPreparePanel(featureId, view, menu);
}

From source file:com.tencent.tws.assistant.support.v4.app.TwsFragmentActivity.java

/**
 * Dispatch onPrepareOptionsMenu() to fragments.
 *///  w  ww.ja v a  2s .  c  o m
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
        if (mOptionsMenuInvalidated) {
            mOptionsMenuInvalidated = false;
            menu.clear();
            onCreatePanelMenu(featureId, menu);
        }
        boolean goforit = onPrepareOptionsPanel(view, menu);
        goforit |= mFragments.dispatchPrepareOptionsMenu(menu);
        return goforit;
    }
    return super.onPreparePanel(featureId, view, menu);
}

From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java

/**
 * This menu contains back, forward and refresh buttons.
 *
 * @param menu/*  ww  w .ja v  a2s  .c  o  m*/
 * @return true if there are no an exception while preparing, false otherwise
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    try {
        menu.clear();
        MenuItem itemBack = menu.add("");
        itemBack.setIcon(R.drawable.romanblack_html_menu_back);
        itemBack.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goBack();
                return true;
            }
        });
        if (!webView.canGoBack()) {
            itemBack.setEnabled(false);
        }

        MenuItem itemRefresh = menu.add("");
        itemRefresh.setIcon(R.drawable.romanblack_html_menu_refresh);
        itemRefresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.reload();
                return true;
            }
        });
        if ("".equals(currentUrl) || "about:blank".equals(currentUrl)) {
            itemRefresh.setEnabled(false);
        }

        MenuItem itemForward = menu.add("");
        itemForward.setIcon(R.drawable.romanblack_html_menu_forward);
        itemForward.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goForward();
                return true;
            }
        });
        if (!webView.canGoForward()) {
            itemForward.setEnabled(false);
        }

        return true;

    } catch (Exception ex) {
        return false;
    }
}

From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.global, menu);
    MenuItem item = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    item.setVisible(false);/*from ww w.j  a  v  a 2s.c  om*/
    log.setVisible(true);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false);
    SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered

            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (searchMenuItem != null) {
                searchMenuItem.collapseActionView();
                // this is your adapter that will be filtered
                if (mLeDeviceListAdapter != null) {
                    searchEnabled = true;
                    searchDeviceList(query);
                }
            }
            return false;

        }
    };
    searchView.setOnQueryTextListener(textChangeListener);
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.navitproject.navit.Navit.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //Log.e("Navit","onPrepareOptionsMenu");
    // this gets called every time the menu is opened!!
    // change menu items here!
    menu.clear();

    // group-id,item-id,sort order number
    //menu.add(1, 1, 100, getString(R.string.optionsmenu_zoom_in)); //TRANS
    //menu.add(1, 2, 200, getString(R.string.optionsmenu_zoom_out)); //TRANS

    menu.add(1, 3, 300, getString(R.string.optionsmenu_download_maps)); //TRANS
    menu.add(1, 5, 400, getString(R.string.optionsmenu_toggle_poi)); //TRANS

    menu.add(1, 6, 500, getString(R.string.optionsmenu_address_search)); //TRANS
    menu.add(1, 10, 600, getString(R.string.optionsmenu_set_map_location));

    menu.add(1, 99, 900, getString(R.string.optionsmenu_exit_navit)); //TRANS

    /* Only show the Backup to SD-Card Option if we really have one */
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
        menu.add(1, 7, 700, getString(R.string.optionsmenu_backup_restore)); //TRANS

    return true;/*  w  w w  . ja va  2  s  .co  m*/
}

From source file:app.umitems.greenclock.DeskClock.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // We only want to show it as a menu in landscape, and only for clock/alarm fragment.
    mMenu = menu;//from w  ww .j a v a2  s . c  o m
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (mActionBar.getSelectedNavigationIndex() == ALARM_TAB_INDEX
                || mActionBar.getSelectedNavigationIndex() == CLOCK_TAB_INDEX) {
            // Clear the menu so that it doesn't get duplicate items in case onCreateOptionsMenu
            // was called multiple times.
            menu.clear();
            getMenuInflater().inflate(R.menu.desk_clock_menu, menu);
        }
        // Always return true for landscape, regardless of whether we've inflated the menu, so
        // that when we switch tabs this method will get called and we can inflate the menu.
        return true;
    }
    return false;
}

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    menu.clear();
    getMenuInflater().inflate(R.menu.menu_home, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaGalleryFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    menu.clear();
    // Add Menu Button
    mUpdateItem = menu.add(R.string.theta_update);
    if (mDevice != null) {
        mUpdateItem.setVisible(true);// w  ww  .  j ava 2s . c om
    } else {
        mUpdateItem.setVisible(false);
    }
    mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    mUpdateItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            if (item.getTitle().equals(mUpdateItem.getTitle())) {
                ShootingModeGetTask mode = new ShootingModeGetTask();
                mDownloadTask = new DownloadThetaDataTask();
                mDownloadTask.execute(mode);
            }
            return true;
        }
    });
}

From source file:org.openremote.android.console.GroupActivity.java

/**
 * If there have global or local tabbar, create and update menu before the menu is shown.
 * /*from  w w  w  .  java2 s.  com*/
 * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu)
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (currentGroupView == null || currentGroupView.getGroup() == null) {
        return true;
    }
    TabBar tabBar = currentGroupView.getGroup().getTabBar();
    if (tabBar == null) {
        tabBar = XMLEntityDataBase.globalTabBar;
    }
    if (tabBar != null && tabBar.getTabBarItems().size() > 0) {
        menu.clear();
        ArrayList<TabBarItem> items = tabBar.getTabBarItems();
        int itemSize = items.size();
        for (int i = 0; i < itemSize; i++) {
            MenuItem menuItem = menu.add(0, i, i, items.get(i).getName());
            if (items.get(i).getImage() != null) {
                menuItem.setIcon(ImageUtil
                        .createFromPathQuietly(Constants.FILE_FOLDER_PATH + items.get(i).getImage().getSrc()));
            }
            final Navigate navigate = items.get(i).getNavigate();
            if (navigate != null) {
                menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        handleNavigate(navigate);
                        return true;
                    }

                });
            }
        }
    }
    return true;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.MessagesActivity.java

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

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

    if (mUser != null) {

        ((MenuItem) menu.findItem(R.id.configure_groups)).setVisible(false);
    } else if (mGroup != null) {
        if (mGroup.getPhone().equals(ConstantKeys.STRING_DEFAULT)) {
            inflater.inflate(R.menu.messages_list_no_phone_menu, menu);
        } else {// w  w w.  j  av  a2 s.  c o m
            inflater.inflate(R.menu.messages_list_with_phone_menu, menu);
        }

        if (!mGroup.isAdmin()) {
            ((MenuItem) menu.findItem(R.id.configure_groups)).setVisible(false);
        } else {
            ((MenuItem) menu.findItem(R.id.configure_groups)).setVisible(true);
        }
    }

    if ((timeline != null) && (timeline.getState().equals(State.DISABLED))) {
        menu.clear();
    }

    mMenu = menu;

    return true;
}