Example usage for android.view Menu NONE

List of usage examples for android.view Menu NONE

Introduction

In this page you can find the example usage for android.view Menu NONE.

Prototype

int NONE

To view the source code for android.view Menu NONE.

Click Source Link

Document

Value to use for group and item identifier integers when you don't care about them.

Usage

From source file:com.grarak.kerneladiutor.fragments.tools.ProfileFragment.java

private void load(List<RecyclerViewItem> items) {
    mProfiles = new Profiles(getActivity());
    List<Profiles.ProfileItem> profileItems = mProfiles.getAllProfiles();
    if (mTaskerMode && profileItems.size() == 0) {
        Snackbar.make(getRootView(), R.string.no_profiles, Snackbar.LENGTH_LONG).show();
        return;/* w  ww. ja  va 2  s. c  o  m*/
    }
    for (int i = 0; i < profileItems.size(); i++) {
        final int position = i;
        final CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {
            @Override
            public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.append));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.details));
                final MenuItem onBoot = menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.on_boot))
                        .setCheckable(true);
                onBoot.setChecked(mProfiles.getAllProfiles().get(position).isOnBootEnabled());
                menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.export));
                menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.delete));

                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        List<Profiles.ProfileItem> items = mProfiles.getAllProfiles();
                        switch (item.getItemId()) {
                        case 0:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileActivity.class);
                                intent.putExtra(ProfileActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 2);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 1:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
                                intent.putExtra(ProfileEditActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 3);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 2:
                            if (items.get(position).getName() != null) {
                                List<Profiles.ProfileItem.CommandItem> commands = items.get(position)
                                        .getCommands();
                                if (commands.size() > 0) {
                                    setForegroundText(items.get(position).getName().toUpperCase());
                                    mDetailsFragment.setText(commands);
                                    showForeground();
                                } else {
                                    Utils.toast(R.string.profile_empty, getActivity());
                                }
                            }
                            break;
                        case 3:
                            onBoot.setChecked(!onBoot.isChecked());
                            items.get(position).enableOnBoot(onBoot.isChecked());
                            mProfiles.commit();
                            break;
                        case 4:
                            mExportProfile = items.get(position);
                            requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                            break;
                        case 5:
                            mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                        }
                                    }, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            mProfiles.delete(position);
                                            mProfiles.commit();
                                            reload();
                                        }
                                    }, new DialogInterface.OnDismissListener() {
                                        @Override
                                        public void onDismiss(DialogInterface dialogInterface) {
                                            mDeleteDialog = null;
                                        }
                                    }, getActivity());
                            mDeleteDialog.show();
                            break;
                        }
                        return false;
                    }
                });
            }
        });

        final DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(profileItems.get(i).getName());
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
                if (mTaskerMode) {
                    mSelectDialog = ViewUtils.dialogBuilder(
                            getString(R.string.select_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    ((ProfileTaskerActivity) getActivity()).finish(
                                            descriptionView.getSummary().toString(),
                                            mProfiles.getAllProfiles().get(position).getCommands());
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mSelectDialog = null;
                                }
                            }, getActivity());
                    mSelectDialog.show();
                } else {
                    mApplyDialog = ViewUtils.dialogBuilder(
                            getString(R.string.apply_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    for (Profiles.ProfileItem.CommandItem command : mProfiles.getAllProfiles()
                                            .get(position).getCommands()) {
                                        CPUFreq.ApplyCpu applyCpu;
                                        if (command.getCommand().startsWith("#")
                                                && ((applyCpu = new CPUFreq.ApplyCpu(
                                                        command.getCommand().substring(1)))
                                                                .toString() != null)) {
                                            for (String applyCpuCommand : Service.getApplyCpu(applyCpu,
                                                    RootUtils.getSU())) {
                                                Control.runSetting(applyCpuCommand, null, null, null);
                                            }
                                        } else {
                                            Control.runSetting(command.getCommand(), null, null, null);
                                        }
                                    }
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mApplyDialog = null;
                                }
                            }, getActivity());
                    try {
                        mApplyDialog.show();
                    } catch (NullPointerException ignored) {
                    }
                }
            }
        });

        if (mTaskerMode) {
            items.add(descriptionView);
        } else {
            cardView.addItem(descriptionView);
            items.add(cardView);
        }
    }

    if (!mTaskerMode) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
        int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(getActivity(), Widget.class));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.profile_list);
        Tile.publishProfileTile(profileItems, getActivity());
    }
}

