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

The following examples show how to use android.view.MenuItem#getGroupId() . These examples are extracted from open source projects. 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 Project: android   File: TVShowFragment.java    License: 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 2
@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 3
@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 4
Source Project: mobile-manager-tool   File: GenresFragment.java    License: 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 5
Source Project: 920-text-editor-v2   File: MainActivity.java    License: 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 6
Source Project: android   File: MoviesFragment.java    License: 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 7
Source Project: Carbon   File: NavigationView.java    License: 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 8
Source Project: PopularMovies   File: DiscoverMoviesFragment.java    License: 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 9
Source Project: Exoplayer_VLC   File: PlayerActivity.java    License: 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 10
@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 11
Source Project: talkback   File: ContextMenu.java    License: 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 12
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 13
Source Project: fogger   File: StubMenuItemData.java    License: 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());
}
 
Example 14
Source Project: Carbon   File: BottomSheetLayout.java    License: 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 15
@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 16
public boolean contextItemSelected(MenuItem item) {
	MyLog.entry("item = " + item);
	final boolean result = item.getGroupId() == groupId && doContextItemSelected(item);
	MyLog.exit();
	return result;
}
 
Example 17
@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 18
Source Project: Spectaculum   File: EffectManager.java    License: 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 19
/**
 * 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 20
@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);
}