use of android.view.SubMenu in project Shuttle by timusus.
the class MenuUtils method addQueueMenuOptions.
public static void addQueueMenuOptions(final Context context, final PopupMenu menu) {
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, PLAY_NEXT, 0, R.string.play_next);
SubMenu sub = menu.getMenu().addSubMenu(SONG_FRAGMENT_GROUP_ID, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
PlaylistUtils.makePlaylistMenu(context, sub, SONG_FRAGMENT_GROUP_ID);
if (ShuttleUtils.isUpgraded()) {
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, TAGGER, 3, R.string.edit_tags);
}
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, USE_AS_RINGTONE, 5, R.string.ringtone_menu);
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, REMOVE, 6, R.string.remove_from_queue);
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, VIEW_INFO, 7, R.string.song_info);
menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, SHARE, 8, R.string.share);
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, BLACKLIST, 9, R.string.blacklist_title);
menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, DELETE_ITEM, 10, R.string.delete_item);
}
use of android.view.SubMenu in project Shuttle by timusus.
the class SearchActivity method onOverflowClick.
@Override
public void onOverflowClick(View v, int position, Object object) {
PopupMenu menu = new PopupMenu(this, v);
if (object instanceof AlbumArtist) {
menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
} else if (object instanceof Album) {
menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
} else if (object instanceof Song) {
menu.getMenu().add(0, PLAY_NEXT, 0, R.string.play_next);
menu.getMenu().add(0, USE_AS_RINGTONE, 4, R.string.ringtone_menu);
}
SubMenu sub = menu.getMenu().addSubMenu(0, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
PlaylistUtils.makePlaylistMenu(this, sub, 0);
menu.getMenu().add(0, QUEUE, 2, R.string.add_to_queue);
if (ShuttleUtils.isUpgraded()) {
menu.getMenu().add(0, TAGGER, 3, R.string.edit_tags);
}
menu.getMenu().add(0, DELETE_ITEM, 6, R.string.delete_item);
menu.setOnMenuItemClickListener(item -> {
Observable<List<Song>> songsObservable = null;
if (object instanceof Song) {
songsObservable = Observable.just(Collections.singletonList((Song) object));
} else if (object instanceof AlbumArtist) {
songsObservable = ((AlbumArtist) object).getSongsObservable();
} else if (object instanceof Album) {
songsObservable = ((Album) object).getSongsObservable();
}
switch(item.getItemId()) {
case PLAY_SELECTION:
songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playAll(songs, () -> {
final String message = getString(R.string.emptyplaylist);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}));
return true;
case PLAY_NEXT:
songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playNext(SearchActivity.this, songs));
return true;
case NEW_PLAYLIST:
songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> PlaylistUtils.createPlaylistDialog(SearchActivity.this, songs));
return true;
case PLAYLIST_SELECTED:
songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
PlaylistUtils.addToPlaylist(this, playlist, songs);
});
return true;
case USE_AS_RINGTONE:
ShuttleUtils.setRingtone(SearchActivity.this, ((Song) object));
return true;
case QUEUE:
songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.addToQueue(SearchActivity.this, songs));
return true;
case TAGGER:
TaggerDialog.newInstance((Serializable) object).show(getSupportFragmentManager());
return true;
case DELETE_ITEM:
DialogUtils.DeleteDialogBuilder builder = new DialogUtils.DeleteDialogBuilder().context(this).songsToDelete(songsObservable);
if (object instanceof Song) {
builder.singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Collections.singletonList(((Song) object).name));
} else if (object instanceof AlbumArtist) {
builder.singleMessageId(R.string.delete_album_artist_desc).multipleMessage(R.string.delete_album_artist_desc_multiple).itemNames(Collections.singletonList(((AlbumArtist) object).name));
} else if (object instanceof Album) {
builder.singleMessageId(R.string.delete_album_desc).multipleMessage(R.string.delete_album_desc_multiple).itemNames(Collections.singletonList(((Album) object).name));
}
builder.build().show();
return true;
}
return false;
});
menu.show();
}
use of android.view.SubMenu in project Shuttle by timusus.
the class FolderFragment method onOverflowClick.
@Override
public void onOverflowClick(View v, int position, BaseFileObject fileObject) {
PopupMenu menu = new PopupMenu(getActivity(), v);
if (fileObject.fileType == FileType.FILE) {
//Play this song next
menu.getMenu().add(FRAGMENT_GROUPID, PLAY_NEXT, 4, R.string.play_next);
//Tag editor
if (ShuttleUtils.isUpgraded()) {
menu.getMenu().add(FRAGMENT_GROUPID, TAGGER, 5, R.string.edit_tags);
}
//Set this song as the ringtone
menu.getMenu().add(FRAGMENT_GROUPID, USE_AS_RINGTONE, 6, R.string.ringtone_menu);
if (FileHelper.canReadWrite(new File(fileObject.path))) {
//Rename File
menu.getMenu().add(FRAGMENT_GROUPID, RENAME, 7, R.string.rename_file);
//Delete File
menu.getMenu().add(FRAGMENT_GROUPID, DELETE_ITEM, 8, R.string.delete_item);
}
menu.getMenu().add(FRAGMENT_GROUPID, VIEW_INFO, 9, R.string.song_info);
} else {
//Play all files in this dir
menu.getMenu().add(FRAGMENT_GROUPID, PLAY_SELECTION, 0, R.string.play_selection);
//Set this directory as initial directory
menu.getMenu().add(FRAGMENT_GROUPID, SET_INITIAL_DIR, 4, R.string.set_initial_dir);
if (FileHelper.canReadWrite(new File(fileObject.path))) {
//Rename dir
menu.getMenu().add(FRAGMENT_GROUPID, RENAME, 5, R.string.rename_folder);
//Delete dir
menu.getMenu().add(FRAGMENT_GROUPID, DELETE_ITEM, 6, R.string.delete_item);
}
}
//Bring up the add to playlist menu
SubMenu sub = menu.getMenu().addSubMenu(FRAGMENT_GROUPID, ADD_TO_PLAYLIST, 2, R.string.add_to_playlist);
PlaylistUtils.makePlaylistMenu(getActivity(), sub, FRAGMENT_GROUPID);
//Add to queue
menu.getMenu().add(FRAGMENT_GROUPID, QUEUE, 3, R.string.add_to_queue);
menu.getMenu().add(FRAGMENT_GROUPID, RESCAN, 4, R.string.scan_file);
menu.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case TAGGER:
FileHelper.getSong(new File(fileObject.path)).subscribeOn(Schedulers.io()).subscribe(song -> TaggerDialog.newInstance(song).show(getFragmentManager()));
return true;
case QUEUE:
FileHelper.getSongList(new File(fileObject.path), true, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.addToQueue(getActivity(), songs));
return true;
case DELETE_ITEM:
MaterialDialog.Builder builder = DialogUtils.getBuilder(getActivity()).title(R.string.delete_item).icon(DrawableUtils.getBlackDrawable(getActivity(), R.drawable.ic_dialog_alert));
if (fileObject.fileType == FileType.FILE) {
builder.content(String.format(getResources().getString(R.string.delete_file_confirmation_dialog), fileObject.name));
} else {
builder.content(String.format(getResources().getString(R.string.delete_folder_confirmation_dialog), fileObject.path));
}
builder.positiveText(R.string.button_ok).onPositive((materialDialog, dialogAction) -> {
if (FileHelper.deleteFile(new File(fileObject.path))) {
mAdapter.removeItem(position);
CustomMediaScanner.scanFiles(Collections.singletonList(fileObject.path), null);
} else {
Toast.makeText(getActivity(), fileObject.fileType == FileType.FOLDER ? R.string.delete_folder_failed : R.string.delete_file_failed, Toast.LENGTH_LONG).show();
}
});
builder.negativeText(R.string.cancel).show();
return true;
case RENAME:
View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_rename, null);
final CustomEditText editText = (CustomEditText) customView.findViewById(R.id.editText);
ThemeUtils.themeEditText(editText);
editText.setText(fileObject.name);
builder = DialogUtils.getBuilder(getActivity());
if (fileObject.fileType == FileType.FILE) {
builder.title(R.string.rename_file);
} else {
builder.title(R.string.rename_folder);
}
builder.customView(customView, false);
builder.positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
if (editText.getText() != null) {
if (FileHelper.renameFile(getActivity(), fileObject, editText.getText().toString())) {
mAdapter.notifyDataSetChanged();
} else {
Toast.makeText(getActivity(), fileObject.fileType == FileType.FOLDER ? R.string.rename_folder_failed : R.string.rename_file_failed, Toast.LENGTH_LONG).show();
}
}
});
builder.negativeText(R.string.cancel).show();
return true;
case USE_AS_RINGTONE:
FileHelper.getSong(new File(fileObject.path)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(song -> ShuttleUtils.setRingtone(getContext(), song));
return true;
case PLAY_NEXT:
FileHelper.getSongList(new File(fileObject.path), false, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playNext(getActivity(), songs));
return true;
case PLAY_SELECTION:
final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getString(R.string.gathering_songs), false);
FileHelper.getSongList(new File(fileObject.path), true, fileObject.fileType == FileType.FILE).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
MusicUtils.playAll(songs, 0, () -> {
final String message = getContext().getString(R.string.emptyplaylist);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
});
if (isAdded() && progressDialog.isShowing()) {
progressDialog.dismiss();
}
});
return true;
case NEW_PLAYLIST:
List<BaseFileObject> fileObjects = new ArrayList<>();
fileObjects.add(fileObject);
PlaylistUtils.createFileObjectPlaylistDialog(getActivity(), fileObjects);
return true;
case PLAYLIST_SELECTED:
final Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
FileHelper.getSongList(new File(fileObject.path), true, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> PlaylistUtils.addToPlaylist(getContext(), playlist, songs));
return true;
case SET_INITIAL_DIR:
SettingsManager.getInstance().setFolderBrowserInitialDir(fileObject.path);
Toast.makeText(getActivity(), fileObject.path + getResources().getString(R.string.initial_dir_set_message), Toast.LENGTH_SHORT).show();
return true;
case RESCAN:
if (fileObject instanceof FolderObject) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_progress, null);
TextView pathsTextView = (TextView) view.findViewById(R.id.paths);
pathsTextView.setText(fileObject.path);
ProgressBar indeterminateProgress = (ProgressBar) view.findViewById(R.id.indeterminateProgress);
DrawableCompat.setTint(DrawableCompat.wrap(indeterminateProgress.getIndeterminateDrawable()), ColorUtils.getAccentColor());
ProgressBar horizontalProgress = (ProgressBar) view.findViewById(R.id.horizontalProgress);
DrawableCompat.setTint(DrawableCompat.wrap(horizontalProgress.getProgressDrawable()), ColorUtils.getAccentColor());
MaterialDialog dialog = DialogUtils.getBuilder(getContext()).title(R.string.scanning).customView(view, false).negativeText(R.string.close).show();
FileHelper.getSongList(new File(fileObject.path), true, false).map(songs -> Stream.of(songs).map(song -> song.path).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(paths -> {
ViewUtils.fadeOut(indeterminateProgress, null);
ViewUtils.fadeIn(horizontalProgress, null);
horizontalProgress.setMax(paths.size());
CustomMediaScanner.scanFiles(paths, new CustomMediaScanner.ScanCompletionListener() {
@Override
public void onPathScanned(String path) {
horizontalProgress.setProgress(horizontalProgress.getProgress() + 1);
pathsTextView.setText(path);
}
@Override
public void onScanCompleted() {
if (isAdded() && dialog.isShowing()) {
dialog.dismiss();
}
}
});
});
} else {
CustomMediaScanner.scanFiles(Collections.singletonList(fileObject.path), new CustomMediaScanner.ScanCompletionListener() {
@Override
public void onPathScanned(String path) {
}
@Override
public void onScanCompleted() {
Toast.makeText(getContext(), R.string.scan_complete, Toast.LENGTH_LONG).show();
}
});
}
return true;
case VIEW_INFO:
DialogUtils.showFileInfoDialog(getActivity(), (FileObject) fileObject);
break;
}
return false;
});
menu.show();
}
use of android.view.SubMenu in project android_frameworks_base by ParanoidAndroid.
the class ShareActionProvider method onPrepareSubMenu.
/**
* {@inheritDoc}
*/
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
// Clear since the order of items may change.
subMenu.clear();
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
PackageManager packageManager = mContext.getPackageManager();
final int expandedActivityCount = dataModel.getActivityCount();
final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);
// Populate the sub-menu with a sub set of the activities.
for (int i = 0; i < collapsedActivityCount; i++) {
ResolveInfo activity = dataModel.getActivity(i);
subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
}
if (collapsedActivityCount < expandedActivityCount) {
// Add a sub-menu for showing all activities as a list item.
SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount, mContext.getString(R.string.activity_chooser_view_see_all));
for (int i = 0; i < expandedActivityCount; i++) {
ResolveInfo activity = dataModel.getActivity(i);
expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
}
}
}
use of android.view.SubMenu in project platform_frameworks_base by android.
the class ListContextMenu method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem item = menu.add(0, 0, 0, "Really long menu item name");
item.setTitleCondensed("Long name");
item.setIcon(R.drawable.black_square);
SubMenu sm = menu.addSubMenu(0, 0, 0, "The 2nd item, a sub menu").setIcon(R.drawable.black_square_stretchable);
item = sm.getItem();
item.setTitleCondensed("Sub menu");
sm.add(1, 0, 0, "Subitem 1");
sm.add(1, 0, 0, "Subitem 2");
sm.add(1, 0, 0, "Subitem 3");
sm.setGroupCheckable(1, true, true);
menu.add(0, 0, 0, "Item 3");
menu.add(0, 0, 0, "Item 4");
menu.add(0, 0, 0, "Item 5");
menu.add(0, 0, 0, "Item 6");
menu.add(0, 0, 0, "Item 7");
menu.add(0, 0, 0, "Item 8");
menu.add(0, 0, 0, "Item 9");
sm = menu.addSubMenu(0, 0, 0, "Item 10 SM");
sm.add(0, 0, 0, "Subitem 1");
sm.add(0, 0, 0, "Subitem 2");
sm.add(0, 0, 0, "Subitem 3");
sm.add(0, 0, 0, "Subitem 4");
sm.add(0, 0, 0, "Subitem 5");
sm.add(0, 0, 0, "Subitem 6");
sm.add(0, 0, 0, "Subitem 7");
sm.add(0, 0, 0, "Subitem 8");
return true;
}
Aggregations