From source file:com.inovex.zabbixmobile.activities.BaseActivity.java

private void toggleServerSelectionMode() {
    Menu menu = mNavigationView.getMenu();
    if (mServerSelectMode) {
        // show normal menu
        menu.setGroupVisible(R.id.grp1, true);
        menu.setGroupVisible(R.id.grp2, true);
        menu.removeGroup(R.id.grp0_server);
        mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle));

    } else {//from ww w.  j  a  v a2 s. c  o  m
        // show server selection list
        menu.setGroupVisible(R.id.grp1, false);
        menu.setGroupVisible(R.id.grp2, false);
        for (int i = 0; i < mServersListAdapter.getCount(); i++) {
            ZabbixServer server = mServersListAdapter.getItem(i);
            menu.add(R.id.grp0_server, (int) server.getId(), Menu.NONE, server.getName())
                    .setIcon(R.drawable.ic_monitor_grey600_24dp);
        }
        mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle_flipped));
    }
    mServerSelectMode = !mServerSelectMode;
}

From source file:it.unibs.sandroide.lib.beacon.ui.BeaconTagActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*from w  w w  . ja v  a 2s . c om*/

    menu.add(0, MENU_ADD, Menu.NONE, "Load").setIcon(android.R.drawable.ic_menu_add);
    menu.add(0, MENU_LIST, Menu.NONE, "Save").setIcon(android.R.drawable.ic_menu_upload);
    return super.onPrepareOptionsMenu(menu);
}

From source file:android.support.v7.widget.ShareActionProvider.java

/**
 * {@inheritDoc}//from w  ww  . j  av a2s  . c  om
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:de.sindzinski.wetter.MainActivity.java

private void addLocationToNavigation() {
    Cursor locationCursor = this.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING }, "", new String[] {}, null);

    final Menu menu = navigationView.getMenu();
    int i = 0;/*  ww w  .  j a  va2  s . co  m*/
    while (locationCursor.moveToNext()) {
        i++;
        String locationSetting = locationCursor.getString(
                locationCursor.getColumnIndex(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING));
        menu.add(R.id.group1, i, Menu.NONE, locationSetting)
                .setIcon(ContextCompat.getDrawable(this, R.drawable.ic_home_black_24dp));
    }
    locationCursor.close();
}

From source file:com.example.FilteredShareActionProvider.java

/**
 * {@inheritDoc}/*from ww  w  .j a v  a  2s . c o m*/
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    FilteredActivityChooserModel dataModel = FilteredActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:edu.chalmers.dat255.audiobookplayer.view.BookshelfFragment.java

