From 6d6609187bc481613cd4cb1cdae977a3fe62dac5 Mon Sep 17 00:00:00 2001 From: marin Date: Thu, 9 Nov 2017 11:29:02 +0100 Subject: [PATCH] Add dropdown menu and switch to background option --- .../newpipe/player/MainVideoPlayer.java | 102 ++++++++++++++++-- .../schabi/newpipe/player/VideoPlayer.java | 17 ++- .../drawable-hdpi/ic_more_vert_black_24dp.png | Bin 0 -> 132 bytes .../drawable-hdpi/ic_more_vert_white_24dp.png | Bin 0 -> 134 bytes .../drawable-mdpi/ic_more_vert_black_24dp.png | Bin 0 -> 108 bytes .../drawable-mdpi/ic_more_vert_white_24dp.png | Bin 0 -> 112 bytes .../ic_more_vert_black_24dp.png | Bin 0 -> 155 bytes .../ic_more_vert_white_24dp.png | Bin 0 -> 158 bytes .../ic_more_vert_black_24dp.png | Bin 0 -> 205 bytes .../ic_more_vert_white_24dp.png | Bin 0 -> 216 bytes .../ic_more_vert_black_24dp.png | Bin 0 -> 272 bytes .../ic_more_vert_white_24dp.png | Bin 0 -> 305 bytes .../main/res/layout/activity_main_player.xml | 32 ++---- app/src/main/res/menu/menu_videooptions.xml | 21 ++++ app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/styles.xml | 2 + 16 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_more_vert_black_24dp.png create mode 100644 app/src/main/res/drawable-hdpi/ic_more_vert_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_more_vert_black_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_more_vert_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_more_vert_black_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_more_vert_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_more_vert_black_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_more_vert_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_more_vert_black_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_more_vert_white_24dp.png create mode 100644 app/src/main/res/menu/menu_videooptions.xml diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index c275e55a7..3beab8188 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.graphics.Color; import android.media.AudioManager; import android.os.Build; @@ -33,6 +34,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log; import android.view.GestureDetector; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; @@ -58,6 +60,8 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.ThemeHelper; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.List; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -150,6 +154,17 @@ public final class MainVideoPlayer extends Activity { if (playerImpl != null) playerImpl.destroy(); } + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + if (playerImpl.isSomePopupMenuVisible()) { + playerImpl.moreOptionsPopupMenu.dismiss(); + playerImpl.getQualityPopupMenu().dismiss(); + playerImpl.getPlaybackSpeedPopupMenu().dismiss(); + } + } + /*////////////////////////////////////////////////////////////////////////// // Utils //////////////////////////////////////////////////////////////////////////*/ @@ -222,7 +237,6 @@ public final class MainVideoPlayer extends Activity { private ImageButton repeatButton; private ImageButton shuffleButton; - private ImageButton screenRotationButton; private ImageButton playPauseButton; private ImageButton playPreviousButton; private ImageButton playNextButton; @@ -234,6 +248,10 @@ public final class MainVideoPlayer extends Activity { private boolean queueVisible; + private ImageButton moreOptionsButton; + public int moreOptionsPopupMenuGroupId = 89; + public PopupMenu moreOptionsPopupMenu; + VideoPlayerImpl(final Context context) { super("VideoPlayerImpl" + MainVideoPlayer.TAG, context); } @@ -249,10 +267,12 @@ public final class MainVideoPlayer extends Activity { this.repeatButton = rootView.findViewById(R.id.repeatButton); this.shuffleButton = rootView.findViewById(R.id.shuffleButton); - this.screenRotationButton = rootView.findViewById(R.id.screenRotationButton); this.playPauseButton = rootView.findViewById(R.id.playPauseButton); this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton); this.playNextButton = rootView.findViewById(R.id.playNextButton); + this.moreOptionsButton = rootView.findViewById(R.id.moreOptionsButton); + this.moreOptionsPopupMenu = new PopupMenu(context, moreOptionsButton); + this.moreOptionsPopupMenu.getMenuInflater().inflate(R.menu.menu_videooptions, moreOptionsPopupMenu.getMenu()); titleTextView.setSelected(true); channelTextView.setSelected(true); @@ -276,7 +296,7 @@ public final class MainVideoPlayer extends Activity { playPauseButton.setOnClickListener(this); playPreviousButton.setOnClickListener(this); playNextButton.setOnClickListener(this); - screenRotationButton.setOnClickListener(this); + moreOptionsButton.setOnClickListener(this); } /*////////////////////////////////////////////////////////////////////////// @@ -348,6 +368,28 @@ public final class MainVideoPlayer extends Activity { finish(); } + public void onPlayBackgroundButtonClicked() { + if (DEBUG) Log.d(TAG, "onPlayBackgroundButtonClicked() called"); + if (playerImpl.getPlayer() == null) return; + + setRecovery(); + final Intent intent = NavigationHelper.getPlayerIntent( + context, + BackgroundPlayer.class, + this.getPlayQueue(), + this.getRepeatMode(), + this.getPlaybackSpeed(), + this.getPlaybackPitch(), + this.getPlaybackQuality() + ); + context.startService(intent); + + ((View) getControlAnimationView().getParent()).setVisibility(View.GONE); + destroy(); + finish(); + } + + @Override public void onClick(View v) { super.onClick(v); @@ -360,9 +402,6 @@ public final class MainVideoPlayer extends Activity { } else if (v.getId() == playNextButton.getId()) { onPlayNext(); - } else if (v.getId() == screenRotationButton.getId()) { - onScreenRotationClicked(); - } else if (v.getId() == queueButton.getId()) { onQueueClicked(); return; @@ -372,6 +411,8 @@ public final class MainVideoPlayer extends Activity { } else if (v.getId() == shuffleButton.getId()) { onShuffleClicked(); return; + } else if (v.getId() == moreOptionsButton.getId()) { + onMoreOptionsClicked(); } if (getCurrentState() != STATE_COMPLETED) { @@ -405,6 +446,32 @@ public final class MainVideoPlayer extends Activity { queueVisible = false; } + private void onMoreOptionsClicked() { + if (DEBUG) Log.d(TAG, "onMoreOptionsClicked() called"); + buildMoreOptionsMenu(); + + try { + Field[] fields = moreOptionsPopupMenu.getClass().getDeclaredFields(); + for (Field field : fields) { + if ("mPopup".equals(field.getName())) { + field.setAccessible(true); + Object menuPopupHelper = field.get(moreOptionsPopupMenu); + Class classPopupHelper = Class.forName(menuPopupHelper + .getClass().getName()); + Method setForceIcons = classPopupHelper.getMethod( + "setForceShowIcon", boolean.class); + setForceIcons.invoke(menuPopupHelper, true); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + moreOptionsPopupMenu.show(); + isSomePopupMenuVisible = true; + showControls(300); + } + private void onScreenRotationClicked() { if (DEBUG) Log.d(TAG, "onScreenRotationClicked() called"); toggleOrientation(); @@ -555,6 +622,27 @@ public final class MainVideoPlayer extends Activity { setShuffleButton(shuffleButton, playQueue.isShuffled()); } + private void buildMoreOptionsMenu() { + if (moreOptionsPopupMenu == null) return; + moreOptionsPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + switch (menuItem.getItemId()) { + case R.id.toggleOrientation: + onScreenRotationClicked(); + break; + case R.id.switchPopup: + onFullScreenButtonClicked(); + break; + case R.id.switchBackground: + onPlayBackgroundButtonClicked(); + break; + } + return false; + } + }); + } + private void buildQueue() { queueLayout = findViewById(R.id.playQueuePanel); @@ -785,4 +873,4 @@ public final class MainVideoPlayer extends Activity { } } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 1a386d45d..ef72bfd90 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -124,12 +124,11 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. private View topControlsRoot; private TextView qualityTextView; - private ImageButton fullScreenButton; private ValueAnimator controlViewAnimator; private Handler controlsVisibilityHandler = new Handler(); - private boolean isSomePopupMenuVisible = false; + boolean isSomePopupMenuVisible = false; private int qualityPopupMenuGroupId = 69; private PopupMenu qualityPopupMenu; @@ -166,7 +165,6 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. this.bottomControlsRoot = rootView.findViewById(R.id.bottomControls); this.topControlsRoot = rootView.findViewById(R.id.topControls); this.qualityTextView = rootView.findViewById(R.id.qualityTextView); - this.fullScreenButton = rootView.findViewById(R.id.fullScreenButton); //this.aspectRatioFrameLayout.setAspectRatio(16.0f / 9.0f); @@ -186,7 +184,6 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. super.initListeners(); playbackSeekBar.setOnSeekBarChangeListener(this); playbackSpeedTextView.setOnClickListener(this); - fullScreenButton.setOnClickListener(this); qualityTextView.setOnClickListener(this); } @@ -453,9 +450,7 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. @Override public void onClick(View v) { if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]"); - if (v.getId() == fullScreenButton.getId()) { - onFullScreenButtonClicked(); - } else if (v.getId() == qualityTextView.getId()) { + if (v.getId() == qualityTextView.getId()) { onQualitySelectorClicked(); } else if (v.getId() == playbackSpeedTextView.getId()) { onPlaybackSpeedClicked(); @@ -753,14 +748,14 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. return qualityTextView; } - public ImageButton getFullScreenButton() { - return fullScreenButton; - } - public PopupMenu getQualityPopupMenu() { return qualityPopupMenu; } + public PopupMenu getPlaybackSpeedPopupMenu() { + return playbackSpeedPopupMenu; + } + public View getSurfaceForeground() { return surfaceForeground; } diff --git a/app/src/main/res/drawable-hdpi/ic_more_vert_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_more_vert_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..22acc550088d98f9d98ced517de75b5e8ead3c7c GIT binary patch literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B5}8r;B4q1>@UGdwClSM3^70uIQ21 z47_&cJkx~*+Z%R2IKOxGVZM^fH+7^Mmwc{S?NKJ@tD@b{HffqWt7pJW9xm}`3bIR@ eOD6DrGLJi>8B(9~m^Tk-EQ6=3pUXO@geCy;;w$k0 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_more_vert_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_more_vert_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..67f07e473442d1f5bd5dc486a42ce4bedf40b425 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K;ucwP+h{y4_mv-_VP!M4WR9aA@ zB9L2TV$k7bqBi~Tf{Y7K)@EPe&B(sMnUQ&cV?}1b!p)H;o34MJ iAa}{R%7g#se7OLo1Hz}Zd6xqXX7F_Nb6Mw<&;$T!hAw^p literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_more_vert_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_more_vert_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..0e4f2f6ea0564fe9d6ebdb4bea0df48aced9de0f GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1V^0^ykP60RiERoU4^0niv(+!U z$~^Ty`=RMavMX4xeQ2uS{l}xxJ=eVCD820|N5W*kJjJ67$C*FG*QAUgq7iWp7Wo)^m*JsBN#kg L{an^LB{Ts5on9xv literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_more_vert_black_24dp.png b/app/src/main/res/drawable-xhdpi/ic_more_vert_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9f10aa2759a2e53beb129849c9b0e6ee5f7ae97b GIT binary patch literal 155 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0DBu^K|kP61PR}A@_6b0BGTJ|c& z&2zArUdgs%qoJD@@9neO|NgtXV7^DW)MQ81qkHN%-79zXF}ZeKv~Tuphvz#4Z3DJ9 zo+<2n{rTU)UWQJm<&*zc>PM$^=S_g|6%VwoI2{_d>%srJ7&|&vk-TbVh<5S;l;%8hhyk$Kc9U$ho zN!;a@as7tMKN^!>mP|UmC!qU^(pC>$p{$8fOT;)oR_iUC=UG0_`?VR+LIzJ)KbLh* G2~7aOZ8w1c literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_more_vert_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_more_vert_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..94d5ab98c6d3b3548536f04a2d635fb5c4a05b88 GIT binary patch literal 205 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhawrg*wIhEy=Vy=KqV>>$DV@#Ph3 zmm-(IJxlAmHdKggydBZHA?LrN(f;zraK2yFla}<&ocsFTF&FO*>g+$WJLfsbvhR#o zqU5?6`INL2k&sND<*?!p=%CFlpb5%Rrp)D#!8^w7WtAYxjJ8qaZaq8!Lha3*C xpO9i0)g!jJUB|8aV$u`{=V%64OvRJ&URzP%pP$_?yn*gx@O1TaS?83{1OO~yQ~m$| literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_more_vert_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_more_vert_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..d32281307232fefc363e19d9d2728af62b440a8d GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw=6kw0hGg7(d(E5ckb#KX!!teA z8+IJIbSd_mp~lgrEob_e9cxnR1kZ18I^5b~uj)DJpG>-%nby>)6J_QWKRvd(S?`Ri~_DWys(>8rgyQv zG%aCaz>Js9>y=L)eUVgRxJx3oN6$@sv5NTO?u&4dNh*K$SbOB%sZae;9uIUXgQu&X J%Q~loCIECSTxI|O literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_more_vert_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_more_vert_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4642a3b66e690a25544c7a65b5484607c76e9e4d GIT binary patch literal 272 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcgu6w#ThEy=Vz2TVE>>%O(aeKF| z&%}AAoaYX07I~@2Qzf){=E~b*b6q_X?JD-aXZn{o>8SH070*d=@0yRCD&F7PI4|Iy zgr>dT{)s<*uuMbP?bJzL!+Uj>du1MOpP(^y_vJlXtsXdjo_CdTHuJx`L9zyy z_bjw};Pttx=xP2JS*8CI?{O?lw)*qOUytSD#5&t0XL`98ez{Y*;jMY`-`}^VtDMwJ z5#Pjpv-OQrnIiiQFtvL^tj8o3AbA2TH#1Zw0j|Uo=)7NS4apHKER!-ifL>(qboFyt I=akR{05Df}#Q*>R literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_more_vert_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_more_vert_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..2f2cb3d004f6e828917b5f6b1decc7fe5d99b445 GIT binary patch literal 305 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcget5b#hE&{od&7{g$w9>R;>#mP zB_2gJIy{WxDHIfl;54zZ?(Dj(@bmNJ>M(=pX9D&J05vf@IA0RFIB;_s@2aW4t^P!s z?~T5q@wxa<`?f89Li_gpTlKB*dwsOb9#+$?m6!M>7BklVVk|aEPh1DJ$>V{EJl=XH?V({#-awY-(QL|0?dORlc*XtSl(} z&d3n4k$a}x{MZxU-fiZ-$+m%8aD#C}>V?${Gwe!OwoRt{8X v))3p#FqiR-(={Oe2E;4(u$C!;+}~cs6m#}#(>L)Q#vrbztDnm{r-UW|mL!4d literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_main_player.xml b/app/src/main/res/layout/activity_main_player.xml index 5c6349c35..6086dd5cb 100644 --- a/app/src/main/res/layout/activity_main_player.xml +++ b/app/src/main/res/layout/activity_main_player.xml @@ -209,7 +209,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" - android:layout_toLeftOf="@+id/screenRotationButton" + android:layout_toLeftOf="@+id/queueButton" android:gravity="center" android:minHeight="35dp" android:minWidth="40dp" @@ -218,28 +218,13 @@ tools:ignore="RtlHardcoded,RtlSymmetry" tools:text="1x" /> - - @@ -454,4 +440,4 @@ tools:visibility="visible"/> - \ No newline at end of file + diff --git a/app/src/main/res/menu/menu_videooptions.xml b/app/src/main/res/menu/menu_videooptions.xml new file mode 100644 index 000000000..2fbde0412 --- /dev/null +++ b/app/src/main/res/menu/menu_videooptions.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index abf7c7b09..81fb5752d 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -20,6 +20,7 @@ + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 8f0bb02cd..5aa777956 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -27,6 +27,7 @@ @drawable/ic_history_black_24dp @drawable/ic_drag_handle_black_24dp @drawable/ic_fiber_manual_record_black_24dp + @drawable/ic_more_vert_black_24dp @color/light_separator_color @color/light_contrast_background_color @@ -65,6 +66,7 @@ @drawable/ic_history_white_24dp @drawable/ic_drag_handle_white_24dp @drawable/ic_fiber_manual_record_white_24dp + @drawable/ic_more_vert_white_24dp @color/dark_separator_color @color/dark_contrast_background_color