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.andrew.apollo.ui.fragments.profile.ApolloFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        final long[] songList = mSongList != null ? mSongList : new long[] { mSelectedId };

        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(songList, 0, false);
            return true;
        case FragmentMenuItems.PLAY_NEXT:
            MusicUtils.playNext(songList);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), songList);
            return true;
        case FragmentMenuItems.ADD_TO_FAVORITES:
            onAddToFavorites();//from  w  w  w  . ja  va 2 s. c o m
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            onRemoveFromFavorites();
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(songList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long playlistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), songList, playlistId);
            refresh();
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.DELETE:
            return onDelete(songList);
        case FragmentMenuItems.MORE_BY_ARTIST:
            long artistId = MusicUtils.getIdForArtist(getContext(), mArtistName);
            long[] tracks = MusicUtils.getSongListForArtist(getActivity(), artistId);
            NavUtils.openArtistProfile(getActivity(), mArtistName, tracks);
            return true;
        case FragmentMenuItems.REMOVE_FROM_PLAYLIST:
            return onRemoveFromPlaylist();
        case FragmentMenuItems.REMOVE_FROM_RECENT:
            return onRemoveFromRecent();
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.epishie.tabs.feature.subreddits.SubredditsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.sidebar) {
        mDrawer.openDrawer(GravityCompat.END);
        return true;
    } else if (item.getItemId() == R.id.refresh) {
        LinksFragment fragment = mAdapter.getFragment(mPages.getCurrentItem());
        if (fragment != null) {
            fragment.refresh();//from  ww  w . j  av a 2 s . c  om
        }
        return true;
    } else if (item.getGroupId() == R.id.sort) {
        for (int i = 0; i < SORT_OPTIONS.size(); i++) {
            if (SORT_OPTIONS.get(i).first == item.getItemId()) {
                mAdapter.setSort(Sort.values()[i]);
                getSupportActionBar().setTitle(SORT_OPTIONS.get(i).second);
                invalidateOptionsMenu();
                break;
            }
        }
    } else {
        return super.onOptionsItemSelected(item);
    }

    return true;
}

From source file:org.zeroxlab.zeroxbenchmark.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.zeroxbenchmark.ActivitySettings");
        }/*  www. ja va2 s  .  c  om*/
        return true;
    }

From source file:com.asksven.commandcenter.BasicMasterFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();

    // check if the called back fragment is the one that has initiated the menu action
    // based on the group id. if not do noting
    if (item.getGroupId() == m_iContextMenuId) {
        try {/*  w  w  w .jav  a  2 s  . c  o  m*/
            m_myCommand = m_myItems.get(menuInfo.position);
        } catch (Exception e) {
            m_myCommand = null;
            Log.e(TAG, "An error occured getting the selected command: " + e.getMessage());
        }

        switch (item.getItemId()) {
        case CONTEXT_ADD_ID:
            if (m_myCommand != null) {
                showDetails(-1);
            }
            return true;

        case CONTEXT_DELETE_ID:

            if (m_myCommand != null) {
                Log.i(TAG, "Deleting command");
                // TODO add yes/no dialog
                deleteCommand(m_myCommand.getId());
            }
            return true;

        case CONTEXT_EDIT_ID:

            if (m_myCommand != null) {
                Log.i(TAG, "Editing command");
                showDetails(m_myCommand.getId());
            }
            return true;

        case CONTEXT_EXECUTE_ID:
            if (m_myCommand != null) {
                Log.i(TAG, "Running command");
                executeCommand(m_myCommand);
                refreshList();
            }
            return true;

        case CONTEXT_RELOAD:
            if (m_myCommand != null) {
                //                   new RefreshCommandsCacheTask().execute("");
                this.refreshCommandsCache();
            }
            return true;

        case CONTEXT_REFRESH:
            if (m_myCommand != null) {
                refreshList();
                return true;
            }

        case CONTEXT_ADDUSER_ID:
            if (m_myCommand != null) {
                Log.i(TAG, "Copying command to user commands");
                copyToUser(m_myCommand);
                refreshList();
                return true;
            }

        default:
            return false;
        }
    } else {
        return super.onContextItemSelected(item);
    }

}

From source file:com.cyanogenmod.eleven.ui.fragments.AudioPlayerFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        default:/*from ww  w . j  ava  2  s  .co m*/
            break;
        }
    }

    return super.onContextItemSelected(item);
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

private boolean onTrackItemClick(MenuItem item, int type) {
    if (player == null || item.getGroupId() != MENU_GROUP_TRACKS) {
        return false;
    }//from  ww  w  .  j  av a  2  s  .  com
    player.selectTrack(type, item.getItemId() - ID_OFFSET);
    return true;
}

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

