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.alfresco.mobile.android.application.fragments.fileexplorer.FileActions.java

private void getMenu(Menu menu) {
    menu.clear();//w  w  w .  java 2 s . c om

    MenuItem mi;

    if (getFragment() instanceof ListingModeFragment) {
        switch (((ListingModeFragment) getFragment()).getMode()) {
        case FileExplorerFragment.MODE_LISTING:
            if (selectedFolder.isEmpty()) {
                mi = menu.add(Menu.NONE, R.id.menu_upload, Menu.FIRST + 30, R.string.upload);
                mi.setIcon(R.drawable.ic_upload);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

                mi = menu.add(Menu.NONE, R.id.menu_action_share, Menu.FIRST + 100, R.string.share);
                mi.setIcon(R.drawable.ic_share);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }

            mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
            mi.setIcon(R.drawable.ic_delete);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            break;

        case FileExplorerFragment.MODE_PICK:

            if (selectedFolder.isEmpty()) {
                mi = menu.add(Menu.NONE, R.id.menu_file_send, Menu.FIRST, R.string.action_upload);
                mi.setIcon(R.drawable.ic_upload);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS);
            }

            break;

        default:
            break;
        }
        mi = menu.add(Menu.NONE, R.id.menu_select_all, Menu.FIRST + 200, R.string.select_all);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*  w  ww.jav  a2  s .co m*/

    if (showOperationsMenu) {
        MenuItem mi = menu.add(Menu.NONE, R.id.menu_notifications, Menu.FIRST, R.string.notifications);
        mi.setIcon(R.drawable.ic_events_dark);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }
}

From source file:pro.dbro.iburn_2012.OpenStreetMapFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!FragmentTabsPager.app.embargoClear) {
        MenuItem unlockItem = menu.add(Menu.NONE, R.id.menu_unlock, Menu.NONE, "Unlock");
        MenuItemCompat.setShowAsAction(unlockItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        unlockItem.setIcon(R.drawable.unlock);
        unlockItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @Override//w  w  w.j  a v  a 2  s .c om
            public boolean onMenuItemClick(MenuItem item) {
                if (!FragmentTabsPager.app.embargoClear) {
                    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

                    alert.setTitle("Enter Unlock Password");

                    // Set an EditText view to get user input 
                    final EditText input = new EditText(getActivity());
                    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                    alert.setView(input);
                    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            String value = input.getText().toString();
                            if (value.compareTo(FragmentTabsPager.app.unlockPassword) == 0) {
                                FragmentTabsPager.app.setEmbargoClear(true);
                                mLocationOverlay.enableMyLocation();
                                getActivity().findViewById(R.id.map_placeholder).setVisibility(View.GONE);
                                mapView.setVisibility(View.VISIBLE);

                            } else {
                                dialog.cancel();
                                AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
                                alert.setTitle("Invalid Password");
                                alert.show();
                            }
                        }
                    });

                    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    });

                    alert.show();
                    //FragmentTabsPager.app.embargoClear = true;
                }
                return false;
            }

        });
    }

}

From source file:com.ustadmobile.port.android.view.CatalogOPDSFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mDeleteOptionAvailable && mSelectedEntries.length > 0) {
        MenuItem item = menu.add(Menu.NONE, MENUCMDID_DELETE, 1, "");
        item.setIcon(R.drawable.ic_delete_white_24dp);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }/* w ww . ja v  a  2s .com*/

    super.onCreateOptionsMenu(menu, inflater);

}

From source file:org.mixare.MixListView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    int base = Menu.FIRST;

    /*define menu items*/
    MenuItem item1 = menu.add(base, base, base, getString(DataView.MENU_ITEM_3));
    MenuItem item2 = menu.add(base, base + 1, base + 1, getString(DataView.MENU_CAM_MODE));
    /*assign icons to the menu items*/
    item1.setIcon(android.R.drawable.ic_menu_mapmode);
    item2.setIcon(android.R.drawable.ic_menu_camera);

    return true;//  w  w w . j av  a  2  s .  c om
}

From source file:com.velli.passwordmanager.FragmentPasswords.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem viewAsButton = menu.findItem(R.id.menu_view_as);
    if (viewAsButton != null) {
        viewAsButton.setIcon(mShowAsList ? R.drawable.ic_action_view_list : R.drawable.ic_action_view_grid);
    }/*  w w  w.ja va  2s.  c  o  m*/
}

From source file:com.todoroo.astrid.actfm.CommentsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (menu.size() > 0) {
        return;//w  w  w .ja v  a 2 s . co m
    }

    MenuItem item;
    boolean showCommentsRefresh = false;
    if (showCommentsRefresh) {
        Activity activity = getActivity();
        if (activity instanceof TaskListActivity) {
            TaskListActivity tla = (TaskListActivity) activity;
            showCommentsRefresh = tla.getTaskEditFragment() == null;
        }
    }
    if (showCommentsRefresh) {
        item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE, R.string.ENA_refresh_comments);
        item.setIcon(R.drawable.icn_menu_refresh_dark);
    }
}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

private void initToolbar() {

    Resources res = getResources();

    mToolbar.setNavigationIcon(R.drawable.ic_drawer_raw);
    mToolbar.setNavigationContentDescription(R.string.tab);

    Menu menu = mToolbar.getMenu();
    List<MenuItemInfo> menuItemInfos = MenuFactory.getInstance(this).getToolbarIcon();
    for (MenuItemInfo item : menuItemInfos) {
        MenuItem menuItem = menu.add(MenuDef.GROUP_TOOLBAR, item.getItemId(), Menu.NONE, item.getTitleResId());
        menuItem.setIcon(MenuManager.makeToolbarNormalIcon(res, item.getIconResId()));

        //menuItem.setShortcut()
        menuItem.setOnMenuItemClickListener(this);
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }/*  w w w. ja  v a 2  s . c o  m*/
    MenuItem menuItem = menu.add(MenuDef.GROUP_TOOLBAR, R.id.m_menu, Menu.NONE, getString(R.string.more_menu));
    menuItem.setIcon(R.drawable.ic_right_menu);
    menuItem.setOnMenuItemClickListener(this);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    tabManager = new TabManager(this);
}

From source file:org.apache.cordova.plugins.Actionable.java

public void buildMenu() {
    for (Actionable act : mMenuItems.values()) {
        MenuItem mi = mMenu.add(Menu.NONE, Menu.NONE, act.getOrder(), act.getTitle());

        mi.setTitleCondensed(act.getTitle());
        mi.setShowAsAction(act.getFlags());

        if (act.isDisabled()) {
            mi.setEnabled(false);//from  w  w w  .j  av  a 2 s. c o m
        }

        if (act.getIcon() != null) {
            mi.setIcon(act.getIcon());
        }
    }
}

From source file:com.barbrdo.app.activities.UserProfileActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem edit = menu.findItem(R.id.action_edit);
    if (isEdit) {
        edit.setIcon(R.drawable.ic_save_white_24dp);
        edit.setTitle(R.string.save);/* w w w  .  j  av a 2s  .  c  o  m*/
    } else {
        edit.setIcon(R.drawable.ic_edit_white_24dp);
        edit.setTitle(R.string.edit);
    }
    return true;
}