Search in sources :

Example 31 with MenuItem

use of android.view.MenuItem in project androidannotations by androidannotations.

the class OptionsMenuActivityTest method subclassTakesPrecedenceInMenuItemHandling.

@Test
public void subclassTakesPrecedenceInMenuItemHandling() {
    MenuItem item = mock(MenuItem.class);
    when(item.getItemId()).thenReturn(R.id.menu_refresh);
    activity.onOptionsItemSelected(item);
    assertThat(activity.menuRefreshSelected).isTrue();
    assertThat(activity.menuRefreshSelectedFromAnnotatedClass).isFalse();
}
Also used : MenuItem(android.view.MenuItem) Test(org.junit.Test)

Example 32 with MenuItem

use of android.view.MenuItem in project androidannotations by androidannotations.

the class OptionsMenuActivityTest method defaultIdUnderscore.

@Test
public void defaultIdUnderscore() {
    MenuItem item = mock(MenuItem.class);
    when(item.getItemId()).thenReturn(R.id.menu_add);
    activity.onOptionsItemSelected(item);
    assertThat(activity.menuAdd).isTrue();
}
Also used : MenuItem(android.view.MenuItem) Test(org.junit.Test)

Example 33 with MenuItem

use of android.view.MenuItem in project simplefacebook by androidquery.

the class MenuActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    int id = getMenu();
    try {
        if (id != 0) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(id, menu);
            if (!PrefUtility.isTestDevice()) {
                menu.removeItem(R.id.debug);
            }
            if (isActionBar()) {
                MenuItem mi = menu.findItem(R.id.refresh);
                if (mi != null) {
                    refreshView = mi.getActionView();
                    aq2.recycle(refreshView);
                    aq2.id(R.id.button_action_refresh).clicked(this, "refreshClicked");
                    if (isBusy()) {
                        showActionProgress(true);
                    }
                }
            }
        }
    } catch (Exception e) {
        AQUtility.report(e);
    }
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem)

Example 34 with MenuItem

use of android.view.MenuItem in project platform_frameworks_base by android.

the class Activity method onProvideKeyboardShortcuts.

@Override
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
    if (menu == null) {
        return;
    }
    KeyboardShortcutGroup group = null;
    int menuSize = menu.size();
    for (int i = 0; i < menuSize; ++i) {
        final MenuItem item = menu.getItem(i);
        final CharSequence title = item.getTitle();
        final char alphaShortcut = item.getAlphabeticShortcut();
        if (title != null && alphaShortcut != MIN_VALUE) {
            if (group == null) {
                final int resource = mApplication.getApplicationInfo().labelRes;
                group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null);
            }
            group.addItem(new KeyboardShortcutInfo(title, alphaShortcut, KeyEvent.META_CTRL_ON));
        }
    }
    if (group != null) {
        data.add(group);
    }
}
Also used : KeyboardShortcutGroup(android.view.KeyboardShortcutGroup) KeyboardShortcutInfo(android.view.KeyboardShortcutInfo) MenuItem(android.view.MenuItem)

Example 35 with MenuItem

use of android.view.MenuItem in project ListenerMusicPlayer by hefuyicoder.

the class AlbumAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final AlbumAdapter.ItemHolder itemHolder, final int position) {
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            int adapterPosition = itemHolder.getAdapterPosition();
            final Album album = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_album_addto_queue:
                            getSongListIdByAlbum(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.NA);
                                }
                            });
                            break;
                        case R.id.popup_album_addto_playlist:
                            getSongListIdByAlbum(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    ListenerUtil.showAddPlaylistDialog(mContext, ids);
                                }
                            });
                            break;
                        case R.id.popup_album_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(position).artistId, arraylist.get(position).artistName);
                            break;
                        case R.id.popup_artist_delete:
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    getSongListIdByAlbum(album.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromFavourate(mContext, ids);
                                        }
                                    });
                                    break;
                                case Constants.NAVIGATE_PLAYLIST_RECENTPLAY:
                                    getSongListIdByAlbum(album.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromRecentlyPlay(mContext, ids);
                                        }
                                    });
                                    break;
                                default:
                                    AlbumSongLoader.getSongsForAlbum(mContext, arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {

                                        @Override
                                        public void call(List<Song> songs) {
                                            long[] ids = new long[songs.size()];
                                            int i = 0;
                                            for (Song song : songs) {
                                                ids[i] = song.id;
                                                i++;
                                            }
                                            if (ids.length == 1) {
                                                ListenerUtil.showDeleteDialog(mContext, songs.get(0).title, ids, new MaterialDialog.SingleButtonCallback() {

                                                    @Override
                                                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                        arraylist.remove(position);
                                                        notifyDataSetChanged();
                                                    }
                                                });
                                            } else {
                                                String songCount = ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, arraylist.get(position).songCount);
                                                ListenerUtil.showDeleteDialog(mContext, songCount, ids, new MaterialDialog.SingleButtonCallback() {

                                                    @Override
                                                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                        arraylist.remove(position);
                                                        notifyDataSetChanged();
                                                    }
                                                });
                                            }
                                        }
                                    });
                                    break;
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_album);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(io.hefuyi.listener.mvp.model.Album) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Song(io.hefuyi.listener.mvp.model.Song) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) List(java.util.List) PopupMenu(android.widget.PopupMenu)

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