Example usage for android.view MenuItem setIcon

List of usage examples for android.view MenuItem setIcon

Introduction

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

Prototype

public MenuItem setIcon(@DrawableRes int iconRes);

Source Link

Document

Change the icon associated with this item.

Usage

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

/**
 * If there is no global and local tabbar, create default menu.
 * Contains "setting" and "logout".//from   www  .j a v  a  2s . c o m
 * 
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.setQwertyMode(true);
    MenuItem setting = menu.add(-1, Constants.MENU_ITEM_SETTING, 0, R.string.setting);
    setting.setIcon(R.drawable.ic_menu_manage);

    if (AppSettingsModel.isSSLEnabled(getApplicationContext())) {
        MenuItem ssl = menu.add(-1, Constants.MENU_ITEM_SSL, 0, R.string.ssl_clientcert);
        ssl.setIcon(R.drawable.ic_menu_lock);
    }

    MenuItem logout = menu.add(-1, Constants.MENU_ITEM_LOGOUT, 1, R.string.logout);
    logout.setIcon(R.drawable.ic_menu_revert);
    return true;
}

From source file:org.getlantern.firetweet.fragment.support.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    if (followItem != null) {
        followItem.setEnabled(userList != null);
        if (userList == null) {
            followItem.setIcon(android.R.color.transparent);
        }// w w w . j  a  v a  2 s. c o m
    }
    if (twitter == null || userList == null)
        return;
    final boolean isMyList = userList.user_id == userList.account_id;
    setMenuItemAvailability(menu, MENU_EDIT, isMyList);
    setMenuItemAvailability(menu, MENU_ADD, isMyList);
    setMenuItemAvailability(menu, MENU_DELETE, isMyList);
    final boolean isFollowing = userList.is_following;
    if (followItem != null) {
        followItem.setVisible(!isMyList);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
    menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
    final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
    extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader());
    extensionsIntent.putExtra(EXTRA_USER_LIST, mUserList);
    addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
}

From source file:com.gbozza.android.popularmovies.fragments.MovieDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        getActivity().onBackPressed();//  www.  ja va2 s .c  o m
        return true;
    case R.id.action_favourite:
        if (checkFavourite(mMovie.getId())) {
            Uri removeFavouriteUri = FavouriteMovieEntry.buildFavouriteUriWithMovieId(mMovie.getId());
            getActivity().getContentResolver().delete(removeFavouriteUri, null, null);
            Toast.makeText(getActivity().getBaseContext(), mFavOffToastMsg, Toast.LENGTH_LONG).show();
            item.setIcon(R.drawable.ic_star_border_white);
        } else {
            ContentValues contentValues = new ContentValues();
            contentValues.put(FavouriteMovieEntry.COLUMN_MOVIE_ID, mMovie.getId());
            contentValues.put(FavouriteMovieEntry.COLUMN_BACKDROP_PATH, mMovie.getBackdropPath());
            contentValues.put(FavouriteMovieEntry.COLUMN_POSTER_PATH, mMovie.getPosterPath());
            contentValues.put(FavouriteMovieEntry.COLUMN_OVERVIEW, mMovie.getOverview());
            contentValues.put(FavouriteMovieEntry.COLUMN_TITLE, mMovie.getOriginalTitle());
            contentValues.put(FavouriteMovieEntry.COLUMN_RELEASE_DATE, mMovie.getReleaseDate());
            contentValues.put(FavouriteMovieEntry.COLUMN_VOTE_AVERAGE, mMovie.getVoteAverage());
            Uri favouriteUri = getActivity().getContentResolver().insert(FavouriteMovieEntry.CONTENT_URI,
                    contentValues);

            if (null != favouriteUri) {
                Toast.makeText(getActivity().getBaseContext(), mFavOnToastMsg, Toast.LENGTH_LONG).show();
                item.setIcon(R.drawable.ic_star);
            }
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

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

    MenuItem muteItem = menu.findItem(R.id.menu_mute_button);
    MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button);

    if (getService() != null && getService().isSynchronized()) {
        // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere
        int foregroundColor = getActivity().getTheme()
                .obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }).getColor(0, -1);

        IUser self = getService().getSessionUser();
        muteItem.setIcon(
                self.isSelfMuted() ? R.drawable.ic_action_microphone_muted : R.drawable.ic_action_microphone);
        deafenItem/*from   w w  w .j  a va  2  s  . com*/
                .setIcon(self.isSelfDeafened() ? R.drawable.ic_action_audio_muted : R.drawable.ic_action_audio);
        muteItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        deafenItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);

        MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth);
        bluetoothItem.setChecked(getService().usingBluetoothSco());
    }
}

