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.android.mms.rcs.FavoriteDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    if (RcsDualSimMananger.getUserIsUseRcsPolicy(FavoriteDetailActivity.this)) {
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
    }/* w ww.  j  ava  2s  . c  o  m*/
    if (!Contact.get(mMsgFrom, false).existsInDatabase()) {
        menu.add(0, MENU_SAVE_TO_CONTACT, 0, R.string.menu_add_to_contacts);
    }
    menu.add(0, MENU_UNFAVORITED, 0, R.string.unfavorited);
    return true;
}

From source file:com.mifos.mifosxdroid.online.SavingsAccountSummaryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    menu.addSubMenu(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_SAVINGS_ACCOUNTS_NAME);
    menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getResources().getString(R.string.documents));

    // This is the ID of Each data table which will be used in onOptionsItemSelected Method
    int SUBMENU_ITEM_ID = 0;
    // Create a Sub Menu that holds a link to all data tables
    SubMenu dataTableSubMenu = menu.getItem(1).getSubMenu();
    if (dataTableSubMenu != null && savingsAccountDataTables != null && savingsAccountDataTables.size() > 0) {
        Iterator<DataTable> dataTableIterator = savingsAccountDataTables.iterator();
        while (dataTableIterator.hasNext()) {
            dataTableSubMenu.add(Menu.NONE, SUBMENU_ITEM_ID, Menu.NONE,
                    dataTableIterator.next().getRegisteredTableName());
            SUBMENU_ITEM_ID++;/*from   w  ww  .  j  av a  2  s.  c  o m*/
        }
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java

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

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

    // Create a listener for search change
    final MenuItem search = menu.findItem(R.id.global_search_menu_search);
    final SearchView searchView = (SearchView) search.getActionView();
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);//from   w  w w. j ava2  s  .co  m

    final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            mSwipeRefreshLayout.setRefreshing(true);
            mEmptyView.setRefreshing(true);

            Message msg = Message.obtain();

            msg.obj = ClementineMessageFactory.buildGlobalSearch(query);
            App.ClementineConnection.mHandler.sendMessage(msg);

            hideSoftInput();

            // Set the actionbar title
            mActionBar.setTitle(getResources().getString(R.string.global_search_query, query));
            mActionBar.setSubtitle("/");

            // Query must be empty in order to collapse the search view.
            searchView.setQuery("", false);
            searchView.setIconified(true);

            // Remove currently present adapters
            mAdapters.clear();
            showList();

            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    searchView.setQueryHint(getString(R.string.global_search_search));

    EditText searchText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchText.setHintTextColor(ContextCompat.getColor(getActivity(), R.color.searchview_edittext_hint));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.alboteanu.android.sunshine.app.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        ViewParent vp = getView().getParent();
        if (vp instanceof CardView) {
            ((View) vp).setVisibility(View.VISIBLE);
        }/*w ww  .j  av a  2  s .co m*/

        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

        if (Utility.usingLocalGraphics(getActivity())) {
            mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
        } else {
            // Use weather art image
            Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId))
                    .error(Utility.getArtResourceForWeatherCondition(weatherId)).crossFade().into(mIconView);
        }

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String dateText = Utility.getFullFriendlyDayString(getActivity(), date);
        mDateView.setText(dateText);

        // Get description from weather condition ID
        //            String description = Utility.getStringForWeatherCondition(getActivity(), weatherId);                //orig
        String description = data.getString(COL_WEATHER_DESC); //eu
        mDescriptionView.setText(description);
        mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description));

        // For accessibility, add a content description to the icon field. Because the ImageView
        // is independently focusable, it's better to have a description of the image. Using
        // null is appropriate when the image is purely decorative or when the image already
        // has text describing it in the same UI component.
        mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description));

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high);
        mHighTempView.setText(highString);
        mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString));

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low);
        mLowTempView.setText(lowString);
        mLowTempView.setContentDescription(getString(R.string.a11y_low_temp, lowString));

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));
        mHumidityView.setContentDescription(getString(R.string.a11y_humidity, mHumidityView.getText()));
        mHumidityLabelView.setContentDescription(mHumidityView.getContentDescription());

        // Read wind speed and direction from cursor and update view
        float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
        float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));
        mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText()));
        mWindLabelView.setContentDescription(mWindView.getContentDescription());

        // Read pressure from cursor and update view
        float pressure = data.getFloat(COL_WEATHER_PRESSURE);
        mPressureView.setText(getString(R.string.format_pressure, pressure));
        mPressureView.setContentDescription(getString(R.string.a11y_pressure, mPressureView.getText()));
        mPressureLabelView.setContentDescription(mPressureView.getContentDescription());

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

    }
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar);

    // We need to start the enter transition after the data has loaded
    if (mTransitionAnimation) {
        activity.supportStartPostponedEnterTransition();

        if (null != toolbarView) {
            activity.setSupportActionBar(toolbarView);

            activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
            activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    } else {
        if (null != toolbarView) {
            Menu menu = toolbarView.getMenu();
            if (null != menu)
                menu.clear();
            toolbarView.inflateMenu(R.menu.detailfragment);
            finishCreatingMenu(toolbarView.getMenu());
        }
    }
    /*
            adRequest = new AdRequest.Builder()
        .addTestDevice(getString(R.string.test_device))
        .build();
            adView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        super.onAdLoaded();
        adView.setVisibility(View.VISIBLE);
    }
            });
            adView.loadAd(adRequest);*/

    getView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInterstitial == null)
                mInterstitial = Utility.requestNewInterstitial(getActivity());
            else if (mInterstitial.isLoaded())
                mInterstitial.show();
        }
    });
}

