Example usage for android.view MenuItem SHOW_AS_ACTION_ALWAYS

List of usage examples for android.view MenuItem SHOW_AS_ACTION_ALWAYS

Introduction

In this page you can find the example usage for android.view MenuItem SHOW_AS_ACTION_ALWAYS.

Prototype

int SHOW_AS_ACTION_ALWAYS

To view the source code for android.view MenuItem SHOW_AS_ACTION_ALWAYS.

Click Source Link

Document

Always show this item as a button in an Action Bar.

Usage

From source file:org.uguess.android.sysinfo.ApplicationManager.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem mi = menu.add(Menu.NONE, MI_DELETE, Menu.NONE, R.string.uninstall);
    mi.setIcon(android.R.drawable.ic_menu_delete);
    Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = menu.add(Menu.NONE, MI_SHARE, Menu.NONE, R.string.share);
    mi.setIcon(android.R.drawable.ic_menu_share);
    Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    if (Util.getSettingsIntent(getActivity().getPackageManager(), "com.android.settings.UsageStats") != null) //$NON-NLS-1$
    {// w w w.  java 2s .  c  o  m
        mi = menu.add(Menu.NONE, MI_USAGE_STATS, Menu.NONE, R.string.usage_stats);
        mi.setIcon(android.R.drawable.ic_menu_recent_history);
        Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_NEVER);
    }

    mi = menu.add(Menu.NONE, MI_REVERT, Menu.NONE, R.string.restore);
    mi.setIcon(android.R.drawable.ic_menu_revert);
    Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = menu.add(Menu.NONE, MI_PREFERENCE, Menu.NONE, R.string.preference);
    mi.setIcon(android.R.drawable.ic_menu_preferences);
    Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_NEVER);
}