From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.info_shibafu528_gallerymultipicker_menu, menu);

    MenuItem gallery = menu.findItem(R.id.info_shibafu528_gallerymultipicker_action_gallery);
    MenuItem shot = menu.findItem(R.id.info_shibafu528_gallerymultipicker_action_take_a_photo);

    if (mMenuIconTheme != null)
        switch (mMenuIconTheme.toLowerCase()) {
        case ICON_THEME_LIGHT:
            gallery.setIcon(R.drawable.info_shibafu528_gallerymultipicker_ic_action_gallery_light);
            shot.setIcon(R.drawable.info_shibafu528_gallerymultipicker_ic_action_take_shot_light);
            break;
        case ICON_THEME_DARK:
            gallery.setIcon(R.drawable.info_shibafu528_gallerymultipicker_ic_action_gallery_dark);
            shot.setIcon(R.drawable.info_shibafu528_gallerymultipicker_ic_action_take_shot_dark);
            break;
        }//www  . j  av a2 s .c o m
    return true;
}

From source file:com.technoxist.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;// w  ww .  j  ava  2s . c  o m

            if (mFavorite) {
                item.setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            if (link != null) {
                String title = cursor.getString(mTitlePos);
                startActivity(Intent.createChooser(
                        new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                        getString(R.string.menu_share)));
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:de.grobox.liberario.fragments.DirectionsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_navigation_expand:
        if (ui.products.getVisibility() == GONE) {
            item.setIcon(getToolbarDrawable(getContext(), R.drawable.ic_action_navigation_unfold_less));
            Preferences.setPref(getActivity(), SHOW_ADV_DIRECTIONS, true);
            showMore(true);/*  ww w.  java  2  s.c  o  m*/
        } else {
            item.setIcon(getToolbarDrawable(getContext(), R.drawable.ic_action_navigation_unfold_more));
            Preferences.setPref(getActivity(), SHOW_ADV_DIRECTIONS, false);
            showLess(true);
        }

        return true;
    case R.id.action_swap_locations:
        swapLocations();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.properties.DetailsFragment.java

public static void getMenu(AlfrescoSession session, Activity activity, Menu menu, Node node,
        boolean actionMode) {
    MenuItem mi;

    if (node == null) {
        return;/*ww w .j  a  v  a 2s .  com*/
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_DOWNLOAD, Menu.FIRST + MenuActionItem.MENU_DOWNLOAD,
                    R.string.download);
            mi.setIcon(R.drawable.ic_download_dark);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion()
                && ((DocumentImpl) node).hasAllowableAction(Action.CAN_SET_CONTENT_STREAM.value())) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_UPDATE, Menu.FIRST + MenuActionItem.MENU_UPDATE,
                    R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(session instanceof CloudSession)) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_WORKFLOW_ADD,
                    Menu.FIRST + MenuActionItem.MENU_WORKFLOW_ADD, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (session.getServiceRegistry().getDocumentFolderService().getPermissions(node).canEdit()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT,
                R.string.edit);
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (session.getServiceRegistry().getDocumentFolderService().getPermissions(node).canDelete()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DELETE, 1000 + MenuActionItem.MENU_DELETE,
                R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!DisplayUtils.hasCentralPane(activity)) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_COMMENT, Menu.FIRST + MenuActionItem.MENU_COMMENT,
                R.string.comments);
        mi.setIcon(R.drawable.ic_comment);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        if (node.isDocument()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_VERSION_HISTORY,
                    Menu.FIRST + MenuActionItem.MENU_VERSION_HISTORY, R.string.version_history);
            mi.setIcon(R.drawable.ic_menu_recent_history);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        mi = menu.add(Menu.NONE, MenuActionItem.MENU_TAGS, Menu.FIRST + MenuActionItem.MENU_TAGS,
                R.string.tags);
        mi.setIcon(R.drawable.mime_tags);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:com.cw.litenote.drawer.Drawer.java

