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.krossovochkin.adsl.MainActivity.java

private void setupNavigationView(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from ww w  .  j  a v a2 s . co m*/
        public boolean onNavigationItemSelected(MenuItem item) {
            if (item.getGroupId() == R.id.checkableGroup) {
                item.setChecked(true);
            }
            // TODO: provide some action depending on item selected - by item.getItemId()
            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    Menu menu = navigationView.getMenu();

    SwitchCompat switchCompat = (SwitchCompat) MenuItemCompat.getActionView(menu.findItem(R.id.switchItem))
            .findViewById(R.id.switchCompat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Toast.makeText(MainActivity.this, "switch is " + (isChecked ? "checked" : "unchecked"),
                    Toast.LENGTH_SHORT).show();
        }
    });

    TextView textView = (TextView) MenuItemCompat.getActionView(menu.findItem(R.id.counterItem))
            .findViewById(R.id.textView);
    textView.setText("5");
}

From source file:com.powermonitor.epitech.CalendarDayFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!getUserVisibleHint()) {
        return super.onContextItemSelected(item);
    }//  w  w  w . ja  va  2  s. com
    if (item.getGroupId() == CustomCalendar.CONTEXT_MENU_GROUP) {
        CustomCalendar.SlotContextMenuInfo info = (CustomCalendar.SlotContextMenuInfo) item.getMenuInfo();
        switch (item.getItemId()) {
        case CustomCalendar.CONTEXT_MENU_ITEM_MODIFY:
            calendar.updateSlot(info.slot, true);
            return true;
        case CustomCalendar.CONTEXT_MENU_ITEM_DELETE:
            onDeleteOptionSelected(info.slot);
            return true;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.andrew.apollo.ui.fragments.GenreFragment.java

/**
 * {@inheritDoc}/*from   www . java  2  s.  c o  m*/
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), mGenreList, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), mGenreList);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.boko.vimusic.ui.fragments.GenreFragment.java

/**
 * {@inheritDoc}/*from   w w w .j  a v  a  2 s.c  om*/
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), mGenreList, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), mGenreList);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor,
        final int highlightColor, final Mode mode, final int... excludedGroups) {
    for (int i = 0, j = menu.size(); i < j; i++) {
        final MenuItem item = menu.getItem(i);
        final Drawable icon = item.getIcon();
        final ContextMenuInfo info = item.getMenuInfo();
        if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) {
            icon.mutate();//from   ww w. j ava 2s  . c om
            if (info instanceof TwidereMenuInfo) {
                final TwidereMenuInfo sInfo = (TwidereMenuInfo) info;
                icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color,
                        mode);
            } else {
                icon.setColorFilter(color, mode);
            }
        }
        if (item.hasSubMenu()) {
            // SubMenu item is always in popup
            applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode,
                    excludedGroups);
        }
    }
}

From source file:com.mongolduu.android.ng.ChartFragment.java

public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != fragmentIndex) {
        return false;
    }/*from   w w  w.j  a v  a 2  s  . c  o  m*/

    AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    SongInfo songinfo = (SongInfo) listview.getAdapter().getItem(menuInfo.position);
    switch (item.getItemId()) {
    case R.id.context_menu_remove_song_from_device:
        deleteSong(songinfo);
        break;
    case R.id.context_menu_download:
        downloadSong(songinfo);
        break;
    case R.id.context_menu_play_song:
        playSong(songinfo);
        break;
    case R.id.context_menu_set_as_ringtone:
        setSongAsRingtone(songinfo);
        break;
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:com.powermonitor.epitech.ConfigModules.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0) {
        return false;
    }/*from  w  ww  .  jav a 2 s .c  o m*/
    if (item.getItemId() == 0) {
        onbRenameClicked();
    }
    if (item.getItemId() == 1) {
        onChangeProfileClicked();
    }
    if (item.getItemId() == 2) {
        if (_selectionPos >= 0 && this.listView.getItemAtPosition(_selectionPos) != null) {
            final Module module = ((Module) this.listView.getItemAtPosition(_selectionPos));
            Intent i = new Intent(this.getActivity(), EditProfile.class);
            i.putExtra(ConfigProfiles.EXTRA_PROFILE_ID, module.getInternalProfileId());
            i.putExtra(EditProfile.EXTRA_IS_INTERNAL, true);
            startActivity(i);
        }
    }
    return true;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapMenuItemIcon(@NonNull MenuItem item, int itemColor, int... excludeGroups) {
    if (ArrayUtils.contains(excludeGroups, item.getGroupId()))
        return;//from   w  w  w  . ja v  a 2s  .  c o m
    final Drawable icon = item.getIcon();
    if (icon == null)
        return;
    if (icon instanceof ActionIconDrawable) {
        ((ActionIconDrawable) icon).setDefaultColor(itemColor);
        item.setIcon(icon);
        return;
    }
    icon.mutate();
    final Drawable.Callback callback = icon.getCallback();
    final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor);
    newIcon.setCallback(callback);
    item.setIcon(newIcon);
}

From source file:org.kaaproject.kaa.demo.smarthousedemo.smarthouse.DevicesFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (getDeviceType().ordinal() == item.getGroupId()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        final SmartDeviceInfo device = mDevicesAdapter.getItem(info.position);
        int menuItemIndex = item.getItemId();
        switch (menuItemIndex) {
        case 0://from w  w w. ja  v a  2s  .c  o  m
            mActivity.getSmartHouseController().deattachEndpoint(device.getEndpointKey(),
                    new DetachEdnpointCallback(device));
            break;
        case 1:
            final String previousDeviceName = device.getDeviceName();
            RenameDeviceDialog.showRenameDeviceDialog(mActivity, previousDeviceName,
                    new RenameDeviceDialogListener() {
                        @Override
                        public void onNewDeviceName(String newDeviceName) {
                            if (!newDeviceName.isEmpty() && !previousDeviceName.equals(newDeviceName)) {
                                mActivity.getDeviceStore().onDeviceRenamed(device, newDeviceName);
                            }
                        }
                    });
            break;
        }
        return true;
    }
    return false;
}

From source file:org.lyricue.android.AvailableSongsFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    if (item.getGroupId() == 2) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

        if (adapter != null) {
            Log.i(TAG, "pos:" + info.position);
            long itemid = adapter.getItemId(info.position);
            String itemtext = adapter.getItem(info.position).main;

            if (item.getItemId() == 0) {
                Log.i(TAG, "add to playlist:" + itemid + "-" + itemtext);
                add_to_playlist(itemid);
            }/* w  w  w .ja v a2 s  .  c  o m*/
        }

        return true;
    } else {
        return false;
    }
}