diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index c219b2430..3bec6c67e 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -9,7 +9,6 @@ import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu import android.view.MenuItem -import android.view.WindowManager import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES import androidx.core.view.isVisible import androidx.lifecycle.Observer @@ -83,7 +82,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog } - setScreenBrightness(getPrefInt("brightness", 100)) } override fun onWindowFocusChanged(hasFocus: Boolean) { @@ -458,21 +456,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } - /** - * 设置屏幕亮度 - */ - override fun setScreenBrightness(value: Int) { - var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE - if (!read_menu.brightnessAuto()) { - brightness = value.toFloat() - if (brightness < 1f) brightness = 1f - brightness /= 255f - } - val params = window.attributes - params.screenBrightness = brightness - window.attributes = params - } - override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) { when (dialogId) { TEXT_COLOR -> { diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt index 62a8a834e..45442dc66 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.readbook import android.content.Context import android.util.AttributeSet +import android.view.WindowManager import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.FrameLayout @@ -59,6 +60,22 @@ class ReadMenu : FrameLayout { iv_brightness_auto.setColorFilter(context.buttonDisabledColor) seek_brightness.isEnabled = true } + setScreenBrightness(context.getPrefInt("brightness", 100)) + } + + /** + * 设置屏幕亮度 + */ + private fun setScreenBrightness(value: Int) { + var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE + if (!brightnessAuto()) { + brightness = value.toFloat() + if (brightness < 1f) brightness = 1f + brightness /= 255f + } + val params = activity?.window?.attributes + params?.screenBrightness = brightness + activity?.window?.attributes = params } fun runMenuIn() { @@ -93,11 +110,10 @@ class ReadMenu : FrameLayout { !brightnessAuto() ) upBrightnessState() - callBack?.setScreenBrightness(context.getPrefInt("brightness", 100)) } seek_brightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - callBack?.setScreenBrightness(progress) + setScreenBrightness(progress) } override fun onStartTrackingTouch(seekBar: SeekBar?) { @@ -231,7 +247,6 @@ class ReadMenu : FrameLayout { } interface CallBack { - fun setScreenBrightness(value: Int) fun autoPage() fun skipToPage(page: Int) fun moveToPrevChapter(last: Boolean)