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 8ce18fa56..71b724228 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -1006,12 +1006,14 @@ public final class MainVideoPlayer extends AppCompatActivity private static final int MOVEMENT_THRESHOLD = 40; - 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(); @Override public boolean onScroll(MotionEvent initialEvent, MotionEvent movingEvent, float distanceX, float distanceY) { - if (!isPlayerGestureEnabled) return false; + if (!isVolumeGestureEnabled && !isBrightnessGestureEnabled) return false; //noinspection PointlessBooleanExpression if (DEBUG && false) Log.d(TAG, "MainVideoPlayer.onScroll = " + @@ -1027,7 +1029,11 @@ public final class MainVideoPlayer extends AppCompatActivity isMoving = true; - if (initialEvent.getX() > playerImpl.getRootView().getWidth() / 2) { + boolean acceptAnyArea = isVolumeGestureEnabled != isBrightnessGestureEnabled; + boolean acceptVolumeArea = acceptAnyArea || initialEvent.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(); @@ -1052,7 +1058,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 05afe2859..16dffc3de 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 aed85beec..636d13b01 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -19,7 +19,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 @@ -894,4 +895,4 @@ @string/grid - \ 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 b1e9fe4c6..92d35a48c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -83,8 +83,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"/> + +