6.6.2 - Alpha5 - 主题色设置页面新布局支持基础功能及新旧布局数据兼容
This commit is contained in:
@@ -295,33 +295,33 @@ object ColorItems {
|
||||
R.color.md_brown_800 to R.string.md_brown_800,
|
||||
R.color.md_brown_900 to R.string.md_brown_900,
|
||||
|
||||
/* grey */
|
||||
/* gray */
|
||||
|
||||
R.color.md_grey_50 to R.string.md_grey_50,
|
||||
R.color.md_grey_100 to R.string.md_grey_100,
|
||||
R.color.md_grey_200 to R.string.md_grey_200,
|
||||
R.color.md_grey_300 to R.string.md_grey_300,
|
||||
R.color.md_grey_400 to R.string.md_grey_400,
|
||||
R.color.md_grey_500 to R.string.md_grey_500,
|
||||
R.color.md_grey_600 to R.string.md_grey_600,
|
||||
R.color.md_grey_700 to R.string.md_grey_700,
|
||||
R.color.md_grey_800 to R.string.md_grey_800,
|
||||
R.color.md_grey_900 to R.string.md_grey_900,
|
||||
R.color.md_gray_50 to R.string.md_gray_50,
|
||||
R.color.md_gray_100 to R.string.md_gray_100,
|
||||
R.color.md_gray_200 to R.string.md_gray_200,
|
||||
R.color.md_gray_300 to R.string.md_gray_300,
|
||||
R.color.md_gray_400 to R.string.md_gray_400,
|
||||
R.color.md_gray_500 to R.string.md_gray_500,
|
||||
R.color.md_gray_600 to R.string.md_gray_600,
|
||||
R.color.md_gray_700 to R.string.md_gray_700,
|
||||
R.color.md_gray_800 to R.string.md_gray_800,
|
||||
R.color.md_gray_900 to R.string.md_gray_900,
|
||||
R.color.md_black_1000 to R.string.md_black_1000,
|
||||
R.color.md_white_1000 to R.string.md_white_1000,
|
||||
|
||||
/* blue grey */
|
||||
/* blue gray */
|
||||
|
||||
R.color.md_blue_grey_50 to R.string.md_blue_grey_50,
|
||||
R.color.md_blue_grey_100 to R.string.md_blue_grey_100,
|
||||
R.color.md_blue_grey_200 to R.string.md_blue_grey_200,
|
||||
R.color.md_blue_grey_300 to R.string.md_blue_grey_300,
|
||||
R.color.md_blue_grey_400 to R.string.md_blue_grey_400,
|
||||
R.color.md_blue_grey_500 to R.string.md_blue_grey_500,
|
||||
R.color.md_blue_grey_600 to R.string.md_blue_grey_600,
|
||||
R.color.md_blue_grey_700 to R.string.md_blue_grey_700,
|
||||
R.color.md_blue_grey_800 to R.string.md_blue_grey_800,
|
||||
R.color.md_blue_grey_900 to R.string.md_blue_grey_900,
|
||||
R.color.md_blue_gray_50 to R.string.md_blue_gray_50,
|
||||
R.color.md_blue_gray_100 to R.string.md_blue_gray_100,
|
||||
R.color.md_blue_gray_200 to R.string.md_blue_gray_200,
|
||||
R.color.md_blue_gray_300 to R.string.md_blue_gray_300,
|
||||
R.color.md_blue_gray_400 to R.string.md_blue_gray_400,
|
||||
R.color.md_blue_gray_500 to R.string.md_blue_gray_500,
|
||||
R.color.md_blue_gray_600 to R.string.md_blue_gray_600,
|
||||
R.color.md_blue_gray_700 to R.string.md_blue_gray_700,
|
||||
R.color.md_blue_gray_800 to R.string.md_blue_gray_800,
|
||||
R.color.md_blue_gray_900 to R.string.md_blue_gray_900,
|
||||
)
|
||||
|
||||
@JvmField
|
||||
@@ -329,17 +329,11 @@ object ColorItems {
|
||||
R.color.android_black to R.string.android_black,
|
||||
R.color.android_blue to R.string.android_blue,
|
||||
R.color.android_cyan to R.string.android_cyan,
|
||||
R.color.android_aqua to R.string.android_aqua,
|
||||
R.color.android_dark_gray to R.string.android_dark_gray,
|
||||
R.color.android_dark_grey to R.string.android_dark_grey,
|
||||
R.color.android_gray to R.string.android_gray,
|
||||
R.color.android_grey to R.string.android_grey,
|
||||
R.color.android_green to R.string.android_green,
|
||||
R.color.android_lime to R.string.android_lime,
|
||||
R.color.android_light_gray to R.string.android_light_gray,
|
||||
R.color.android_light_grey to R.string.android_light_grey,
|
||||
R.color.android_magenta to R.string.android_magenta,
|
||||
R.color.android_fuchsia to R.string.android_fuchsia,
|
||||
R.color.android_maroon to R.string.android_maroon,
|
||||
R.color.android_navy to R.string.android_navy,
|
||||
R.color.android_olive to R.string.android_olive,
|
||||
@@ -373,12 +367,10 @@ object ColorItems {
|
||||
R.color.css_corn_silk to R.string.css_corn_silk,
|
||||
R.color.css_crimson to R.string.css_crimson,
|
||||
R.color.css_cyan to R.string.css_cyan,
|
||||
R.color.css_aqua to R.string.css_aqua,
|
||||
R.color.css_dark_blue to R.string.css_dark_blue,
|
||||
R.color.css_dark_cyan to R.string.css_dark_cyan,
|
||||
R.color.css_dark_goldenrod to R.string.css_dark_goldenrod,
|
||||
R.color.css_dark_gray to R.string.css_dark_gray,
|
||||
R.color.css_dark_grey to R.string.css_dark_grey,
|
||||
R.color.css_dark_green to R.string.css_dark_green,
|
||||
R.color.css_dark_khaki to R.string.css_dark_khaki,
|
||||
R.color.css_dark_magenta to R.string.css_dark_magenta,
|
||||
@@ -390,13 +382,11 @@ object ColorItems {
|
||||
R.color.css_dark_sea_green to R.string.css_dark_sea_green,
|
||||
R.color.css_dark_slate_blue to R.string.css_dark_slate_blue,
|
||||
R.color.css_dark_slate_gray to R.string.css_dark_slate_gray,
|
||||
R.color.css_dark_slate_grey to R.string.css_dark_slate_grey,
|
||||
R.color.css_dark_turquoise to R.string.css_dark_turquoise,
|
||||
R.color.css_dark_violet to R.string.css_dark_violet,
|
||||
R.color.css_deep_pink to R.string.css_deep_pink,
|
||||
R.color.css_deep_sky_blue to R.string.css_deep_sky_blue,
|
||||
R.color.css_dim_gray to R.string.css_dim_gray,
|
||||
R.color.css_dim_grey to R.string.css_dim_grey,
|
||||
R.color.css_dodger_blue to R.string.css_dodger_blue,
|
||||
R.color.css_fire_brick to R.string.css_fire_brick,
|
||||
R.color.css_floral_white to R.string.css_floral_white,
|
||||
@@ -406,7 +396,6 @@ object ColorItems {
|
||||
R.color.css_gold to R.string.css_gold,
|
||||
R.color.css_goldenrod to R.string.css_goldenrod,
|
||||
R.color.css_gray to R.string.css_gray,
|
||||
R.color.css_grey to R.string.css_grey,
|
||||
R.color.css_green to R.string.css_green,
|
||||
R.color.css_green_yellow to R.string.css_green_yellow,
|
||||
R.color.css_honeydew to R.string.css_honeydew,
|
||||
@@ -424,21 +413,18 @@ object ColorItems {
|
||||
R.color.css_light_cyan to R.string.css_light_cyan,
|
||||
R.color.css_light_goldenrod_yellow to R.string.css_light_goldenrod_yellow,
|
||||
R.color.css_light_gray to R.string.css_light_gray,
|
||||
R.color.css_light_grey to R.string.css_light_grey,
|
||||
R.color.css_light_green to R.string.css_light_green,
|
||||
R.color.css_light_pink to R.string.css_light_pink,
|
||||
R.color.css_light_salmon to R.string.css_light_salmon,
|
||||
R.color.css_light_sea_green to R.string.css_light_sea_green,
|
||||
R.color.css_light_sky_blue to R.string.css_light_sky_blue,
|
||||
R.color.css_light_slate_gray to R.string.css_light_slate_gray,
|
||||
R.color.css_light_slate_grey to R.string.css_light_slate_grey,
|
||||
R.color.css_light_steel_blue to R.string.css_light_steel_blue,
|
||||
R.color.css_light_yellow to R.string.css_light_yellow,
|
||||
R.color.css_lime to R.string.css_lime,
|
||||
R.color.css_lime_green to R.string.css_lime_green,
|
||||
R.color.css_linen to R.string.css_linen,
|
||||
R.color.css_magenta to R.string.css_magenta,
|
||||
R.color.css_fuchsia to R.string.css_fuchsia,
|
||||
R.color.css_maroon to R.string.css_maroon,
|
||||
R.color.css_medium_aquamarine to R.string.css_medium_aquamarine,
|
||||
R.color.css_medium_blue to R.string.css_medium_blue,
|
||||
@@ -486,7 +472,6 @@ object ColorItems {
|
||||
R.color.css_sky_blue to R.string.css_sky_blue,
|
||||
R.color.css_slate_blue to R.string.css_slate_blue,
|
||||
R.color.css_slate_gray to R.string.css_slate_gray,
|
||||
R.color.css_slate_grey to R.string.css_slate_grey,
|
||||
R.color.css_snow to R.string.css_snow,
|
||||
R.color.css_spring_green to R.string.css_spring_green,
|
||||
R.color.css_steel_blue to R.string.css_steel_blue,
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.autojs.autojs.execution.ScriptExecution.AbstractScriptExecution
|
||||
import org.autojs.autojs.inrt.autojs.LoopBasedJavaScriptEngineWithDecryption
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.script.ScriptSource
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.BuildConfig
|
||||
import org.autojs.autojs6.R
|
||||
@@ -66,10 +65,10 @@ class ScriptExecuteActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val windowBackground: Drawable = window.decorView.background
|
||||
?: ColorDrawable(getColor(R.color.md_grey_50)).also { window.setBackgroundDrawable(it) }
|
||||
?: ColorDrawable(getColor(R.color.md_gray_50)).also { window.setBackgroundDrawable(it) }
|
||||
|
||||
if (windowBackground is ColorDrawable) windowBackground.color.let { backgroundColor ->
|
||||
val isLightColor = ColorUtils.isLuminanceDark(backgroundColor)
|
||||
val isLightColor = ViewUtils.isLuminanceDark(backgroundColor)
|
||||
ViewUtils.setStatusBarBackgroundColor(this, backgroundColor)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, isLightColor)
|
||||
ViewUtils.setNavigationBarBackgroundColor(this, backgroundColor)
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.autojs.autojs6.databinding.ActivityMainInrtBinding
|
||||
|
||||
class LogActivity : BaseActivity() {
|
||||
|
||||
override val handleStatusBarThemeColorAutomatically = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setupView()
|
||||
|
||||
@@ -22,6 +22,10 @@ import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsSanitize
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsUnwrapped
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component1
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component2
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component3
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component4
|
||||
import org.autojs.autojs.extension.ScriptableExtensions.defineProp
|
||||
import org.autojs.autojs.extension.ScriptableExtensions.prop
|
||||
import org.autojs.autojs.rhino.ProxyObject.Companion.PROXY_GETTER_KEY
|
||||
@@ -34,7 +38,6 @@ import org.autojs.autojs.runtime.api.augment.colors.Colors
|
||||
import org.autojs.autojs.runtime.api.augment.jsox.Numberx
|
||||
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.RhinoUtils
|
||||
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
|
||||
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
|
||||
@@ -540,7 +543,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
fun statusBarAppearanceLightBy(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsOnlyOne(args) { refColor ->
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
Colors.toIntRhino(refColor).also { ViewUtils.setStatusBarAppearanceLight(activity, ColorUtils.isLuminanceDark(it)) }
|
||||
Colors.toIntRhino(refColor).also { ViewUtils.setStatusBarAppearanceLight(activity, ViewUtils.isLuminanceDark(it)) }
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
}
|
||||
UNDEFINED
|
||||
@@ -595,7 +598,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
ScriptRuntime.requiresApi(Build.VERSION_CODES.O)
|
||||
} else {
|
||||
ViewUtils.setNavigationBarAppearanceLight(activity, ColorUtils.isLuminanceDark(it))
|
||||
ViewUtils.setNavigationBarAppearanceLight(activity, ViewUtils.isLuminanceDark(it))
|
||||
}
|
||||
}
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.autojs.autojs.core.pref.Pref.getInt
|
||||
import org.autojs.autojs.core.pref.Pref.putInt
|
||||
import org.autojs.autojs.extension.ArrayExtensions.toHashCode
|
||||
import org.autojs.autojs.theme.ThemeColorManager.defaultThemeColor
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
|
||||
/**
|
||||
@@ -31,9 +31,11 @@ class ThemeColor(@JvmField var colorPrimary: Int, @JvmField var colorPrimaryDark
|
||||
@ScriptInterface
|
||||
fun getColorPrimaryDark() = colorPrimaryDark
|
||||
|
||||
fun isLuminanceLight() = ColorUtils.isLuminanceLight(colorPrimary)
|
||||
@JvmOverloads
|
||||
fun isLuminanceLight(backgroundColorMatters: Boolean = true) = ThemeColorManager.isLuminanceLight(backgroundColorMatters)
|
||||
|
||||
fun isLuminanceDark() = ColorUtils.isLuminanceDark(colorPrimary)
|
||||
@JvmOverloads
|
||||
fun isLuminanceDark(backgroundColorMatters: Boolean = true) = !isLuminanceLight(backgroundColorMatters)
|
||||
|
||||
fun colorPrimary(colorPrimary: Int) = also { this.colorPrimary = colorPrimary }
|
||||
|
||||
|
||||
@@ -14,10 +14,8 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import org.autojs.autojs.theme.internal.ScrollingViewEdgeGlowColorHelper;
|
||||
import org.autojs.autojs.util.ColorUtils;
|
||||
import org.autojs.autojs.util.ViewUtils;
|
||||
@@ -90,8 +88,8 @@ public class ThemeColorHelper {
|
||||
}
|
||||
|
||||
private static void setThumbDrawableTintList(Drawable drawable, int color) {
|
||||
int unselectedColor = ColorUtils.isLuminanceLight(color)
|
||||
? Color.parseColor("#616161") // R.color.md_grey_700
|
||||
int unselectedColor = ViewUtils.isLuminanceLight(color)
|
||||
? Color.parseColor("#616161") // R.color.md_gray_700
|
||||
: Color.DKGRAY;
|
||||
int[] thumbColors = new int[]{
|
||||
color,
|
||||
|
||||
@@ -29,12 +29,6 @@ object ThemeColorManager {
|
||||
ThemeColor.fromPreferences()?.let { currentThemeColor = it } ?: setThemeColor(defaultThemeColor)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isThemeColorLuminanceLight() = currentThemeColor.isLuminanceLight()
|
||||
|
||||
@JvmStatic
|
||||
fun isThemeColorLuminanceDark() = currentThemeColor.isLuminanceDark()
|
||||
|
||||
@JvmStatic
|
||||
fun add(colorMutable: ThemeColorMutable) = ThemeColorMutableManager.add(colorMutable)
|
||||
|
||||
@@ -67,10 +61,6 @@ object ThemeColorManager {
|
||||
ThemeColorWidgetReferenceManager.setColor(themeColor)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主题色并为记录的状态栏和标题栏改变颜色
|
||||
* @param color 主题色RGB值
|
||||
*/
|
||||
fun setThemeColor(color: Int) = setThemeColor(ThemeColor(color))
|
||||
|
||||
private fun saveThemeColorIfNeeded() {
|
||||
@@ -78,10 +68,31 @@ object ThemeColorManager {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorByLuminance(context: Context): Int = ViewUtils.getDayOrNightColorByLuminance(context, colorPrimary)
|
||||
@JvmOverloads
|
||||
fun isLuminanceLight(backgroundColorMatters: Boolean = true): Boolean {
|
||||
return ViewUtils.isLuminanceLight(colorPrimary, backgroundColorMatters)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorResByLuminance(): Int = ViewUtils.getDayOrNightColorResByLuminance(colorPrimary)
|
||||
@JvmOverloads
|
||||
fun isLuminanceDark(backgroundColorMatters: Boolean = true): Boolean {
|
||||
return ViewUtils.isLuminanceDark(colorPrimary, backgroundColorMatters)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorByLuminance(context: Context): Int {
|
||||
return ViewUtils.getDayOrNightColorByLuminance(context, colorPrimary)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorResByLuminance(): Int {
|
||||
return ViewUtils.getDayOrNightColorResByLuminance(colorPrimary)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStatusBarBackgroundColor(activity: Activity) {
|
||||
ViewUtils.setStatusBarBackgroundColor(activity, colorPrimary)
|
||||
}
|
||||
|
||||
private object BackgroundColorManager {
|
||||
|
||||
@@ -105,7 +116,7 @@ object ThemeColorManager {
|
||||
|
||||
fun add(activity: Activity) {
|
||||
activityRefs.add(WeakReference(activity))
|
||||
ViewUtils.setStatusBarBackgroundColor(activity, currentThemeColor.colorPrimary)
|
||||
setStatusBarBackgroundColor(activity)
|
||||
}
|
||||
|
||||
fun setColor(color: Int) {
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
package org.autojs.autojs.theme.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.VERTICAL
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog
|
||||
import org.autojs.autojs.core.image.ColorItems
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs.util.ViewUtils.setMenuIconsColorByColorLuminance
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.MtActivityColorLibrariesBinding
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class ColorLibrariesActivity : ColorSelectBaseActivity() {
|
||||
|
||||
private lateinit var binding: MtActivityColorLibrariesBinding
|
||||
|
||||
private lateinit var mAdapter: ColorLibraryAdapter
|
||||
|
||||
private val customColor: Int
|
||||
get() = Pref.getInt(KEY_CUSTOM_COLOR, getColor(R.color.custom_color_default))
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
ThemeChangeNotifier.themeChanged.observe(this) {
|
||||
setColor(ThemeColorManager.colorPrimary)
|
||||
mAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
MtActivityColorLibrariesBinding.inflate(layoutInflater).let {
|
||||
binding = it
|
||||
setContentView(it.root)
|
||||
setUpToolbar(it.toolbar)
|
||||
setUpAppBar(it.appBar, it.appBarContainer)
|
||||
}
|
||||
|
||||
binding.colorLibrariesRecyclerView.let {
|
||||
it.layoutManager = LinearLayoutManager(this)
|
||||
it.adapter = ColorLibraryAdapter(colorLibraries) { library ->
|
||||
val intent = Intent(this, ColorLibraryActivity::class.java)
|
||||
intent.putExtra("LIBRARY_ID", library.id)
|
||||
startActivity(intent)
|
||||
}.also { mAdapter = it }
|
||||
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_color_libraries, menu)
|
||||
|
||||
binding.toolbar.setMenuIconsColorByColorLuminance(this, currentColor)
|
||||
|
||||
val searchItem = menu.findItem(R.id.action_search_color)
|
||||
val searchView = searchItem.actionView as? SearchView
|
||||
searchView?.queryHint = "搜索颜色库"
|
||||
searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
filterLibraries(query)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
filterLibraries(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
private fun filterLibraries(query: String?) {
|
||||
val filteredLibraries = when {
|
||||
query.isNullOrBlank() -> colorLibraries
|
||||
else -> colorLibraries.filter {
|
||||
val name = it.nameString ?: getString(it.nameRes)
|
||||
name.contains(query, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
mAdapter.updateData(filteredLibraries)
|
||||
}
|
||||
|
||||
// 定位功能可以通过工具栏中的 "action_locate_current_theme_color" 按钮实现,
|
||||
// 按钮点击后找到包含当前主题色的颜色库在列表中的位置,
|
||||
// 然后调用 RecyclerView 的 scrollToPosition() 方法跳转到该项
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||
R.id.action_color_palette -> {
|
||||
showColorPicker()
|
||||
true
|
||||
}
|
||||
R.id.action_search_color -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
true
|
||||
}
|
||||
R.id.action_new_color_library -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
true
|
||||
}
|
||||
R.id.action_locate_current_theme_color -> {
|
||||
locateCurrentThemeColor()
|
||||
true
|
||||
}
|
||||
R.id.action_toggle_color_select_layout -> {
|
||||
isLegacyLayout = true
|
||||
startActivity(this)
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun showColorPicker() {
|
||||
ColorPickerDialog.newBuilder()
|
||||
.setAllowCustom(true)
|
||||
.setAllowPresets(true)
|
||||
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
|
||||
.setShowAlphaSlider(false)
|
||||
.setDialogTitle(R.string.dialog_title_color_palette)
|
||||
.setColor(customColor)
|
||||
.create()
|
||||
.setColorPickerDialogListener { dialogId: Int, color: Int ->
|
||||
savePrefsForLibraries()
|
||||
savePrefsForLegacy(color)
|
||||
|
||||
binding.toolbar.post { binding.toolbar.subtitle = getCurrentColorSummary(this, true) }
|
||||
|
||||
setColorWithAnimation(color)
|
||||
|
||||
ThemeColorManager.setThemeColor(color)
|
||||
ThemeChangeNotifier.notifyThemeChanged()
|
||||
}
|
||||
.show(supportFragmentManager, "ColorPickerTagForColorLibraries")
|
||||
}
|
||||
|
||||
private fun savePrefsForLibraries() {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, COLOR_LIBRARY_CUSTOM_COLOR_ID)
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, 0)
|
||||
}
|
||||
|
||||
private fun savePrefsForLegacy(color: Int) {
|
||||
Pref.putInt(KEY_CUSTOM_COLOR, color or -0x1000000)
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, customColorPosition)
|
||||
}
|
||||
|
||||
|
||||
private fun locateCurrentThemeColor() {
|
||||
// 假设当前主题颜色保存在 ThemeColorManager 中,可以通过它查找对应颜色库
|
||||
val currentColor = ThemeColorManager.colorPrimary
|
||||
// 简单示例:遍历 colorLibraries,找到第一个包含该颜色的库
|
||||
val targetIndex = colorLibraries.indexOfFirst { library ->
|
||||
library.colors.any { colorItem ->
|
||||
getColor(colorItem.colorRes) == currentColor
|
||||
}
|
||||
}
|
||||
if (targetIndex >= 0) {
|
||||
val recyclerView: RecyclerView = findViewById(R.id.color_libraries_recycler_view)
|
||||
recyclerView.smoothScrollToPosition(targetIndex)
|
||||
} else {
|
||||
Toast.makeText(this, "未找到当前颜色所在的颜色库", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSubtitle() = getCurrentColorSummary(this)
|
||||
|
||||
inner class ColorLibraryAdapter(
|
||||
private var libraries: List<ColorLibrary>,
|
||||
private val onItemClick: (ColorLibrary) -> Unit,
|
||||
) : RecyclerView.Adapter<LibraryViewHolder>() {
|
||||
|
||||
// 当上层需要搜索过滤时调用该方法更新数据
|
||||
fun updateData(newLibraries: List<ColorLibrary>) {
|
||||
libraries = newLibraries
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LibraryViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.mt_color_libraries_recycler_view_item, parent, false)
|
||||
return LibraryViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: LibraryViewHolder, position: Int) {
|
||||
val library = libraries[position]
|
||||
holder.bind(library)
|
||||
holder.itemView.setOnClickListener { onItemClick(library) }
|
||||
}
|
||||
|
||||
override fun getItemCount() = libraries.size
|
||||
|
||||
}
|
||||
|
||||
inner class LibraryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
private val colorItemView: ImageView = itemView.findViewById(R.id.library_item)
|
||||
private val libraryName: TextView = itemView.findViewById(R.id.name)
|
||||
private val description: TextView = itemView.findViewById(R.id.description)
|
||||
|
||||
fun bind(library: ColorLibrary) {
|
||||
libraryName.text = library.nameString ?: getString(library.nameRes)
|
||||
|
||||
val size = library.colors.size
|
||||
description.text = resources.getQuantityString(R.plurals.text_items_total_sum, size, size)
|
||||
|
||||
val adjustedContrastColor = ColorUtils.adjustColorForContrast(getColor(R.color.window_background), ThemeColorManager.colorPrimary, 2.3)
|
||||
when {
|
||||
library.id == COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
||||
colorItemView.setImageResource(R.drawable.ic_color_library_default)
|
||||
}
|
||||
!library.isUserDefined -> {
|
||||
colorItemView.setImageResource(R.drawable.ic_color_library_preset)
|
||||
}
|
||||
}
|
||||
colorItemView.imageTintList = ColorStateList.valueOf(adjustedContrastColor)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val COLOR_LIBRARY_CUSTOM_COLOR_ID = 0x10001
|
||||
|
||||
const val COLOR_LIBRARY_DEFAULT_COLORS_ID = 0x20001
|
||||
const val COLOR_LIBRARY_MATERIAL_COLORS_ID = 0x20002
|
||||
const val COLOR_LIBRARY_ANDROID_COLORS_ID = 0x20003
|
||||
const val COLOR_LIBRARY_CSS_COLORS_ID = 0x20004
|
||||
const val COLOR_LIBRARY_WEB_COLORS_ID = 0x20005
|
||||
|
||||
val colorLibraries by lazy {
|
||||
listOf(
|
||||
ColorLibrary(
|
||||
id = COLOR_LIBRARY_DEFAULT_COLORS_ID,
|
||||
nameRes = R.string.color_library_default_colors,
|
||||
titleRes = R.string.color_library_title_default_colors,
|
||||
identifierRes = R.string.color_library_identifier_default_colors,
|
||||
colors = listOf(
|
||||
R.color.md_teal_800 to R.string.md_teal_800,
|
||||
R.color.md_blue_gray_800 to R.string.md_blue_gray_800,
|
||||
R.color.window_background_light to R.string.window_background_light,
|
||||
R.color.window_background_night to R.string.window_background_night,
|
||||
).mapIndexed { index, (colorRes, nameRes) ->
|
||||
ColorItem(index, colorRes, nameRes)
|
||||
},
|
||||
),
|
||||
ColorLibrary(
|
||||
id = COLOR_LIBRARY_MATERIAL_COLORS_ID,
|
||||
nameRes = R.string.color_library_material_design_colors,
|
||||
titleRes = R.string.color_library_title_material_design_colors,
|
||||
identifierRes = R.string.color_library_identifier_material_design_colors,
|
||||
colors = ColorItems.MATERIAL_COLORS.mapIndexed { index, (colorRes, nameRes) ->
|
||||
ColorItem(index, colorRes, nameRes)
|
||||
},
|
||||
),
|
||||
ColorLibrary(
|
||||
id = COLOR_LIBRARY_ANDROID_COLORS_ID,
|
||||
nameRes = R.string.color_library_android_colors,
|
||||
titleRes = R.string.color_library_title_android_colors,
|
||||
identifierRes = R.string.color_library_identifier_android_colors,
|
||||
colors = ColorItems.ANDROID_COLORS.mapIndexed { index, (colorRes, nameRes) ->
|
||||
ColorItem(index, colorRes, nameRes)
|
||||
},
|
||||
),
|
||||
ColorLibrary(
|
||||
id = COLOR_LIBRARY_CSS_COLORS_ID,
|
||||
nameRes = R.string.color_library_css_colors,
|
||||
titleRes = R.string.color_library_title_css_colors,
|
||||
identifierRes = R.string.color_library_identifier_css_colors,
|
||||
colors = ColorItems.CSS_COLORS.mapIndexed { index, (colorRes, nameRes) ->
|
||||
ColorItem(index, colorRes, nameRes)
|
||||
},
|
||||
),
|
||||
ColorLibrary(
|
||||
id = COLOR_LIBRARY_WEB_COLORS_ID,
|
||||
nameRes = R.string.color_library_web_colors,
|
||||
titleRes = R.string.color_library_title_web_colors,
|
||||
identifierRes = R.string.color_library_identifier_web_colors,
|
||||
colors = ColorItems.WEB_COLORS.mapIndexed { index, (colorRes, nameRes) ->
|
||||
ColorItem(index, colorRes, nameRes)
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
data class ColorItem(
|
||||
val id: Int,
|
||||
val colorRes: Int = R.color.md_black_1000,
|
||||
val nameRes: Int = R.string.text_unknown,
|
||||
val colorInt: Int? = null,
|
||||
val nameString: String? = null,
|
||||
)
|
||||
|
||||
data class ColorLibrary(
|
||||
val id: Int,
|
||||
val nameRes: Int = R.string.text_color_library,
|
||||
val titleRes: Int? = null,
|
||||
val identifierRes: Int? = null,
|
||||
val nameString: String? = null,
|
||||
val titleString: String? = null,
|
||||
val colors: List<ColorItem> = emptyList(),
|
||||
var isUserDefined: Boolean = false,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package org.autojs.autojs.theme.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.VERTICAL
|
||||
import org.autojs.autojs.core.image.ColorItems
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColorHelper
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_DEFAULT_COLORS_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_MATERIAL_COLORS_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.ColorItem
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.ColorLibrary
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs.util.ViewUtils.setMenuIconsColorByColorLuminance
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.MtActivityColorLibraryBinding
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class ColorLibraryActivity : ColorSelectBaseActivity() {
|
||||
|
||||
private lateinit var binding: MtActivityColorLibraryBinding
|
||||
|
||||
private lateinit var mAdapter: ColorItemAdapter
|
||||
private lateinit var mLibrary: ColorLibrary
|
||||
|
||||
private var mSelectedPosition = SELECT_NONE
|
||||
private var mSelectedColor: Int? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val libraryId = intent.getIntExtra("LIBRARY_ID", -1)
|
||||
val library = colorLibraries.find { it.id == libraryId }?.also { lib ->
|
||||
mLibrary = lib
|
||||
} ?: throw RuntimeException("Unknown library id: $libraryId")
|
||||
|
||||
MtActivityColorLibraryBinding.inflate(layoutInflater).let {
|
||||
binding = it
|
||||
setContentView(it.root)
|
||||
setUpToolbar(it.toolbar)
|
||||
setUpAppBar(it.appBar, it.appBarContainer)
|
||||
it.toolbar.title = library.let {
|
||||
it.titleString
|
||||
?: it.titleRes?.let { resId -> getString(resId) }
|
||||
?: it.nameString
|
||||
?: getString(it.nameRes)
|
||||
}
|
||||
if (library.id == Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
|
||||
it.toolbar.subtitle = getCurrentColorSummary(this, true)
|
||||
}
|
||||
}
|
||||
|
||||
binding.colorLibraryRecyclerView.let { it ->
|
||||
it.layoutManager = LinearLayoutManager(this)
|
||||
it.adapter = ColorItemAdapter(library.colors) { colorItem, itemView ->
|
||||
savePrefsForLibraries(library, colorItem)
|
||||
savePrefsForLegacy(library, colorItem)
|
||||
|
||||
it.post { binding.toolbar.subtitle = getCurrentColorSummary(this, true) }
|
||||
|
||||
val selectedColor = getColor(colorItem.colorRes).also { mSelectedColor = it }
|
||||
setColorWithAnimation(selectedColor)
|
||||
|
||||
val adapter = it.adapter as ColorItemAdapter
|
||||
val currentPosition = it.getChildViewHolder(itemView).bindingAdapterPosition
|
||||
if (mSelectedPosition != SELECT_NONE) {
|
||||
adapter.notifyItemChanged(mSelectedPosition)
|
||||
mSelectedPosition = currentPosition
|
||||
adapter.notifyItemChanged(currentPosition)
|
||||
} else {
|
||||
mSelectedPosition = currentPosition
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
ThemeColorManager.setThemeColor(selectedColor)
|
||||
ThemeChangeNotifier.notifyThemeChanged()
|
||||
}.also { mAdapter = it }
|
||||
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
||||
setUpSelectedPosition()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpSelectedPosition() {
|
||||
when (Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
|
||||
SELECT_NONE -> when (val legacyIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)) {
|
||||
customColorPosition -> Unit
|
||||
SELECT_NONE, defaultColorPosition -> when (mLibrary.id) {
|
||||
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
||||
val index = mLibrary.colors.indexOfFirst { getColor(it.colorRes) == getColor(R.color.theme_color_default) }
|
||||
if (index >= 0) mSelectedPosition = index
|
||||
}
|
||||
}
|
||||
else -> when (val calculatedIndex = legacyIndex - maxOf(customColorPosition, defaultColorPosition) - 1) {
|
||||
in ColorItems.MATERIAL_COLORS.indices -> {
|
||||
val (colorRes, _) = ColorItems.MATERIAL_COLORS[calculatedIndex]
|
||||
val index = mLibrary.colors.indexOfFirst { it.colorRes == colorRes }
|
||||
if (index >= 0) mSelectedPosition = index
|
||||
}
|
||||
}
|
||||
}
|
||||
mLibrary.id -> {
|
||||
val libraryItemId = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, SELECT_NONE)
|
||||
mSelectedPosition = mLibrary.colors.indexOfFirst { it.id == libraryItemId }.takeIf { it != SELECT_NONE } ?: SELECT_NONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun savePrefsForLibraries(library: ColorLibrary?, colorItem: ColorItem) {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, library?.id ?: -1)
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, colorItem.id)
|
||||
}
|
||||
|
||||
private fun savePrefsForLegacy(library: ColorLibrary?, colorItem: ColorItem) {
|
||||
when (library?.id) {
|
||||
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
||||
if (getColor(colorItem.colorRes) == getColor(R.color.theme_color_default)) {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, defaultColorPosition)
|
||||
} else {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||
}
|
||||
}
|
||||
COLOR_LIBRARY_MATERIAL_COLORS_ID -> {
|
||||
val index = colorItem.id
|
||||
if (index !in ColorItems.MATERIAL_COLORS.indices) {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||
} else {
|
||||
val fixedIndex = maxOf(
|
||||
defaultColorPosition,
|
||||
customColorPosition,
|
||||
) + 1 + index
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, fixedIndex)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_color_library, menu)
|
||||
|
||||
binding.toolbar.setMenuIconsColorByColorLuminance(this, currentColor)
|
||||
|
||||
val searchItem = menu.findItem(R.id.action_search_color)
|
||||
val searchView = searchItem.actionView as? SearchView
|
||||
searchView?.queryHint = "搜索颜色"
|
||||
searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
filterColors(query)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
filterColors(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
private fun filterColors(@Suppress("unused") query: String?) {
|
||||
// if (library == null) return
|
||||
// val filteredColors = if (query.isNullOrBlank()) {
|
||||
// library!!.colors
|
||||
// } else {
|
||||
// library!!.colors.filter { colorItem ->
|
||||
// // 假设可以通过资源 id 获取对应的字符串显示,再做匹配
|
||||
// val name = getString(colorItem.nameRes)
|
||||
// name.contains(query, ignoreCase = true)
|
||||
// }
|
||||
// }
|
||||
// adapter.updateData(filteredColors)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||
R.id.action_search_color -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
true
|
||||
}
|
||||
R.id.action_locate_current_theme_color -> {
|
||||
// locateCurrentColorLibrary()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
inner class ColorItemAdapter(
|
||||
private var items: List<ColorItem>,
|
||||
private val onItemClick: (ColorItem, View) -> Unit,
|
||||
) : RecyclerView.Adapter<ColorViewHolder>() {
|
||||
|
||||
fun updateData(newItems: List<ColorItem>) {
|
||||
items = newItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ColorViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.mt_color_library_recycler_view_item, parent, false)
|
||||
return ColorViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ColorViewHolder, position: Int) {
|
||||
val item = items[position]
|
||||
holder.bind(item, position)
|
||||
holder.itemView.setOnClickListener { onItemClick(item, holder.itemView) }
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
}
|
||||
|
||||
inner class ColorViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
private val colorView: ImageView = itemView.findViewById(R.id.color)
|
||||
private val nameView: TextView = itemView.findViewById(R.id.name)
|
||||
private val descView: TextView = itemView.findViewById(R.id.description)
|
||||
|
||||
fun bind(item: ColorItem, position: Int) {
|
||||
val color = getColor(item.colorRes)
|
||||
ThemeColorHelper.setBackgroundColor(colorView, color)
|
||||
nameView.text = item.nameString ?: getString(item.nameRes)
|
||||
descView.text = String.format("#%06X", 0xFFFFFF and color)
|
||||
setChecked(color, mSelectedPosition == position)
|
||||
}
|
||||
|
||||
fun setChecked(@ColorInt color: Int, checked: Boolean) {
|
||||
if (checked) {
|
||||
colorView.setImageResource(R.drawable.mt_ic_check_white_36dp)
|
||||
val tintRes = if (ViewUtils.isLuminanceLight(color)) R.color.day else R.color.night
|
||||
colorView.imageTintList = ColorStateList.valueOf(getColor(tintRes))
|
||||
} else {
|
||||
colorView.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,6 @@ import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.MtActivityColorSelectBinding
|
||||
@@ -21,9 +17,12 @@ class ColorSelectActivity : ColorSelectBaseActivity() {
|
||||
|
||||
private lateinit var mColorSettingRecyclerView: ColorSettingRecyclerView
|
||||
|
||||
private var mSelectedPosition = SELECT_NONE
|
||||
|
||||
private val mOnItemClickListener = object : OnItemClickListener {
|
||||
override fun onItemClick(v: View?, position: Int) {
|
||||
mColorSettingRecyclerView.selectedThemeColor?.let {
|
||||
mSelectedPosition = position
|
||||
setColorWithAnimation(it.colorPrimary)
|
||||
}
|
||||
}
|
||||
@@ -31,7 +30,7 @@ class ColorSelectActivity : ColorSelectBaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
MtActivityColorSelectBinding.inflate(layoutInflater).also {
|
||||
MtActivityColorSelectBinding.inflate(layoutInflater).let {
|
||||
binding = it
|
||||
setContentView(it.root)
|
||||
setUpToolbar(it.toolbar)
|
||||
@@ -42,21 +41,12 @@ class ColorSelectActivity : ColorSelectBaseActivity() {
|
||||
|
||||
private fun setUpColorSettingRecyclerView(colorSettingRecyclerView: ColorSettingRecyclerView) {
|
||||
mColorSettingRecyclerView = colorSettingRecyclerView.apply {
|
||||
setSelectedColor(currentColor)
|
||||
setUpSelectedPosition(currentColor)
|
||||
setOnItemClickListener(mOnItemClickListener)
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
mColorSettingRecyclerView.selectedThemeColor?.let {
|
||||
ThemeColorManager.setThemeColor(it.colorPrimary)
|
||||
Pref.putString(key(R.string.key_theme_color), getCurrentColorSummary(this))
|
||||
ThemeChangeNotifier.notifyThemeChanged()
|
||||
}
|
||||
super.finish()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_color_select, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
@@ -64,26 +54,12 @@ class ColorSelectActivity : ColorSelectBaseActivity() {
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_color_palette -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
}
|
||||
R.id.action_search_color -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
}
|
||||
R.id.action_new_color_library -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
}
|
||||
R.id.action_locate_current_color -> {
|
||||
ViewUtils.showToast(this, R.string.text_under_development_title)
|
||||
}
|
||||
R.id.action_toggle_color_select_layout -> {
|
||||
isLegacyLayout = true
|
||||
isLegacyLayout = false
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getSubtitle() = getCurrentColorSummary(this)
|
||||
|
||||
}
|
||||
@@ -11,8 +11,9 @@ import com.google.android.material.appbar.AppBarLayout
|
||||
import io.codetail.widget.RevealFrameLayout
|
||||
import org.autojs.autojs.core.image.ColorItems
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_CUSTOM_COLOR_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
||||
import org.autojs.autojs.ui.BaseActivity
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
@@ -59,10 +60,6 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
protected fun finishWithoutSaving() {
|
||||
super.finish()
|
||||
}
|
||||
|
||||
protected open fun getSubtitle(): String? = null
|
||||
|
||||
override fun initThemeColors() {
|
||||
@@ -82,36 +79,34 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
protected fun setColorWithAnimation(colorTo: Int) {
|
||||
val view = mAppBarLayout
|
||||
mAppBarContainer.setBackgroundColor(currentColor)
|
||||
view.setBackgroundColor(colorTo)
|
||||
currentColor = colorTo
|
||||
|
||||
initThemeColors()
|
||||
updateToolbarIconsColor()
|
||||
mToolbar.subtitle = getSubtitle()
|
||||
|
||||
setColor(colorTo)
|
||||
ViewAnimationUtils.createCircularReveal(
|
||||
/* view = */ view,
|
||||
/* centerX = */ view.left,
|
||||
/* centerY = */ view.bottom,
|
||||
/* view = */ mAppBarLayout,
|
||||
/* centerX = */ mAppBarLayout.left,
|
||||
/* centerY = */ mAppBarLayout.bottom,
|
||||
/* startRadius = */ 0f,
|
||||
/* endRadius = */ hypot(view.width.toDouble(), view.height.toDouble()).toFloat(),
|
||||
/* endRadius = */ hypot(mAppBarLayout.width.toDouble(), mAppBarLayout.height.toDouble()).toFloat(),
|
||||
).apply {
|
||||
duration = 500L
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun setColor(colorTo: Int) {
|
||||
mAppBarContainer.setBackgroundColor(currentColor)
|
||||
mAppBarLayout.setBackgroundColor(colorTo)
|
||||
currentColor = colorTo
|
||||
|
||||
initThemeColors()
|
||||
updateToolbarIconsColor()
|
||||
mToolbar.subtitle = getSubtitle()
|
||||
}
|
||||
|
||||
protected fun setUpAppBar(appBar: AppBarLayout, appBarContainer: RevealFrameLayout) {
|
||||
mAppBarLayout = appBar.apply { setBackgroundColor(currentColor) }
|
||||
mAppBarContainer = appBarContainer
|
||||
}
|
||||
|
||||
class ColorItem(var name: String, var themeColor: ThemeColor) {
|
||||
constructor(name: String, color: Int) : this(name, ThemeColor(color))
|
||||
}
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(v: View?, position: Int)
|
||||
}
|
||||
@@ -122,11 +117,13 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
|
||||
val KEY_CUSTOM_COLOR = "${ColorSettingRecyclerView::class.java.name}.COLOR_SETTING_CUSTOM_COLOR"
|
||||
val KEY_SELECTED_COLOR_INDEX = "${ColorSettingRecyclerView::class.java.name}.SELECTED_COLOR_INDEX"
|
||||
val KEY_SELECTED_COLOR_LIBRARY_ID = "${ColorSettingRecyclerView::class.java.name}.SELECTED_COLOR_LIBRARY_ID"
|
||||
val KEY_SELECTED_COLOR_LIBRARY_ITEM_ID = "${ColorSettingRecyclerView::class.java.name}.SELECTED_COLOR_LIBRARY_ITEM_ID"
|
||||
|
||||
val customColorPosition: Int
|
||||
get() = /* return mColors.size() - 1; */ 0
|
||||
|
||||
private val defaultColorPosition: Int
|
||||
val defaultColorPosition: Int
|
||||
get() = customColorPosition + 1
|
||||
|
||||
var isLegacyLayout: Boolean
|
||||
@@ -135,7 +132,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
|
||||
val colorItems by lazy {
|
||||
mutableListOf<Pair</* colorRes */ Int, /* nameRes */ Int>>().apply {
|
||||
add(customColorPosition, 0 to R.string.mt_custom)
|
||||
add(customColorPosition, R.color.custom_color_default to R.string.mt_custom)
|
||||
add(defaultColorPosition, R.color.theme_color_default to R.string.theme_color_default)
|
||||
addAll(ColorItems.MATERIAL_COLORS)
|
||||
}
|
||||
@@ -144,8 +141,8 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
@JvmStatic
|
||||
fun startActivity(context: Context) {
|
||||
val cls = when (isLegacyLayout) {
|
||||
true -> ColorSelectLegacyActivity::class.java
|
||||
else -> ColorSelectActivity::class.java
|
||||
true -> ColorSelectActivity::class.java
|
||||
else -> ColorLibrariesActivity::class.java
|
||||
}
|
||||
val titleRes = when (isLegacyLayout) {
|
||||
true -> R.string.mt_color_picker_title
|
||||
@@ -156,22 +153,80 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
}
|
||||
if (context is ColorSelectBaseActivity) {
|
||||
intent.putExtra("currentColor", context.currentColor)
|
||||
context.finishWithoutSaving()
|
||||
context.finish()
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getCurrentColorSummary(context: Context): String {
|
||||
val index = Pref.getInt(KEY_SELECTED_COLOR_INDEX, defaultColorPosition)
|
||||
val colorItem = colorItems[index]
|
||||
val (colorRes, nameRes) = colorItem
|
||||
val name = context.getString(nameRes)
|
||||
val colorInt = when (index) {
|
||||
customColorPosition -> Pref.getInt(KEY_CUSTOM_COLOR, context.getColor(R.color.md_blue_grey_800))
|
||||
else -> context.getColor(colorRes)
|
||||
fun getCurrentColorSummary(context: Context, isBrief: Boolean = false): String = when {
|
||||
isLegacyLayout -> when (val index = Pref.getInt(KEY_SELECTED_COLOR_INDEX, defaultColorPosition)) {
|
||||
SELECT_NONE -> {
|
||||
val colorInt = ThemeColorManager.colorPrimary
|
||||
ColorUtils.toString(colorInt).uppercase()
|
||||
}
|
||||
else -> {
|
||||
val colorItem = colorItems[index]
|
||||
val (colorRes, nameRes) = colorItem
|
||||
val name = context.getString(nameRes)
|
||||
val colorInt = when (index) {
|
||||
customColorPosition -> Pref.getInt(KEY_CUSTOM_COLOR, context.getColor(R.color.custom_color_default))
|
||||
else -> context.getColor(colorRes)
|
||||
}
|
||||
"$name [${ColorUtils.toString(colorInt).uppercase()}]"
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
var identifier: String? = null
|
||||
var colorName: String? = null
|
||||
val colorInt = ThemeColorManager.colorPrimary
|
||||
val libraryId = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)
|
||||
val libraryItemId = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, SELECT_NONE)
|
||||
when (libraryId) {
|
||||
COLOR_LIBRARY_CUSTOM_COLOR_ID -> {
|
||||
identifier = context.getString(R.string.mt_custom)
|
||||
}
|
||||
SELECT_NONE -> {
|
||||
val legacyIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||
when (legacyIndex) {
|
||||
customColorPosition -> identifier = context.getString(R.string.color_library_identifier_custom)
|
||||
SELECT_NONE, defaultColorPosition -> identifier = context.getString(R.string.color_library_identifier_default_colors)
|
||||
else -> {
|
||||
val calculatedIndex = legacyIndex - maxOf(customColorPosition, defaultColorPosition) - 1
|
||||
if (calculatedIndex in ColorItems.MATERIAL_COLORS.indices) {
|
||||
val (_, nameRes) = ColorItems.MATERIAL_COLORS[calculatedIndex]
|
||||
identifier = context.getString(R.string.color_library_identifier_material_design_colors)
|
||||
colorName = context.getString(nameRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> colorLibraries.find { it.id == libraryId }?.let { lib ->
|
||||
identifier = when {
|
||||
lib.isUserDefined -> context.getString(R.string.color_library_identifier_custom)
|
||||
else -> lib.identifierRes?.let { resId -> context.getString(resId) }
|
||||
}
|
||||
if (libraryItemId != -1) {
|
||||
lib.colors.find { it.id == libraryItemId }?.let { item ->
|
||||
colorName = item.nameString
|
||||
?: item.nameRes.takeUnless {
|
||||
it == R.string.text_unknown
|
||||
}?.let { context.getString(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val colorString = ColorUtils.toString(colorInt).uppercase()
|
||||
when {
|
||||
identifier != null && colorName != null -> when {
|
||||
isBrief -> "$colorName [$colorString]"
|
||||
else -> "$identifier | $colorName [$colorString]"
|
||||
}
|
||||
identifier != null -> "$identifier | $colorString"
|
||||
colorName != null -> "$colorName [$colorString]"
|
||||
else -> colorString
|
||||
}
|
||||
}
|
||||
return "$name [${ColorUtils.toString(colorInt).uppercase()}]"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package org.autojs.autojs.theme.app
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.MtActivityColorSelectLegacyBinding
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on Mar 20, 2025.
|
||||
*/
|
||||
class ColorSelectLegacyActivity : ColorSelectBaseActivity() {
|
||||
|
||||
private lateinit var binding: MtActivityColorSelectLegacyBinding
|
||||
|
||||
private lateinit var mColorSettingRecyclerView: ColorSettingRecyclerViewLegacy
|
||||
|
||||
private val mOnItemClickListener = object : OnItemClickListener {
|
||||
override fun onItemClick(v: View?, position: Int) {
|
||||
mColorSettingRecyclerView.selectedThemeColor?.let {
|
||||
setColorWithAnimation(it.colorPrimary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
MtActivityColorSelectLegacyBinding.inflate(layoutInflater).also {
|
||||
binding = it
|
||||
setContentView(it.root)
|
||||
setUpToolbar(it.toolbar)
|
||||
setUpColorSettingRecyclerView(it.colorSettingRecyclerView)
|
||||
setUpAppBar(it.appBar, it.appBarContainer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpColorSettingRecyclerView(colorSettingRecyclerView: ColorSettingRecyclerViewLegacy) {
|
||||
mColorSettingRecyclerView = colorSettingRecyclerView.apply {
|
||||
setSelectedColor(currentColor)
|
||||
setOnItemClickListener(mOnItemClickListener)
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
mColorSettingRecyclerView.selectedThemeColor?.let {
|
||||
ThemeColorManager.setThemeColor(it.colorPrimary)
|
||||
Pref.putString(key(R.string.key_theme_color), getCurrentColorSummary(this))
|
||||
ThemeChangeNotifier.notifyThemeChanged()
|
||||
}
|
||||
super.finish()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_color_select_legacy, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_toggle_color_select_layout -> {
|
||||
isLegacyLayout = false
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,16 +9,29 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.ThemeColorRecyclerView
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs.theme.ThemeColorHelper
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_CUSTOM_COLOR_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_DEFAULT_COLORS_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_MATERIAL_COLORS_ID
|
||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.KEY_SELECTED_COLOR_INDEX
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.KEY_SELECTED_COLOR_LIBRARY_ID
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.KEY_SELECTED_COLOR_LIBRARY_ITEM_ID
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.SELECT_NONE
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.colorItems
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.customColorPosition
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.defaultColorPosition
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
|
||||
class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
@@ -31,17 +44,17 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
|
||||
private var mOnItemClickListener: ColorSelectBaseActivity.OnItemClickListener? = null
|
||||
|
||||
private var mSelectedPosition = ColorSelectBaseActivity.SELECT_NONE
|
||||
private var mSelectedPosition = SELECT_NONE
|
||||
|
||||
val selectedThemeColor: ThemeColor?
|
||||
get() = when {
|
||||
mSelectedPosition < 0 -> null
|
||||
mSelectedPosition == customColorPosition -> customColor
|
||||
else -> context.getColor(ColorSelectBaseActivity.colorItems[mSelectedPosition].first)
|
||||
else -> context.getColor(colorItems[mSelectedPosition].first)
|
||||
}?.let { ThemeColor(it) }
|
||||
|
||||
private val customColor: Int
|
||||
get() = Pref.getInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, context.getColor(R.color.md_blue_grey_800))
|
||||
get() = Pref.getInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, context.getColor(R.color.custom_color_default))
|
||||
|
||||
private val mActualOnItemClickListener = OnClickListener { v ->
|
||||
getChildViewHolder(v)?.let { holder ->
|
||||
@@ -63,7 +76,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setSelectedPosition(currentPosition: Int) {
|
||||
if (mSelectedPosition != ColorSelectBaseActivity.SELECT_NONE) {
|
||||
if (mSelectedPosition != SELECT_NONE) {
|
||||
adapter!!.notifyItemChanged(mSelectedPosition)
|
||||
mSelectedPosition = currentPosition
|
||||
adapter!!.notifyItemChanged(currentPosition)
|
||||
@@ -71,21 +84,53 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
mSelectedPosition = currentPosition
|
||||
adapter!!.notifyDataSetChanged()
|
||||
}
|
||||
Pref.putInt(ColorSelectBaseActivity.KEY_SELECTED_COLOR_INDEX, mSelectedPosition)
|
||||
savePrefsForLegacy()
|
||||
savePrefsForLibraries()
|
||||
selectedThemeColor?.let {
|
||||
ThemeColorManager.setThemeColor(it.colorPrimary)
|
||||
ThemeChangeNotifier.notifyThemeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun setSelectedColor(colorPrimary: Int) {
|
||||
for ((i, colorItem) in ColorSelectBaseActivity.colorItems.withIndex()) {
|
||||
val color = when (i) {
|
||||
customColorPosition -> customColor
|
||||
else -> context.getColor(colorItem.first)
|
||||
private fun savePrefsForLegacy() {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, mSelectedPosition)
|
||||
}
|
||||
|
||||
private fun savePrefsForLibraries() {
|
||||
when (mSelectedPosition) {
|
||||
0 -> {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, COLOR_LIBRARY_CUSTOM_COLOR_ID)
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, 0)
|
||||
}
|
||||
if (color == colorPrimary) {
|
||||
setSelectedPosition(i)
|
||||
return
|
||||
1 -> {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, COLOR_LIBRARY_DEFAULT_COLORS_ID)
|
||||
colorLibraries.find { it.id == COLOR_LIBRARY_DEFAULT_COLORS_ID }!!.colors.find { colorItem ->
|
||||
context.getColor(colorItem.colorRes) == context.getColor(R.color.theme_color_default)
|
||||
}?.let { Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, it.id) }
|
||||
}
|
||||
else -> {
|
||||
selectedThemeColor?.colorPrimary?.let { c ->
|
||||
colorLibraries.find { it.id == COLOR_LIBRARY_MATERIAL_COLORS_ID }!!.colors.find { colorItem ->
|
||||
context.getColor(colorItem.colorRes) == c
|
||||
}?.let {
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, COLOR_LIBRARY_MATERIAL_COLORS_ID)
|
||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, it.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mSelectedPosition = ColorSelectBaseActivity.SELECT_NONE
|
||||
}
|
||||
|
||||
fun setUpSelectedPosition(currentColor: Int) {
|
||||
val selectedIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||
colorItems.getOrNull(selectedIndex)?.let {
|
||||
setSelectedPosition(selectedIndex)
|
||||
} ?: when (currentColor) {
|
||||
context.getColor(R.color.theme_color_default) -> {
|
||||
setSelectedPosition(defaultColorPosition)
|
||||
}
|
||||
else -> mSelectedPosition = SELECT_NONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun showColorPicker(v: View) {
|
||||
@@ -97,13 +142,13 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
.setDialogTitle(R.string.mt_color_picker_title)
|
||||
.setColor(customColor)
|
||||
.create()
|
||||
.setColorPickerDialogListener { _: Int, color: Int ->
|
||||
val customColor = color or -0x1000000
|
||||
Pref.putInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, customColor)
|
||||
.setColorPickerDialogListener { dialogId: Int, color: Int ->
|
||||
val c = color or -0x1000000
|
||||
Pref.putInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, c)
|
||||
setSelectedPosition(customColorPosition)
|
||||
mOnItemClickListener?.onItemClick(v, customColorPosition)
|
||||
}
|
||||
.show((context as ColorSelectBaseActivity).supportFragmentManager, "ColorPickerTag")
|
||||
.show((context as FragmentActivity).supportFragmentManager, "ColorPickerTagForColorSelect")
|
||||
}
|
||||
|
||||
fun setOnItemClickListener(onItemClickListener: ColorSelectBaseActivity.OnItemClickListener?) {
|
||||
@@ -117,7 +162,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val colorItem = ColorSelectBaseActivity.colorItems[position]
|
||||
val colorItem = colorItems[position]
|
||||
val (colorRes, nameRes) = colorItem
|
||||
val color = when (position) {
|
||||
customColorPosition -> customColor
|
||||
@@ -131,7 +176,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = ColorSelectBaseActivity.colorItems.size
|
||||
override fun getItemCount() = colorItems.size
|
||||
|
||||
}
|
||||
|
||||
@@ -150,7 +195,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
||||
if (checked) {
|
||||
colorView.setImageResource(R.drawable.mt_ic_check_white_36dp)
|
||||
val selectedThemeColorRes = selectedThemeColor?.colorPrimary?.let {
|
||||
if (ColorUtils.isLuminanceLight(it)) R.color.day else R.color.night
|
||||
if (ViewUtils.isLuminanceLight(it)) R.color.day else R.color.night
|
||||
} ?: R.color.night_day
|
||||
colorView.imageTintList = ColorStateList.valueOf(context.getColor(selectedThemeColorRes))
|
||||
} else {
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
package org.autojs.autojs.theme.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.ThemeColorRecyclerView
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs.theme.ThemeColorHelper
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.customColorPosition
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs6.R
|
||||
|
||||
class ColorSettingRecyclerViewLegacy : ThemeColorRecyclerView {
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
|
||||
|
||||
private var mOnItemClickListener: ColorSelectBaseActivity.OnItemClickListener? = null
|
||||
|
||||
private var mSelectedPosition = ColorSelectBaseActivity.SELECT_NONE
|
||||
|
||||
val selectedThemeColor: ThemeColor?
|
||||
get() = when {
|
||||
mSelectedPosition < 0 -> null
|
||||
mSelectedPosition == customColorPosition -> customColor
|
||||
else -> context.getColor(ColorSelectBaseActivity.colorItems[mSelectedPosition].first)
|
||||
}?.let { ThemeColor(it) }
|
||||
|
||||
private val customColor: Int
|
||||
get() = Pref.getInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, context.getColor(R.color.md_blue_grey_800))
|
||||
|
||||
private val mActualOnItemClickListener = OnClickListener { v ->
|
||||
getChildViewHolder(v)?.let { holder ->
|
||||
when (val pos = holder.bindingAdapterPosition) {
|
||||
customColorPosition -> showColorPicker(v)
|
||||
else -> {
|
||||
setSelectedPosition(pos)
|
||||
mOnItemClickListener?.onItemClick(v, pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
adapter = Adapter()
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(DividerItemDecoration(context, VERTICAL))
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setSelectedPosition(currentPosition: Int) {
|
||||
if (mSelectedPosition != ColorSelectBaseActivity.SELECT_NONE) {
|
||||
adapter!!.notifyItemChanged(mSelectedPosition)
|
||||
mSelectedPosition = currentPosition
|
||||
adapter!!.notifyItemChanged(currentPosition)
|
||||
} else {
|
||||
mSelectedPosition = currentPosition
|
||||
adapter!!.notifyDataSetChanged()
|
||||
}
|
||||
Pref.putInt(ColorSelectBaseActivity.KEY_SELECTED_COLOR_INDEX, mSelectedPosition)
|
||||
}
|
||||
|
||||
fun setSelectedColor(colorPrimary: Int) {
|
||||
for ((i, colorItem) in ColorSelectBaseActivity.colorItems.withIndex()) {
|
||||
val color = when (i) {
|
||||
customColorPosition -> customColor
|
||||
else -> context.getColor(colorItem.first)
|
||||
}
|
||||
if (color == colorPrimary) {
|
||||
setSelectedPosition(i)
|
||||
return
|
||||
}
|
||||
}
|
||||
mSelectedPosition = ColorSelectBaseActivity.SELECT_NONE
|
||||
}
|
||||
|
||||
private fun showColorPicker(v: View) {
|
||||
ColorPickerDialog.newBuilder()
|
||||
.setAllowCustom(true)
|
||||
.setAllowPresets(false)
|
||||
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
|
||||
.setShowAlphaSlider(false)
|
||||
.setDialogTitle(R.string.mt_color_picker_title)
|
||||
.setColor(customColor)
|
||||
.create()
|
||||
.apply {
|
||||
setColorPickerDialogListener(object : ColorPickerDialogListener {
|
||||
override fun onColorSelected(dialogId: Int, @ColorInt color: Int) {
|
||||
val c = color or -0x1000000
|
||||
Pref.putInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, c)
|
||||
setSelectedPosition(customColorPosition)
|
||||
mOnItemClickListener?.onItemClick(v, customColorPosition)
|
||||
}
|
||||
|
||||
override fun onDialogDismissed(dialogId: Int) {}
|
||||
})
|
||||
}
|
||||
.show((context as FragmentActivity).supportFragmentManager, "Tag")
|
||||
}
|
||||
|
||||
fun setOnItemClickListener(onItemClickListener: ColorSelectBaseActivity.OnItemClickListener?) {
|
||||
mOnItemClickListener = onItemClickListener
|
||||
}
|
||||
|
||||
private inner class Adapter : RecyclerView.Adapter<ViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.mt_color_setting_recycler_view_item, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val colorItem = ColorSelectBaseActivity.colorItems[position]
|
||||
val (colorRes, nameRes) = colorItem
|
||||
val color = when (position) {
|
||||
customColorPosition -> customColor
|
||||
else -> context.getColor(colorRes)
|
||||
}
|
||||
holder.apply {
|
||||
setColor(color)
|
||||
nameView.text = context.getString(nameRes)
|
||||
nameView.setTextColor(context.getColor(R.color.color_selector_item_text))
|
||||
setChecked(mSelectedPosition == position)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = ColorSelectBaseActivity.colorItems.size
|
||||
|
||||
}
|
||||
|
||||
private inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
var colorView: ImageView
|
||||
var nameView: TextView
|
||||
|
||||
init {
|
||||
itemView.setOnClickListener(mActualOnItemClickListener)
|
||||
colorView = itemView.findViewById(R.id.color)
|
||||
nameView = itemView.findViewById(R.id.name)
|
||||
}
|
||||
|
||||
fun setChecked(checked: Boolean) {
|
||||
if (checked) {
|
||||
colorView.setImageResource(R.drawable.mt_ic_check_white_36dp)
|
||||
val selectedThemeColorRes = selectedThemeColor?.colorPrimary?.let {
|
||||
if (ColorUtils.isLuminanceLight(it)) R.color.day else R.color.night
|
||||
} ?: R.color.night_day
|
||||
colorView.imageTintList = ColorStateList.valueOf(context.getColor(selectedThemeColorRes))
|
||||
} else {
|
||||
colorView.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
|
||||
fun setColor(c: Int) = ThemeColorHelper.setBackgroundColor(colorView, c)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package org.autojs.autojs.theme.widget;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.autojs.autojs.theme.ThemeColor;
|
||||
import org.autojs.autojs.theme.ThemeColorManager;
|
||||
import org.autojs.autojs.theme.ThemeColorMutable;
|
||||
import org.autojs.autojs.util.ColorUtils;
|
||||
import org.autojs.autojs.util.ViewUtils;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ public class ThemeColorFloatingActionButton extends FloatingActionButton impleme
|
||||
int colorAccent = color.colorAccent;
|
||||
int colorForContrast = ColorUtils.adjustColorForContrast(getContext().getColor(R.color.window_background), colorAccent, 1.15);
|
||||
setBackgroundTintList(ColorStateList.valueOf(colorForContrast));
|
||||
var tintColorRes = ColorUtils.isLuminanceLight(colorForContrast)
|
||||
var tintColorRes = ViewUtils.isLuminanceLight(colorForContrast)
|
||||
? R.color.fab_tint_dark
|
||||
: R.color.fab_tint_light;
|
||||
var tintColor = getResources().getColor(tintColorRes, null);
|
||||
|
||||
@@ -5,9 +5,8 @@ import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs.theme.ThemeColorManager.add
|
||||
import org.autojs.autojs.theme.ThemeColorManager.getDayOrNightColorByLuminance
|
||||
import org.autojs.autojs.theme.ThemeColorManager.isThemeColorLuminanceLight
|
||||
import org.autojs.autojs.theme.ThemeColorMutable
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs.util.ViewUtils.applyColorFilterWith
|
||||
import org.autojs.autojs.util.ViewUtils.onceGlobalLayout
|
||||
import org.autojs.autojs6.R
|
||||
@@ -36,21 +35,22 @@ open class ThemeColorToolbar : Toolbar, ThemeColorMutable {
|
||||
setTitleTextAppearance(context, R.style.TextAppearanceMainTitle)
|
||||
}
|
||||
|
||||
override fun setThemeColor(color: ThemeColor) {
|
||||
onceGlobalLayout { applyThemeColor(color) }
|
||||
override fun setThemeColor(themeColor: ThemeColor) {
|
||||
onceGlobalLayout { applyThemeColor(themeColor) }
|
||||
}
|
||||
|
||||
private fun applyThemeColor(color: ThemeColor) {
|
||||
val aimColor = getDayOrNightColorByLuminance(context)
|
||||
private fun applyThemeColor(themeColor: ThemeColor) {
|
||||
val currentThemeColor = themeColor.colorPrimary
|
||||
val tintColor = ViewUtils.getDayOrNightColorByLuminance(context, currentThemeColor)
|
||||
|
||||
setBackgroundColor(color.colorPrimary)
|
||||
setTitleTextColor(aimColor)
|
||||
setSubtitleTextColor(aimColor)
|
||||
setBackgroundColor(currentThemeColor)
|
||||
setTitleTextColor(tintColor)
|
||||
setSubtitleTextColor(tintColor)
|
||||
|
||||
navigationIcon?.let { navigationIcon = it.applyColorFilterWith(aimColor) }
|
||||
collapseIcon?.let { collapseIcon = it.applyColorFilterWith(aimColor) }
|
||||
overflowIcon?.let { overflowIcon = it.applyColorFilterWith(aimColor) }
|
||||
navigationIcon?.let { navigationIcon = it.applyColorFilterWith(tintColor) }
|
||||
collapseIcon?.let { collapseIcon = it.applyColorFilterWith(tintColor) }
|
||||
overflowIcon?.let { overflowIcon = it.applyColorFilterWith(tintColor) }
|
||||
|
||||
popupTheme = if (isThemeColorLuminanceLight()) R.style.PopupMenuThemeLight else R.style.PopupMenuThemeDark
|
||||
popupTheme = if (ViewUtils.isLuminanceLight(currentThemeColor)) R.style.PopupMenuThemeLight else R.style.PopupMenuThemeDark
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.LocaleUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.BuildConfig
|
||||
import org.autojs.autojs6.R
|
||||
|
||||
/**
|
||||
@@ -48,6 +47,10 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
|
||||
ThemeChangeNotifier.themeChanged.observe(this) {
|
||||
initThemeColors()
|
||||
if (handleStatusBarThemeColorAutomatically) {
|
||||
ThemeColorManager.setStatusBarBackgroundColor(this)
|
||||
setUpStatusBarAppearanceLightByThemeColor()
|
||||
}
|
||||
}
|
||||
|
||||
// @Dubious by SuperMonster003 on Oct 28, 2024.
|
||||
@@ -71,7 +74,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
initThemeColors()
|
||||
if (handleStatusBarThemeColorAutomatically && !BuildConfig.isInrt) {
|
||||
if (handleStatusBarThemeColorAutomatically) {
|
||||
ThemeColorManager.addActivityStatusBar(this)
|
||||
setUpStatusBarAppearanceLightByThemeColor()
|
||||
}
|
||||
@@ -95,7 +98,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
protected fun setUpStatusBarAppearanceLightByThemeColor() {
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ThemeColorManager.isThemeColorLuminanceDark())
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ThemeColorManager.isLuminanceDark())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,9 +5,6 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@@ -65,6 +62,9 @@ import org.autojs.autojs.ui.widget.SearchViewItem
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs.util.UpdateUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs.util.ViewUtils.onceGlobalLayout
|
||||
import org.autojs.autojs.util.ViewUtils.setMenuIconsColorByThemeColorLuminance
|
||||
import org.autojs.autojs.util.ViewUtils.setNavigationIconColorByThemeColorLuminance
|
||||
import org.autojs.autojs.util.WorkingDirectoryUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.ActivityMainBinding
|
||||
@@ -278,7 +278,8 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
}
|
||||
|
||||
private fun setUpToolbarColors() {
|
||||
ViewUtils.setToolbarMenuIconsColorByThemeColorLuminance(this, mToolbar)
|
||||
mToolbar.setMenuIconsColorByThemeColorLuminance(this)
|
||||
mToolbar.setNavigationIconColorByThemeColorLuminance(this)
|
||||
mSearchViewItem?.initThemeColors()
|
||||
}
|
||||
|
||||
@@ -287,7 +288,7 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
val tabSelectedColor: Int
|
||||
val tabSelectedIndicatorColor: Int
|
||||
when {
|
||||
ThemeColorManager.isThemeColorLuminanceLight() -> {
|
||||
ThemeColorManager.isLuminanceLight() -> {
|
||||
tabNormalColor = getColor(R.color.tab_text_dark)
|
||||
tabSelectedColor = getColor(R.color.tab_selected_text_dark)
|
||||
tabSelectedIndicatorColor = getColor(R.color.tab_indicator_dark)
|
||||
@@ -399,11 +400,11 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
private fun setUpSearchMenuItem(searchMenuItem: MenuItem) {
|
||||
mSearchViewItem = object : SearchViewItem(this, searchMenuItem) {
|
||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||
setUpToolbarCollapseIconColor()
|
||||
if (isCurrentPageDocs) {
|
||||
mDocsSearchItemExpanded = true
|
||||
mLogMenuItem.setIcon(R.drawable.ic_ali_up)
|
||||
}
|
||||
mToolbar.onceGlobalLayout { setUpToolbarColors() }
|
||||
return super.onMenuItemActionExpand(item)
|
||||
}
|
||||
|
||||
@@ -431,18 +432,6 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpToolbarCollapseIconColor() {
|
||||
val collapseIcon = mToolbar.collapseIcon
|
||||
if (collapseIcon != null) {
|
||||
val isThemeColorLuminanceLight = ThemeColorManager.isThemeColorLuminanceLight()
|
||||
val fullColor = getColor(if (isThemeColorLuminanceLight) R.color.day_full else R.color.night_full)
|
||||
collapseIcon.setTintList(ColorStateList.valueOf(fullColor))
|
||||
collapseIcon.setTint(fullColor)
|
||||
collapseIcon.colorFilter = PorterDuffColorFilter(fullColor, PorterDuff.Mode.SRC_IN)
|
||||
mToolbar.collapseIcon = collapseIcon
|
||||
}
|
||||
}
|
||||
|
||||
private fun submitForwardQuery() {
|
||||
val event = QueryEvent.FIND_FORWARD
|
||||
EventBus.getDefault().post(event)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.autojs.autojs.ui.main.drawer
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
@@ -29,6 +30,7 @@ import org.autojs.autojs.pluginclient.JsonSocketServer
|
||||
import org.autojs.autojs.service.AccessibilityService
|
||||
import org.autojs.autojs.service.ForegroundService
|
||||
import org.autojs.autojs.service.NotificationService
|
||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity
|
||||
import org.autojs.autojs.ui.floating.CircularMenu
|
||||
import org.autojs.autojs.ui.floating.FloatyWindowManger
|
||||
@@ -102,6 +104,12 @@ open class DrawerFragment : Fragment() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
ThemeChangeNotifier.themeChanged.observe(this) {
|
||||
mThemeColorItem.subtitle = ColorSelectBaseActivity.getCurrentColorSummary(mContext)
|
||||
mDrawerMenu.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
mContext = requireContext()
|
||||
|
||||
mActivity = requireActivity() as MainActivity
|
||||
|
||||
@@ -24,7 +24,6 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import org.autojs.autojs.ui.BaseActivity
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.DisplayUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
@@ -41,7 +40,7 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
abstract var highlightGrammarName: String
|
||||
abstract var highlightThemeLanguage: String
|
||||
|
||||
open var themeColorDayNight = R.color.md_blue_grey_50 to R.color.md_blue_grey_900
|
||||
open var themeColorDayNight = R.color.md_blue_gray_50 to R.color.md_blue_gray_900
|
||||
|
||||
private lateinit var internalTextView: TextView
|
||||
private lateinit var internalFabView: FloatingActionButton
|
||||
@@ -145,14 +144,14 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
|
||||
if (ViewUtils.isNightModeYes(this)) {
|
||||
internalFabView.backgroundTintList = ColorStateList.valueOf(themeColorNight)
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ColorUtils.isLuminanceDark(themeColorNight)) getColor(R.color.night) else getColor(R.color.day))
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ViewUtils.isLuminanceDark(themeColorNight)) getColor(R.color.night) else getColor(R.color.day))
|
||||
ViewUtils.setStatusBarBackgroundColor(this, themeColorNight)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ColorUtils.isLuminanceDark(themeColorNight))
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ViewUtils.isLuminanceDark(themeColorNight))
|
||||
} else {
|
||||
internalFabView.backgroundTintList = ColorStateList.valueOf(themeColorDay)
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ColorUtils.isLuminanceDark(themeColorDay)) getColor(R.color.night) else getColor(R.color.day))
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ViewUtils.isLuminanceDark(themeColorDay)) getColor(R.color.night) else getColor(R.color.day))
|
||||
ViewUtils.setStatusBarBackgroundColor(this, themeColorDay)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ColorUtils.isLuminanceDark(themeColorDay))
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ViewUtils.isLuminanceDark(themeColorDay))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.theme.ThemeColorManagerCompat
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.FileUtils
|
||||
import org.autojs.autojs6.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SearchViewItem implements MenuItemCompat.OnActionExpandListener, Se
|
||||
}
|
||||
|
||||
public void initThemeColors() {
|
||||
boolean isThemeColorLuminanceLight = ThemeColorManager.isThemeColorLuminanceLight();
|
||||
boolean isThemeColorLuminanceLight = ThemeColorManager.isLuminanceLight();
|
||||
int fullColor = mActivity.getColor(isThemeColorLuminanceLight ? R.color.day_full : R.color.night_full);
|
||||
int hintColor = mActivity.getColor(isThemeColorLuminanceLight ? R.color.day : R.color.night);
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ class ToolbarMenuItem : LinearLayout {
|
||||
}
|
||||
|
||||
private val colorEnabled: Int
|
||||
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
|
||||
get() = when (ThemeColorManager.isLuminanceLight()) {
|
||||
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_dark)
|
||||
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_light)
|
||||
}
|
||||
|
||||
private val colorDisabled: Int
|
||||
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
|
||||
get() = when (ThemeColorManager.isLuminanceLight()) {
|
||||
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_dark)
|
||||
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_light)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import androidx.core.graphics.ColorUtils
|
||||
import org.autojs.autojs.app.GlobalAppContext
|
||||
import org.autojs.autojs.core.image.ColorTable
|
||||
import org.autojs.autojs.theme.ThemeColor
|
||||
import org.autojs.autojs6.R
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.text.RegexOption.IGNORE_CASE
|
||||
@@ -281,7 +280,7 @@ object ColorUtils {
|
||||
* </a>
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isLuminanceLight(@ColorInt color: Int) = luminance(color) > 0.179
|
||||
fun isLuminanceLight(@ColorInt color: Int) = luminance(color) >= 0.179
|
||||
|
||||
@JvmStatic
|
||||
fun isLuminanceDark(@ColorInt color: Int) = !isLuminanceLight(color)
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.R.color.day
|
||||
import org.autojs.autojs6.R.color.night
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -170,6 +172,28 @@ object ViewUtils {
|
||||
activity.window.addFlags(flags)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun isLuminanceLight(color: Int, backgroundColorMatters: Boolean = true) = when {
|
||||
!backgroundColorMatters -> ColorUtils.isLuminanceLight(color)
|
||||
!isNightModeEnabled -> ColorUtils.luminance(color) >= 0.224
|
||||
else -> ColorUtils.luminance(color) >= 0.141
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun isLuminanceDark(color: Int, backgroundColorMatters: Boolean = true) = !isLuminanceLight(color, backgroundColorMatters)
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorByLuminance(context: Context, color: Int): Int {
|
||||
return context.getColor(if (isLuminanceLight(color)) day else night)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorResByLuminance(color: Int): Int {
|
||||
return if (isLuminanceLight(color)) day else night
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isStatusBarAppearanceLight(activity: Activity): Boolean {
|
||||
return !isStatusBarAppearanceDark(activity)
|
||||
@@ -191,7 +215,7 @@ object ViewUtils {
|
||||
}
|
||||
|
||||
fun setStatusBarAppearanceLightByColorLuminance(activity: Activity, aimColor: Int) {
|
||||
val shouldBeLight = ColorUtils.isLuminanceDark(aimColor)
|
||||
val shouldBeLight = isLuminanceDark(aimColor)
|
||||
setStatusBarAppearanceLight(activity, shouldBeLight)
|
||||
}
|
||||
|
||||
@@ -472,14 +496,6 @@ object ViewUtils {
|
||||
toolbar.setTitlesTextColorByColorLuminance(context, aimColor)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorByLuminance(context: Context, aimColor: Int): Int = context.getColor(getDayOrNightColorResByLuminance(aimColor))
|
||||
|
||||
@JvmStatic
|
||||
fun getDayOrNightColorResByLuminance(aimColor: Int): Int {
|
||||
return if (ColorUtils.isLuminanceLight(aimColor)) R.color.day else R.color.night
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun showToast(context: Context, stringRes: Int) = showToast(context, stringRes, false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user