pull/1395/head
gedoor 3 years ago
parent cffce34d1d
commit 33a7b83b27
  1. 2
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 48
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 98
      app/src/main/java/io/legado/app/lib/theme/TintHelper.kt
  4. 23
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt

@ -158,7 +158,7 @@ abstract class BaseActivity<VB : ViewBinding>(
private fun setupSystemBar() {
if (fullScreen && !isInMultiWindow) {
ATH.fullScreen(this)
fullScreen(true)
}
val isTransparentStatusBar = AppConfig.isTransparentStatusBar
val statusBarColor = ThemeStore.statusBarColor(this, isTransparentStatusBar)

@ -1,13 +1,7 @@
package io.legado.app.lib.theme
import android.annotation.SuppressLint
import android.app.Activity
import android.app.ActivityManager
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.view.View
import android.view.WindowManager
import android.widget.EdgeEffect
import android.widget.ScrollView
import androidx.annotation.ColorInt
@ -25,48 +19,6 @@ import splitties.init.appCtx
@Suppress("unused", "MemberVisibilityCanBePrivate")
object ATH {
@SuppressLint("CommitPrefEdits")
fun didThemeValuesChange(context: Context, since: Long): Boolean {
return ThemeStore.isConfigured(context) && ThemeStore.prefs(context).getLong(
ThemeStorePrefKeys.VALUES_CHANGED,
-1
) > since
}
fun fullScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.window.setDecorFitsSystemWindows(true)
}
fullScreenO(activity)
activity.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
}
@Suppress("DEPRECATION")
private fun fullScreenO(activity: Activity) {
activity.window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
activity.window.clearFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
}
fun setTaskDescriptionColorAuto(activity: Activity) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity))
}
fun setTaskDescriptionColor(activity: Activity, @ColorInt color: Int) {
val color1: Int = ColorUtils.stripAlpha(color)
@Suppress("DEPRECATION")
activity.setTaskDescription(
ActivityManager.TaskDescription(
activity.title as String,
null,
color1
)
)
}
fun setTint(
view: View,
@ColorInt color: Int,

@ -6,7 +6,6 @@ import android.content.res.ColorStateList
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.graphics.drawable.RippleDrawable
import android.os.Build
import android.view.View
import android.widget.*
import androidx.annotation.CheckResult
@ -68,10 +67,8 @@ object TintHelper {
when (view) {
is Button -> {
sl = getDisabledColorStateList(color, disabled)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) {
val rd = view.getBackground() as RippleDrawable
rd.setColor(ColorStateList.valueOf(rippleColor))
}
val rd = view.getBackground() as RippleDrawable
rd.setColor(ColorStateList.valueOf(rippleColor))
// Disabled text color state for buttons, may get overridden later by ATE tags
view.setTextColor(
@ -133,8 +130,10 @@ object TintHelper {
}
fun setTintAuto(
view: View, @ColorInt color: Int,
isBackground: Boolean, isDark: Boolean
view: View,
@ColorInt color: Int,
isBackground: Boolean,
isDark: Boolean
) {
var isBg = isBackground
if (!isBg) {
@ -166,26 +165,22 @@ object TintHelper {
else -> isBg = true
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
!isBg && view.background is RippleDrawable
) {
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
val rd = view.background as RippleDrawable
@SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor(
view.context,
if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light
)
val checked = ColorUtils.adjustAlpha(color, 0.4f)
val sl = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked),
intArrayOf(android.R.attr.state_activated),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(unchecked, checked, checked)
)
rd.setColor(sl)
}
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
val rd = view.background as RippleDrawable
@SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor(
view.context,
if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light
)
val checked = ColorUtils.adjustAlpha(color, 0.4f)
val sl = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked),
intArrayOf(android.R.attr.state_activated),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(unchecked, checked, checked)
)
rd.setColor(sl)
}
if (isBg) {
// Need to tint the isBackground of a view
@ -223,14 +218,7 @@ object TintHelper {
color
)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButton.buttonTintList = sl
} else {
radioButton.buttonDrawable = createTintedDrawable(
ContextCompat.getDrawable(radioButton.context, R.drawable.abc_btn_radio_material),
sl
)
}
radioButton.buttonTintList = sl
}
fun setTint(seekBar: SeekBar, @ColorInt color: Int, useDarker: Boolean) {
@ -241,15 +229,8 @@ object TintHelper {
if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light
)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
seekBar.thumbTintList = s1
seekBar.progressTintList = s1
} else {
val progressDrawable = createTintedDrawable(seekBar.progressDrawable, s1)
seekBar.progressDrawable = progressDrawable
val thumbDrawable = createTintedDrawable(seekBar.thumb, s1)
seekBar.thumb = thumbDrawable
}
seekBar.thumbTintList = s1
seekBar.progressTintList = s1
}
@JvmOverloads
@ -258,17 +239,10 @@ object TintHelper {
skipIndeterminate: Boolean = false
) {
val sl = ColorStateList.valueOf(color)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.progressTintList = sl
progressBar.secondaryProgressTintList = sl
if (!skipIndeterminate)
progressBar.indeterminateTintList = sl
} else {
if (!skipIndeterminate && progressBar.indeterminateDrawable != null)
progressBar.indeterminateDrawable.setTint(color)
if (progressBar.progressDrawable != null)
progressBar.progressDrawable.setTint(color)
}
progressBar.progressTintList = sl
progressBar.secondaryProgressTintList = sl
if (!skipIndeterminate)
progressBar.indeterminateTintList = sl
}
@ -320,18 +294,7 @@ object TintHelper {
color
)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
box.buttonTintList = sl
} else {
val drawable =
createTintedDrawable(
ContextCompat.getDrawable(
box.context,
R.drawable.abc_btn_check_material
), sl
)
box.buttonDrawable = drawable
}
box.buttonTintList = sl
}
fun setTint(image: ImageView, @ColorInt color: Int) {
@ -463,6 +426,7 @@ object TintHelper {
return drawable1
}
@SuppressLint("DiscouragedPrivateApi", "SoonBlockedPrivateApi")
fun setCursorTint(editText: EditText, @ColorInt color: Int) {
try {
val fCursorDrawableRes = TextView::class.java.getDeclaredField("mCursorDrawableRes")

@ -42,6 +42,29 @@ val Activity.windowSize: DisplayMetrics
return displayMetrics
}
fun Activity.fullScreen(fullScreen: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(fullScreen)
}
@Suppress("DEPRECATION")
if (fullScreen) {
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
window.clearFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
} else {
window.decorView.systemUiVisibility = 0
window.addFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
}
}
/**
* 设置状态栏颜色
*/

Loading…
Cancel
Save