Java Code Examples for android.view.SubMenu#clear()

The following examples show how to use android.view.SubMenu#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Kandroid with GNU General Public License v3.0 6 votes vote down vote up
private void populateProjectsMenu() {
    if (mProjectList == null) {
        if (BuildConfig.DEBUG) Log.d("Kandroid", "Tried to populate drawer, but mDashboard was null");
        return;
    }
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
    List<KanboardProject> projList = mProjectList;
    if (preferences.getBoolean("projects_sort_alphabetic", false))
        Collections.sort(projList);
    NavigationView nav = (NavigationView) findViewById(R.id.nav_view);
    SubMenu projMenu = nav.getMenu().findItem(R.id.projects).getSubMenu();
    projMenu.clear();
    for (KanboardProject item: projList)
        projMenu.add(Menu.NONE, item.getId(), Menu.NONE, item.getName())
                .setIcon(R.drawable.project);
}
 
Example 2
Source File: DynamicShareActionProvider.java    From DynamicShareActionProvider with Apache License 2.0 6 votes vote down vote up
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();
    if (pm != null && list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
            ResolveInfo resolveInfo = list.get(i);
            OnMenuItemClickUpdateIntentListener itemListener = new OnMenuItemClickUpdateIntentListener();
            itemListener.setPosition(i);
            MenuItem item = subMenu.add(resolveInfo.loadLabel(pm))
                    .setIcon(resolveInfo.loadIcon(pm))
                    .setOnMenuItemClickListener(itemListener);
        }
    } else {
        String msg;
        if (shareIntent == null || shareIntent.getType() == null || shareIntent.getType().equals("")) {
            msg = context.getString(R.string.no_share_type);
        } else if (list == null || list.size() <= 0) {
            String formatMsg = context.getString(R.string.no_app_to_share);
            msg = String.format(formatMsg, shareIntent.getType());
        } else {
            msg = context.getString(R.string.error_occurred);
        }

        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }
}
 
Example 3
Source File: ForumFilterProvider.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
	if (replayItem != null) {
		return;
	}
	
	subMenu.clear();
	replayItem = subMenu.add(0, 1, 1, R.string.newly_reply).setIcon(R.drawable.ic_new_replay_checked);
	publishItem = subMenu.add(0, 2, 2, R.string.newly_publish).setIcon(R.drawable.ic_new_publish_unchecked);
	if (mListener != null) {
		replayItem.setOnMenuItemClickListener(mListener);
		publishItem.setOnMenuItemClickListener(mListener);
	}

}
 
Example 4
Source File: MainActivity.java    From Kandroid with GNU General Public License v3.0 6 votes vote down vote up
private void populateProjectsMenu() {
    if (mProjectList == null) {
        if (BuildConfig.DEBUG) Log.d("Kandroid", "Tried to populate drawer, but mDashboard was null");
        return;
    }
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
    List<KanboardProject> projList = mProjectList;
    if (preferences.getBoolean("projects_sort_alphabetic", false))
        Collections.sort(projList);
    NavigationView nav = (NavigationView) findViewById(R.id.nav_view);
    SubMenu projMenu = nav.getMenu().findItem(R.id.projects).getSubMenu();
    projMenu.clear();
    for (KanboardProject item: projList)
        projMenu.add(Menu.NONE, item.getId(), Menu.NONE, item.getName())
                .setIcon(R.drawable.project);
}
 
Example 5
Source File: PlusActionProvider.java    From HightCopyWX with Apache License 2.0 6 votes vote down vote up
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();
    subMenu.add(Menu.NONE,0,Menu.NONE,mContext.getString(R.string.multi_chat))
            .setIcon(R.drawable.multi_chat)
            .setOnMenuItemClickListener(this);
    subMenu.add(Menu.NONE,1,Menu.NONE,mContext.getString(R.string.add_friends))
            .setIcon(R.drawable.add_friends)
            .setOnMenuItemClickListener(this);
    subMenu.add(Menu.NONE,2,Menu.NONE,mContext.getString(R.string.scan))
            .setIcon(R.drawable.scan)
            .setOnMenuItemClickListener(this);
    subMenu.add(Menu.NONE,3,Menu.NONE,mContext.getString(R.string.pay_money))
            .setIcon(R.drawable.pay_money)
            .setOnMenuItemClickListener(this);
    subMenu.add(Menu.NONE,4,Menu.NONE,mContext.getString(R.string.help_devise))
            .setIcon(R.drawable.help_advise)
            .setOnMenuItemClickListener(this);
}
 
