优化代码

pull/32/head
Invinciblelee 6 years ago
parent 8b1a462aff
commit 315f7142f7
  1. 6
      app/build.gradle
  2. 4
      app/src/main/AndroidManifest.xml
  3. 84
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  4. 10
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  5. 4
      app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt
  6. 2
      app/src/main/java/io/legado/app/lib/theme/ColorUtils.kt
  7. 25
      app/src/main/java/io/legado/app/lib/theme/DrawableUtil.kt
  8. 43
      app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt
  9. 81
      app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt
  10. 2
      app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt
  11. 38
      app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt
  12. 34
      app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt
  13. 22
      app/src/main/java/io/legado/app/lib/theme/TintHelper.kt
  14. 6
      app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt
  15. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt
  16. 3
      app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt
  17. 3
      app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt
  18. 2
      app/src/main/res/values-v21/styles.xml
  19. 64
      app/src/main/res/values/styles.xml

@ -42,13 +42,11 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

@ -23,7 +23,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/CAppTheme"
android:theme="@style/AppTheme.Light"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".ui.search.SearchActivity">
</activity>
@ -32,7 +32,7 @@
<activity
android:name=".ui.main.MainActivity"
android:label="@string/app_name"
android:theme="@style/CAppTheme.NoActionBar">
android:theme="@style/AppTheme.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

@ -1,17 +1,17 @@
package io.legado.app.base
import android.annotation.SuppressLint
import android.graphics.PorterDuff
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
import io.legado.app.R
import io.legado.app.lib.theme.ColorUtil
import io.legado.app.lib.theme.MaterialValueHelper
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.ThemeStore
import java.util.*
import io.legado.app.lib.theme.getPrimaryTextColor
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
@ -34,47 +34,45 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
* 设置MENU图标颜色
*/
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val primaryTextColor = MaterialValueHelper
.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.primaryColor(this)))
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this)))
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default)
for (i in 0 until menu.size()) {
val drawable = menu.getItem(i).icon
if (drawable != null) {
drawable.mutate()
drawable.setColorFilter(primaryTextColor, PorterDuff.Mode.SRC_ATOP)
(menu.getItem(i) as MenuItemImpl).let {//overflow:展开的item
DrawableUtils.setTint(it.icon, if (it.requiresOverflow()) defaultTextColor else primaryTextColor)
}
}
return super.onCreateOptionsMenu(menu)
}
@SuppressLint("PrivateApi")
override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean {
if (menu != null) {
//展开菜单显示图标
if (menu.javaClass.simpleName.equals("MenuBuilder", ignoreCase = true)) {
try {
var method = menu.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE)
method.isAccessible = true
method.invoke(menu, true)
method = menu.javaClass.getDeclaredMethod("getNonActionItems")
val menuItems = method.invoke(menu) as ArrayList<MenuItem>
if (menuItems.isNotEmpty()) {
for (menuItem in menuItems) {
val drawable = menuItem.icon
if (drawable != null) {
drawable.mutate()
drawable.setColorFilter(
resources.getColor(R.color.tv_text_default),
PorterDuff.Mode.SRC_ATOP
)
}
}
}
} catch (ignored: Exception) {
}
}
}
return super.onMenuOpened(featureId, menu)
}
// @SuppressLint("PrivateApi")
// override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean {
// if (menu != null) {
// //展开菜单显示图标
// if (menu.javaClass.simpleName.equals("MenuBuilder", ignoreCase = true)) {
// try {
// var method = menu.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE)
// method.isAccessible = true
// method.invoke(menu, true)
// method = menu.javaClass.getDeclaredMethod("getNonActionItems")
// val menuItems = method.invoke(menu) as ArrayList<MenuItem>
// if (menuItems.isNotEmpty()) {
// for (menuItem in menuItems) {
// val drawable = menuItem.icon
// if (drawable != null) {
// drawable.mutate()
// drawable.setColorFilter(
// resources.getColor(R.color.tv_text_default),
// PorterDuff.Mode.SRC_ATOP
// )
// }
// }
// }
// } catch (ignored: Exception) {
// }
// }
// }
// return super.onMenuOpened(featureId, menu)
// }
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
item?.let {
@ -91,10 +89,10 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
}
protected fun initTheme() {
if (ColorUtil.isColorLight(ThemeStore.primaryColor(this))) {
setTheme(R.style.CAppTheme)
if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) {
setTheme(R.style.AppTheme_Light)
} else {
setTheme(R.style.CAppThemeBarDark)
setTheme(R.style.AppTheme_Dark)
}
}
}

