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:net.lapasa.fleetingdreamrecorder.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    int index = viewPager.getCurrentItem();
    Fragment f = pagerAdapter.getItem(index);

    if (f instanceof AlarmsListFragment) {
        AlarmsListFragment alarmsFrag = (AlarmsListFragment) f;
        return alarmsFrag.onCreateOptionsMenu(menu);
    }//from   www .  ja  v a2  s . c o  m

    // Otherwise
    menu.clear();
    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.config.ConfigMenuEditorFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    menu.add(Menu.NONE, R.id.config_menu_save, Menu.FIRST, "Save");
    menu.add(Menu.NONE, R.id.config_menu_send, Menu.FIRST, "Send");
    menu.add(Menu.NONE, R.id.config_menu_reset, Menu.FIRST, "Reset");
    menu.add(Menu.NONE, R.id.config_menu_clear, Menu.FIRST, "Clear");
}

From source file:com.upenn.chriswang1990.sunshine.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
        mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));

        //read city name and update
        String cityName = data.getString(COL_CITY_NAME);
        mCityNameView.setText(cityName);
        mCityNameView.setContentDescription(getString(R.string.a11y_city_name, cityName));

        // Read date from cursor and update views for day of week and date
        long unixTimestamp = data.getLong(COL_WEATHER_DATE_UNIX);
        String timezoneID = data.getString(COL_TIMEZONE_ID);
        String dateText = Utility.getFullFriendlyDayString(getActivity(), unixTimestamp, timezoneID);
        mDateView.setText(dateText);// w w  w.j  a  v  a  2 s .  co m

        // Read description from cursor and update view
        String description = Utility.getStringForWeatherCondition(getActivity(), weatherId);
        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
        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(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());

        forecastStr = String.format(getContext().getString(R.string.format_share_string), cityName, dateText,
                description, highString, lowString);

        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 (activity instanceof DetailActivity) {
            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.detail_fragment);
                finishCreatingMenu(toolbarView.getMenu());
            }
        }
    }
}

From source file:us.shandian.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    getMenuInflater().inflate(R.menu.new_post, menu);
    if (mBitmap != null) {
        menu.findItem(R.id.post_pic).setTitle(R.string.delete_picture)
                .setIcon(android.R.drawable.ic_menu_delete);
    }/* w  w  w  . j  a  v a2  s  .  c om*/
    mEmoticonMenu = menu.findItem(R.id.post_emoticon);
    return true;
}

From source file:com.bangz.smartmute.RulelistFragment.java

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

    Activity parentActivity = getActivity();
    if (!(parentActivity instanceof BaseActivity && ((BaseActivity) parentActivity).isDrawerOpened())) {
        menu.clear();

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

        super.onCreateOptionsMenu(menu, inflater);
    }//from  www  .j ava 2s .c o m

}

From source file:com.decad3nce.aegis.AegisActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.clear();
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.full_menu, menu);
    fullMenu = menu;//from w w  w. ja  va2s  .  c o m

    switch (mTabsAdapter.getCurrentTab()) {
    case 0:
        showItem(R.id.alarm_menu_settings, menu);
        mAlarmEnabledPreference = (Switch) menu.findItem(R.id.alarm_menu_settings).getActionView()
                .findViewById(R.id.alarm_toggle);
        addAdminListener(R.id.alarm_toggle, alarmEnabled, mAlarmEnabledPreference);
        break;

    case 1:
        showItem(R.id.lock_menu_settings, menu);
        mLockEnabledPreference = (Switch) menu.findItem(R.id.lock_menu_settings).getActionView()
                .findViewById(R.id.lock_toggle);
        addAdminListener(R.id.lock_toggle, lockEnabled, mLockEnabledPreference);
        break;

    case 2:
        showItem(R.id.wipe_menu_settings, menu);
        mWipeEnabledPreference = (Switch) menu.findItem(R.id.wipe_menu_settings).getActionView()
                .findViewById(R.id.wipe_toggle);
        addAdminListener(R.id.wipe_toggle, wipeEnabled, mWipeEnabledPreference);
        break;

    case 3:
        showItem(R.id.locate_menu_settings, menu);
        mLocateEnabledPreference = (Switch) menu.findItem(R.id.locate_menu_settings).getActionView()
                .findViewById(R.id.locate_toggle);
        addAdminListener(R.id.locate_toggle, locateEnabled, mLocateEnabledPreference);
        break;
    }
    return true;
}

