Added dead zone to auto rotate.

This commit is contained in:
Koen 2023-09-27 13:11:38 +02:00
parent 5b4d142f07
commit 3527d8bac6
3 changed files with 42 additions and 21 deletions

View file

@ -213,19 +213,27 @@ class Settings : FragmentedStorageFileJson() {
fun isAutoRotate() = autoRotate == 1 || (autoRotate == 2 && StateApp.instance.getCurrentSystemAutoRotate());
@FormField("Background Behavior", FieldForm.DROPDOWN, "", 5)
@FormField("Auto-Rotate Dead Zone", FieldForm.DROPDOWN, "Auto-rotate deadzone in degrees", 5)
@DropdownFieldOptionsId(R.array.auto_rotate_dead_zone)
var autoRotateDeadZone: Int = 0;
fun getAutoRotateDeadZoneDegrees(): Int {
return autoRotateDeadZone * 5;
}
@FormField("Background Behavior", FieldForm.DROPDOWN, "", 6)
@DropdownFieldOptionsId(R.array.player_background_behavior)
var backgroundPlay: Int = 2;
fun isBackgroundContinue() = backgroundPlay == 1;
fun isBackgroundPictureInPicture() = backgroundPlay == 2;
@FormField("Resume After Preview", FieldForm.DROPDOWN, "When watching a video in preview mode, resume at the position when opening the video", 4)
@FormField("Resume After Preview", FieldForm.DROPDOWN, "When watching a video in preview mode, resume at the position when opening the video", 7)
@DropdownFieldOptionsId(R.array.resume_after_preview)
var resumeAfterPreview: Int = 1;
@FormField("Live Chat Webview", FieldForm.TOGGLE, "Use the live chat web window when available over native implementation.", 5)
@FormField("Live Chat Webview", FieldForm.TOGGLE, "Use the live chat web window when available over native implementation.", 8)
var useLiveChatWindow: Boolean = true;
fun shouldResumePreview(previewedPosition: Long): Boolean{

View file

@ -2,7 +2,9 @@ package com.futo.platformplayer.listeners
import android.content.Context
import android.view.OrientationEventListener
import com.futo.platformplayer.Settings
import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.logging.Logger
class OrientationManager : OrientationEventListener {
@ -11,32 +13,37 @@ class OrientationManager : OrientationEventListener {
var orientation : Orientation = Orientation.PORTRAIT;
constructor(context: Context) : super(context) { }
constructor(context: Context, rate: Int) : super(context, rate) { }
init {
}
override fun onOrientationChanged(orientationAnglep: Int) {
if(orientationAnglep == -1)
if (orientationAnglep == -1) return
val deadZone = Settings.instance.playback.getAutoRotateDeadZoneDegrees()
val isInDeadZone = when (orientation) {
Orientation.PORTRAIT -> orientationAnglep in 0 until (60 - deadZone) || orientationAnglep in (300 + deadZone) .. 360
Orientation.REVERSED_LANDSCAPE -> orientationAnglep in (60 + deadZone) until (140 - deadZone)
Orientation.REVERSED_PORTRAIT -> orientationAnglep in (140 + deadZone) until (220 - deadZone)
Orientation.LANDSCAPE -> orientationAnglep in (220 + deadZone) until (300 - deadZone)
}
if (isInDeadZone) {
return;
}
var newOrientation = Orientation.PORTRAIT;
if(orientationAnglep > 60 && orientationAnglep < 140)
newOrientation = Orientation.REVERSED_LANDSCAPE;
else if(orientationAnglep >= 140 && orientationAnglep <= 220)
newOrientation = Orientation.REVERSED_PORTRAIT;
else if(orientationAnglep >= 220 && orientationAnglep <= 300)
newOrientation = Orientation.LANDSCAPE;
else
newOrientation = Orientation.PORTRAIT;
val newOrientation = when (orientationAnglep) {
in 60 until 140 -> Orientation.REVERSED_LANDSCAPE
in 140 until 220 -> Orientation.REVERSED_PORTRAIT
in 220 until 300 -> Orientation.LANDSCAPE
else -> Orientation.PORTRAIT
}
if(newOrientation != orientation) {
orientation = newOrientation;
onOrientationChanged.emit(newOrientation);
Logger.i("OrientationManager", "Orientation=$newOrientation orientationAnglep=$orientationAnglep");
if (newOrientation != orientation) {
orientation = newOrientation
onOrientationChanged.emit(newOrientation)
}
}
//TODO: Perhaps just use ActivityInfo orientations instead..
enum class Orientation {
PORTRAIT,

View file

@ -99,6 +99,12 @@
<item>Enabled</item>
<item>Same as System</item>
</string-array>
<string-array name="auto_rotate_dead_zone">
<item>0</item>
<item>5</item>
<item>10</item>
<item>20</item>
</string-array>
<string-array name="enabled_disabled_array">
<item>Disabled</item>
<item>Enabled</item>