@ -18,7 +18,7 @@ object ATH {
@SuppressLint("CommitPrefEdits")
fun didThemeValuesChange(context: Context, since: Long): Boolean {
return ThemeStore.isConfigured(context) && ThemeStore.prefs(context).getLong(
ThemeStore.VALUES_CHANGED,
ThemeStorePrefKeys.VALUES_CHANGED,
-1
) > since
}
@ -35,7 +35,7 @@ object ATH {
}
fun setLightStatusbarAuto(activity: Activity, bgColor: Int) {
setLightStatusbar(activity, ColorUtil.isColorLight(bgColor))
setLightStatusbar(activity, ColorUtils.isColorLight(bgColor))
}
fun setLightStatusbar(activity: Activity, enabled: Boolean) {
@ -64,7 +64,7 @@ object ATH {
}
fun setLightNavigationbarAuto(activity: Activity, bgColor: Int) {
setLightNavigationbar(activity, ColorUtil.isColorLight(bgColor))
setLightNavigationbar(activity, ColorUtils.isColorLight(bgColor))
}
fun setNavigationbarColorAuto(activity: Activity) {
@ -86,7 +86,7 @@ object ATH {
val color1: Int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Task description requires fully opaque color
color1 = ColorUtil.stripAlpha(color)
color1 = ColorUtils.stripAlpha(color)
// Sets color of entry in the system recents page
activity.setTaskDescription(ActivityManager.TaskDescription(activity.title as String, null, color1))
}
@ -103,7 +103,7 @@ object ATH {
fun setAlertDialogTint(dialog: AlertDialog): AlertDialog {
val colorStateList = Selector.colorBuild()
.setDefaultColor(ThemeStore.accentColor(dialog.context))
.setPressedColor(ColorUtil.darkenColor(ThemeStore.accentColor(dialog.context)))
.setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(dialog.context)))
.create()
if (dialog.getButton(AlertDialog.BUTTON_NEGATIVE) != null) {
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(colorStateList)

@ -6,10 +6,10 @@ import androidx.annotation.AttrRes
/**
* @author Aidan Follestad (afollestad)
*/
object ATHUtil {
object ATHUtils {
fun isWindowBackgroundDark(context: Context): Boolean {
return !ColorUtil.isColorLight(ATHUtil.resolveColor(context, android.R.attr.windowBackground))
return !ColorUtils.isColorLight(resolveColor(context, android.R.attr.windowBackground))
}
@JvmOverloads

@ -4,7 +4,7 @@ import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.annotation.FloatRange
object ColorUtil {
object ColorUtils {
fun intToString(intColor: Int): String {
return String.format("#%06X", 0xFFFFFF and intColor)

@ -1,25 +0,0 @@
package io.legado.app.lib.theme
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.TransitionDrawable
import androidx.annotation.ColorInt
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object DrawableUtil {
fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable {
return createTransitionDrawable(ColorDrawable(startColor), ColorDrawable(endColor))
}
fun createTransitionDrawable(start: Drawable, end: Drawable): TransitionDrawable {
val drawables = arrayOfNulls<Drawable>(2)
drawables[0] = start
drawables[1] = end
return TransitionDrawable(drawables)
}
}

@ -0,0 +1,43 @@
package io.legado.app.lib.theme
import android.content.res.ColorStateList
import android.graphics.PorterDuff
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.TransitionDrawable
import androidx.annotation.ColorInt
import androidx.core.graphics.drawable.DrawableCompat
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object DrawableUtils {
fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable {
return createTransitionDrawable(ColorDrawable(startColor), ColorDrawable(endColor))
}
fun createTransitionDrawable(start: Drawable, end: Drawable): TransitionDrawable {
val drawables = arrayOfNulls<Drawable>(2)
drawables[0] = start
drawables[1] = end
return TransitionDrawable(drawables)
}
fun setTintList(drawable: Drawable, tint: ColorStateList, tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP) {
val wrappedDrawable = DrawableCompat.wrap(drawable)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTintList(wrappedDrawable, tint)
}
fun setTint(drawable: Drawable, @ColorInt tint: Int, tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP) {
val wrappedDrawable = DrawableCompat.wrap(drawable)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTint(wrappedDrawable, tint)
}
}

@ -4,42 +4,73 @@ import android.annotation.SuppressLint
import android.content.Context
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import io.legado.app.R
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object MaterialValueHelper {
@SuppressLint("PrivateResource")
@ColorInt
fun Context.getPrimaryTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(this, R.color.primary_text_default_material_light)
} else ContextCompat.getColor(this, R.color.primary_text_default_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun Context.getSecondaryTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(this, R.color.secondary_text_default_material_light)
} else ContextCompat.getColor(this, R.color.secondary_text_default_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun getPrimaryTextColor(context: Context, dark: Boolean): Int {
@SuppressLint("PrivateResource")
@ColorInt
fun Context.getPrimaryDisabledTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(context, R.color.primary_text_default_material_light)
} else ContextCompat.getColor(context, R.color.primary_text_default_material_dark)
}
ContextCompat.getColor(this, R.color.primary_text_disabled_material_light)
} else ContextCompat.getColor(this, R.color.primary_text_disabled_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun getSecondaryTextColor(context: Context, dark: Boolean): Int {
@SuppressLint("PrivateResource")
@ColorInt
fun Context.getSecondaryDisabledTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(context, R.color.secondary_text_default_material_light)
} else ContextCompat.getColor(context, R.color.secondary_text_default_material_dark)
}
ContextCompat.getColor(this, R.color.secondary_text_disabled_material_light)
} else ContextCompat.getColor(this, R.color.secondary_text_disabled_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun getPrimaryDisabledTextColor(context: Context, dark: Boolean): Int {
@SuppressLint("PrivateResource")
@ColorInt
fun Fragment.getPrimaryTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(context, R.color.primary_text_disabled_material_light)
} else ContextCompat.getColor(context, R.color.primary_text_disabled_material_dark)
}
ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_light)
} else ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun Fragment.getSecondaryTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_light)
} else ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun Fragment.getPrimaryDisabledTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_light)
} else ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_dark)
}
@SuppressLint("PrivateResource")
@ColorInt
fun getSecondaryDisabledTextColor(context: Context, dark: Boolean): Int {
@SuppressLint("PrivateResource")
@ColorInt
fun Fragment.getSecondaryDisabledTextColor(dark: Boolean): Int {
return if (dark) {
ContextCompat.getColor(context, R.color.secondary_text_disabled_material_light)
} else ContextCompat.getColor(context, R.color.secondary_text_disabled_material_dark)
}
ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_light)
} else ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_dark)
}

