Example usage for android.view MenuItem getGroupId

List of usage examples for android.view MenuItem getGroupId

Introduction

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

Prototype

public int getGroupId();

Source Link

Document

Return the group identifier that this menu item is part of.

Usage

From source file:com.nachiket.titan.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    Intent intent = item.getIntent();//from www  .j  a v  a2 s .com

    switch (item.getItemId()) {
    case MENU_EXPAND:
        expand(intent);
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case MENU_NEW_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_RENAME_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename,
                intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_DELETE:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
        break;
    case MENU_ADD_TO_PLAYLIST: {
        SubMenu playlistMenu = item.getSubMenu();
        playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent);
        Cursor cursor = Playlist.queryPlaylists(getContentResolver());
        if (cursor != null) {
            for (int i = 0, count = cursor.getCount(); i != count; ++i) {
                cursor.moveToPosition(i);
                long id = cursor.getLong(0);
                String name = cursor.getString(1);
                Intent copy = new Intent(intent);
                copy.putExtra("playlist", id);
                copy.putExtra("playlistName", name);
                playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy);
            }
            cursor.close();
        }
        break;
    }
    case MENU_SELECT_PLAYLIST:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent));
        break;
    case MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    }

    return true;
}

From source file:android.support.v7.internal.view.menu.MenuBuilder.java

void setExclusiveItemChecked(MenuItem item) {
    final int group = item.getGroupId();

    final int N = mItems.size();
    for (int i = 0; i < N; i++) {
        MenuItemImpl curItem = mItems.get(i);
        if (curItem.getGroupId() == group) {
            if (!curItem.isExclusiveCheckable())
                continue;
            if (!curItem.isCheckable())
                continue;

            // Check the item meant to be checked, uncheck the others (that are in the group)
            curItem.setCheckedInt(curItem == item);
        }//from  w ww  .  j  a v a  2  s. co m
    }
}

From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java

public boolean handleSelectedContextItem(AdapterView.AdapterContextMenuInfo info, MenuItem item) {

    try {/*from  w  w w.j  a v a 2 s .  c  om*/

        // Let's get the item
        ForumPostData data = (ForumPostData) info.targetView.getTag();

        // Divide & conquer
        if (item.getGroupId() == 0) {

            // REQUESTS
            switch (item.getItemId()) {

            case 0:
                startActivity(
                        new Intent(context, ProfileActivity.class).putExtra("profile", data.getProfileData()));
                break;

            case 1:
                Toast.makeText(context, R.string.info_forum_quote_warning, Toast.LENGTH_SHORT).show();
                textareaContent.setText(

                        textareaContent.getText().insert(

                                textareaContent.getSelectionStart(), Constants.BBCODE_TAG_QUOTE_IN.replace(

                                        "{number}", data.getPostId() + ""

                                ).replace(

                                        "{username}", data.getProfileData().getUsername()

                                )

                        )

                );
                selectedQuotes.put(data.getPostId(),
                        (data.isCensored() ? getString(R.string.general_censored) : data.getContent()));
                break;

            case 2:
                generatePopupWithLinks(data.getContent());
                break;

            case 3:
                startActivity(
                        new Intent(context, ForumReportActivity.class).putExtra("postId", data.getPostId()));
                break;

            default:
                Toast.makeText(context, R.string.msg_unimplemented, Toast.LENGTH_SHORT).show();
                break;

            }

        }

        return true;

    } catch (Exception ex) {

        ex.printStackTrace();
        return false;

    }

}

From source file:org.planetmono.dcuploader.ActivityUploader.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int id = item.getItemId();
    int group = item.getGroupId();

    if (group == MENU_GROUP_SELECT_GALLERY) {
        switch (id) {
        case MENU_ADD_GALLERY:
            startActivityForResult(new Intent(this, ActivityGalleryChooser.class),
                    Application.ACTION_ADD_GALLERY);

            return true;
        default:/*from   w ww  . j  av  a 2s.  c o  m*/
            resolveTarget(ids.get(id));

            setDefaultImage();

            if (!passThrough)
                ((Button) findViewById(R.id.upload_visit)).setEnabled(true);

            return true;
        }
    } else if (group == MENU_GROUP_VISIT) {
        visitPage(id);

        return true;
    }

    return true;
}

From source file:mp.teardrop.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == MENU_GROUP_ROUND_BUTTON) {

        Limiter limiter = mPagerAdapter.getCurrentLimiter();
        Intent intent = null;// ww  w .  j a  v a 2 s  .  c o  m

        switch (mPagerAdapter.getCurrentType()) {
        case MediaUtils.TYPE_FILE:
            intent = new Intent();
            intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE);
            intent.putExtra("file", limiter == null ? "/" : limiter.data.toString());
            break;
        case MediaUtils.TYPE_UNIFIED:
            if (limiter != null && limiter.type <= 20) {
                intent = new Intent();
                intent.putExtra(LibraryAdapter.DATA_TYPE, limiter.type);
                intent.putExtra(LibraryAdapter.DATA_ID, (Long) limiter.data);
            } //else continue with null limiter, which will play the entire MediaStore
            break;
        }

        mRoundPlayAllButton.setVisibility(View.GONE);

        pickSongs(intent, item.getItemId() == MENU_PLAY_ALL ? ACTION_PLAY_ALL : ACTION_ENQUEUE_ALL);

        return true;
    }

    if (item.getGroupId() != 0) {
        return super.onContextItemSelected(item);
    }

    final Intent intent = item.getIntent();

    switch (item.getItemId()) {
    case MENU_EXPAND:
        expand(intent);
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
        }
        break;
    case MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case MENU_NEW_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_RENAME_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename,
                intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case MENU_ADD_TO_PLAYLIST: {
        SubMenu playlistMenu = item.getSubMenu();
        playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent);
        Cursor cursor = Playlist.queryPlaylists(getContentResolver());
        if (cursor != null) {
            for (int i = 0, count = cursor.getCount(); i != count; ++i) {
                cursor.moveToPosition(i);
                long id = cursor.getLong(0);
                String name = cursor.getString(1);
                Intent copy = new Intent(intent);
                copy.putExtra("playlist", id);
                copy.putExtra("playlistName", name);
                playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy);
            }
            cursor.close();
        }
        break;
    }
    case MENU_SELECT_PLAYLIST:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent));
        break;
    case MENU_MORE_FROM_ARTIST: {
        String selection = "_id=";
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(-1, selection);
        updateLimiterViews();
        break;
    }
    case MENU_MORE_FROM_ALBUM:
        setLimiter(-1, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    }

    return true;
}