From source file:com.vishwa.pinit.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_search:
        final MenuItem createNoteItem = mMenu.getItem(1);
        createNoteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        item.setOnActionExpandListener(new OnActionExpandListener() {

            @Override//from w w w  .  j a v  a 2s.c o  m
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                createNoteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                return true;
            }
        });
        break;
    case R.id.action_create_note:
        mMapEditMode = MapEditMode.CREATE_NOTE;
        hideNoteEditButtons();
        mMenu.findItem(R.id.action_create_note).setVisible(false);
        mMenu.findItem(R.id.action_cancel).setVisible(true).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        Toast.makeText(getApplicationContext(), "Press and hold the location where you'd like to create a note",
                Toast.LENGTH_SHORT).show();
        break;
    case R.id.action_logout:
        if (ParseFacebookUtils.getSession() != null) {
            ParseFacebookUtils.getSession().closeAndClearTokenInformation();
        }
        ParseUser.logOut();
        finish();
        break;
    case R.id.action_refresh:
        if (!PinItUtils.isOnline(getApplicationContext())) {
            PinItUtils.createAlert("Internet connection not found.",
                    "Connect to the Internet and press the refresh button at the top", this);
            mHasInternet = false;
            hideNonRefreshMenuItems();

        } else {
            mHasInternet = true;
            showNonRefreshMenuItems();
            loadMapWhenOnline();

            mMap.getUiSettings().setAllGesturesEnabled(true);
            mMap.getUiSettings().setZoomControlsEnabled(true);
            mMap.getUiSettings().setZoomGesturesEnabled(true);
        }
        break;
    case R.id.action_edit_location:
        if (mFocusedMarker != null) {
            Toast.makeText(getApplicationContext(), "Press and hold the current note and then drag it to where "
                    + "you'd like to position it and click save", Toast.LENGTH_LONG).show();
            mMenu.findItem(R.id.action_save).setVisible(true);
            mMenu.findItem(R.id.action_cancel).setVisible(true);
            mMenu.findItem(R.id.action_create_note).setVisible(false);
            mMenu.findItem(R.id.action_search).setVisible(false);
            mMenu.findItem(R.id.action_edit).setVisible(false);
            for (Marker marker : mMarkerList) {
                marker.setDraggable(false);
            }
            mFocusedMarker.setDraggable(true);
        } else {
            Toast.makeText(getApplicationContext(),
                    "Please click on the note you'd like " + "to move and then try again", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    case R.id.action_save:
        if (mHasInternet) {
            setProgressBarIndeterminateVisibility(true);
            ParseQuery query = new ParseQuery("Note");
            query.getInBackground(mNoteStore.get(mFocusedMarker.getId()).getNoteId(), new GetCallback() {
                public void done(ParseObject object, ParseException e) {
                    if (e == null) {
                        ParseGeoPoint geopoint = new ParseGeoPoint(mFocusedMarker.getPosition().latitude,
                                mFocusedMarker.getPosition().longitude);
                        object.put("geopoint", geopoint);
                        object.saveInBackground(new SaveCallback() {

                            @Override
                            public void done(ParseException e) {
                                if (e == null) {
                                    setProgressBarIndeterminateVisibility(false);
                                    mFocusedMarker.setDraggable(false);
                                    hideNoteEditButtons();
                                    mMenu.findItem(R.id.action_edit).setVisible(true);
                                    Toast.makeText(getApplicationContext(), "Note location updated!",
                                            Toast.LENGTH_LONG).show();
                                } else {
                                    PinItUtils.createAlert("This note could not be updated.",
                                            "We apologize, this note update failed, please try again",
                                            MainActivity.this);
                                }
                            }
                        });
                    } else {
                        PinItUtils.createAlert("This note could not be updated.",
                                "We apologize, this note update failed, please try again", MainActivity.this);
                    }
                }
            });
        }
        break;
    case R.id.action_delete_note:
        if (mFocusedMarker != null) {
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.setTitle("Are you sure?");
            dialog.setMessage("Please confirm that you'd like to delete this note.");
            dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    final Note note = mNoteStore.get(mFocusedMarker.getId());
                    ParseQuery query = new ParseQuery("Note");
                    query.getInBackground(note.getNoteId(), new GetCallback() {

                        @Override
                        public void done(ParseObject object, ParseException e) {
                            if (e == null) {
                                object.deleteInBackground(new DeleteCallback() {

                                    @Override
                                    public void done(ParseException e) {
                                        if (e == null) {
                                            Toast.makeText(getApplicationContext(), "Note deleted!",
                                                    Toast.LENGTH_SHORT).show();
                                            if (mFocusedMarker != null) {
                                                mNoteStore.remove(mFocusedMarker.getId());
                                                mReverseNoteStore.remove(note.getNoteId());
                                                Iterator<Marker> iterator = mMarkerList.iterator();
                                                while (iterator.hasNext()) {
                                                    Marker marker = iterator.next();
                                                    if (marker.getId().equals(mFocusedMarker.getId())) {
                                                        mFocusedMarker.remove();
                                                        mFocusedMarker = null;
                                                        iterator.remove();
                                                        break;
                                                    }
                                                }
                                                hideNoteEditButtons();
                                            }
                                        }
                                    }
                                });
                            } else {
                                PinItUtils.createAlert("Something's gone wrong",
                                        "Please try deleting the note again", MainActivity.this);
                            }
                        }
                    });
                }
            });
            dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            dialog.show();
        }
        break;
    case R.id.action_edit_note:
        if (mFocusedMarker != null) {
            Note note = mNoteStore.get(mFocusedMarker.getId());
            Intent intent = new Intent(this, EditNoteActivity.class);
            intent.putExtra("note", note);
            startActivityForResult(intent, REQUEST_CODE_EDIT_NOTE);
        } else {
            Toast.makeText(getApplicationContext(),
                    "Please click on the note you'd like " + "to edit and then try again", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    case R.id.action_cancel:
        if (mFocusedMarker != null) {
            double latitude = mNoteStore.get(mFocusedMarker.getId()).getNoteLatitude();
            double longitude = mNoteStore.get(mFocusedMarker.getId()).getNoteLongitude();
            LatLng geopoint = new LatLng(latitude, longitude);
            mFocusedMarker.setPosition(geopoint);
            mFocusedMarker.setDraggable(false);
            mFocusedMarker.hideInfoWindow();
        }
        if (mMapEditMode == MapEditMode.CREATE_NOTE) {
            mMapEditMode = MapEditMode.DEFAULT_MODE;
        }
        hideNoteEditButtons();
        break;
    case R.id.action_settings:
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivityForResult(settingsIntent, REQUEST_CODE_CHANGE_SETTINGS);
        break;
    case R.id.action_about:
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
        break;
    default:
        return super.onOptionsItemSelected(item);
    }

    return true;
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

@Override
public void onResume() {
    super.onResume();
    invalidateOptionsMenu();//from   w  ww.java  2 s .  c o  m
    if (wasHideToolbar != isHideToolbar) {
        wasHideToolbar = isHideToolbar;

        List<KiwixWebView> newWebViews = new ArrayList<>();
        for (int i = 0; i < mWebViews.size(); i++) {
            KiwixWebView newView = getWebView(mWebViews.get(i).getUrl());
            newWebViews.add(i, newView);
        }
        mWebViews = newWebViews;
        selectTab(currentWebViewIndex);
    }
    if (refresh) {
        refresh = false;
        recreate();
    }
    if (menu != null) {
        refreshBookmarkSymbol(menu);
    }
    if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
        if (menu != null) {
            menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
    } else {
        if (menu != null) {
            menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
    }

    if (settings.getBoolean(KiwixSettingsActivity.PREF_BOTTOM_TOOLBAR, false)) {
        pageBottomTabLayout.setVisibility(View.VISIBLE);
    } else {
        pageBottomTabLayout.setVisibility(View.GONE);
    }

    Intent intent = getIntent();
    if (intent.getAction() != null) {

        if (intent.getAction().equals(Intent.ACTION_PROCESS_TEXT)) {
            final String zimFile = ZimContentProvider.getZimFile();
            saveTabStates();
            Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
            i.putExtra("zimFile", zimFile);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT));
            }
            intent.setAction("");
            startActivityForResult(i, REQUEST_FILE_SEARCH);
        } else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)) {
            intent.setAction("");
            goToSearch(false);
        } else if (intent.getAction().equals(KiwixSearchWidget.STAR_CLICKED)) {
            intent.setAction("");
            goToBookmarks();
        } else if (intent.getAction().equals(KiwixSearchWidget.MIC_CLICKED)) {
            intent.setAction("");
            goToSearch(true);
        }

    }
    updateWidgets(this);
}