@ -8,7 +8,7 @@ import com.google.android.material.navigation.NavigationView
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object NavigationViewUtil {
object NavigationViewUtils {
fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val iconSl = ColorStateList(

@ -26,7 +26,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
override fun primaryColor(@ColorInt color: Int): ThemeStore {
mEditor.putInt(ThemeStorePrefKeys.KEY_PRIMARY_COLOR, color)
if (autoGeneratePrimaryDark(mContext))
primaryColorDark(ColorUtil.darkenColor(color))
primaryColorDark(ColorUtils.darkenColor(color))
return this
}
@ -35,7 +35,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun primaryColorAttr(@AttrRes colorAttr: Int): ThemeStore {
return primaryColor(ATHUtil.resolveColor(mContext, colorAttr))
return primaryColor(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun primaryColorDark(@ColorInt color: Int): ThemeStore {
@ -48,7 +48,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun primaryColorDarkAttr(@AttrRes colorAttr: Int): ThemeStore {
return primaryColorDark(ATHUtil.resolveColor(mContext, colorAttr))
return primaryColorDark(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun accentColor(@ColorInt color: Int): ThemeStore {
@ -61,7 +61,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun accentColorAttr(@AttrRes colorAttr: Int): ThemeStore {
return accentColor(ATHUtil.resolveColor(mContext, colorAttr))
return accentColor(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun statusBarColor(@ColorInt color: Int): ThemeStore {
@ -74,7 +74,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun statusBarColorAttr(@AttrRes colorAttr: Int): ThemeStore {
return statusBarColor(ATHUtil.resolveColor(mContext, colorAttr))
return statusBarColor(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun navigationBarColor(@ColorInt color: Int): ThemeStore {
@ -87,7 +87,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun navigationBarColorAttr(@AttrRes colorAttr: Int): ThemeStore {
return navigationBarColor(ATHUtil.resolveColor(mContext, colorAttr))
return navigationBarColor(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun textColorPrimary(@ColorInt color: Int): ThemeStore {
@ -100,7 +100,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun textColorPrimaryAttr(@AttrRes colorAttr: Int): ThemeStore {
return textColorPrimary(ATHUtil.resolveColor(mContext, colorAttr))
return textColorPrimary(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun textColorPrimaryInverse(@ColorInt color: Int): ThemeStore {
@ -113,7 +113,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun textColorPrimaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore {
return textColorPrimaryInverse(ATHUtil.resolveColor(mContext, colorAttr))
return textColorPrimaryInverse(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun textColorSecondary(@ColorInt color: Int): ThemeStore {
@ -126,7 +126,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun textColorSecondaryAttr(@AttrRes colorAttr: Int): ThemeStore {
return textColorSecondary(ATHUtil.resolveColor(mContext, colorAttr))
return textColorSecondary(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun textColorSecondaryInverse(@ColorInt color: Int): ThemeStore {
@ -139,7 +139,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
override fun textColorSecondaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore {
return textColorSecondaryInverse(ATHUtil.resolveColor(mContext, colorAttr))
return textColorSecondaryInverse(ATHUtils.resolveColor(mContext, colorAttr))
}
override fun backgroundColor(color: Int): ThemeStore {
@ -179,7 +179,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
// Static getters
@CheckResult
protected fun prefs(context: Context): SharedPreferences {
internal fun prefs(context: Context): SharedPreferences {
return context.getSharedPreferences(ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT, Context.MODE_PRIVATE)
}
@ -192,7 +192,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun primaryColor(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_PRIMARY_COLOR,
ATHUtil.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64"))
ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64"))
)
}
@ -201,7 +201,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun primaryColorDark(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_PRIMARY_COLOR_DARK,
ATHUtil.resolveColor(context, R.attr.colorPrimaryDark, Color.parseColor("#37474F"))
ATHUtils.resolveColor(context, R.attr.colorPrimaryDark, Color.parseColor("#37474F"))
)
}
@ -210,7 +210,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun accentColor(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_ACCENT_COLOR,
ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
)
}
@ -235,7 +235,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun textColorPrimary(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY,
ATHUtil.resolveColor(context, android.R.attr.textColorPrimary)
ATHUtils.resolveColor(context, android.R.attr.textColorPrimary)
)
}
@ -244,7 +244,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun textColorPrimaryInverse(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE,
ATHUtil.resolveColor(context, android.R.attr.textColorPrimaryInverse)
ATHUtils.resolveColor(context, android.R.attr.textColorPrimaryInverse)
)
}
@ -253,7 +253,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun textColorSecondary(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY,
ATHUtil.resolveColor(context, android.R.attr.textColorSecondary)
ATHUtils.resolveColor(context, android.R.attr.textColorSecondary)
)
}
@ -262,7 +262,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun textColorSecondaryInverse(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE,
ATHUtil.resolveColor(context, android.R.attr.textColorSecondaryInverse)
ATHUtils.resolveColor(context, android.R.attr.textColorSecondaryInverse)
)
}
@ -271,7 +271,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun backgroundColor(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_BACKGROUND_COLOR,
ATHUtil.resolveColor(context, android.R.attr.colorBackground)
ATHUtils.resolveColor(context, android.R.attr.colorBackground)
)
}

@ -6,26 +6,26 @@ package io.legado.app.lib.theme
internal interface ThemeStorePrefKeys {
companion object {
val CONFIG_PREFS_KEY_DEFAULT = "app_themes"
val IS_CONFIGURED_KEY = "is_configured"
val IS_CONFIGURED_VERSION_KEY = "is_configured_version"
val VALUES_CHANGED = "values_changed"
const val CONFIG_PREFS_KEY_DEFAULT = "app_themes"
const val IS_CONFIGURED_KEY = "is_configured"
const val IS_CONFIGURED_VERSION_KEY = "is_configured_version"
const val VALUES_CHANGED = "values_changed"
val KEY_PRIMARY_COLOR = "primary_color"
val KEY_PRIMARY_COLOR_DARK = "primary_color_dark"
val KEY_ACCENT_COLOR = "accent_color"
val KEY_STATUS_BAR_COLOR = "status_bar_color"
val KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color"
const val KEY_PRIMARY_COLOR = "primary_color"
const val KEY_PRIMARY_COLOR_DARK = "primary_color_dark"
const val KEY_ACCENT_COLOR = "accent_color"
const val KEY_STATUS_BAR_COLOR = "status_bar_color"
const val KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color"
val KEY_TEXT_COLOR_PRIMARY = "text_color_primary"
val KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse"
val KEY_TEXT_COLOR_SECONDARY = "text_color_secondary"
val KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse"
const val KEY_TEXT_COLOR_PRIMARY = "text_color_primary"
const val KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse"
const val KEY_TEXT_COLOR_SECONDARY = "text_color_secondary"
const val KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse"
val KEY_BACKGROUND_COLOR = "backgroundColor"
const val KEY_BACKGROUND_COLOR = "backgroundColor"
val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar"
val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar"
val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar"
const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar"
const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
}
}

@ -46,13 +46,13 @@ object TintHelper {
}
fun setTintSelector(view: View, @ColorInt color: Int, darker: Boolean, useDarkTheme: Boolean) {
val isColorLight = ColorUtil.isColorLight(color)
val isColorLight = ColorUtils.isColorLight(color)
val disabled = ContextCompat.getColor(
view.context,
if (useDarkTheme) R.color.ate_button_disabled_dark else R.color.ate_button_disabled_light
)
val pressed = ColorUtil.shiftColor(color, if (darker) 0.9f else 1.1f)
val activated = ColorUtil.shiftColor(color, if (darker) 1.1f else 0.9f)
val pressed = ColorUtils.shiftColor(color, if (darker) 0.9f else 1.1f)
val activated = ColorUtils.shiftColor(color, if (darker) 1.1f else 0.9f)
val rippleColor = getDefaultRippleColor(view.context, isColorLight)
val textColor = ContextCompat.getColor(
view.context,
@ -107,7 +107,7 @@ object TintHelper {
var drawable: Drawable? = view.background
if (drawable != null) {
drawable = createTintedDrawable(drawable, sl)
ViewUtil.setBackgroundCompat(view, drawable)
ViewUtils.setBackgroundCompat(view, drawable)
}
if (view is TextView && view !is Button) {
@ -127,7 +127,7 @@ object TintHelper {
view: View, @ColorInt color: Int,
background: Boolean
) {
setTintAuto(view, color, background, ATHUtil.isWindowBackgroundDark(view.context))
setTintAuto(view, color, background, ATHUtils.isWindowBackgroundDark(view.context))
}
fun setTintAuto(
@ -175,7 +175,7 @@ object TintHelper {
view.context,
if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light
)
val checked = ColorUtil.adjustAlpha(color, 0.4f)
val checked = ColorUtils.adjustAlpha(color, 0.4f)
val sl = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked),
@ -195,7 +195,7 @@ object TintHelper {
var drawable: Drawable? = view.background
if (drawable != null) {
drawable = createTintedDrawable(drawable, color)
ViewUtil.setBackgroundCompat(view, drawable)
ViewUtils.setBackgroundCompat(view, drawable)
}
}
}
@ -209,7 +209,7 @@ object TintHelper {
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked)
), intArrayOf(
// Rdio button includes own alpha for disabled state
ColorUtil.stripAlpha(
ColorUtils.stripAlpha(
ContextCompat.getColor(
radioButton.context,
if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light
@ -335,9 +335,9 @@ object TintHelper {
): Drawable? {
var tint = tint
if (useDarker) {
tint = ColorUtil.shiftColor(tint, 1.1f)
tint = ColorUtils.shiftColor(tint, 1.1f)
}
tint = ColorUtil.adjustAlpha(tint, if (compatSwitch && !thumb) 0.5f else 1.0f)
tint = ColorUtils.adjustAlpha(tint, if (compatSwitch && !thumb) 0.5f else 1.0f)
val disabled: Int
var normal: Int
if (thumb) {
@ -362,7 +362,7 @@ object TintHelper {
// Stock switch includes its own alpha
if (!compatSwitch) {
normal = ColorUtil.stripAlpha(normal)
normal = ColorUtils.stripAlpha(normal)
}
val sl = ColorStateList(

@ -10,7 +10,7 @@ import androidx.annotation.ColorInt
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object ViewUtil {
object ViewUtils {
fun removeOnGlobalLayoutListener(v: View, listener: ViewTreeObserver.OnGlobalLayoutListener) {
v.viewTreeObserver.removeOnGlobalLayoutListener(listener)
@ -21,7 +21,7 @@ object ViewUtil {
}
fun setBackgroundTransition(view: View, newDrawable: Drawable): TransitionDrawable {
val transition = DrawableUtil.createTransitionDrawable(view.background, newDrawable)
val transition = DrawableUtils.createTransitionDrawable(view.background, newDrawable)
setBackgroundCompat(view, transition)
return transition
}
@ -32,7 +32,7 @@ object ViewUtil {
val start = oldColor ?: ColorDrawable(view.solidColor)
val end = ColorDrawable(newColor)
val transition = DrawableUtil.createTransitionDrawable(start, end)
val transition = DrawableUtils.createTransitionDrawable(start, end)
setBackgroundCompat(view, transition)

@ -4,7 +4,7 @@ import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.lib.theme.ColorUtil
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.dp
@ -26,7 +26,7 @@ class ATEAccentBgTextView : AppCompatTextView {
background = Selector.shapeBuild()
.setCornerRadius(3.dp)
.setDefaultBgColor(ThemeStore.accentColor(context))
.setPressedBgColor(ColorUtil.darkenColor(ThemeStore.accentColor(context)))
.setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context)))
.create()
setTextColor(Color.WHITE)
}

@ -4,13 +4,14 @@ import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.Switch
import androidx.appcompat.widget.SwitchCompat
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore
/**
* @author Aidan Follestad (afollestad)
*/
class ATEStockSwitch : Switch {
class ATEStockSwitch : SwitchCompat {
constructor(context: Context) : super(context) {
init(context, null)

@ -4,13 +4,14 @@ import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.Switch
import androidx.appcompat.widget.SwitchCompat
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore
/**
* @author Aidan Follestad (afollestad)
*/
class ATESwitch : Switch {
class ATESwitch : SwitchCompat {
constructor(context: Context) : super(context) {
init(context, null)

@ -1,5 +1,5 @@
<resources>
<style name="CAppTheme.NoActionBar">
<style name="AppTheme.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

@ -1,23 +1,25 @@
<resources xmlns:tools="http://schemas.android.com/tools">
//**************************************************************Theme******************************************************************************//
<!-- 亮色主题 -->
<style name="CAppTheme" parent="Base.AppTheme">
<style name="AppTheme.Light" parent="Base.AppTheme">
<item name="actionBarStyle">@style/AppTheme.AppBarOverlay.Light</item>
</style>
<!-- 暗色主题 -->
<style name="CAppThemeBarDark" parent="Base.AppTheme">
<style name="AppTheme.Dark" parent="Base.AppTheme">
<item name="actionBarStyle">@style/AppTheme.AppBarOverlay.Dark</item>
</style>
<!-- 透明主题 -->
<style name="CAppTransparentTheme" parent="Base.AppTheme">
<style name="AppTheme.Transparent" parent="Base.AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<!-- Welcome主题 -->
<style name="CAppWelcomeTheme" parent="Base.AppTheme">
<style name="AppTheme.Welcome" parent="Base.AppTheme">
<item name="android:windowNoTitle">true</item>
</style>
@ -27,41 +29,54 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionOverflowMenuStyle">@style/PopupMenu</item>
<item name="android:itemTextAppearance">@style/MenuItemTextStyle</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="actionOverflowMenuStyle">@style/Style.PopupMenu</item>
<item name="android:itemTextAppearance">@style/Style.MenuItemText</item>
<item name="android:popupMenuStyle">@style/Style.PopupMenu</item>
</style>
<style name="NavigationViewStyle">
<item name="android:listPreferredItemHeightSmall">44dp</item>
<style name="AppTheme.AppBarOverlay.Light" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">@color/md_grey_900</item>
</style>
<style name="AppTheme.AppBarOverlay.Dark" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorAccent">@color/md_grey_100</item>
</style>
<style name="alertDialogTheme" parent="Theme.AppCompat.DayNight.Dialog.Alert">
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="overlapAnchor">false</item>
<item name="colorAccent">@color/md_grey_900</item>
</style>
<style name="AppTheme.AlertDialog" parent="Theme.AppCompat.DayNight.Dialog.Alert">
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/background_card</item>
<item name="android:textColor">@color/tv_text_default</item>
<item name="android:textColorPrimary">@color/tv_text_default</item>
<item name="textColorAlertDialogListItem">@color/tv_text_default</item>
</style>
//**************************************************************System Style******************************************************************************//
<style name="Style.NavigationView" parent="android:Widget">
<item name="android:listPreferredItemHeightSmall">44dp</item>
</style>
<style name="MenuItemTextStyle" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<style name="Style.Toolbar.NoPadding" parent="Base.Widget.AppCompat.Toolbar">
<item name="contentInsetStartWithNavigation">0dp</item>
</style>
<style name="Style.MenuItemText" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@color/menu_color_default</item>
<item name="android:textSize">16sp</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<style name="Style.PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@color/background_menu</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="overlapAnchor">false</item>
<item name="colorAccent">@color/md_grey_900</item>
</style>
<style name="NoPaddingToolbar" parent="Base.Widget.AppCompat.Toolbar">
<item name="contentInsetStartWithNavigation">0dp</item>
</style>
//**************************************************************Widget Style******************************************************************************//
<style name="Style.Shadow.Top" parent="android:Widget">
<item name="android:layout_width">match_parent</item>
@ -75,15 +90,6 @@
<item name="android:background">@drawable/bg_shadow_bottom</item>
</style>
<style name="AppTheme.AppBarOverlay.Light" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">@color/md_grey_900</item>
</style>
<style name="AppTheme.AppBarOverlay.Dark" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorAccent">@color/md_grey_100</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="Activity.Permission" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>

Loading…
Cancel
Save