Fix fullscreen reader for notch device (#2595)

* Fix fullscreen reader for notch device

* Make cutout mode configurable

* Rename cutout option
This commit is contained in:
onlymash 2020-02-17 23:40:49 +08:00 committed by GitHub
parent a7ece4fdf3
commit 12aa04be93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 1 deletions

View File

@ -19,6 +19,8 @@ object PreferenceKeys {
const val fullscreen = "fullscreen" const val fullscreen = "fullscreen"
const val cutoutShort = "cutout_short"
const val keepScreenOn = "pref_keep_screen_on_key" const val keepScreenOn = "pref_keep_screen_on_key"
const val customBrightness = "pref_custom_brightness_key" const val customBrightness = "pref_custom_brightness_key"

View File

@ -67,6 +67,8 @@ class PreferencesHelper(val context: Context) {
fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true) fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true)
fun cutoutShort() = rxPrefs.getBoolean(Keys.cutoutShort, true)
fun keepScreenOn() = rxPrefs.getBoolean(Keys.keepScreenOn, true) fun keepScreenOn() = rxPrefs.getBoolean(Keys.keepScreenOn, true)
fun customBrightness() = rxPrefs.getBoolean(Keys.customBrightness, false) fun customBrightness() = rxPrefs.getBoolean(Keys.customBrightness, false)

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.reader package eu.kanade.tachiyomi.ui.reader
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.ProgressDialog import android.app.ProgressDialog
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -8,6 +9,7 @@ import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import android.view.animation.Animation import android.view.animation.Animation
@ -565,6 +567,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
subscriptions += preferences.fullscreen().asObservable() subscriptions += preferences.fullscreen().asObservable()
.subscribe { setFullscreen(it) } .subscribe { setFullscreen(it) }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
subscriptions += preferences.cutoutShort().asObservable()
.subscribe { setCutoutShort(it)}
}
subscriptions += preferences.keepScreenOn().asObservable() subscriptions += preferences.keepScreenOn().asObservable()
.subscribe { setKeepScreenOn(it) } .subscribe { setKeepScreenOn(it) }
@ -646,6 +653,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
} }
} }
@TargetApi(Build.VERSION_CODES.P)
private fun setCutoutShort(enabled: Boolean) {
window.attributes.layoutInDisplayCutoutMode = when (enabled) {
true -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
false -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
}
}
/** /**
* Sets the keep screen on mode according to [enabled]. * Sets the keep screen on mode according to [enabled].
*/ */

View File

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.reader package eu.kanade.tachiyomi.ui.reader
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.widget.CompoundButton import android.widget.CompoundButton
import android.widget.Spinner import android.widget.Spinner
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
@ -61,6 +63,10 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
background_color.bindToPreference(preferences.readerTheme()) background_color.bindToPreference(preferences.readerTheme())
show_page_number.bindToPreference(preferences.showPageNumber()) show_page_number.bindToPreference(preferences.showPageNumber())
fullscreen.bindToPreference(preferences.fullscreen()) fullscreen.bindToPreference(preferences.fullscreen())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cutout_short.visibility = View.VISIBLE
cutout_short.bindToPreference(preferences.cutoutShort())
}
keepscreen.bindToPreference(preferences.keepScreenOn()) keepscreen.bindToPreference(preferences.keepScreenOn())
long_tap.bindToPreference(preferences.readWithLongTap()) long_tap.bindToPreference(preferences.readWithLongTap())
} }

View File

@ -74,6 +74,13 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_fullscreen titleRes = R.string.pref_fullscreen
defaultValue = true defaultValue = true
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
switchPreference {
key = Keys.cutoutShort
titleRes = R.string.pref_cutout_short
defaultValue = true
}
}
switchPreference { switchPreference {
key = Keys.keepScreenOn key = Keys.keepScreenOn
titleRes = R.string.pref_keep_screen_on titleRes = R.string.pref_keep_screen_on

View File

@ -125,6 +125,16 @@
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constraintTop_toBottomOf="@id/true_color" /> app:layout_constraintTop_toBottomOf="@id/true_color" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/cutout_short"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/pref_cutout_short"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/fullscreen" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/keepscreen" android:id="@+id/keepscreen"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -132,7 +142,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/pref_keep_screen_on" android:text="@string/pref_keep_screen_on"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constraintTop_toBottomOf="@id/fullscreen" /> app:layout_constraintTop_toBottomOf="@id/cutout_short" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/long_tap" android:id="@+id/long_tap"

View File

@ -183,6 +183,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Fullscreen</string> <string name="pref_fullscreen">Fullscreen</string>
<string name="pref_cutout_short">Show content in cutout area</string>
<string name="pref_lock_orientation">Lock orientation</string> <string name="pref_lock_orientation">Lock orientation</string>
<string name="pref_page_transitions">Page transitions</string> <string name="pref_page_transitions">Page transitions</string>
<string name="pref_double_tap_anim_speed">Double tap animation speed</string> <string name="pref_double_tap_anim_speed">Double tap animation speed</string>