Search in sources :

Example 41 with MenuItem

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();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) MenuItem(android.view.MenuItem) ForegroundImageView(io.hefuyi.listener.widget.ForegroundImageView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TimelyView(io.hefuyi.listener.widget.timely.TimelyView) LyricView(io.hefuyi.listener.widget.LyricView) TextView(android.widget.TextView) PlayPauseView(io.hefuyi.listener.widget.PlayPauseView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) PopupMenu(android.widget.PopupMenu)

Example 42 with MenuItem

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;
        }
    }
}
Also used : MenuItem(android.view.MenuItem)

Example 43 with MenuItem

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()));
    }
}
Also used : NavigationViewActions.setIconForMenuItem(android.support.design.testutils.NavigationViewActions.setIconForMenuItem) MenuItem(android.view.MenuItem) NavigationViewActions.removeMenuItem(android.support.design.testutils.NavigationViewActions.removeMenuItem) Menu(android.view.Menu) TestUtilsActions.reinflateMenu(android.support.design.testutils.TestUtilsActions.reinflateMenu) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 44 with MenuItem

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);
}
Also used : ColorInt(android.support.annotation.ColorInt) NavigationViewActions.setIconForMenuItem(android.support.design.testutils.NavigationViewActions.setIconForMenuItem) MenuItem(android.view.MenuItem) NavigationViewActions.removeMenuItem(android.support.design.testutils.NavigationViewActions.removeMenuItem) Resources(android.content.res.Resources) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 45 with MenuItem

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);
}
Also used : MenuItem(android.view.MenuItem)

Aggregations

MenuItem (android.view.MenuItem)761 View (android.view.View)140 Intent (android.content.Intent)86 TextView (android.widget.TextView)78 PopupMenu (android.widget.PopupMenu)62 ImageView (android.widget.ImageView)58 Menu (android.view.Menu)52 SearchView (android.support.v7.widget.SearchView)46 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 RecyclerView (android.support.v7.widget.RecyclerView)36 MenuInflater (android.view.MenuInflater)35 AdapterView (android.widget.AdapterView)33 ListView (android.widget.ListView)32 SubMenu (android.view.SubMenu)30 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)25 Parcelable (android.os.Parcelable)24 Toolbar (android.support.v7.widget.Toolbar)24 Bundle (android.os.Bundle)19 PopupMenu (android.support.v7.widget.PopupMenu)19