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:com.xandy.calendar.AllInOneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    mOptionsMenu = menu;// w w  w  . j  a  va2  s . com
    getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);

    // Add additional options (if any).
    Integer extensionMenuRes = mExtensions.getExtensionMenuResource(menu);
    if (extensionMenuRes != null) {
        getMenuInflater().inflate(extensionMenuRes, menu);
    }

    mSearchMenu = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) mSearchMenu.getActionView();
    if (mSearchView != null) {
        Utils.setUpSearchView(mSearchView, this);
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setOnSuggestionListener(this);
    }

    // Hide the "show/hide controls" button if this is a phone
    // or the view type is "Month" or "Agenda".

    mControlsMenu = menu.findItem(R.id.action_hide_controls);
    if (!mShowCalendarControls) {
        if (mControlsMenu != null) {
            mControlsMenu.setVisible(false);
            mControlsMenu.setEnabled(false);
        }
    } else if (mControlsMenu != null && mController != null
            && (mController.getViewType() == ViewType.MONTH || mController.getViewType() == ViewType.AGENDA)) {
        mControlsMenu.setVisible(false);
        mControlsMenu.setEnabled(false);
    } else if (mControlsMenu != null) {
        mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
    }

    MenuItem menuItem = menu.findItem(R.id.action_today);
    if (Utils.isJellybeanOrLater()) {
        // replace the default top layer drawable of the today icon with a
        // custom drawable that shows the day of the month of today
        LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
        Utils.setTodayIcon(icon, this, mTimeZone);
    } else {
        menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light);
    }
    return true;
}

From source file:nya.miku.wishmaster.ui.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.menu = menu;
    MenuItem itemUpdate = menu.add(Menu.NONE, R.id.menu_update, 1, R.string.menu_update);
    MenuItem itemSave = menu.add(Menu.NONE, R.id.menu_save_attachment, 2, R.string.menu_save_attachment);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        itemUpdate.setIcon(ThemeUtils.getActionbarIcon(getTheme(), getResources(), R.attr.actionRefresh));
        itemSave.setIcon(ThemeUtils.getActionbarIcon(getTheme(), getResources(), R.attr.actionSave));
        CompatibilityImpl.setShowAsActionIfRoom(itemUpdate);
        CompatibilityImpl.setShowAsActionIfRoom(itemSave);
    } else {/*from   ww  w .  j  a va2s  . c o m*/
        itemUpdate.setIcon(R.drawable.ic_menu_refresh);
        itemSave.setIcon(android.R.drawable.ic_menu_save);
    }
    menu.add(Menu.NONE, R.id.menu_open_external, 3, R.string.menu_open).setIcon(R.drawable.ic_menu_set_as);
    menu.add(Menu.NONE, R.id.menu_share, 4, R.string.menu_share).setIcon(android.R.drawable.ic_menu_share);
    menu.add(Menu.NONE, R.id.menu_share_link, 5, R.string.menu_share_link)
            .setIcon(android.R.drawable.ic_menu_share);
    menu.add(Menu.NONE, R.id.menu_search_google, 6, R.string.menu_search_google)
            .setIcon(android.R.drawable.ic_menu_search);
    menu.add(Menu.NONE, R.id.menu_open_browser, 7, R.string.menu_open_browser)
            .setIcon(R.drawable.ic_menu_browser);
    updateMenu();

    return true;
}

From source file:com.ringdroid.RingdroidEditActivity.java

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

    item = menu.add(0, CMD_SAVE, 0, R.string.menu_save);
    item.setIcon(R.drawable.menu_save);

    item = menu.add(0, CMD_RESET, 0, R.string.menu_reset);
    item.setIcon(R.drawable.menu_reset);

    // item = menu.add(0, CMD_ABOUT, 0, R.string.menu_about);
    // item.setIcon(R.drawable.menu_about);

    item = menu.add(0, CMD_USE_ALL, 0, R.string.use_all);
    item.setIcon(R.drawable.ic_menu_chat_dashboard);

    return true;//from   ww  w.j a v a2 s.  c  o m
}

