feat: 防止背景颜色透明,出现重影,花屏

pull/254/head
gedoor 4 years ago
parent a7a9f2e61c
commit ce5f8bc7b8
  1. 45
      app/src/main/java/io/legado/app/App.kt
  2. 39
      app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt

@ -20,6 +20,7 @@ import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefInt
@ -83,30 +84,38 @@ class App : Application() {
.apply()
}
AppConfig.isNightTheme -> {
val primary =
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
val accent =
getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
val background =
getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color))
val bBackground =
getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850))
ThemeStore.editTheme(this)
.coloredNavigationBar(true)
.primaryColor(
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
).accentColor(
getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
).backgroundColor(
getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color))
).bottomBackground(
getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850))
).apply()
.primaryColor(ColorUtils.withAlpha(primary, 1f))
.accentColor(ColorUtils.withAlpha(accent, 1f))
.backgroundColor(ColorUtils.withAlpha(background, 1f))
.bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
.apply()
}
else -> {
val primary =
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_indigo_800))
val accent =
getPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_red_600))
val background =
getPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
val bBackground =
getPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
ThemeStore.editTheme(this)
.coloredNavigationBar(true)
.primaryColor(
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_indigo_800))
).accentColor(
getPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_red_600))
).backgroundColor(
getPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
).bottomBackground(
getPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
).apply()
.primaryColor(ColorUtils.withAlpha(primary, 1f))
.accentColor(ColorUtils.withAlpha(accent, 1f))
.backgroundColor(ColorUtils.withAlpha(background, 1f))
.bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
.apply()
}
}
}

@ -14,6 +14,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.jaredrummler.android.colorpicker.*
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ColorUtils
class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs),
ColorPickerDialogListener {
@ -22,8 +23,9 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
private val sizeLarge = 1
private var onShowDialogListener: OnShowDialogListener? = null
private var color = Color.BLACK
private var mColor = Color.BLACK
private var showDialog: Boolean = false
@ColorPickerDialog.DialogType
private var dialogType: Int = 0
private var colorShape: Int = 0
@ -42,7 +44,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
val a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference)
showDialog = a.getBoolean(R.styleable.ColorPreference_cpv_showDialog, true)
dialogType = a.getInt(R.styleable.ColorPreference_cpv_dialogType, ColorPickerDialog.TYPE_PRESETS)
dialogType =
a.getInt(R.styleable.ColorPreference_cpv_dialogType, ColorPickerDialog.TYPE_PRESETS)
colorShape = a.getInt(R.styleable.ColorPreference_cpv_colorShape, ColorShape.CIRCLE)
allowPresets = a.getBoolean(R.styleable.ColorPreference_cpv_allowPresets, true)
allowCustom = a.getBoolean(R.styleable.ColorPreference_cpv_allowCustom, true)
@ -50,7 +53,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
showColorShades = a.getBoolean(R.styleable.ColorPreference_cpv_showColorShades, true)
previewSize = a.getInt(R.styleable.ColorPreference_cpv_previewSize, sizeNormal)
val presetsResId = a.getResourceId(R.styleable.ColorPreference_cpv_colorPresets, 0)
dialogTitle = a.getResourceId(R.styleable.ColorPreference_cpv_dialogTitle, R.string.cpv_default_title)
dialogTitle =
a.getResourceId(R.styleable.ColorPreference_cpv_dialogTitle, R.string.cpv_default_title)
presets = if (presetsResId != 0) {
context.resources.getIntArray(presetsResId)
} else {
@ -67,7 +71,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
override fun onClick() {
super.onClick()
if (onShowDialogListener != null) {
onShowDialogListener!!.onShowColorPickerDialog(title as String, color)
onShowDialogListener!!.onShowColorPickerDialog(title as String, mColor)
} else if (showDialog) {
val dialog = ColorPickerDialogCompat.newBuilder()
.setDialogType(dialogType)
@ -78,7 +82,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
.setAllowCustom(allowCustom)
.setShowAlphaSlider(showAlphaSlider)
.setShowColorShades(showColorShades)
.setColor(color)
.setColor(mColor)
.create()
dialog.setColorPickerDialogListener(this)
getActivity().supportFragmentManager
@ -111,10 +115,12 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
val v = io.legado.app.ui.widget.prefs.Preference.bindView<ColorPanelView>(context, holder, icon, title, summary, widgetLayoutResource,
io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30)
val v = io.legado.app.ui.widget.prefs.Preference.bindView<ColorPanelView>(
context, holder, icon, title, summary, widgetLayoutResource,
io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30
)
if (v is ColorPanelView) {
v.color = color
v.color = mColor
}
super.onBindViewHolder(holder)
}
@ -122,10 +128,10 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
override fun onSetInitialValue(defaultValue: Any?) {
super.onSetInitialValue(defaultValue)
if (defaultValue is Int) {
color = (defaultValue as Int?)!!
persistInt(color)
mColor = if (!showAlphaSlider) ColorUtils.withAlpha(defaultValue, 1f) else defaultValue
persistInt(mColor)
} else {
color = getPersistedInt(-0x1000000)
mColor = getPersistedInt(-0x1000000)
}
}
@ -147,8 +153,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
* @param color The newly selected color
*/
fun saveValue(@ColorInt color: Int) {
this.color = color
persistInt(this.color)
mColor = if (showAlphaSlider) color else ColorUtils.withAlpha(color, 1f)
persistInt(mColor)
notifyChanged()
callChangeListener(color)
}
@ -231,17 +237,23 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
class Builder internal constructor() {
internal var colorPickerDialogListener: ColorPickerDialogListener? = null
@StringRes
internal var dialogTitle = R.string.cpv_default_title
@StringRes
internal var presetsButtonText = R.string.cpv_presets
@StringRes
internal var customButtonText = R.string.cpv_custom
@StringRes
internal var selectedButtonText = R.string.cpv_select
@DialogType
internal var dialogType = TYPE_PRESETS
internal var presets = MATERIAL_COLORS
@ColorInt
internal var color = Color.BLACK
internal var dialogId = 0
@ -249,6 +261,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
internal var allowPresets = true
internal var allowCustom = true
internal var showColorShades = true
@ColorShape
internal var colorShape = ColorShape.CIRCLE

Loading…
Cancel
Save