Java Code Examples for android.view.MenuItem#getGroupId()

The following examples show how to use android.view.MenuItem#getGroupId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoviesFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == FRAGMENT_ID && getUserVisibleHint()) {
        int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;

        switch (item.getItemId()) {
            case FAVORITES: {
                Movie movie = (Movie) mAdapter.getItem(position);
                if (!AppUtils.isFavorite(getActivity(), movie.title)) {
                    ContentValues values = new ContentValues();
                    values.put(FavoritesTable.COLUMN_TITLE, movie.title);
                    values.put(FavoritesTable.COLUMN_LINK, movie.link);
                    values.put(FavoritesTable.COLUMN_TYPE, AppUtils.MOVIE);
                    values.put(FavoritesTable.COLUMN_IMAGE, movie.imageUri);
                    values.put(FavoritesTable.COLUMN_RATING, movie.rating);
                    getActivity().getContentResolver().insert(FavoritesContentProvider.CONTENT_URI, values);
                    Toast.makeText(this.getActivity(), movie.title + getString(R.string.favourites_added), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this.getActivity(), movie.title + getString(R.string.favourites_already_added), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        }
    }
    return super.onContextItemSelected(item);
}
 
Example 2
Source File: TVShowFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == FRAGMENT_ID && getUserVisibleHint()) {
        int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;

        switch (item.getItemId()) {
            case FAVORITES: {
                TVShow tvShow = (TVShow) mAdapter.getItem(position);
                if (!AppUtils.isFavorite(getActivity(), tvShow.title)) {
                    ContentValues values = new ContentValues();
                    values.put(FavoritesTable.COLUMN_TITLE, tvShow.title);
                    values.put(FavoritesTable.COLUMN_LINK, tvShow.link);
                    values.put(FavoritesTable.COLUMN_TYPE, AppUtils.TVSHOW);
                    values.put(FavoritesTable.COLUMN_IMAGE, tvShow.imageUri);
                    values.put(FavoritesTable.COLUMN_RATING, tvShow.rating);
                    getActivity().getContentResolver().insert(FavoritesContentProvider.CONTENT_URI, values);
                    Toast.makeText(this.getActivity(), tvShow.title + getString(R.string.favourites_added), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this.getActivity(), tvShow.title + getString(R.string.favourites_already_added), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        }
    }
    return super.onContextItemSelected(item);
}
 
Example 3
Source File: SearchBookActivity.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.action_book_source_manage:
            BookSourceActivity.startThis(this, requestSource);
            break;
        case android.R.id.home:
            SoftInputUtil.hideIMM(getCurrentFocus());
            finish();
            break;
        default:
            if (item.getGroupId() == R.id.source_group) {
                item.setChecked(true);
                if (Objects.equals(getString(R.string.all_source), item.getTitle().toString())) {
                    MApplication.SEARCH_GROUP = null;
                } else {
                    MApplication.SEARCH_GROUP = item.getTitle().toString();
                }
                mPresenter.initSearchEngineS(MApplication.SEARCH_GROUP);
            }
    }
    return super.onOptionsItemSelected(item);
}
 
Example 4
Source File: MainActivity.java    From 920-text-editor-v2 with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param menuResId
 * @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");
    }
    boolean enable = status != MenuDef.STATUS_DISABLED;
    if (menuItem.isEnabled() == enable) {
        return;
    }
    Drawable icon = menuItem.getIcon();
    if (!enable) {
        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));
        }
    }
}
 
Example 5
Source File: GenresFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	if(item.getGroupId()==mFragmentGroupId){
     switch (item.getItemId()) {
         case ADD_TO_LOVE:
             long[] list = MusicUtils.getSongListForGenre(getActivity(),
                     										Long.parseLong(mCurrentId));
             MusicUtils.playAll(getActivity(), list, 0);
             break;
         default:
             break;
     }
     return true;
 }
    return super.onContextItemSelected(item);
}
 
Example 6
Source File: EntitySelectActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getGroupId() == MENU_ACTION_GROUP) {
        triggerDetailAction(item.getItemId() - MENU_ACTION);
    }
    switch (item.getItemId()) {
        case MENU_SORT:
            createSortMenu();
            return true;
        case MENU_MAP:
            Intent i = new Intent(this,
                    HiddenPreferences.shouldUseMapboxMap() ? EntityMapboxActivity.class : EntityMapActivity.class);
            this.startActivityForResult(i, MAP_SELECT);
            return true;
        // handling click on the barcode scanner's actionbar
        // trying to set the onclicklistener in its view in the onCreateOptionsMenu method does not work because it returns null
        case R.id.barcode_scan_action_bar:
            barcodeScanOnClickListener.onClick(null);
            return true;
        // this is needed because superclasses do not implement the menu_settings click
        case R.id.menu_settings:
            HomeScreenBaseActivity.createPreferencesMenu(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: DiscoverMoviesFragment.java    From PopularMovies with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getGroupId() == R.id.menu_sort_group) {
        viewModel.setSortMoviesBy(item.getItemId());
        item.setChecked(true);
    }

    return super.onOptionsItemSelected(item);
}
 