From source file:org.path.episample.android.activities.MainMenuActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    int showOption = MenuItem.SHOW_AS_ACTION_IF_ROOM;
    MenuItem item;/*  w w  w  . j av  a  2s .c  o  m*/
    if (currentFragment != ScreenList.WEBKIT) {
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
        actionBar.show();

        item = menu.add(Menu.NONE, MENU_MAIN_MENU, Menu.NONE, getString(R.string.main_menu));
        item.setIcon(R.drawable.ic_action_home).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        //item = menu.add(Menu.NONE, MENU_FILL_FORM, Menu.NONE, getString(R.string.enter_data_button));
        //item.setIcon(R.drawable.ic_action_collections_collection).setShowAsAction(showOption);

        // Using a file for this work now
        String get = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_GET_BLANK);
        if (get.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_PULL_FORMS, Menu.NONE, getString(R.string.get_forms));
            item.setIcon(R.drawable.ic_action_av_download).setShowAsAction(showOption);

            //item = menu.add(Menu.NONE, MENU_CLOUD_FORMS, Menu.NONE, getString(R.string.get_forms));
            //item.setIcon(R.drawable.ic_action_cloud).setShowAsAction(showOption);
        }

        String send = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_FINALIZED);
        if (send.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_PUSH_FORMS, Menu.NONE, getString(R.string.send_data));
            item.setIcon(R.drawable.ic_action_av_upload).setShowAsAction(showOption);
        }

        String manage = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_MANAGE_FORMS);
        if (manage.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_MANAGE_FORMS, Menu.NONE, getString(R.string.manage_files));
            item.setIcon(R.drawable.trash).setShowAsAction(showOption);
        }

        String settings = PropertiesSingleton.getProperty(appName,
                AdminPreferencesActivity.KEY_ACCESS_SETTINGS);
        if (settings.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_PREFERENCES, Menu.NONE, getString(R.string.general_preferences));
            item.setIcon(R.drawable.ic_menu_preferences).setShowAsAction(showOption);
        }
        item = menu.add(Menu.NONE, MENU_ADMIN_PREFERENCES, Menu.NONE, getString(R.string.admin_preferences));
        item.setIcon(R.drawable.ic_action_device_access_accounts).setShowAsAction(showOption);

        String backup = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_BACKUP_CENSUS);
        if (backup != null && backup.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_BACKUP_CENSUS, Menu.NONE, getString(R.string.backup_census));
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }

        String restore = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_RESTORE_CENSUS);
        if (restore != null && restore.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_RESTORE_CENSUS, Menu.NONE, getString(R.string.restore_census));
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }

        String invalidateCensus = PropertiesSingleton.getProperty(appName,
                AdminPreferencesActivity.KEY_INVALIDATE_CENSUS);
        if (invalidateCensus != null && invalidateCensus.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_MARK_CENSUS_AS_INVALID, Menu.NONE,
                    getString(R.string.invalidate_census));
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }

        String edit = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_EDIT_CENSUS);
        if (edit != null && edit.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_EDIT_CENSUS, Menu.NONE, getString(R.string.edit_census));
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }

        String removeCensus = PropertiesSingleton.getProperty(appName,
                AdminPreferencesActivity.KEY_REMOVE_CENSUS);
        if (removeCensus != null && removeCensus.equalsIgnoreCase("true")) {
            item = menu.add(Menu.NONE, MENU_REMOVE_CENSUS, Menu.NONE, getString(R.string.remove_census));
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }

        /*String send_receive_bt = PropertiesSingleton.getProperty(appName,
                AdminPreferencesActivity.KEY_SEND_RECEIVE_BLUETOOTH);
        if (send_receive_bt != null && send_receive_bt.equalsIgnoreCase("true")) {
           item = menu.add(Menu.NONE, MENU_SEND_REVEIVE_BLUETOOTH, Menu.NONE, getString(R.string.send_receive_bluetooth));
           item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }*/

        item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, getString(R.string.about));
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    } else {
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    }

    return true;
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

