Separate options for volume and brightness gestures

This commit is contained in:
Ritiek Malhotra 2018-08-31 19:30:40 +05:30
parent ad065e9281
commit 5931cd6af7
5 changed files with 37 additions and 15 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -17,7 +17,8 @@
<string name="autoplay_through_intent_key" translatable="false">autoplay_through_intent</string>
<string name="use_old_player_key" translatable="false">use_oldplayer</string>
<string name="player_gesture_controls_key" translatable="false">player_gesture_controls</string>
<string name="volume_gesture_control_key" translatable="false">volume_gesture_control</string>
<string name="brightness_gesture_control_key" translatable="false">brightness_gesture_control</string>
<string name="resume_on_audio_focus_gain_key" translatable="false">resume_on_audio_focus_gain</string>
<string name="popup_remember_size_pos_key" translatable="false">popup_remember_size_pos_key</string>
<string name="use_inexact_seek_key" translatable="false">use_inexact_seek_key</string>
@ -892,4 +893,4 @@
</string-array>
</resources>
</resources>

View File

@ -82,8 +82,10 @@
<string name="metadata_cache_wipe_complete_notice">Metadata cache wiped</string>
<string name="auto_queue_title">Auto-queue next stream</string>
<string name="auto_queue_summary">Auto-append a related stream when playing the last stream in a non-repeating queue.</string>
<string name="player_gesture_controls_title">Player gesture controls</string>
<string name="player_gesture_controls_summary">Use gestures to control the brightness and volume of the player</string>
<string name="volume_gesture_control_title">Volume gesture control</string>
<string name="volume_gesture_control_summary">Use gestures to control the volume of the player</string>
<string name="brightness_gesture_control_title">Brightness gesture control</string>
<string name="brightness_gesture_control_summary">Use gestures to control the brightness of the player</string>
<string name="show_search_suggestions_title">Search suggestions</string>
<string name="show_search_suggestions_summary">Show suggestions when searching</string>
<string name="enable_search_history_title">Search history</string>

View File

@ -106,9 +106,15 @@
<SwitchPreference
android:defaultValue="true"
android:key="@string/player_gesture_controls_key"
android:summary="@string/player_gesture_controls_summary"
android:title="@string/player_gesture_controls_title"/>
android:key="@string/volume_gesture_control_key"
android:summary="@string/volume_gesture_control_summary"
android:title="@string/volume_gesture_control_title"/>
<SwitchPreference
android:defaultValue="true"
android:key="@string/brightness_gesture_control_key"
android:summary="@string/brightness_gesture_control_summary"
android:title="@string/brightness_gesture_control_title"/>
<SwitchPreference
android:defaultValue="true"