Example 8
Source File: PlayerActivity.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private boolean onTrackItemClick(MenuItem item, int type) {
  if (player == null || item.getGroupId() != MENU_GROUP_TRACKS) {
    return false;
  }
  player.selectTrack(type, item.getItemId() - ID_OFFSET);
  return true;
}
 
Example 9
Source File: XpraActivity.java    From xpra-client with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onNavigationItemSelected(MenuItem item) {
	if(item.getGroupId() == R.id.xpra_windows_group) {
		return xpraClient.onWindowSelected(item.getItemId());
	}
	switch (item.getItemId()) {
	case R.id.drawer_disconnect:
		finish();
		return true;

	default:
		return false;
	}
}
 
Example 10
Source File: PlayerActivity.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 5 votes vote down vote up
private boolean onTrackItemClick(MenuItem item, int type) {
    if (player == null || item.getGroupId() != MENU_GROUP_TRACKS) {
        return false;
    }
    player.setSelectedTrack(type, item.getItemId() - ID_OFFSET);
    return true;
}
 
Example 11
Source File: NavigationView.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public Item(MenuItem item) {
    id = item.getItemId();
    icon = item.getIcon();
    tint = MenuItemCompat.getIconTintList(item);
    groupId = item.getGroupId();
    title = item.getTitle();
}
 
Example 12
Source File: ContextMenu.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void setGroupVisible(int group, boolean visible) {
  for (MenuItem item : items) {
    if (item.getGroupId() == group) {
      item.setVisible(visible);
    }
  }
}
 
Example 13
Source File: YalpStoreActivity.java    From YalpStore with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            startActivity(new Intent(this, PreferenceActivity.class));
            break;
        case R.id.action_logout:
            showLogOutDialog();
            break;
        case R.id.action_search:
            if (!onSearchRequested()) {
                showFallbackSearchDialog();
            }
            break;
        case R.id.action_updates:
            startActivity(new Intent(this, UpdatableAppsActivity.class));
            break;
        case R.id.action_installed_apps:
            startActivity(new Intent(this, InstalledAppsActivity.class));
            break;
        case R.id.action_categories:
            startActivity(new Intent(this, CategoryListActivity.class));
            break;
        case R.id.action_about:
            startActivity(new Intent(this, AboutActivity.class));
            break;
        case R.id.action_bug_report:
            startActivity(new Intent(this, BugReportActivity.class));
            break;
        case R.id.action_wishlist:
            startActivity(new Intent(this, WishlistActivity.class));
            break;
        case R.id.action_history:
            startActivity(new Intent(this, HistoryActivity.class));
            break;
        case R.id.filter_system_apps:
        case R.id.filter_apps_with_ads:
        case R.id.filter_paid_apps:
        case R.id.filter_gsf_dependent_apps:
        case R.id.filter_category:
        case R.id.filter_rating:
        case R.id.filter_downloads:
            new FilterMenu(this).onOptionsItemSelected(item);
            break;
        case R.id.action_new_account:
            new LoginDialogBuilder(this).show();
            return true;
        case R.id.action_accounts:
            return true;
        default:
            if (item.getGroupId() != R.id.group_accounts) {
                return super.onOptionsItemSelected(item);
            }
            return switchAccount(item.getItemId());
    }
    return true;
}
 
Example 14
Source File: MusicSongListFragment.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    if( item.getGroupId() == mFragmentGroupId ){
        switch (item.getItemId()) {
            case ADD_TO_LOVE:
                //MusicUtils.playAll(getActivity(), mCursor, mSelectedPosition);
                ContentValues value = new ContentValues();
                value.put("id", mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns._ID)));
                value.put("name", mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns.TITLE)));
                value.put("filePath", mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns.DATA)));
                value.put("thumbPath", mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns.ARTIST)));
                value.put("createDate", TimeUtil.dateToStrLong(new Date()));
                Log.i(">>>music", value.toString());
                MusicDBHelper.addFavoriteMusic(getActivity(), value);
                UIHelp.showToast(getActivity(), "添加成功");

                Intent intent = new Intent();
                Bundle mBundle = new Bundle();
                mBundle.putParcelable("music", value);
                intent.putExtras(mBundle);
                intent.setAction(ActionManager.ACTION_MSG_MUSIC_CHANGED);
                getActivity().sendBroadcast(intent);
                break;
            case DELETE: {
                getActivity().getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,MediaStore.Audio.Media._ID + "=" +
                        mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns._ID)),null);
                refresh();
                UIHelp.showToast(getActivity(),"[" + mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.AudioColumns.TITLE)) + "]删除成功");
                int pathColumnIndex = mCursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                if(pathColumnIndex>-1){
                    String path =  mCursor.getString(pathColumnIndex);
                    File selectedFile = new File(path);
                    selectedFile.delete();
                    refresh();
                }
                break;
            }
            default:
                break;
        }
    }
    return super.onContextItemSelected(item);
}
 
