[Android] Refactor video player tracks menu
Geoffrey Métais
git at videolan.org
Wed Nov 21 10:29:06 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Nov 20 18:26:04 2018 +0100| [9b0ff1f660b2ec24331d94cda1dccf2b19dacfee] | committer: Geoffrey Métais
Refactor video player tracks menu
> https://code.videolan.org/videolan/vlc-android/commit/9b0ff1f660b2ec24331d94cda1dccf2b19dacfee
---
vlc-android/res/values/strings.xml | 4 ++
vlc-android/res/values/styles.xml | 1 +
.../org/videolan/vlc/gui/dialogs/ContextSheet.kt | 4 ++
.../vlc/gui/video/VideoPlayerActivity.java | 84 ++++++++++------------
vlc-android/src/org/videolan/vlc/util/Constants.kt | 4 ++
5 files changed, 51 insertions(+), 46 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 82d514845..3567a5ddd 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -654,4 +654,8 @@
<string name="download_the_selected">Download selection</string>
<string name="next">Next</string>
<string name="download">Download</string>
+ <string name="ctx_player_video_track">Select video track</string>
+ <string name="ctx_player_audio_track">Audio track</string>
+ <string name="ctx_player_subs_track">Subtitles track</string>
+ <string name="ctx_player_tracks_title">Media tracks</string>
</resources>
diff --git a/vlc-android/res/values/styles.xml b/vlc-android/res/values/styles.xml
index 2601b9be4..521ab7210 100644
--- a/vlc-android/res/values/styles.xml
+++ b/vlc-android/res/values/styles.xml
@@ -257,6 +257,7 @@
<item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/orange800</item>
+ <item name="background_default">@color/grey850</item>
<item name="rounded_bg">@drawable/rounded_corners</item>
<item name="advanced_options_style">@style/Theme.MaterialComponents.Dialog</item>
<item name="ic_playasaudio_on">@drawable/ic_playasaudio_on_w</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index 9d1776110..9b05dcbba 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -92,6 +92,10 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr
if (flags and CTX_PLAY_ALL != 0) add(Simple(CTX_PLAY_ALL, getString(R.string.play_all), R.drawable.ic_ctx_play_all_normal))
if (flags and CTX_PLAY_AS_AUDIO != 0) add(Simple(CTX_PLAY_AS_AUDIO, getString(R.string.play_as_audio), R.drawable.ic_ctx_play_as_audio_normal))
if (flags and CTX_PLAY_GROUP != 0) add(Simple(CTX_PLAY_GROUP, getString(R.string.play), R.drawable.ic_ctx_play_normal))
+ if (flags and CTX_VIDEO_TRACK != 0) add(Simple(CTX_VIDEO_TRACK, getString(R.string.ctx_player_video_track), R.drawable.ic_ctx_information_normal))
+ if (flags and CTX_AUDIO_TRACK != 0) add(Simple(CTX_AUDIO_TRACK, getString(R.string.ctx_player_audio_track), R.drawable.ic_ctx_information_normal))
+ if (flags and CTX_SUBS_TRACK != 0) add(Simple(CTX_SUBS_TRACK, getString(R.string.ctx_player_subs_track), R.drawable.ic_ctx_information_normal))
+ if (flags and CTX_PICK_SUBS != 0) add(Simple(CTX_PICK_SUBS, getString(R.string.subtitle_select), R.drawable.ic_ctx_information_normal))
if (flags and CTX_APPEND != 0) add(Simple(CTX_APPEND, getString(R.string.append), R.drawable.ic_ctx_append_normal))
if (flags and CTX_INFORMATION != 0) add(Simple(CTX_INFORMATION, getString(R.string.info), R.drawable.ic_ctx_information_normal))
if (flags and CTX_DELETE != 0) add(Simple(CTX_DELETE, getString(R.string.delete), R.drawable.ic_ctx_delete_normal))
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 4863323e8..f5b39f41f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -98,6 +98,8 @@ import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.audio.PlaylistAdapter;
import org.videolan.vlc.gui.browser.FilePickerActivity;
import org.videolan.vlc.gui.browser.FilePickerFragmentKt;
+import org.videolan.vlc.gui.dialogs.ContextSheetKt;
+import org.videolan.vlc.gui.dialogs.CtxActionReceiver;
import org.videolan.vlc.gui.dialogs.RenderersDialog;
import org.videolan.vlc.gui.helpers.OnRepeatListener;
import org.videolan.vlc.gui.helpers.PlayerOptionsDelegate;
@@ -143,7 +145,7 @@ import androidx.recyclerview.widget.RecyclerView;
public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackSettingsController,
PlaybackService.Client.Callback, PlaybackService.Callback,PlaylistAdapter.IPlayer,
- OnClickListener, OnLongClickListener, StoragePermissionsDelegate.CustomActionController {
+ OnClickListener, OnLongClickListener, StoragePermissionsDelegate.CustomActionController, CtxActionReceiver {
private final static String TAG = "VLC/VideoPlayerActivity";
@@ -1718,53 +1720,43 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
}
};
- public void onAudioSubClick(View anchor){
- if (anchor == null) {
- initOverlay();
- anchor = mHudBinding.playerOverlayTracks;
+ public void onAudioSubClick(View anchor) {
+ int flags = 0;
+ if (enableSubs) {
+ flags |= Constants.CTX_DOWNLOAD_SUBTITLES;
+ if (mDisplayManager.isPrimary()) flags |= Constants.CTX_PICK_SUBS;
}
- final AppCompatActivity context = this;
- final PopupMenu popupMenu = new PopupMenu(this, anchor);
- final Menu menu = popupMenu.getMenu();
- popupMenu.getMenuInflater().inflate(R.menu.audiosub_tracks, menu);
- //FIXME network subs cannot be enabled & screen cast display is broken with picker
- menu.findItem(R.id.video_menu_subtitles_picker).setEnabled(mDisplayManager.isPrimary() && enableSubs);
- menu.findItem(R.id.video_menu_subtitles_download).setEnabled(enableSubs);
- menu.findItem(R.id.video_menu_video_track).setVisible(mService.getVideoTracksCount() > 2);
- menu.findItem(R.id.video_menu_audio_track).setEnabled(mService.getAudioTracksCount() > 0);
- menu.findItem(R.id.video_menu_subtitles).setEnabled(mService.getSpuTracksCount() > 0);
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- if (item.getItemId() == R.id.video_menu_audio_track) {
- selectAudioTrack();
- return true;
- } else if (item.getItemId() == R.id.video_menu_video_track) {
- selectVideoTrack();
- return true;
- } else if (item.getItemId() == R.id.video_menu_subtitles) {
- selectSubtitles();
- return true;
- } else if (item.getItemId() == R.id.video_menu_subtitles_picker) {
- if (mUri == null)
- return false;
- mShowingDialog = true;
- final Intent filePickerIntent = new Intent(context, FilePickerActivity.class);
- filePickerIntent.setData(Uri.parse(FileUtils.getParent(mUri.toString())));
- context.startActivityForResult(filePickerIntent, 0);
- return true;
- } else if (item.getItemId() == R.id.video_menu_subtitles_download) {
- if (mUri == null)
- return false;
- MediaUtils.INSTANCE.getSubs(VideoPlayerActivity.this, mService.getCurrentMediaWrapper());
- }
+ if (mService.getVideoTracksCount() > 2) flags |= Constants.CTX_VIDEO_TRACK;
+ if (mService.getAudioTracksCount() > 0) flags |= Constants.CTX_AUDIO_TRACK;
+ if (mService.getSpuTracksCount() > 0) flags |= Constants.CTX_SUBS_TRACK;
+ ContextSheetKt.showContext(this, this, -1, getString(R.string.ctx_player_tracks_title), flags);
+ hideOverlay(false);
+ }
- hideOverlay(true);
- return false;
- }
- });
- popupMenu.show();
- showOverlay();
+ @Override
+ public void onCtxAction(int position, int option) {
+ if (mUri == null) return;
+ switch (option) {
+ case Constants.CTX_VIDEO_TRACK:
+ selectVideoTrack();
+ break;
+ case Constants.CTX_AUDIO_TRACK:
+ selectAudioTrack();
+ break;
+ case Constants.CTX_SUBS_TRACK:
+ selectSubtitles();
+ break;
+ case Constants.CTX_PICK_SUBS:
+ mShowingDialog = true;
+ final Intent filePickerIntent = new Intent(this, FilePickerActivity.class);
+ filePickerIntent.setData(Uri.parse(FileUtils.getParent(mUri.toString())));
+ startActivityForResult(filePickerIntent, 0);
+ break;
+ case Constants.CTX_DOWNLOAD_SUBTITLES:
+ final MediaWrapper mw = mService != null ? mService.getCurrentMediaWrapper() : null;
+ if (mw != null) MediaUtils.INSTANCE.getSubs(VideoPlayerActivity.this, mw);
+ break;
+ }
}
@Override
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index be89e170d..e0f307ab0 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -158,6 +158,10 @@ const val CTX_ITEM_DL = 1 shl 16
const val CTX_REMOVE_FROM_PLAYLIST = 1 shl 17
const val CTX_STOP_AFTER_THIS = 1 shl 18
const val CTX_RENAME = 1 shl 19
+const val CTX_AUDIO_TRACK = 1 shl 20
+const val CTX_SUBS_TRACK = 1 shl 21
+const val CTX_PICK_SUBS = 1 shl 22
+const val CTX_VIDEO_TRACK = 1 shl 23
const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO
const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE
More information about the Android
mailing list