Example 6
Source File: LibraryFragment.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSortOrderMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
    String currentSortOrder = fragment.getSortOrder();
    sortOrderMenu.clear();

    if (fragment instanceof AlbumsFragment) {
        sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z));
        sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A));
        sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST));
        sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_YEAR));
        sortOrderMenu.add(0, R.id.action_album_sort_order_date_added, 4, R.string.sort_order_date_added)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_DATE_ADDED));
    } else if (fragment instanceof ArtistsFragment) {
        sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_A_Z));
        sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_Z_A));
    } else if (fragment instanceof SongsFragment) {
        sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_A_Z));
        sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A));
        sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST));
        sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM));
        sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR));
        sortOrderMenu.add(0, R.id.action_song_sort_order_date_added, 5, R.string.sort_order_date_added)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_DATE_ADDED));
    }

    sortOrderMenu.setGroupCheckable(0, true, true);
}
 
Example 7
Source File: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public static void overflowsubmenu(Context context, SubMenu subMenu) {
    String[] cols = new String[]{
            MediaStore.Audio.Playlists._ID,
            MediaStore.Audio.Playlists.NAME
    };
    ContentResolver resolver = context.getContentResolver();
    if (resolver == null) {
        System.out.println("resolver = null");
    } else {
        String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
        Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                cols, whereclause, null,
                MediaStore.Audio.Playlists.NAME);
        subMenu.clear();
        subMenu.add(0, Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
        if (cur != null && cur.getCount() > 0) {
            //sub.addSeparator(1, 0);
            cur.moveToFirst();
            while (!cur.isAfterLast()) {
                Intent intent = new Intent();
                intent.putExtra("playlist", cur.getLong(0));
                subMenu.add(0, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
                cur.moveToNext();
            }
        }
        if (cur != null) {
            cur.close();
        }
    }
}
 
Example 8
Source File: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public static void makePlaylistMenu(Context context, SubMenu sub, int groupdId) {
    String[] cols = new String[]{
            MediaStore.Audio.Playlists._ID,
            MediaStore.Audio.Playlists.NAME
    };
    ContentResolver resolver = context.getContentResolver();
    if (resolver == null) {
        System.out.println("resolver = null");
    } else {
        String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
        Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                cols, whereclause, null,
                MediaStore.Audio.Playlists.NAME);
        sub.clear();
        sub.add(groupdId, Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
        if (cur != null && cur.getCount() > 0) {
            //sub.addSeparator(1, 0);
            cur.moveToFirst();
            while (!cur.isAfterLast()) {
                Intent intent = new Intent();
                intent.putExtra("playlist", cur.getLong(0));
                sub.add(groupdId, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
                cur.moveToNext();
            }
        }
        if (cur != null) {
            cur.close();
        }
    }
}
 
Example 9
Source File: LibraryFragment.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSortOrderMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
    String currentSortOrder = fragment.getSortOrder();
    sortOrderMenu.clear();

    if (fragment instanceof AlbumsFragment) {
        sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z));
        sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A));
        sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST));
        sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_YEAR));
    } else if (fragment instanceof ArtistsFragment) {
        sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_A_Z));
        sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_Z_A));
    } else if (fragment instanceof SongsFragment) {
        sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_A_Z));
        sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A));
        sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST));
        sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM));
        sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR));
    }

    sortOrderMenu.setGroupCheckable(0, true, true);
}
 
Example 10
Source File: MusicUtils.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
/**
 * Fills out the given submenu with items for "new playlist" and
 * any existing playlists. When the user selects an item, the
 * application will receive PLAYLIST_SELECTED with the Uri of
 * the selected playlist, NEW_PLAYLIST if a new playlist
 * should be created, and QUEUE if the "current playlist" was
 * selected.
 *
 * @param context The context to use for creating the menu items
 * @param sub     The submenu to add the items to.
 */