public Drawer(AppCompatActivity activity) {
    drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);

    mNavigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    mNavigationView.setItemIconTintList(null);// use original icon color

    // set icon for folder draggable: portrait
    if (Util.isPortraitOrientation(MainAct.mAct) && (MainAct.mPref_show_note_attribute != null)) {
        if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                .equalsIgnoreCase("yes"))
            mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP)
                    .setIcon(R.drawable.btn_check_on_holo_light);
        else//from  w ww  .j  a  v a 2s .c  o  m
            mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP)
                    .setIcon(R.drawable.btn_check_off_holo_light);
    }

    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            menuItem.setChecked(true);
            switch (menuItem.getItemId()) {
            case R.id.ADD_NEW_FOLDER:
                FolderUi.renewFirstAndLast_folderId();
                FolderUi.addNewFolder(MainAct.mAct, FolderUi.mLastExist_folderTableId + 1,
                        MainAct.mFolder.getAdapter());
                return true;

            case R.id.ENABLE_FOLDER_DRAG_AND_DROP:
                if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                        .equalsIgnoreCase("yes")) {
                    menuItem.setIcon(R.drawable.btn_check_off_holo_light);
                    MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                            .apply();
                    DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
                    listView.setDragEnabled(false);
                    Toast.makeText(act,
                            act.getResources().getString(R.string.drag_folder) + ": "
                                    + act.getResources().getString(R.string.set_disable),
                            Toast.LENGTH_SHORT).show();
                } else {
                    menuItem.setIcon(R.drawable.btn_check_on_holo_light);
                    MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "yes")
                            .apply();
                    DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
                    listView.setDragEnabled(true);
                    Toast.makeText(act,
                            act.getResources().getString(R.string.drag_folder) + ": "
                                    + act.getResources().getString(R.string.set_enable),
                            Toast.LENGTH_SHORT).show();
                }
                MainAct.mFolder.getAdapter().notifyDataSetChanged();
                act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                return true;

            case R.id.DELETE_FOLDERS:

                DB_drawer dB_drawer = new DB_drawer(act);
                if (dB_drawer.getFoldersCount(true) > 0) {
                    closeDrawer();
                    MainAct.mMenu.setGroupVisible(R.id.group_notes, false); //hide the menu
                    DeleteFolders delFoldersFragment = new DeleteFolders();
                    MainAct.mFragmentTransaction = MainAct.mAct.getSupportFragmentManager().beginTransaction();
                    MainAct.mFragmentTransaction.setCustomAnimations(R.anim.fragment_slide_in_left,
                            R.anim.fragment_slide_out_left, R.anim.fragment_slide_in_right,
                            R.anim.fragment_slide_out_right);
                    MainAct.mFragmentTransaction.replace(R.id.content_frame, delFoldersFragment)
                            .addToBackStack("delete_folders").commit();
                } else {
                    Toast.makeText(act, R.string.config_export_none_toast, Toast.LENGTH_SHORT).show();
                }
                return true;

            default:
                return true;
            }
        }
    });

    act = activity;
    listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    drawerToggle = new ActionBarDrawerToggle(act, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            MainAct.mToolbar, /* tool bar */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerOpened(View drawerView) {
            System.out.println("Drawer / _onDrawerOpened ");

            if (act.getSupportActionBar() != null) {
                act.getSupportActionBar().setTitle(R.string.app_name);
                MainAct.mToolbar.setLogo(R.drawable.ic_launcher);
            }

            act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

            if (listView.getCount() > 0) {
                // will call Folder_adapter _getView to update audio playing high light
                listView.invalidateViews();
            }
        }

        public void onDrawerClosed(View view) {
            System.out.println("Drawer / _onDrawerClosed / FolderUi.getFocus_folderPos() = "
                    + FolderUi.getFocus_folderPos());

            FragmentManager fragmentManager = act.getSupportFragmentManager();
            if (fragmentManager.getBackStackEntryCount() == 0) {
                act.invalidateOptionsMenu(); // creates a call to onPrepareOptionsMenu()

                DB_drawer dB_drawer = new DB_drawer(act);
                if (dB_drawer.getFoldersCount(true) > 0) {
                    int pos = listView.getCheckedItemPosition();
                    MainAct.mFolderTitle = dB_drawer.getFolderTitle(pos, true);

                    if (act.getSupportActionBar() != null) {
                        act.getSupportActionBar().setTitle(MainAct.mFolderTitle);
                        MainAct.mToolbar.setLogo(null);
                    }
                }

                MainAct.openFolder();
            }
        }
    };
}

From source file:com.doplgangr.secrecy.views.FilesListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem item = menu.findItem(R.id.action_switch_interface);
    item.setIcon(isGallery ? R.drawable.ic_list : R.drawable.ic_gallery);
}