void toggleActionItemsConfig() {
    if (menu != null) {
        MenuItem random = menu.findItem(R.id.menu_randomarticle);
        MenuItem home = menu.findItem(R.id.menu_home);
        if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
            random.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            home.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        } else {/*from   w ww  . j a  v a2 s.  com*/
            random.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            home.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
    }
}

From source file:com.vishwa.pinit.MainActivity.java

@Override
public boolean onSearchRequested() {
    if (mSearchMenuItem.isActionViewExpanded()) {
        mSearchMenuItem.collapseActionView();
        return false;
    }//from www  .  j a v a2  s.  co m
    final MenuItem createNoteItem = mMenu.getItem(1);
    createNoteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    mSearchMenuItem.expandActionView();
    mSearchMenuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            createNoteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            return true;
        }
    });
    return false;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    /*//w w w  .j a va 2 s.  c  om
     * int MENU_ACTION_WITH_TEXT=0;
     * 
     * //Temp- for backward compatibility with OS 3 features
     * 
     * if(!usingListSpinner()){ try{ //setting the value equivalent to
     * desired expression
     * //MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_WITH_TEXT
     * java.lang.reflect.Field
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_IF_ROOM");
     * MENU_ACTION_WITH_TEXT=field.getInt(MenuItem.class);
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_WITH_TEXT");
     * MENU_ACTION_WITH_TEXT|=field.getInt(MenuItem.class); }catch(Exception
     * e){ //reset value irrespective of cause MENU_ACTION_WITH_TEXT=0; }
     * 
     * }
     */

    // Add menu option for auto adding items from string array in intent
    // extra if they exist
    if (mExtraItems != null) {
        menu.add(0, MENU_INSERT_FROM_EXTRAS, 0, R.string.menu_auto_add)
                .setIcon(android.R.drawable.ic_menu_upload);
    }

    MenuItem item = null;

    View searchView = mItemsView.getSearchView();
    if (searchView != null) {
        item = menu.add(0, MENU_SEARCH_ADD, 0, R.string.menu_search_add);
        MenuItemCompat.setActionView(item, searchView);
        MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    mAddPanel.setVisibility(searchView == null ? View.VISIBLE : View.GONE);

    item = menu.add(0, MENU_SORT_LIST, 0, R.string.menu_sort_list)
            .setIcon(android.R.drawable.ic_menu_sort_alphabetically);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    if (mListSortActionProvider == null) {
        mListSortActionProvider = new ListSortActionProvider(this);
    }
    MenuItemCompat.setActionProvider(item, mListSortActionProvider);

    // Standard menu

    // tentatively moved "new list" to drawer
    //item = menu.add(0, MENU_NEW_LIST, 0, R.string.new_list)
    //      .setIcon(R.drawable.ic_menu_add_list).setShortcut('0', 'n');
    // MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    item = menu.add(0, MENU_CLEAN_UP_LIST, 0, R.string.clean_up_list).setIcon(R.drawable.ic_menu_cleanup)
            .setShortcut('1', 'c');
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(0, MENU_PICK_ITEMS, 0, R.string.menu_pick_items).setIcon(android.R.drawable.ic_menu_add)
            .setShortcut('2', 'p').
            // tentatively replaced by buttons in drawer.
            setVisible(false);

    /*
     * menu.add(0, MENU_SHARE, 0, R.string.share)
     * .setIcon(R.drawable.contact_share001a) .setShortcut('4', 's');
     */

    menu.add(0, MENU_THEME, 0, R.string.theme).setIcon(android.R.drawable.ic_menu_manage).setShortcut('3', 't');

    menu.add(0, MENU_PREFERENCES, 0, R.string.preferences).setIcon(android.R.drawable.ic_menu_preferences)
            .setShortcut('4', 'p');

    menu.add(0, MENU_RENAME_LIST, 0, R.string.rename_list).setIcon(android.R.drawable.ic_menu_edit)
            .setShortcut('5', 'r');

    menu.add(0, MENU_DELETE_LIST, 0, R.string.delete_list).setIcon(android.R.drawable.ic_menu_delete);

    menu.add(0, MENU_SEND, 0, R.string.send).setIcon(android.R.drawable.ic_menu_send).setShortcut('7', 's');

    if (addLocationAlertPossible()) {
        menu.add(0, MENU_ADD_LOCATION_ALERT, 0, R.string.shopping_add_alert)
                .setIcon(android.R.drawable.ic_menu_mylocation).setShortcut('8', 'l');
    }

    menu.add(0, MENU_MARK_ALL_ITEMS, 0, R.string.mark_all_items).setIcon(android.R.drawable.ic_menu_agenda)
            .setShortcut('9', 'm');

    menu.add(0, MENU_UNMARK_ALL_ITEMS, 0, R.string.unmark_all_items);

    menu.add(0, MENU_SYNC_WEAR, 0, R.string.sync_wear);

    // Add distribution menu items last.
    mDistribution.onCreateOptionsMenu(menu);

    // NOTE:
    // Dynamically added menu items are included in onPrepareOptionsMenu()
    // instead of here!
    // (Explanation see there.)

    return true;
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    menu.clear();//  w ww.  j  a  v  a 2s. c  o m

    if (mSendDiscreetMode && !mForwardMessageMode) {
        // When we're in send-a-single-message mode from the lock screen, don't show
        // any menus.
        return true;
    }

    if (isRecipientCallable()) {
        MenuItem item = menu.add(0, MENU_CALL_RECIPIENT, 0, R.string.menu_call)
                .setIcon(R.drawable.ic_menu_call_holo_light).setTitle(R.string.menu_call);
        if (!isRecipientsEditorVisible()) {
            // If we're not composing a new message, show the call icon in the actionbar
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
    }

    if (MmsConfig.getMmsEnabled() && mIsSmsEnabled) {
        if (!isSubjectEditorVisible()) {
            menu.add(0, MENU_ADD_SUBJECT, 0, R.string.add_subject).setIcon(R.drawable.ic_menu_edit);
        }
        if (!mWorkingMessage.hasAttachment()) {
            menu.add(0, MENU_ADD_ATTACHMENT, 0, R.string.add_attachment)
                    .setIcon(R.drawable.ic_menu_attachment_holo_light).setTitle(R.string.add_attachment)
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // add to actionbar
        }
    }

    menu.add(0, MENU_ADD_TEMPLATE, 0, R.string.template_insert).setIcon(android.R.drawable.ic_menu_add)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    if (isPreparedForSending() && mIsSmsEnabled) {
        menu.add(0, MENU_SEND, 0, R.string.send).setIcon(android.R.drawable.ic_menu_send);
    }

    if (!mWorkingMessage.hasSlideshow() && mIsSmsEnabled && mEnableEmoticons) {
        menu.add(0, MENU_INSERT_SMILEY, 0, R.string.menu_insert_smiley).setIcon(R.drawable.ic_menu_emoticons);
    }

    if (getRecipients().size() > 1) {
        menu.add(0, MENU_GROUP_PARTICIPANTS, 0, R.string.menu_group_participants);
    }

    if (mMsgListAdapter.getCount() > 0 && mIsSmsEnabled) {
        // Removed search as part of b/1205708
        //menu.add(0, MENU_SEARCH, 0, R.string.menu_search).setIcon(
        //        R.drawable.ic_menu_search);
        Cursor cursor = mMsgListAdapter.getCursor();
        if ((null != cursor) && (cursor.getCount() > 0)) {
            menu.add(0, MENU_DELETE_THREAD, 0, R.string.delete_thread)
                    .setIcon(android.R.drawable.ic_menu_delete);
        }
    } else if (mIsSmsEnabled) {
        menu.add(0, MENU_DISCARD, 0, R.string.discard).setIcon(android.R.drawable.ic_menu_delete);
    }

    buildAddAddressToContactMenuItem(menu);

    // Add to Blacklist item (if enabled) and we are running on CyanogenMod
    // This allows the app to be run on non-blacklist enabled roms (including Stock)
    if (MessageUtils.isCyanogenMod(this)) {
        if (BlacklistUtils.isBlacklistEnabled(this)) {
            menu.add(0, MENU_ADD_TO_BLACKLIST, 0, R.string.add_to_blacklist)
                    .setIcon(R.drawable.ic_block_message_holo_dark)
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
    }

    if (mConversation.getThreadId() > 0) {
        menu.add(0, MENU_CONVERSATION_OPTIONS, 0, R.string.menu_conversation_options);
    }

    menu.add(0, MENU_PREFERENCES, 0, R.string.menu_preferences).setIcon(android.R.drawable.ic_menu_preferences);

    if (LogTag.DEBUG_DUMP) {
        menu.add(0, MENU_DEBUG_DUMP, 0, R.string.menu_debug_dump);
    }

    return true;
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void updateFromPreferences(boolean finish) {
    SettingConstants.initializeLogoMap(getApplicationContext(), true);

    Fragment test1 = mSectionsPagerAdapter.getRegisteredFragment(1);

    if (test1 instanceof FragmentProgramsList) {
        ((FragmentProgramsList) test1).updateChannels();
    }//w ww  .j a  v a  2s  . com

    Fragment fragment = mSectionsPagerAdapter.getRegisteredFragment(2);

    if (fragment instanceof FragmentFavorites) {
        ((FragmentFavorites) fragment).updateSynchroButton(null);
        ((FragmentFavorites) fragment).updateProgramsList();
    }

    boolean programTableActivated = PrefUtils.getBooleanValue(R.string.PROG_TABLE_ACTIVATED,
            R.bool.prog_table_activated_default);
    Fragment test = mSectionsPagerAdapter.getRegisteredFragment(3);

    if (!programTableActivated && test instanceof ProgramTableFragment) {
        ((ProgramTableFragment) test).removed();
        mSectionsPagerAdapter.destroyItem(mViewPager, 3, mSectionsPagerAdapter.getRegisteredFragment(3));
        mSectionsPagerAdapter.notifyDataSetChanged();
        actionBar.removeTabAt(3);
    } else if (!(test instanceof ProgramTableFragment) && programTableActivated) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(3)).setTabListener(this));
        mSectionsPagerAdapter.notifyDataSetChanged();
        mSectionsPagerAdapter.instantiateItem(mViewPager, 3);
    } else if (test instanceof ProgramTableFragment) {
        if (!((ProgramTableFragment) test).checkTimeBlockSize()
                && !((ProgramTableFragment) test).updateTable()) {
            ((ProgramTableFragment) test).updateChannelBar();
            ((ProgramTableFragment) test).updateMarkings();
        }
    }

    if (mDebugMenuItem != null) {
        boolean dataUpdateLogEnabled = PrefUtils.getBooleanValue(R.string.WRITE_DATA_UPDATE_LOG,
                R.bool.write_data_update_log_default);
        boolean reminderLogEnabled = PrefUtils.getBooleanValue(R.string.WRITE_REMINDER_LOG,
                R.bool.write_reminder_log_default);

        mDebugMenuItem.setVisible(dataUpdateLogEnabled || reminderLogEnabled);

        mSendDataUpdateLogItem.setEnabled(dataUpdateLogEnabled);
        mDeleteDataUpdateLogItem.setEnabled(dataUpdateLogEnabled);
        mSendReminderLogItem.setEnabled(reminderLogEnabled);
        mDeleteReminderLogItem.setEnabled(reminderLogEnabled);
    }

    UiUtils.updateImportantProgramsWidget(getApplicationContext());
    UiUtils.updateRunningProgramsWidget(getApplicationContext());

    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(SettingConstants.UPDATE_TIME_BUTTONS));
    updateScrollMenu();

    if (mUpdateItem != null && !TvDataUpdateService.IS_RUNNING) {
        if (PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default)
                .equals("0")) {
            mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        } else {
            mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            invalidateOptionsMenu();
        }
    }

    new UpdateAlarmValue().onReceive(TvBrowser.this, null);

    if (PrefUtils.getBooleanValue(R.string.DARK_STYLE,
            R.bool.dark_style_default) != SettingConstants.IS_DARK_THEME) {
        SettingConstants.IS_DARK_THEME = PrefUtils.getBooleanValue(R.string.DARK_STYLE,
                R.bool.dark_style_default);

        Favorite.resetMarkIcons(SettingConstants.IS_DARK_THEME);
        ProgramUtils.resetReminderMarkIcon(SettingConstants.IS_DARK_THEME);

        PluginServiceConnection[] plugins = PluginHandler.getAvailablePlugins();

        for (PluginServiceConnection plugin : plugins) {
            plugin.loadIcon();
        }

        finish = true;
    }

    if (finish) {
        finish();
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

public void updateProgressIcon(final boolean progress) {
    handler.post(new Runnable() {
        @Override//from   w w  w.j a  v a 2s. c  om
        public void run() {
            if (progress) {
                mUpdateItem.setActionView(R.layout.progressbar);
                mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            } else {
                if (!PrefUtils
                        .getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default)
                        .equals("0")) {
                    mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                    invalidateOptionsMenu();
                }

                mUpdateItem.setActionView(null);
            }
        }
    });
}