Search in sources :

Example 71 with SubMenu

use of android.view.SubMenu in project GestureViews by alexvasilkov.

the class SettingsMenu method addSubMenu.

private <T> void addSubMenu(Menu menu, T[] items, T selected, @StringRes int titleId) {
    SubMenu sub = menu.addSubMenu(titleId);
    sub.setGroupCheckable(Menu.NONE, true, true);
    for (int i = 0; i < items.length; i++) {
        MenuItem item = sub.add(Menu.NONE, titleId, i, items[i].toString());
        item.setCheckable(true);
        item.setChecked(items[i] == selected);
    }
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem)

Example 72 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class AlbumArtistFragment method onAlbumArtistOverflowClicked.

@Override
public void onAlbumArtistOverflowClicked(View v, AlbumArtist albumArtist) {
    PopupMenu menu = new PopupMenu(AlbumArtistFragment.this.getActivity(), v);
    menu.inflate(R.menu.menu_artist);
    SubMenu sub = menu.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
    PlaylistUtils.createPlaylistMenu(sub);
    menu.setOnMenuItemClickListener(MenuUtils.getAlbumArtistClickListener(getContext(), albumArtist, taggerDialog -> taggerDialog.show(getChildFragmentManager()), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> UpgradeDialog.getUpgradeDialog(getActivity()).show(), null));
    menu.show();
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) RequestManager(com.bumptech.glide.RequestManager) MenuInflater(android.view.MenuInflater) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Menu(android.view.Menu) View(android.view.View) Observable(io.reactivex.Observable) SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Disposable(io.reactivex.disposables.Disposable) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Nullable(android.support.annotation.Nullable) SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) Collections(java.util.Collections) SubMenu(android.view.SubMenu) PopupMenu(android.support.v7.widget.PopupMenu)

Example 73 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class AlbumArtistFragment method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // Strip the 'asc' or 'desc' flag, we just want to know the sort type
    int sortOrder = SortManager.getInstance().getArtistsSortOrder();
    switch(sortOrder) {
        case SortManager.ArtistSort.DEFAULT:
            MenuItem sortDefault = menu.findItem(R.id.sort_default);
            if (sortDefault != null) {
                sortDefault.setChecked(true);
            }
            break;
        case SortManager.ArtistSort.NAME:
            MenuItem sortArtistName = menu.findItem(R.id.sort_artist_name);
            if (sortArtistName != null) {
                sortArtistName.setChecked(true);
            }
            break;
    }
    MenuItem sortAscending = menu.findItem(R.id.sort_ascending);
    if (sortAscending != null) {
        sortAscending.setChecked(SortManager.getInstance().getArtistsAscending());
    }
    int displayType = SettingsManager.getInstance().getArtistDisplayType();
    switch(displayType) {
        case ViewType.ARTIST_LIST:
            MenuItem viewAsList = menu.findItem(R.id.view_as_list);
            if (viewAsList != null) {
                viewAsList.setChecked(true);
            }
            break;
        case ViewType.ARTIST_GRID:
            MenuItem viewAsGrid = menu.findItem(R.id.view_as_grid);
            if (viewAsGrid != null) {
                viewAsGrid.setChecked(true);
            }
            break;
        case ViewType.ARTIST_CARD:
            MenuItem viewAsGridCard = menu.findItem(R.id.view_as_grid_card);
            if (viewAsGridCard != null) {
                viewAsGridCard.setChecked(true);
            }
            break;
        case ViewType.ARTIST_PALETTE:
            MenuItem viewAsGridPalette = menu.findItem(R.id.view_as_grid_palette);
            if (viewAsGridPalette != null) {
                viewAsGridPalette.setChecked(true);
            }
            break;
    }
    MenuItem gridMenuItem = menu.findItem(MENU_GRID_SIZE);
    if (displayType == ViewType.ARTIST_LIST) {
        gridMenuItem.setVisible(false);
    } else {
        gridMenuItem.setVisible(true);
        SubMenu subMenu = gridMenuItem.getSubMenu();
        if (subMenu != null) {
            subMenu.findItem(SettingsManager.getInstance().getArtistColumnCount(getResources())).setChecked(true);
        }
    }
}
Also used : MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu)