From source file:net.ddns.mlsoftlaberge.contactslist.ui.ContactsListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Sends a request to the People app to display the create contact screen
    case R.id.menu_add_contact:
        final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
        startActivity(intent);/*  ww  w.jav a 2  s . c  o  m*/
        break;
    // For platforms earlier than Android 3.0, triggers the search activity
    case R.id.menu_search:
        if (!Utils.hasHoneycomb()) {
            getActivity().onSearchRequested();
        }
        break;
    // Sends a request to the People app to display the create contact screen
    case R.id.menu_starred:
        // switch the starred flag on/off
        if (starredfind == 0) {
            starredfind = 1;
            item.setIcon(R.drawable.btn_star_big_on);
        } else {
            starredfind = 0;
            item.setIcon(R.drawable.btn_star_big_off);
        }
        // reread the list with new flag
        getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
        break;
    case R.id.menu_budget:
        // instantiate an activity
        Intent intentbudget = new Intent(getActivity(), ContactsBudgetActivity.class);
        // add animation options
        //ActivityOptions options = ActivityOptions.makeScaleUpAnimation(mContainer,0,0,
        //        200,400);
        // start the activity
        //startActivity(intentbudget , options.toBundle());
        startActivity(intentbudget);

        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    try {/* w ww .j av  a 2  s. c om*/
        getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

        menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

        // Add either a "next" or "finish" button to the action bar, depending on which page
        // is currently selected.
        MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
                (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                        : R.string.action_next);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        item.setIcon(R.drawable.ic_menu_forward);

        MenuItem stepItem = menu.add(Menu.NONE, R.id.action_step_ten, Menu.NONE,
                step10 ? R.string.action_step_ten : R.string.action_step_one);

        stepItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem turn_on_flash_Item = menu.add(Menu.NONE, R.id.action_turn_on_flash, Menu.NONE,
                R.string.action_turn_on_light);

        turn_on_flash_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        turn_on_flash_Item.setIcon(R.drawable.ic_menu_flashlight);

        MenuItem filter_Item = menu.add(Menu.NONE, R.id.action_filter, Menu.NONE, R.string.filter);

        filter_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        filter_Item.setIcon(R.drawable.filter);

        MenuItem search_Item = menu.add(Menu.NONE, R.id.action_search, Menu.NONE, R.string.search);

        search_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem addCustomer_Item = menu.add(Menu.NONE, R.id.action_new_customer, Menu.NONE,
                R.string.new_customer);

        addCustomer_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        setTitle();
        progressbar.setProgress(mPager.getCurrentItem() + 1);
        progressbar.setMax(mPagerAdapter.getCount());
        final Handler handler = new Handler();
        progressbar.setVisibility(View.VISIBLE);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callCount--;
                if (callCount <= 0) {
                    progressbar.setVisibility(View.GONE);
                }
            }
        }, 3000);
        callCount++;
    } catch (Exception ex) {
        ex.toString();
    }
    return true;
}

From source file:de.enlightened.peris.PerisMain.java

public final boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final String customChatForum = this.application.getSession().getServer().chatForum;
    final String customChatThread = this.application.getSession().getServer().chatThread;

    final MenuItem newMailItem = menu.findItem(R.id.main_menu_new_mail);
    newMailItem.setVisible(false);//from  www .  ja  v  a  2s .  c om

    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    if (this.serverUserid == null || !getString(R.string.subforum_id).contentEquals("0")) {
        searchMenuItem.setVisible(false);
    }

    final MenuItem itemLogin = menu.findItem(R.id.main_menu_open_login);
    final MenuItem itemChat = menu.findItem(R.id.main_menu_open_chat);

    if (this.serverUserid == null) {
        itemLogin.setVisible(true);
        itemChat.setVisible(false);
    } else {
        itemLogin.setVisible(false);

        if ((!getString(R.string.chat_thread).contentEquals("0"))
                || (!customChatForum.contentEquals("0") && !customChatThread.contentEquals("0"))) {
            itemChat.setVisible(true);
        }
    }

    if (this.seperator != null) {
        itemLogin.setVisible(false);
        itemChat.setVisible(false);
    }

    if (ThemeSetter.getForegroundDark(this.background)) {
        itemLogin.setIcon(R.drawable.ic_action_accounts_dark);
        itemChat.setIcon(R.drawable.ic_action_group_dark);
        newMailItem.setIcon(R.drawable.ic_action_email_dark);
    }
    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.node.browser.DocumentFolderBrowserFragment.java

