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:org.ros.android.app_chooser.ExchangeActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    int groupId = item.getGroupId();
    switch (groupId) {
    case INSTALLED_ITEM_ID:
        switch (menuItemIndex) {
        case 0:// w ww  . j  ava2 s  .  com
            uninstallApp(installedAppListView);
            return true;
        default:
            return false;
        }
    case AVAILABLE_ITEM_ID:
        switch (menuItemIndex) {
        case 0:
            installApp(availableAppListView);
            return true;
        default:
            return false;
        }
    default:
        return false;
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public void onNavigationItemActionClick(MenuItem item) {
    String title = item.getTitle().toString();
    MenuMetadata meta = dataUtils.getDrawerMetadata(item);
    String path = meta.path;// ww  w  . j  a  v  a2  s. c o  m

    switch (item.getGroupId()) {
    case STORAGES_GROUP:
        if (!path.equals("/")) {
            GeneralDialogCreation.showPropertiesDialogForStorage(
                    RootHelper.generateBaseFile(new File(path), true), mainActivity,
                    mainActivity.getAppTheme());
        }
        break;
    // not to remove the first bookmark (storage) and permanent bookmarks
    case SERVERS_GROUP:
    case CLOUDS_GROUP:
    case FOLDERS_GROUP:
        if (dataUtils.containsBooks(new String[] { title, path }) != -1) {
            mainActivity.renameBookmark(title, path);
        } else if (path.startsWith("smb:/")) {
            mainActivity.showSMBDialog(title, path, true);
        } else if (path.startsWith("ssh:/")) {
            mainActivity.showSftpDialog(title, path, true);
        } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_DROPBOX)) {
            GeneralDialogCreation.showCloudDialog(mainActivity, mainActivity.getAppTheme(), OpenMode.DROPBOX);
        } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE)) {
            GeneralDialogCreation.showCloudDialog(mainActivity, mainActivity.getAppTheme(), OpenMode.GDRIVE);
        } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_BOX)) {
            GeneralDialogCreation.showCloudDialog(mainActivity, mainActivity.getAppTheme(), OpenMode.BOX);
        } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_ONE_DRIVE)) {
            GeneralDialogCreation.showCloudDialog(mainActivity, mainActivity.getAppTheme(), OpenMode.ONEDRIVE);
        }
    }
}

From source file:org.thomasamsler.android.flashcards.fragment.CardSetsFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int listItemPosition = (int) getListAdapter().getItemId(info.position);

    switch (item.getGroupId()) {

    case MENU_ITEM_ADD:
        addCard(listItemPosition);/*  ww w.j a  v  a 2s. c  o m*/
        break;
    case MENU_ITEM_DELETE:
        deleteCardSet(listItemPosition);
        break;
    default:
        Log.w(AppConstants.LOG_TAG, "List context menu selection not recognized.");
    }

    return false;
}

From source file:org.zeroxlab.benchmark.Benchmark.java