private void addAndReplace(final MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    mApp.oMPDAsyncHelper.execAsync(new Runnable() {
        @Override//from  ww  w .  j a  v  a  2  s .  c  o  m
        public void run() {
            boolean replace = false;
            boolean play = false;
            switch (item.getGroupId()) {
            case ADD_REPLACE_PLAY:
                replace = true;
                play = true;
                break;
            case ADD_REPLACE:
                replace = true;
                break;
            case ADD_PLAY:
                final MPDStatus status = mApp.oMPDAsyncHelper.oMPD.getStatus();

                /**
                 * Let the user know if we're not going to play the added music.
                 */
                if (status.isRandom() && status.isState(MPDStatus.STATE_PLAYING)) {
                    Tools.notifyUser(R.string.notPlayingInRandomMode);
                } else {
                    play = true;
                }
                break;
            default:
                break;
            }
            add(mItems.get((int) info.id), replace, play);
        }
    });
}

From source file:io.jawg.osmcontributor.ui.activities.MapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ((OsmTemplateApplication) getApplication()).init(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    ((OsmTemplateApplication) getApplication()).getOsmTemplateComponent().inject(this);
    ButterKnife.bind(this);

    PreferenceManager.setDefaultValues(this, R.xml.pref_accessibility, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_connection, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false);
    setSupportActionBar(toolbar);/*from   www .  j  a  va 2 s  .  c o  m*/

    eventBus.post(new UpdateFirstConnectionEvent());
    checkFirstStart();

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getGroupId()) {
            case R.id.drawer_options_group:
                onOptionsClick(menuItem);
                break;
            case R.id.sync:
                onOptionsSyncClick(menuItem);
                break;
            }
            return true;
        }
    });
    filterView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.select_all_item) {
                selectAllMenuItem.setChecked(!selectAllMenuItem.isChecked());
                onSelectAllClick();
            } else if (menuItem.getItemId() != R.id.display_open_notes_item
                    && menuItem.getItemId() != R.id.display_closed_notes_item
                    && menuItem.getItemId() != R.id.display_yes_accessibility
                    && menuItem.getItemId() != R.id.display_limited_accessibility
                    && menuItem.getItemId() != R.id.display_no_accessibility
                    && menuItem.getItemId() != R.id.display_unknown_accessibility) {
                menuItem.setChecked(!menuItem.isChecked());
                onFilterItemClick(menuItem);
            } else {
                menuItem.setChecked(!menuItem.isChecked());
                onOtherItemClick(menuItem);
            }
            return true;
        }
    });

    selectAllMenuItem = filterView.getMenu().findItem(R.id.select_all_item);

    if (configManager.hasPoiAddition()) {
        navigationView.getMenu().findItem(R.id.replay_tuto_menu).setVisible(true);
    }

    navigationView.getMenu().findItem(R.id.save_changes).setEnabled(false);

    drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {

        }

        @Override
        public void onDrawerOpened(View drawerView) {
            eventBus.post(new PleaseTellIfDbChanges());
        }

        @Override
        public void onDrawerClosed(View drawerView) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }
    });

    if (FlavorUtils.isBus()) {
        eventBus.post(new PleaseApplyNoteFilterEvent(false, false));
        List<Poi.AccessibilityType> accessibilityTypesToHide = new ArrayList<>();
        eventBus.post(new PleaseApplyAccessibilityFilter(accessibilityTypesToHide));
    }
    navigationView.getMenu().findItem(R.id.manage_poi_types)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    startPoiTypeEditionActivity();
                    return true;
                }
            });

    // Get the arpi fragment.
    arpiGlFragment = (ArpiGlFragment) getFragmentManager().findFragmentById(R.id.engine_fragment);
    getFragmentManager().beginTransaction().hide(arpiGlFragment).commit();

    if (sharedPreferences.getBoolean(getString(R.string.easter_egg), false)) {
        navigationView.getMenu().findItem(R.id.arpi_view).setVisible(true);
    }
}

From source file:ca.spencerelliott.mercury.Changesets.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    super.onContextItemSelected(item);

    //Check to see if this selection was a contact selected from the sub menu
    if (item.getGroupId() == CONTACT_GROUP) {
        //Setup committer linking here

        return false;
    }/*from  w w  w .  j  a  v  a2 s  .  co m*/

    //Called if the user clicked on the option to email the committer
    if (item.getItemId() == EMAIL_PERSON) {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:test@test.com?subject=Regarding revision..."));
        startActivity(intent);
    }

    //Opens up the changeset on the native web page
    if (item.getItemId() == VIEW_BROWSER) {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(changesets_data.get(last_item_touched).getLink()));

        if (intent != null)
            startActivity(intent);
    }

    //Open the window to link the committer with a contact in the device
    if (item.getItemId() == LINK_COMMITTER) {

    }

    //Message the contact linked to the committer
    if (item.getItemId() == MESSAGE_COMMITTER) {

    }

    //Unlink the contact from the committer
    if (item.getItemId() == UNLINK_COMMITTER) {

    }

    return true;
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.ToolbarManager.java

/**
 * This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
 * Toolbar as ActionBar, or after inflating menu.
 *///  w  w w  .  j  a  v a  2 s.co  m
public void onPrepareMenu() {
    if (mGroupChanged || mMenuDataChanged) {
        mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

        Menu menu = mToolbar.getMenu();
        for (int i = 0, count = menu.size(); i < count; i++) {
            MenuItem item = menu.getItem(i);
            item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
        }

        mMenuDataChanged = false;
    }
}