Example 74 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class AlbumArtistFragment method setupContextualToolbar.

private void setupContextualToolbar() {
    ContextualToolbar contextualToolbar = ContextualToolbar.findContextualToolbar(this);
    if (contextualToolbar != null) {
        contextualToolbar.getMenu().clear();
        contextualToolbar.inflateMenu(R.menu.context_menu_general);
        SubMenu sub = contextualToolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
        if (playlistMenuDisposable != null) {
            playlistMenuDisposable.dispose();
        }
        playlistMenuDisposable = PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe();
        contextualToolbar.setOnMenuItemClickListener(MenuUtils.getAlbumArtistMenuClickListener(getContext(), () -> contextualToolbarHelper.getItems(), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> contextualToolbarHelper.finish()));
        contextualToolbarHelper = new ContextualToolbarHelper<>(contextualToolbar, new ContextualToolbarHelper.Callback() {

            @Override
            public void notifyItemChanged(int position, SelectableViewModel viewModel) {
                adapter.notifyItemChanged(position, 0);
            }

            @Override
            public void notifyDatasetChanged() {
                adapter.notifyItemRangeChanged(0, adapter.items.size(), 0);
            }
        });
    }
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) RequestManager(com.bumptech.glide.RequestManager) MenuInflater(android.view.MenuInflater) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Menu(android.view.Menu) View(android.view.View) Observable(io.reactivex.Observable) SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Disposable(io.reactivex.disposables.Disposable) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Nullable(android.support.annotation.Nullable) SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) Collections(java.util.Collections) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) SubMenu(android.view.SubMenu) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar)

Example 75 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class AlbumFragment method onAlbumOverflowClicked.

@Override
public void onAlbumOverflowClicked(View v, Album album) {
    PopupMenu menu = new PopupMenu(getContext(), v);
    menu.inflate(R.menu.menu_album);
    SubMenu sub = menu.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
    PlaylistUtils.createPlaylistMenu(sub);
    menu.setOnMenuItemClickListener(MenuUtils.getAlbumMenuClickListener(getContext(), album, taggerDialog -> taggerDialog.show(getChildFragmentManager()), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> UpgradeDialog.getUpgradeDialog(getActivity()).show(), null));
    menu.show();
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) Fragment(android.support.v4.app.Fragment) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) Disposable(io.reactivex.disposables.Disposable) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) Nullable(android.support.annotation.Nullable) SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ShuffleView(com.simplecity.amp_library.ui.modelviews.ShuffleView) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) DataManager(com.simplecity.amp_library.utils.DataManager) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) SubMenu(android.view.SubMenu) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

SubMenu (android.view.SubMenu)80 MenuItem (android.view.MenuItem)38 View (android.view.View)11 LayoutInflater (android.view.LayoutInflater)10 PackageManager (android.content.pm.PackageManager)9 Bundle (android.os.Bundle)9 Nullable (android.support.annotation.Nullable)9 ViewGroup (android.view.ViewGroup)9 R (com.simplecity.amp_library.R)9 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)9 SelectableViewModel (com.simplecity.amp_library.ui.modelviews.SelectableViewModel)9 ContextualToolbar (com.simplecity.amp_library.ui.views.ContextualToolbar)9 ContextualToolbarHelper (com.simplecity.amp_library.utils.ContextualToolbarHelper)9 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)9 PlaylistUtils (com.simplecity.amp_library.utils.PlaylistUtils)9 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)9 Disposable (io.reactivex.disposables.Disposable)9 ResolveInfo (android.content.pm.ResolveInfo)8 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)8 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)8