public void getMenu(AlfrescoSession session, Menu menu, Folder parentFolder) {
    MenuItem mi;

    if (parentFolder == null) {
        return;/*from   w ww .  jav  a 2 s .  com*/
    }
    try {
        permission = session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder);
    } catch (Exception e) {
        return;
    }

    mi = menu.add(Menu.NONE, R.id.menu_search_from_folder, Menu.FIRST + 10, R.string.search);
    mi.setIcon(R.drawable.ic_search_light);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), parentFolder,
            ConfigurableActionHelper.ACTION_CREATE_DOC)
            || ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), parentFolder,
                    ConfigurableActionHelper.ACTION_CREATE_FOLDER)
            || ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), parentFolder,
                    ConfigurableActionHelper.ACTION_NODE_UPLOAD)) {
        displayFab();
    }
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mService == null)
        return false;
    MenuItem item = menu.findItem(PARTY_SHUFFLE);
    if (item != null) {
        int shuffle = MusicUtils.getCurrentShuffleMode();
        if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle_off);
        } else {// ww  w . j av a 2  s . c o  m
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle);
        }
    }

    item = menu.findItem(ADD_TO_PLAYLIST);
    if (item != null) {
        SubMenu sub = item.getSubMenu();
        MusicUtils.makePlaylistMenu(this, sub);
    }

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    menu.setGroupVisible(1, !km.inKeyguardRestrictedInputMode());

    return true;
}

From source file:com.synox.android.ui.activity.FileDisplayActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    menu.findItem(R.id.action_create_dir).setVisible(false);

    MenuItem layoutView = menu.findItem(R.id.action_changeView);
    if (mAppPreferences.getInt("layoutMode", 0) == R.drawable.ic_list) {
        layoutView.setIcon(R.drawable.ic_list);
    } else {//  ww  w  . j  a  va2  s  .c o m
        layoutView.setIcon(R.drawable.ic_grid);
    }
    return true;
}

From source file:com.example.julia.popularmovies.details.DetailFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_favorite: {
        if (mMovie != null) {
            // check if movie is in favorites or not
            new AsyncTask<Void, Void, Boolean>() {

                @Override//from  w  w w. java 2  s  . com
                protected Boolean doInBackground(Void... params) {
                    return isFavorited();
                }

                @Override
                protected void onPostExecute(final Boolean isFavored) {
                    // if it is in favorites
                    if (isFavored) {
                        // delete from favorites
                        new AsyncTask<Void, Void, Void>() {
                            @Override
                            protected Void doInBackground(Void... params) {
                                getActivity().getContentResolver().delete(MovieEntry.CONTENT_URI,
                                        MovieEntry.COLUMN_ID + " = ?",
                                        new String[] { Long.toString(mMovie.getId()) });
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void v) {
                                item.setIcon(R.drawable.ic_favorite_border_white_48dp);
                                Toast.makeText(getActivity(), "Removed from favorites", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }.execute();
                    }
                    // if it's not in favorites - add to favorites
                    else {
                        new AsyncTask<Void, Void, Void>() {
                            @Override
                            protected Void doInBackground(Void... params) {
                                ContentValues values = new ContentValues();

                                values.put(MovieEntry.COLUMN_ID, mMovie.getId());
                                values.put(MovieEntry.COLUMN_TITLE, mMovie.getTitle());
                                values.put(MovieEntry.COLUMN_DATE, mMovie.getDate());
                                values.put(MovieEntry.COLUMN_PLOT, mMovie.getPlot());
                                values.put(MovieEntry.COLUMN_POSTER, mMovie.getPoster());
                                values.put(MovieEntry.COLUMN_RATING, mMovie.getRating());
                                values.put(MovieEntry.COLUMN_BACKDROP, mMovie.getBackdrop());
                                values.put(MovieEntry.COLUMN_GENRES, mMovie.getGenres());
                                values.put(MovieEntry.COLUMN_RUNTIME, mMovie.getRuntime());

                                getActivity().getContentResolver().insert(MovieEntry.CONTENT_URI, values);
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void v) {
                                item.setIcon(R.drawable.ic_favorite_white_48dp);
                                Toast.makeText(getActivity(), "Marked as favorite", Toast.LENGTH_SHORT).show();
                            }
                        }.execute();
                    }
                }
            }.execute();
        }
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}