Gesture controls can individually be enabled/disabled and can be toggled to use system or non-system values.

This commit is contained in:
Koen 2024-01-08 13:56:11 +01:00
commit 745aad385b
5 changed files with 67 additions and 17 deletions

View file

@ -813,20 +813,20 @@ class Settings : FragmentedStorageFileJson() {
var gestureControls = GestureControls(); var gestureControls = GestureControls();
@Serializable @Serializable
class GestureControls { class GestureControls {
@FormField(R.string.volume_slider, FieldForm.TOGGLE, -1, 1) @FormField(R.string.volume_slider, FieldForm.TOGGLE, R.string.volume_slider_descr, 1)
var volumeSlider: Boolean = true; var volumeSlider: Boolean = true;
@FormField(R.string.brightness_slider, FieldForm.TOGGLE, -1, 2) @FormField(R.string.brightness_slider, FieldForm.TOGGLE, R.string.brightness_slider_descr, 2)
var brightnessSlider: Boolean = true; var brightnessSlider: Boolean = true;
@FormField(R.string.toggle_full_screen, FieldForm.TOGGLE, -1, 3) @FormField(R.string.toggle_full_screen, FieldForm.TOGGLE, R.string.toggle_full_screen_descr, 3)
var toggleFullscreen: Boolean = true; var toggleFullscreen: Boolean = true;
@FormField(R.string.system_brightness, FieldForm.TOGGLE, -1, 4) @FormField(R.string.system_brightness, FieldForm.TOGGLE, R.string.system_brightness_descr, 4)
var useSystemBrightness: Boolean = false; var useSystemBrightness: Boolean = true;
@FormField(R.string.system_brightness, FieldForm.TOGGLE, -1, 4) @FormField(R.string.system_volume, FieldForm.TOGGLE, R.string.system_volume_descr, 5)
var useSystemVolume: Boolean = false; var useSystemVolume: Boolean = true;
} }
@FormField(R.string.info, FieldForm.GROUP, -1, 20) @FormField(R.string.info, FieldForm.GROUP, -1, 20)

View file

@ -145,7 +145,6 @@ import com.futo.polycentric.core.Opinion
import com.futo.polycentric.core.toURLInfoSystemLinkUrl import com.futo.polycentric.core.toURLInfoSystemLinkUrl
import com.google.protobuf.ByteString import com.google.protobuf.ByteString
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -1372,7 +1371,9 @@ class VideoDetailView : ConstraintLayout {
val toResume = _videoResumePositionMilliseconds; val toResume = _videoResumePositionMilliseconds;
_videoResumePositionMilliseconds = 0; _videoResumePositionMilliseconds = 0;
loadCurrentVideo(toResume); loadCurrentVideo(toResume);
if (!Settings.instance.gestureControls.useSystemVolume) {
_player.setGestureSoundFactor(1.0f); _player.setGestureSoundFactor(1.0f);
}
updateQueueState(); updateQueueState();

View file

@ -3,8 +3,10 @@ package com.futo.platformplayer.views.behavior
import android.animation.Animator import android.animation.Animator
import android.animation.AnimatorSet import android.animation.AnimatorSet
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.drawable.Animatable import android.graphics.drawable.Animatable
import android.media.AudioManager
import android.util.AttributeSet import android.util.AttributeSet
import android.view.GestureDetector import android.view.GestureDetector
import android.view.LayoutInflater import android.view.LayoutInflater
@ -60,6 +62,7 @@ class GestureControlView : LinearLayout {
private val _progressSound: CircularProgressBar; private val _progressSound: CircularProgressBar;
private var _animatorSound: ObjectAnimator? = null; private var _animatorSound: ObjectAnimator? = null;
private var _brightnessFactor = 1.0f; private var _brightnessFactor = 1.0f;
private var _originalBrightnessFactor = 1.0f;
private var _adjustingBrightness: Boolean = false; private var _adjustingBrightness: Boolean = false;
private val _layoutControlsBrightness: FrameLayout; private val _layoutControlsBrightness: FrameLayout;
private val _progressBrightness: CircularProgressBar; private val _progressBrightness: CircularProgressBar;
@ -560,10 +563,34 @@ class GestureControlView : LinearLayout {
fun setFullscreen(isFullScreen: Boolean) { fun setFullscreen(isFullScreen: Boolean) {
if (isFullScreen) { if (isFullScreen) {
val c = context
if (c is Activity && Settings.instance.gestureControls.useSystemBrightness) {
_brightnessFactor = c.window.attributes.screenBrightness
if (_brightnessFactor == -1.0f) {
_brightnessFactor = android.provider.Settings.System.getInt(
context.contentResolver,
android.provider.Settings.System.SCREEN_BRIGHTNESS
) / 255.0f;
}
_originalBrightnessFactor = _brightnessFactor
}
if (Settings.instance.gestureControls.useSystemVolume) {
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
_soundFactor = currentVolume.toFloat() / maxVolume.toFloat()
}
onBrightnessAdjusted.emit(_brightnessFactor); onBrightnessAdjusted.emit(_brightnessFactor);
onSoundAdjusted.emit(_soundFactor); onSoundAdjusted.emit(_soundFactor);
} else {
val c = context
if (c is Activity && Settings.instance.gestureControls.useSystemBrightness) {
onBrightnessAdjusted.emit(_originalBrightnessFactor);
} else { } else {
onBrightnessAdjusted.emit(1.0f); onBrightnessAdjusted.emit(1.0f);
}
//onSoundAdjusted.emit(1.0f); //onSoundAdjusted.emit(1.0f);
stopAdjustingBrightness(); stopAdjustingBrightness();
stopAdjustingSound(); stopAdjustingSound();

View file

@ -1,15 +1,18 @@
package com.futo.platformplayer.views.video package com.futo.platformplayer.views.video
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.media.AudioManager
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.WindowManager
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.TextView import android.widget.TextView
@ -235,15 +238,30 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
gestureControl.setupTouchArea(_layoutControls, background); gestureControl.setupTouchArea(_layoutControls, background);
gestureControl.onSeek.subscribe { seekFromCurrent(it); }; gestureControl.onSeek.subscribe { seekFromCurrent(it); };
gestureControl.onSoundAdjusted.subscribe { setVolume(it) }; gestureControl.onSoundAdjusted.subscribe {
if (Settings.instance.gestureControls.useSystemVolume) {
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (it * maxVolume).toInt(), 0)
} else {
setVolume(it)
}
};
gestureControl.onToggleFullscreen.subscribe { setFullScreen(!isFullScreen) }; gestureControl.onToggleFullscreen.subscribe { setFullScreen(!isFullScreen) };
gestureControl.onBrightnessAdjusted.subscribe { gestureControl.onBrightnessAdjusted.subscribe {
if (context is Activity && Settings.instance.gestureControls.useSystemBrightness) {
val window = context.window
val layout: WindowManager.LayoutParams = window.attributes
layout.screenBrightness = it
window.attributes = layout
} else {
if (it == 1.0f) { if (it == 1.0f) {
_overlay_brightness.visibility = View.GONE; _overlay_brightness.visibility = View.GONE;
} else { } else {
_overlay_brightness.visibility = View.VISIBLE; _overlay_brightness.visibility = View.VISIBLE;
_overlay_brightness.setBackgroundColor(Color.valueOf(0.0f, 0.0f, 0.0f, (1.0f - it)).toArgb()); _overlay_brightness.setBackgroundColor(Color.valueOf(0.0f, 0.0f, 0.0f, (1.0f - it)).toArgb());
} }
}
}; };
if(!isInEditMode) { if(!isInEditMode) {
@ -730,7 +748,6 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
} }
} }
fun setGestureSoundFactor(soundFactor: Float) { fun setGestureSoundFactor(soundFactor: Float) {
gestureControl.setSoundFactor(soundFactor); gestureControl.setSoundFactor(soundFactor);
} }

View file

@ -346,10 +346,15 @@
<string name="info">Info</string> <string name="info">Info</string>
<string name="gesture_controls">Gesture controls</string> <string name="gesture_controls">Gesture controls</string>
<string name="volume_slider">Volume slider</string> <string name="volume_slider">Volume slider</string>
<string name="volume_slider_descr">Enable slide gesture to change volume</string>
<string name="brightness_slider">Brightness slider</string> <string name="brightness_slider">Brightness slider</string>
<string name="toggle_full_screen">Toogle full screen</string> <string name="brightness_slider_descr">Enable slide gesture to change brightness</string>
<string name="toggle_full_screen">Toggle full screen</string>
<string name="toggle_full_screen_descr">Enable swipe gesture to toggle fullscreen</string>
<string name="system_brightness">System brightness</string> <string name="system_brightness">System brightness</string>
<string name="system_brightness_descr">Gesture controls adjust system brightness</string>
<string name="system_volume">System volume</string> <string name="system_volume">System volume</string>
<string name="system_volume_descr">Gesture controls adjust system volume</string>
<string name="live_chat_webview">Live Chat Webview</string> <string name="live_chat_webview">Live Chat Webview</string>
<string name="full_screen_portrait">Fullscreen portrait</string> <string name="full_screen_portrait">Fullscreen portrait</string>
<string name="allow_full_screen_portrait">Allow fullscreen portrait</string> <string name="allow_full_screen_portrait">Allow fullscreen portrait</string>