@SuppressWarnings("rawtypes")
@Override//  w  ww . java2s  .  co  m
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // check that the menuInfo is of the correct type
    // this method is allowed to have quite a high cyclomatic complexity as
    // it would otherwise cause code duplication

    if (menuInfo instanceof ExpandableListContextMenuInfo && adapter != null) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        // get the provided book position
        int bookIndex = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        // trackIndex will be -1 if group is clicked
        int trackIndex = ExpandableListView.getPackedPositionChild(info.packedPosition);
        // get the type of the context menu
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        // create an empty array to prevent trying to loop over an
        // uninitialized variable
        IContextMenuItem[] menuItems = new IContextMenuItem[0];
        String title = "";
        // fill the context menu with the correct items
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            // get all menu items from the child context menu
            menuItems = ChildContextMenuItem.values();
            // set the context menu's title to that of the value of the
            // child
            title = adapter.getChild(bookIndex, trackIndex);

        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            // get all menu items from the group context menu
            menuItems = GroupContextMenuItem.values();
            // set the context menu's title to that of the value of the book
            title = adapter.getGroup(bookIndex);
        }
        // set the title
        menu.setHeaderTitle(title);
        // populate the context menu with items in the order they were
        // declared in the enum declaration.
        for (IContextMenuItem item : menuItems) {
            // as this only loops when menuItems is of either of type
            // GroupContextMenuItem[] or ChildContextMenuItem[], Enum can be
            // used as a raw type
            menu.add(Menu.NONE, ((Enum) item).ordinal(), ((Enum) item).ordinal(), item.getText());
        }
    }
}

From source file:com.audiokernel.euphonyrmt.fragments.SongsFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.songs, container, false);
    mList = (AbsListView) view.findViewById(R.id.list);
    registerForContextMenu(mList);//from w  w w.  j a  v  a2  s  .  c  om
    mList.setOnItemClickListener(this);

    mLoadingView = view.findViewById(R.id.loadingLayout);
    mLoadingTextView = (TextView) view.findViewById(R.id.loadingText);
    mNoResultView = view.findViewById(R.id.noResultLayout);
    mLoadingTextView.setText(getLoadingText());

    final View headerView = inflater.inflate(R.layout.song_header, null, false);
    mCoverArt = (ImageView) view.findViewById(R.id.albumCover);
    if (mCoverArt != null) {
        mHeaderArtist = (TextView) view.findViewById(R.id.tracks_artist);
        mHeaderInfo = (TextView) view.findViewById(R.id.tracks_info);
        mCoverArtProgress = (ProgressBar) view.findViewById(R.id.albumCoverProgress);
        mAlbumMenu = (ImageButton) view.findViewById(R.id.album_menu);
    } else {
        mHeaderArtist = (TextView) headerView.findViewById(R.id.tracks_artist);
        mHeaderInfo = (TextView) headerView.findViewById(R.id.tracks_info);
        mCoverArt = (ImageView) headerView.findViewById(R.id.albumCover);
        mCoverArtProgress = (ProgressBar) headerView.findViewById(R.id.albumCoverProgress);
        mAlbumMenu = (ImageButton) headerView.findViewById(R.id.album_menu);
    }

    mCoverArtListener = new AlbumCoverDownloadListener(mCoverArt, mCoverArtProgress, false);
    mCoverHelper = new CoverAsyncHelper();
    mCoverHelper.setCoverMaxSizeFromScreen(getActivity());
    final ViewTreeObserver vto = mCoverArt.getViewTreeObserver();
    vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (mCoverHelper != null) {
                mCoverHelper.setCachedCoverMaxSize(mCoverArt.getMeasuredHeight());
            }
            return true;
        }
    });
    mCoverHelper.addCoverDownloadListener(mCoverArtListener);

    ((TextView) headerView.findViewById(R.id.separator_title)).setText(R.string.songs);
    ((ListView) mList).addHeaderView(headerView, null, false);

    mPopupMenu = new PopupMenu(getActivity(), mAlbumMenu);
    mPopupMenu.getMenu().add(Menu.NONE, ADD, Menu.NONE, R.string.addAlbum);
    mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE, Menu.NONE, R.string.addAndReplace);
    mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE_PLAY, Menu.NONE, R.string.addAndReplacePlay);
    mPopupMenu.getMenu().add(Menu.NONE, ADD_PLAY, Menu.NONE, R.string.addAndPlay);
    mPopupMenu.getMenu().add(Menu.NONE, GOTO_ARTIST, Menu.NONE, R.string.goToArtist);

    mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            final int itemId = item.getItemId();
            if (itemId == GOTO_ARTIST) {
                final Intent intent = new Intent(getActivity(), SimpleLibraryActivity.class);
                intent.putExtra("artist", mAlbum.getArtist());
                startActivityForResult(intent, -1);
            } else {
                mApp.oMPDAsyncHelper.execAsync(new Runnable() {
                    @Override
                    public void run() {
                        boolean replace = false;
                        boolean play = false;
                        switch (itemId) {
                        case ADD_REPLACE_PLAY:
                            replace = true;
                            play = true;
                            break;
                        case ADD_REPLACE:
                            replace = true;
                            break;
                        case ADD_PLAY:
                            play = true;
                            break;
                        default:
                            break;
                        }
                        try {
                            mApp.oMPDAsyncHelper.oMPD.add(mAlbum, replace, play);
                            Tools.notifyUser(R.string.albumAdded, mAlbum);
                        } catch (final IOException | MPDException e) {
                            Log.e(TAG, "Failed to add, replace, play.", e);
                        }
                    }
                });
            }
            return true;
        }
    });

    mAlbumMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(mPopupMenu));
    mAlbumMenu.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            mPopupMenu.show();
        }
    });

    mCoverPopupMenu = new PopupMenu(getActivity(), mCoverArt);
    mCoverPopupMenu.getMenu().add(POPUP_COVER_BLACKLIST, POPUP_COVER_BLACKLIST, 0, R.string.otherCover);
    mCoverPopupMenu.getMenu().add(POPUP_COVER_SELECTIVE_CLEAN, POPUP_COVER_SELECTIVE_CLEAN, 0,
            R.string.resetCover);
    mCoverPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            final int groupId = item.getGroupId();
            boolean result = true;

            if (groupId == POPUP_COVER_BLACKLIST) {
                final AlbumInfo albumInfo = new AlbumInfo(mAlbum);

                CoverManager.getInstance().markWrongCover(albumInfo);
                updateCover(albumInfo);
                updateNowPlayingSmallFragment(albumInfo);
            } else if (groupId == POPUP_COVER_SELECTIVE_CLEAN) {
                final AlbumInfo albumInfo = new AlbumInfo(mAlbum);

                CoverManager.getInstance().clear(albumInfo);
                updateCover(albumInfo);
                updateNowPlayingSmallFragment(albumInfo);
            } else {
                result = false;
            }

            return result;
        }
    });

    mCoverArt.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            mCoverPopupMenu.show();
            return false;
        }
    });

    updateFromItems();

    return view;
}

