use of android.view.MenuItem in project ListenerMusicPlayer by hefuyicoder.
the class QuickControlsFragment method setUpPopupMenu.
private void setUpPopupMenu(ImageView popupMenu) {
popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(getContext(), v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_song_goto_album:
if (mSlidingUpPanelLayout != null) {
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
NavigationUtil.navigateToAlbum(getActivity(), MusicPlayer.getCurrentAlbumId(), MusicPlayer.getAlbumName(), null);
}
break;
case R.id.popup_song_goto_artist:
if (mSlidingUpPanelLayout != null) {
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
NavigationUtil.navigateToAlbum(getActivity(), MusicPlayer.getCurrentArtistId(), MusicPlayer.getArtistName(), null);
}
break;
case R.id.popup_song_addto_playlist:
ListenerUtil.showAddPlaylistDialog(getActivity(), new long[] { MusicPlayer.getCurrentAudioId() });
break;
case R.id.popup_song_delete:
long[] deleteIds = { MusicPlayer.getCurrentAudioId() };
ListenerUtil.showDeleteDialog(getContext(), MusicPlayer.getTrackName(), deleteIds, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
}
});
break;
}
return false;
}
});
menu.inflate(R.menu.menu_now_playing);
menu.show();
}
});
}
use of android.view.MenuItem in project material-components-android by material-components.
the class BottomNavigationMenuView method tryRestoreSelectedItemId.
void tryRestoreSelectedItemId(int itemId) {
final int size = mMenu.size();
for (int i = 0; i < size; i++) {
MenuItem item = mMenu.getItem(i);
if (itemId == item.getItemId()) {
mSelectedItemId = itemId;
mSelectedItemPosition = i;
item.setChecked(true);
break;
}
}
}
use of android.view.MenuItem in project material-components-android by material-components.
the class NavigationViewTest method testBasics.
@Test
public void testBasics() {
// Open our drawer
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
// Check the contents of the Menu object
final Menu menu = mNavigationView.getMenu();
assertNotNull("Menu should not be null", menu);
assertEquals("Should have matching number of items", MENU_CONTENT_ITEM_IDS.length + 1, menu.size());
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
final MenuItem currItem = menu.getItem(i);
assertEquals("ID for Item #" + i, MENU_CONTENT_ITEM_IDS[i], currItem.getItemId());
}
// Check that we have the expected menu items in our NavigationView
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
onView(allOf(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer)))).check(matches(isDisplayed()));
}
}
use of android.view.MenuItem in project material-components-android by material-components.
the class NavigationViewTest method testCheckedAppearance.
@Test
public void testCheckedAppearance() {
// Open our drawer
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
// Reconfigure our navigation view to use foreground (text) and background visuals
// with explicitly different colors for the checked state
final Resources res = activityTestRule.getActivity().getResources();
onView(withId(R.id.start_drawer)).perform(setItemTextColor(ResourcesCompat.getColorStateList(res, R.color.color_state_list_sand, null)));
onView(withId(R.id.start_drawer)).perform(setItemBackgroundResource(R.drawable.test_drawable_state_list));
@ColorInt final int uncheckedItemForeground = ResourcesCompat.getColor(res, R.color.sand_default, null);
@ColorInt final int checkedItemForeground = ResourcesCompat.getColor(res, R.color.sand_checked, null);
@ColorInt final int uncheckedItemBackground = ResourcesCompat.getColor(res, R.color.test_green, null);
@ColorInt final int checkedItemBackground = ResourcesCompat.getColor(res, R.color.test_blue, null);
// Verify that all items are rendered with unchecked visuals
verifyCheckedAppearance(0, uncheckedItemForeground, checkedItemForeground, uncheckedItemBackground, checkedItemBackground);
// Mark one of the items as checked
onView(withId(R.id.start_drawer)).perform(setCheckedItem(R.id.destination_profile));
// And verify that it's now rendered with checked visuals
verifyCheckedAppearance(R.id.destination_profile, uncheckedItemForeground, checkedItemForeground, uncheckedItemBackground, checkedItemBackground);
// Register a navigation listener that "marks" the selected item
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
return true;
}
});
// Click one of our items
onView(allOf(withText(mMenuStringContent.get(R.id.destination_people)), isDescendantOfA(withId(R.id.start_drawer)))).perform(click());
// and verify that it's now checked
verifyCheckedAppearance(R.id.destination_people, uncheckedItemForeground, checkedItemForeground, uncheckedItemBackground, checkedItemBackground);
// Register a navigation listener that doesn't "mark" the selected item
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
return false;
}
});
// Click another items
onView(allOf(withText(mMenuStringContent.get(R.id.destination_settings)), isDescendantOfA(withId(R.id.start_drawer)))).perform(click());
// and verify that the checked state remains on the previously clicked item
// since the current navigation listener returns false from its callback
// implementation
verifyCheckedAppearance(R.id.destination_people, uncheckedItemForeground, checkedItemForeground, uncheckedItemBackground, checkedItemBackground);
}
use of android.view.MenuItem in project sqlbrite by square.
the class ItemsFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem item = menu.add(R.string.new_item).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
listener.onNewItemClicked(getListId());
return true;
}
});
MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
}
Aggregations