From source file:com.supremainc.biostar2.user.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    MenuInflater inflater = mContext.getMenuInflater();
    if (mPermissionDataProvider.getPermission(PERMISSION_MODULE.USER, true)) {
        switch (mSubMode) {
        default://from   w w w.j  a v a 2s.c o m
        case MODE_NORMAL:
            initActionbar(mTitle);
            inflater.inflate(R.menu.user_list_admin, menu);
            break;
        case MODE_DELETE:
            initActionbar(getString(R.string.delete) + " " + getString(R.string.user));
            inflater.inflate(R.menu.delete_confirm, menu);
            break;
        }
    } else {
        inflater.inflate(R.menu.menu, menu);
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:cc.softwarefactory.lokki.android.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    menu.clear();
    if (mNavigationDrawerFragment != null && !mNavigationDrawerFragment.isDrawerOpen()) {
        if (selectedOption == 0) { // Map
            getMenuInflater().inflate(R.menu.map, menu);
            MenuItem menuItem = menu.findItem(R.id.action_visibility);
            if (menuItem != null) {
                Log.e(TAG, "onPrepareOptionsMenu - Visible: " + MainApplication.visible);
                if (MainApplication.visible) {
                    menuItem.setIcon(R.drawable.ic_visible);
                } else {
                    menuItem.setIcon(R.drawable.ic_invisible);
                }//from ww  w .  ja  v a 2  s.  c om
            }
        } else if (selectedOption == 2) { // Contacts screen
            getMenuInflater().inflate(R.menu.contacts, menu);
        } else if (selectedOption == -10) { // Add contacts screen
            getMenuInflater().inflate(R.menu.add_contact, menu);
        }
        getMenuInflater().inflate(R.menu.main_activity_actions, menu);
        menu.findItem(R.id.action_logout).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.mobintum.bluechat.fragments.BluetoothChatFragment.java

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

    if (getActivity().onCreateOptionsMenu(menu)) {
        menu.clear();
        inflater.inflate(R.menu.bluetooth_chat, menu);
    }//from  w ww.j ava2  s. c  o  m
    super.onCreateOptionsMenu(menu, inflater);

}

From source file:com.odoo.addons.crm.CRMLeads.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    menu.clear();
    inflater.inflate(R.menu.menu_leads, menu);
    setHasSearchView(this, menu, R.id.menu_lead_search);
}

From source file:com.yacorso.nowaste.views.activities.DrawerActivity.java

private void loadNavItems() {
    int index = 0;
    Menu navigationMenu = navigationView.getMenu();
    navigationMenu.clear();
    navigationItems.clear();/*from  w ww  . j ava 2 s .co m*/

    SubMenu fridgeSection = navigationMenu.addSubMenu(getText(R.string.menu_section_fridges));
    List<Fridge> fridges = currentUser.getFridges();
    for (Fridge fridge : fridges) {
        navigationItems.put(index, fridge);
        fridgeSection.add(0, index++, 0, fridge.getName()).setIcon(R.drawable.ic_fridge);
    }

    SubMenu customListSection = navigationMenu.addSubMenu(getText(R.string.menu_section_custom_lists));
    List<CustomList> customLists = currentUser.getCustomLists();

    for (CustomList customList : customLists) {
        navigationItems.put(index, customList);
        customListSection.add(1, index++, 0, customList.getName()).setIcon(R.drawable.ic_folder);
    }

    navigationMenu.add(2, index++, 0, R.string.menu_add_foodlist).setIcon(R.drawable.ic_add_circle_white);
    navigationMenu.add(3, index, 0, R.string.menu_title_settings).setIcon(R.drawable.ic_setting_dark);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getGroupId() < 2) {
                changeFragment(menuItem.getItemId(), true);
            } else if (menuItem.getGroupId() == 2) {
                launchDialog(ChooseTypeFoodListDialog.newInstance());
            } else if (menuItem.getGroupId() == 3) {
                changeFragment(menuItem.getItemId(), false);
            }

            return true;
        }
    });

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
}

From source file:com.kii.sample.balance.list.BalanceListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    menu.clear();
    inflater.inflate(R.menu.menu_list, menu);
}