From source file:org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder.java

/**
 * Convenience method to reduce multi-line function call to single line.
 *///from   w  w  w.java 2 s . c  o  m
private static void addContextMenuItem(ContextMenu menu, int id, int resourceId,
        OnMenuItemClickListener listener) {
    menu.add(Menu.NONE, id, Menu.NONE, resourceId).setOnMenuItemClickListener(listener);
}

From source file:com.janela.mobile.ui.user.HomeActivity.java

@Override
public void onLoadFinished(Loader<List<User>> listLoader, List<User> orgs) {
    this.orgs = orgs;

    int sharedPreferencesOrgId = sharedPreferences.getInt(PREF_ORG_ID, -1);
    int targetOrgId = org == null ? sharedPreferencesOrgId : org.getId();

    Menu menu = navigationView.getMenu();
    menu.removeGroup(R.id.user_select);/*from   w w  w  .j  av a 2  s.  c o  m*/
    for (int i = 0; i < orgs.size(); ++i) {
        final MenuItem item = menu.add(R.id.user_select, i, Menu.NONE, orgs.get(i).getLogin());
        avatars.bind(item, orgs.get(i));
        if (orgs.get(i).getId() == targetOrgId) {
            setOrg(orgs.get(i));
        }
    }

    // If the target org is invalid (e.g. first login), select the first one
    if (targetOrgId == -1 && orgs.size() > 0) {
        setOrg(orgs.get(0));
    }

    menu.setGroupVisible(R.id.user_select, false);
}