From 5931cd6af7439ed71c1978425df0001b35328d6a Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Fri, 31 Aug 2018 19:30:40 +0530 Subject: [PATCH] Separate options for volume and brightness gestures --- .../schabi/newpipe/player/MainVideoPlayer.java | 13 +++++++++---- .../newpipe/player/helper/PlayerHelper.java | 16 ++++++++++++---- app/src/main/res/values/settings_keys.xml | 5 +++-- app/src/main/res/values/strings.xml | 6 ++++-- app/src/main/res/xml/video_audio_settings.xml | 12 +++++++++--- 5 files changed, 37 insertions(+), 15 deletions(-) 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 41e7c305d..414c55e81 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -978,7 +978,8 @@ public final class MainVideoPlayer extends AppCompatActivity return super.onDown(e); } - private final boolean isPlayerGestureEnabled = PlayerHelper.isPlayerGestureEnabled(getApplicationContext()); + private final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(getApplicationContext()); + private final boolean isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(getApplicationContext()); private final int maxVolume = playerImpl.getAudioReactor().getMaxVolume(); @@ -986,7 +987,7 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - if (!isPlayerGestureEnabled) return false; + if (!isVolumeGestureEnabled && !isBrightnessGestureEnabled) return false; //noinspection PointlessBooleanExpression if (DEBUG && false) Log.d(TAG, "MainVideoPlayer.onScroll = " + @@ -1002,7 +1003,11 @@ public final class MainVideoPlayer extends AppCompatActivity isMoving = true; - if (e1.getX() > playerImpl.getRootView().getWidth() / 2) { + boolean acceptAnyArea = isVolumeGestureEnabled != isBrightnessGestureEnabled; + boolean acceptVolumeArea = acceptAnyArea || e1.getX() > playerImpl.getRootView().getWidth() / 2; + boolean acceptBrightnessArea = acceptAnyArea || !acceptVolumeArea; + + if (isVolumeGestureEnabled && acceptVolumeArea) { playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY); float currentProgressPercent = (float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength(); @@ -1027,7 +1032,7 @@ public final class MainVideoPlayer extends AppCompatActivity if (playerImpl.getBrightnessRelativeLayout().getVisibility() == View.VISIBLE) { playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE); } - } else { + } else if (isBrightnessGestureEnabled && acceptBrightnessArea) { playerImpl.getBrightnessProgressBar().incrementProgressBy((int) distanceY); float currentProgressPercent = (float) playerImpl.getBrightnessProgressBar().getProgress() / playerImpl.getMaxGestureLength(); diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index ae187a834..52e268b24 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -169,8 +169,12 @@ public class PlayerHelper { return isResumeAfterAudioFocusGain(context, false); } - public static boolean isPlayerGestureEnabled(@NonNull final Context context) { - return isPlayerGestureEnabled(context, true); + public static boolean isVolumeGestureEnabled(@NonNull final Context context) { + return isVolumeGestureEnabled(context, true); + } + + public static boolean isBrightnessGestureEnabled(@NonNull final Context context) { + return isBrightnessGestureEnabled(context, true); } public static boolean isUsingOldPlayer(@NonNull final Context context) { @@ -306,8 +310,12 @@ public class PlayerHelper { return getPreferences(context).getBoolean(context.getString(R.string.resume_on_audio_focus_gain_key), b); } - private static boolean isPlayerGestureEnabled(@NonNull final Context context, final boolean b) { - return getPreferences(context).getBoolean(context.getString(R.string.player_gesture_controls_key), b); + private static boolean isVolumeGestureEnabled(@NonNull final Context context, final boolean b) { + return getPreferences(context).getBoolean(context.getString(R.string.volume_gesture_control_key), b); + } + + private static boolean isBrightnessGestureEnabled(@NonNull final Context context, final boolean b) { + return getPreferences(context).getBoolean(context.getString(R.string.brightness_gesture_control_key), b); } private static boolean isUsingOldPlayer(@NonNull final Context context, final boolean b) { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 02f065285..1a8158297 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -17,7 +17,8 @@ autoplay_through_intent use_oldplayer - player_gesture_controls + volume_gesture_control + brightness_gesture_control resume_on_audio_focus_gain popup_remember_size_pos_key use_inexact_seek_key @@ -892,4 +893,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eaeeb2685..ddb889a64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,8 +82,10 @@ Metadata cache wiped Auto-queue next stream Auto-append a related stream when playing the last stream in a non-repeating queue. - Player gesture controls - Use gestures to control the brightness and volume of the player + Volume gesture control + Use gestures to control the volume of the player + Brightness gesture control + Use gestures to control the brightness of the player Search suggestions Show suggestions when searching Search history diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index a547ffaf2..5ac5bb733 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -106,9 +106,15 @@ + android:key="@string/volume_gesture_control_key" + android:summary="@string/volume_gesture_control_summary" + android:title="@string/volume_gesture_control_title"/> + +