public static void makePlaylistMenu(Context context, SubMenu sub) {
    String[] cols = new String[]{
            MediaStore.Audio.Playlists._ID,
            MediaStore.Audio.Playlists.NAME
    };
    ContentResolver resolver = context.getContentResolver();
    if (resolver == null) {
        System.out.println("resolver = null");
    } else {
        String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
        Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                cols, whereclause, null,
                MediaStore.Audio.Playlists.NAME);
        sub.clear();
        sub.add(1, Defs.QUEUE, 0, R.string.queue);
        sub.add(1, Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
        if (cur != null && cur.getCount() > 0) {
            //sub.addSeparator(1, 0);
            cur.moveToFirst();
            while (!cur.isAfterLast()) {
                Intent intent = new Intent();
                intent.putExtra("playlist", cur.getLong(0));
                sub.add(1, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
                cur.moveToNext();
            }
        }
        if (cur != null) {
            cur.close();
        }
    }
}
 
Example 11
Source File: DrawerService.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void overrideNotebooks(OnDrawerSelectionChangedListener listener, Collection<Notebook> notebooks){
    final Menu overview = view.getMenu();
    final SubMenu notebookSubmenu = overview.findItem(R.id.navigation_notebooks).getSubMenu();

    notebookSubmenu.clear();

    for(Notebook book : notebooks){
        addNotebook(view.getContext(), notebookSubmenu, listener, book);
    }
}
 
Example 12
Source File: DrawerService.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void overrideTags(OnDrawerSelectionChangedListener listener, Collection<Tag> tags){
    final Menu overview = view.getMenu();
    final SubMenu tagSubmenu = overview.findItem(R.id.navigation_tags).getSubMenu();

    tagSubmenu.clear();

    for(Tag tag : tags){
        addTag(tagSubmenu, listener, tag);
    }
}
 
Example 13
Source File: ViewAsActionProvider.java    From Contacts with MIT License 5 votes vote down vote up
@Override
public void onPrepareSubMenu(SubMenu subMenu)
{
	//super.onPrepareSubMenu(subMenu);
	subMenu.clear();
	
	MenuItem list = subMenu.add("List");
	list.setIcon(R.drawable.ic_action_view_as_list);
	
	MenuItem gridA = subMenu.add("Big grid");
	gridA.setIcon(R.drawable.ic_action_view_as_big_grid);
	
	MenuItem gridB = subMenu.add("Small grid");
	gridB.setIcon(R.drawable.ic_action_view_as_small_grid);
}
 
Example 14
Source File: SocialShareActionProvider.java    From android-atleap with Apache License 2.0 5 votes vote down vote up
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();


    for (int i = 0; i < SOCIAL_NETWORK_PROVIDERS.size(); i++) {
        ShareItem shareItem = SOCIAL_NETWORK_PROVIDERS.get(i);
        subMenu.add(0, i, i, shareItem.name).setOnMenuItemClickListener(this);
    }
}
 
Example 15
Source File: BrowserActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void createFileMenu(final ContextMenu menu, final String path) {
    final BookSettings bs = SettingsManager.getBookSettings(path);
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);
    menu.setHeaderTitle(path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(false);
    menu.findItem(R.id.bookmenu_openbookfolder).setVisible(false);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 16
Source File: RecentActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void onCreateBookMenu(final ContextMenu menu, final BookNode node) {
    final BookSettings bs = node.settings;
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);

    menu.setHeaderTitle(node.path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);

    final BookShelfAdapter bookShelf = getController().getBookShelf(node);
    final BookShelfAdapter current = bookcaseView != null ? getController().getBookShelf(
            bookcaseView.getCurrentList()) : null;
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(
            bookShelf != null && current != null && bookShelf != current);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 17
Source File: LibraryFragment.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSortOrderMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
    String currentSortOrder = fragment.getSortOrder();
    sortOrderMenu.clear();

    if (fragment instanceof AlbumsFragment) {
        sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z));
        sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A));
        sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST));
        sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_YEAR));
    } else if (fragment instanceof ArtistsFragment) {
        sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_A_Z));
        sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.ArtistSortOrder.ARTIST_Z_A));
    } else if (fragment instanceof SongsFragment) {
        sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_A_Z));
        sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A));
        sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST));
        sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM));
        sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
                .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR));
    }

    sortOrderMenu.setGroupCheckable(0, true, true);
}