@Override
public boolean onOptionsItemSelected(MenuItem menu) {
    if (menu.getGroupId() == GROUP_DEFAULT && menu.getItemId() == SETTINGS_ID) {
        org.zeroxlab.utils.Util.launchActivity(this, "org.zeroxlab.benchmark.ActivitySettings");
    }//from   w w w . java2 s.  co  m
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.AccountsDashboardFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mResolver = getContentResolver();//from  ww  w.j av  a  2  s. c  o m
    final View view = getView();
    if (view == null)
        throw new AssertionError();
    final Context context = view.getContext();
    final TwidereApplication application = TwidereApplication.getInstance(context);
    mImageLoader = application.getMediaLoaderWrapper();
    mListView.setItemsCanFocus(true);
    mAdapter = new MergeAdapter();
    final LayoutInflater inflater = getLayoutInflater(savedInstanceState);
    mAccountsAdapter = new AccountSelectorAdapter(context, inflater, this);
    mAccountOptionsAdapter = new AccountOptionsAdapter(context);
    mAppMenuAdapter = new AppMenuAdapter(context);
    mAccountSelectorView = inflater.inflate(R.layout.header_drawer_account_selector, mListView, false);
    mAccountsSelector = (RecyclerView) mAccountSelectorView.findViewById(R.id.other_accounts_list);
    final LinearLayoutManager layoutManager = new FixedLinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    layoutManager.setStackFromEnd(true);
    mAccountsSelector.setLayoutManager(layoutManager);
    mAccountsSelector.setAdapter(mAccountsAdapter);
    mAccountsSelector.setItemAnimator(null);
    mAccountProfileContainer = mAccountSelectorView.findViewById(R.id.profile_container);
    mNoAccountContainer = mAccountSelectorView.findViewById(R.id.no_account_container);
    mAccountProfileImageView = (ShapedImageView) mAccountSelectorView.findViewById(R.id.profile_image);
    mAccountProfileBannerView = (ImageView) mAccountSelectorView.findViewById(R.id.account_profile_banner);
    mFloatingProfileImageSnapshotView = (ImageView) mAccountSelectorView
            .findViewById(R.id.floating_profile_image_snapshot);
    mAccountProfileNameView = (TextView) mAccountSelectorView.findViewById(R.id.name);
    mAccountProfileScreenNameView = (TextView) mAccountSelectorView.findViewById(R.id.screen_name);
    mAccountsToggleMenu = (ActionMenuView) mAccountSelectorView.findViewById(R.id.toggle_menu);
    final SupportMenuInflater menuInflater = new SupportMenuInflater(context);
    menuInflater.inflate(R.menu.action_dashboard_timeline_toggle, mAccountsToggleMenu.getMenu());
    mAccountsToggleMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getGroupId() != AccountToggleProvider.MENU_GROUP)
                return false;
            final ParcelableAccount[] accounts = mAccountActionProvider.getAccounts();
            final ParcelableAccount account = accounts[item.getOrder()];
            final ContentValues values = new ContentValues();
            final boolean newActivated = !account.is_activated;
            mAccountActionProvider.setAccountActivated(account.account_id, newActivated);
            values.put(Accounts.IS_ACTIVATED, newActivated);
            final String where = Expression.equals(Accounts.ACCOUNT_ID, account.account_id).getSQL();
            mResolver.update(Accounts.CONTENT_URI, values, where, null);
            return true;
        }
    });

    mAccountProfileContainer.setOnClickListener(this);

    mAdapter.addView(mAccountSelectorView, true);
    mAdapter.addAdapter(mAccountOptionsAdapter);
    mAdapter.addView(inflater.inflate(R.layout.layout_divider_drawer, mListView, false), false);
    mAdapter.addAdapter(mAppMenuAdapter);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    getLoaderManager().initLoader(0, null, this);
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

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

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);/*from   ww  w.j a  v  a2 s  .c  o m*/
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = new PlaylistInputDialog(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_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(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_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 CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = new PlaylistDialog(this, intent,
                (id == LibraryAdapter.HEADER_ID ? (MediaAdapter) mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

From source file:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mResolver = getContentResolver();/*from w  w  w.j  a va  2  s .c  om*/
    final View view = getView();
    assert view != null;
    final Context context = view.getContext();
    final LayoutInflater inflater = getLayoutInflater(savedInstanceState);
    mAccountsAdapter = new AccountSelectorAdapter(inflater, this);
    final LinearLayoutManager layoutManager = new FixedLinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    layoutManager.setStackFromEnd(true);
    mAccountsSelector.setLayoutManager(layoutManager);
    mAccountsSelector.setAdapter(mAccountsAdapter);
    mAccountsSelector.setItemAnimator(null);
    final SupportMenuInflater menuInflater = new SupportMenuInflater(context);
    menuInflater.inflate(R.menu.action_dashboard_timeline_toggle, mAccountsToggleMenu.getMenu());
    mAccountsToggleMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getGroupId() != AccountToggleProvider.MENU_GROUP) {
                switch (item.getItemId()) {
                case R.id.compose: {
                    final ParcelableAccount account = mAccountsAdapter.getSelectedAccount();
                    if (account == null)
                        return true;
                    final Intent composeIntent = new Intent(INTENT_ACTION_COMPOSE);
                    composeIntent.setClass(getActivity(), ComposeActivity.class);
                    composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key);
                    startActivity(composeIntent);
                    return true;
                }
                }
                return false;
            }
            final ParcelableAccount[] accounts = mAccountActionProvider.getAccounts();
            final ParcelableAccount account = accounts[item.getOrder()];
            final ContentValues values = new ContentValues();
            final boolean newActivated = !account.is_activated;
            mAccountActionProvider.setAccountActivated(account.account_key, newActivated);
            values.put(Accounts.IS_ACTIVATED, newActivated);
            final String where = Expression.equalsArgs(Accounts.ACCOUNT_KEY).getSQL();
            final String[] whereArgs = { account.account_key.toString() };
            mResolver.update(Accounts.CONTENT_URI, values, where, whereArgs);
            return true;
        }
    });

    mAccountProfileContainer.setOnClickListener(this);

    mAccountProfileBannerView.setInAnimation(getContext(), android.R.anim.fade_in);
    mAccountProfileBannerView.setOutAnimation(getContext(), android.R.anim.fade_out);
    mAccountProfileBannerView.setFactory(new ViewSwitcher.ViewFactory() {
        @Override
        public View makeView() {
            return inflater.inflate(R.layout.layout_account_dashboard_profile_image, mAccountProfileBannerView,
                    false);
        }
    });

    mNavigationView.setNavigationItemSelectedListener(this);
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    loadAccounts();

    updateSystemWindowsInsets();
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

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

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);//from www. ja  va  2 s  .c  om
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = PlaylistInputDialog.newInstance(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_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(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_MENU_PLUGINS: {
        queryPluginsForIntent(intent);
        break;
    }
    case CTX_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 CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = PlaylistDialog.newInstance(this, intent,
                (id == LibraryAdapter.HEADER_ID ? mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DELETE_MESSAGE:
        LinphoneActivity.instance().getChatStorage().deleteMessage(item.getGroupId());
        invalidate();/*from  ww  w.  j  av a  2  s  . c  om*/
        break;
    case MENU_SAVE_PICTURE:
        saveImage(item.getGroupId());
        break;
    case MENU_COPY_TEXT:
        copyTextMessageToClipboard(item.getGroupId());
        break;
    case MENU_PICTURE_SMALL:
        uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL);
        break;
    case MENU_PICTURE_MEDIUM:
        uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.MEDIUM);
        break;
    case MENU_PICTURE_LARGE:
        uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.LARGE);
        break;
    case MENU_PICTURE_REAL:
        uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.REAL);
        break;
    }
    return true;
}

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

/**
 *
 * @param menuResId/* ww  w .  j ava  2 s  . co m*/
 * @param status {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_NORMAL}, {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_DISABLED}
 */
public void setMenuStatus(@IdRes int menuResId, int status) {
    MenuItem menuItem = mToolbar.getMenu().findItem(menuResId);
    if (menuItem == null) {
        throw new RuntimeException("Can't find a menu item");
    }
    Drawable icon = menuItem.getIcon();
    if (status == MenuDef.STATUS_DISABLED) {
        menuItem.setEnabled(false);
        menuItem.setIcon(MenuManager.makeToolbarDisabledIcon(icon));
    } else {
        menuItem.setEnabled(true);
        if (menuItem.getGroupId() == MenuDef.GROUP_TOOLBAR) {
            menuItem.setIcon(MenuManager.makeToolbarNormalIcon(icon));
        } else {
            menuItem.setIcon(MenuManager.makeMenuNormalIcon(icon));
        }
    }
}