From source file:it.feio.android.omninotes.ListFragment.java

private void checkSortActionPerformed(MenuItem item) {
    if (item.getGroupId() == Constants.MENU_SORT_GROUP_ID) {
        final String[] arrayDb = getResources().getStringArray(R.array.sortable_columns);
        prefs.edit().putString(Constants.PREF_SORTING_COLUMN, arrayDb[item.getOrder()]).commit();
        initNotesList(mainActivity.getIntent());
        // Resets list scrolling position
        listViewPositionOffset = 16;//from  w  w  w  .j  av a 2  s. c om
        listViewPosition = 0;
        restoreListScrollPosition();
        // Updates app widgets
        BaseActivity.notifyAppWidgets(mainActivity);
    }
}

From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    // Declare...
    AdapterView.AdapterContextMenuInfo info;

    // Let's try to get some menu information via a try/catch
    try {/*  w  w  w .  j  a  va 2s  .c o  m*/

        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    } catch (ClassCastException e) {

        e.printStackTrace();
        return false;

    }

    try {

        // Let's get the item
        ForumPostData data = (ForumPostData) info.targetView.getTag();

        // Divide & conquer
        if (item.getGroupId() == 0) {

            // REQUESTS
            switch (item.getItemId()) {

            case 0:
                startActivity(
                        new Intent(context, ProfileActivity.class).putExtra("profile", data.getProfileData()));
                break;

            case 1:
                Toast.makeText(context, R.string.info_forum_quote_warning, Toast.LENGTH_SHORT).show();
                textareaContent.setText(

                        textareaContent.getText().insert(

                                textareaContent.getSelectionStart(), Constants.BBCODE_TAG_QUOTE_IN.replace(

                                        "{number}", data.getPostId() + ""

                                ).replace(

                                        "{username}", data.getProfileData().getUsername()

                                )

                        )

                );
                selectedQuotes.put(data.getPostId(),
                        (data.isCensored() ? getString(R.string.general_censored) : data.getContent()));
                break;

            case 2:
                generatePopupWithLinks(data.getContent());
                break;

            case 3:
                startActivity(
                        new Intent(context, ForumReportActivity.class).putExtra("postId", data.getPostId()));
                break;

            default:
                Toast.makeText(context, R.string.msg_unimplemented, Toast.LENGTH_SHORT).show();
                break;

            }

        }

    } catch (Exception ex) {

        ex.printStackTrace();
        return false;

    }

    return true;

}

From source file:com.dycody.android.idealnote.ListFragment.java

private void checkSortActionPerformed(MenuItem item) {
    if (item.getGroupId() == Constants.MENU_SORT_GROUP_ID) {
        final String[] arrayDb = getResources().getStringArray(R.array.sortable_columns);
        prefs.edit().putString(Constants.PREF_SORTING_COLUMN, arrayDb[item.getOrder()]).apply();
        initNotesList(mainActivity.getIntent());
        // Resets list scrolling position
        listViewPositionOffset = 16;/*from   www. j a  v a2  s.c  o m*/
        listViewPosition = 0;
        restoreListScrollPosition();
        toggleSearchLabel(false);
        // Updates app widgets
        BaseActivity.notifyAppWidgets(mainActivity);
    } else {
        ((IdealNote) getActivity().getApplication()).getAnalyticsHelper()
                .trackActionFromResourceId(getActivity(), item.getItemId());
    }
}

From source file:co.taqat.call.ChatFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DELETE_MESSAGE:
        if (chatRoom != null) {
            LinphoneChatMessage message = getMessageForId(item.getGroupId());
            if (message != null) {
                chatRoom.deleteMessage(message);
                invalidate();//ww w  . j a  v a  2s . c  o  m
            }
        }
        break;
    case MENU_COPY_TEXT:
        copyTextMessageToClipboard(item.getGroupId());
        break;
    case MENU_RESEND_MESSAGE:
        resendMessage(item.getGroupId());
        break;
    case MENU_PICTURE_SMALL:
        sendImageMessage(filePathToUpload, SIZE_SMALL);
        break;
    case MENU_PICTURE_MEDIUM:
        sendImageMessage(filePathToUpload, SIZE_MEDIUM);
        break;
    case MENU_PICTURE_LARGE:
        sendImageMessage(filePathToUpload, SIZE_LARGE);
        break;
    case MENU_PICTURE_REAL:
        sendImageMessage(filePathToUpload, SIZE_MAX);
        break;
    }
    return true;
}