Example 15
Source File: MenuSheetView.java    From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items},
 * while inserting separators between items when necessary.
 *
 * Adapted from the Design support library's NavigationMenuPresenter implementation
 */
private void prepareMenuItems() {
    items.clear();
    int currentGroupId = 0;

    // Iterate over the menu items
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                // Flatten the submenu
                SubMenu subMenu = item.getSubMenu();
                if (subMenu.hasVisibleItems()) {
                    if (menuType == LIST) {
                        items.add(SheetMenuItem.SEPARATOR);

                        // Add a header item if it has text
                        if (!TextUtils.isEmpty(item.getTitle())) {
                            items.add(SheetMenuItem.of(item));
                        }
                    }

                    // Add the sub-items
                    for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
                        MenuItem subMenuItem = subMenu.getItem(subI);
                        if (subMenuItem.isVisible()) {
                            items.add(SheetMenuItem.of(subMenuItem));
                        }
                    }

                    // Add one more separator to the end to close it off if we have more items
                    if (menuType == LIST && i != menu.size() - 1) {
                        items.add(SheetMenuItem.SEPARATOR);
                    }
                }
            } else {
                int groupId = item.getGroupId();
                if (groupId != currentGroupId && menuType == LIST) {
                    items.add(SheetMenuItem.SEPARATOR);
                }
                items.add(SheetMenuItem.of(item));
                currentGroupId = groupId;
            }
        }
    }
}
 
Example 16
Source File: EffectManager.java    From Spectaculum with Apache License 2.0 4 votes vote down vote up
private boolean doMenuActionEffect(MenuItem item) {
    if(item.getGroupId() == R.id.action_list_effects) {
        return selectEffect(item.getItemId());
    }
    return false;
}
 
Example 17
Source File: ChooseSyncBaseContextMenuHelper.java    From PADListener with GNU General Public License v2.0 4 votes vote down vote up
public boolean contextItemSelected(MenuItem item) {
	MyLog.entry("item = " + item);
	final boolean result = item.getGroupId() == groupId && doContextItemSelected(item);
	MyLog.exit();
	return result;
}
 
Example 18
Source File: ActivityApp.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (upIntent != null)
			if (NavUtils.shouldUpRecreateTask(this, upIntent))
				TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
			else
				NavUtils.navigateUpTo(this, upIntent);
		return true;
	case R.id.menu_usage:
		optionUsage();
		return true;
	case R.id.menu_accounts:
		optionAccounts();
		return true;
	case R.id.menu_applications:
		optionApplications();
		return true;
	case R.id.menu_contacts:
		if (item.getGroupId() != 0) {
			optionContacts(item.getGroupId());
			return true;
		} else
			return false;
	case R.id.menu_whitelists:
		optionWhitelists(null);
		return true;
	case R.id.menu_apply:
		optionTemplate();
		return true;
	case R.id.menu_clear:
		optionClear();
		return true;
	case R.id.menu_export:
		optionExport();
		return true;
	case R.id.menu_import:
		optionImport();
		return true;
	case R.id.menu_submit:
		optionSubmit();
		return true;
	case R.id.menu_fetch:
		optionFetch();
		return true;
	case R.id.menu_settings:
		optionSettings();
		return true;
	case R.id.menu_dump:
		optionDump();
		return true;
	case R.id.menu_legend:
		optionLegend();
		return true;
	case R.id.menu_tutorial:
		optionTutorial();
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
Example 19
Source File: BottomSheetLayout.java    From Carbon with Apache License 2.0 4 votes vote down vote up
public Item(MenuItem menuItem) {
    groupId = menuItem.getGroupId();
    icon = menuItem.getIcon();
    iconTint = MenuItemCompat.getIconTintList(menuItem);
    title = menuItem.getTitle();
}
 
Example 20
Source File: StubMenuItemData.java    From fogger with Apache License 2.0 4 votes vote down vote up
public static StubMenuItemData create(MenuItem menuItem) {
    return new StubMenuItemData(menuItem.getGroupId(),
            menuItem.getItemId(), menuItem.getOrder(), menuItem.getTitle().toString());
}