From source file:pl.edu.agh.schedule.myschedule.MyScheduleActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    for (String location : mDataHelper.getLocations()) {
        menu.add(location);/*from ww w.  j  av a2 s. c om*/
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:ru.sawimmod.activities.SawimActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    ChatView chatView = getChatView();//from w  w  w  .  j av a 2s.  c  om
    RosterView rosterView = getRosterView();
    StartWindowView startWindowView = (StartWindowView) getSupportFragmentManager()
            .findFragmentByTag(StartWindowView.TAG);
    VirtualListView virtualListView = (VirtualListView) getSupportFragmentManager()
            .findFragmentByTag(VirtualListView.TAG);
    if (virtualListView != null && virtualListView.isAdded()) {
        virtualListView.onPrepareOptionsMenu_(menu);
        return true;
    } else if (chatView != null && chatView.isAdded() && !SawimApplication.isManyPane()) {
        chatView.onPrepareOptionsMenu_(menu);
        return true;
    } else if ((rosterView != null && rosterView.isAdded())
            || (startWindowView != null && startWindowView.isAdded())) {
        Protocol p = RosterHelper.getInstance().getProtocol(0);
        if (RosterHelper.getInstance().getProtocolCount() == 1 && p != null) {
            menu.add(Menu.NONE, RosterHelper.MENU_CONNECT, Menu.NONE, R.string.connect)
                    .setTitle((p.isConnected() || p.isConnecting()) ? R.string.disconnect : R.string.connect);
            menu.add(Menu.NONE, RosterHelper.MENU_STATUS, Menu.NONE, R.string.status);
            if (p.getXStatusInfo() != null)
                menu.add(Menu.NONE, RosterHelper.MENU_XSTATUS, Menu.NONE, R.string.xstatus);
            if ((p instanceof Icq) || (p instanceof Mrim))
                menu.add(Menu.NONE, RosterHelper.MENU_PRIVATE_STATUS, Menu.NONE, R.string.private_status);
            if (p instanceof Mrim && p.isConnected()) {
                menu.add(Menu.NONE, RosterHelper.MENU_SEND_SMS, Menu.NONE, R.string.send_sms);
            }
            if (p.isConnected()) {
                if (p instanceof Xmpp) {
                    if (((Xmpp) p).hasS2S()) {
                        menu.add(Menu.NONE, RosterHelper.MENU_DISCO, Menu.NONE, R.string.service_discovery);
                    }
                    menu.add(Menu.NONE, RosterHelper.MENU_ADHOC, Menu.NONE, R.string.account_settings);
                }
                menu.add(Menu.NONE, RosterHelper.MENU_GROUPS, Menu.NONE, R.string.manage_contact_list);
                if (p instanceof Icq) {
                    menu.add(Menu.NONE, RosterHelper.MENU_MYSELF, Menu.NONE, R.string.myself);
                } else {
                    if (p instanceof Xmpp) {
                        menu.add(Menu.NONE, RosterHelper.MENU_NOTES, Menu.NONE, R.string.notes);
                    }
                    if (p.hasVCardEditor())
                        menu.add(Menu.NONE, RosterHelper.MENU_MYSELF, Menu.NONE, R.string.myself);
                    if (p instanceof Mrim)
                        menu.add(Menu.NONE, RosterHelper.MENU_MICROBLOG, Menu.NONE, R.string.microblog);
                }
            }
        }
        menu.add(Menu.NONE, MENU_OPTIONS, Menu.NONE, R.string.options);
        menu.add(Menu.NONE, MENU_QUIT, Menu.NONE, R.string.quit);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.rowland.hashtrace.ui.fragments.DetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    // Clear old menu.
    menu.clear();
    // Inflate new menu.
    inflater.inflate(R.menu.menu_detailsfragment, menu);
}

From source file:ru.arturvasilov.udacity.sunshinewatches.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);
        }/*from   www .  j  a v a 2s  .  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);
        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));

        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);
            if (activity.getSupportActionBar() != null) {
                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());
        }
    }
}