6.6.2 - Alpha5 - 主题色设置页面新布局支持定位功能
This commit is contained in:
@@ -11,7 +11,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
@@ -57,7 +56,7 @@ class ColorLibrariesActivity : ColorSelectBaseActivity() {
|
|||||||
it.layoutManager = LinearLayoutManager(this)
|
it.layoutManager = LinearLayoutManager(this)
|
||||||
it.adapter = ColorLibraryAdapter(colorLibraries) { library ->
|
it.adapter = ColorLibraryAdapter(colorLibraries) { library ->
|
||||||
val intent = Intent(this, ColorLibraryActivity::class.java)
|
val intent = Intent(this, ColorLibraryActivity::class.java)
|
||||||
intent.putExtra("LIBRARY_ID", library.id)
|
intent.putExtra(INTENT_IDENTIFIER_LIBRARY_ID, library.id)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}.also { mAdapter = it }
|
}.also { mAdapter = it }
|
||||||
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
||||||
@@ -98,10 +97,6 @@ class ColorLibrariesActivity : ColorSelectBaseActivity() {
|
|||||||
mAdapter.updateData(filteredLibraries)
|
mAdapter.updateData(filteredLibraries)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定位功能可以通过工具栏中的 "action_locate_current_theme_color" 按钮实现,
|
|
||||||
// 按钮点击后找到包含当前主题色的颜色库在列表中的位置,
|
|
||||||
// 然后调用 RecyclerView 的 scrollToPosition() 方法跳转到该项
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||||
R.id.action_color_palette -> {
|
R.id.action_color_palette -> {
|
||||||
showColorPicker()
|
showColorPicker()
|
||||||
@@ -157,24 +152,15 @@ class ColorLibrariesActivity : ColorSelectBaseActivity() {
|
|||||||
|
|
||||||
private fun savePrefsForLegacy(color: Int) {
|
private fun savePrefsForLegacy(color: Int) {
|
||||||
Pref.putInt(KEY_CUSTOM_COLOR, color or -0x1000000)
|
Pref.putInt(KEY_CUSTOM_COLOR, color or -0x1000000)
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, customColorPosition)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, customColorPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun locateCurrentThemeColor() {
|
private fun locateCurrentThemeColor() {
|
||||||
// 假设当前主题颜色保存在 ThemeColorManager 中,可以通过它查找对应颜色库
|
checkAndGetTargetInfoForThemeColorLocate()?.let { target ->
|
||||||
val currentColor = ThemeColorManager.colorPrimary
|
Intent(this, ColorLibraryActivity::class.java).apply {
|
||||||
// 简单示例:遍历 colorLibraries,找到第一个包含该颜色的库
|
putExtra(INTENT_IDENTIFIER_LIBRARY_ID, target.libraryId)
|
||||||
val targetIndex = colorLibraries.indexOfFirst { library ->
|
putExtra(INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO, target.libraryItemId)
|
||||||
library.colors.any { colorItem ->
|
}.let { startActivity(it) }
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package org.autojs.autojs.theme.app
|
package org.autojs.autojs.theme.app
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.animation.ArgbEvaluator
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
@@ -14,8 +20,10 @@ import androidx.annotation.ColorInt
|
|||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearSmoothScroller
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.recyclerview.widget.RecyclerView.VERTICAL
|
import androidx.recyclerview.widget.RecyclerView.VERTICAL
|
||||||
|
import androidx.recyclerview.widget.ThemeColorRecyclerView
|
||||||
import org.autojs.autojs.core.image.ColorItems
|
import org.autojs.autojs.core.image.ColorItems
|
||||||
import org.autojs.autojs.core.pref.Pref
|
import org.autojs.autojs.core.pref.Pref
|
||||||
import org.autojs.autojs.theme.ThemeChangeNotifier
|
import org.autojs.autojs.theme.ThemeChangeNotifier
|
||||||
@@ -26,10 +34,14 @@ import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRAR
|
|||||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.ColorItem
|
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.ColorLibrary
|
||||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
||||||
|
import org.autojs.autojs.util.ColorUtils
|
||||||
import org.autojs.autojs.util.ViewUtils
|
import org.autojs.autojs.util.ViewUtils
|
||||||
|
import org.autojs.autojs.util.ViewUtils.onceGlobalLayout
|
||||||
import org.autojs.autojs.util.ViewUtils.setMenuIconsColorByColorLuminance
|
import org.autojs.autojs.util.ViewUtils.setMenuIconsColorByColorLuminance
|
||||||
import org.autojs.autojs6.R
|
import org.autojs.autojs6.R
|
||||||
import org.autojs.autojs6.databinding.MtActivityColorLibraryBinding
|
import org.autojs.autojs6.databinding.MtActivityColorLibraryBinding
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
import androidx.core.graphics.ColorUtils as AndroidColorUtils
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
class ColorLibraryActivity : ColorSelectBaseActivity() {
|
class ColorLibraryActivity : ColorSelectBaseActivity() {
|
||||||
@@ -39,17 +51,21 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
private lateinit var mAdapter: ColorItemAdapter
|
private lateinit var mAdapter: ColorItemAdapter
|
||||||
private lateinit var mLibrary: ColorLibrary
|
private lateinit var mLibrary: ColorLibrary
|
||||||
|
|
||||||
|
private var mInitiallyIdScrollTo by Delegates.notNull<Int>()
|
||||||
|
|
||||||
private var mSelectedPosition = SELECT_NONE
|
private var mSelectedPosition = SELECT_NONE
|
||||||
private var mSelectedColor: Int? = null
|
private var mSelectedColor: Int? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val libraryId = intent.getIntExtra("LIBRARY_ID", -1)
|
val libraryId = intent.getIntExtra(INTENT_IDENTIFIER_LIBRARY_ID, -1)
|
||||||
val library = colorLibraries.find { it.id == libraryId }?.also { lib ->
|
val library = colorLibraries.find { it.id == libraryId }?.also { lib ->
|
||||||
mLibrary = lib
|
mLibrary = lib
|
||||||
} ?: throw RuntimeException("Unknown library id: $libraryId")
|
} ?: throw RuntimeException("Unknown library id: $libraryId")
|
||||||
|
|
||||||
|
mInitiallyIdScrollTo = intent.getIntExtra(INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO, -1)
|
||||||
|
|
||||||
MtActivityColorLibraryBinding.inflate(layoutInflater).let {
|
MtActivityColorLibraryBinding.inflate(layoutInflater).let {
|
||||||
binding = it
|
binding = it
|
||||||
setContentView(it.root)
|
setContentView(it.root)
|
||||||
@@ -91,15 +107,21 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
ThemeColorManager.setThemeColor(selectedColor)
|
ThemeColorManager.setThemeColor(selectedColor)
|
||||||
ThemeChangeNotifier.notifyThemeChanged()
|
ThemeChangeNotifier.notifyThemeChanged()
|
||||||
}.also { mAdapter = it }
|
}.also { mAdapter = it }
|
||||||
|
|
||||||
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
|
||||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
||||||
|
|
||||||
setUpSelectedPosition()
|
setUpSelectedPosition()
|
||||||
|
|
||||||
|
it.onceGlobalLayout {
|
||||||
|
scrollToPositionOnceIfNeeded(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUpSelectedPosition() {
|
private fun setUpSelectedPosition() {
|
||||||
when (Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
|
when (Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
|
||||||
SELECT_NONE -> when (val legacyIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)) {
|
SELECT_NONE -> when (val legacyIndex = Pref.getInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)) {
|
||||||
customColorPosition -> Unit
|
customColorPosition -> Unit
|
||||||
SELECT_NONE, defaultColorPosition -> when (mLibrary.id) {
|
SELECT_NONE, defaultColorPosition -> when (mLibrary.id) {
|
||||||
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
||||||
@@ -122,6 +144,91 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun scrollToPositionOnceIfNeeded(recyclerView: ThemeColorRecyclerView) {
|
||||||
|
if (mInitiallyIdScrollTo < 0) return
|
||||||
|
val targetPosition = mLibrary.colors.indexOfFirst { it.id == mInitiallyIdScrollTo }
|
||||||
|
if (targetPosition < 0) {
|
||||||
|
mInitiallyIdScrollTo = -1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val targetItem = mLibrary.colors[targetPosition]
|
||||||
|
|
||||||
|
if (recyclerView.findViewHolderForAdapterPosition(targetPosition) != null) {
|
||||||
|
highlightColorItem(recyclerView, targetPosition, targetItem)
|
||||||
|
} else {
|
||||||
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||||
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
|
recyclerView.removeOnScrollListener(this)
|
||||||
|
highlightColorItem(recyclerView, targetPosition, targetItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
val layoutManager = recyclerView.layoutManager as? LinearLayoutManager
|
||||||
|
layoutManager?.let { manager ->
|
||||||
|
val smoothScroller = object : LinearSmoothScroller(this) {
|
||||||
|
override fun getVerticalSnapPreference() = SNAP_TO_START
|
||||||
|
}.apply { this.targetPosition = targetPosition }
|
||||||
|
manager.startSmoothScroll(smoothScroller)
|
||||||
|
} ?: recyclerView.smoothScrollToPosition(targetPosition)
|
||||||
|
|
||||||
|
mInitiallyIdScrollTo = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun highlightColorItem(recyclerView: RecyclerView, targetPosition: Int, targetItem: ColorItem) {
|
||||||
|
val viewHolder = recyclerView.findViewHolderForAdapterPosition(targetPosition)
|
||||||
|
viewHolder?.itemView?.let { itemView ->
|
||||||
|
val originalColor = (itemView.background as? ColorDrawable)?.color ?: getColor(R.color.window_background)
|
||||||
|
|
||||||
|
val highlightColor = ColorUtils.adjustColorForContrast(
|
||||||
|
originalColor, getColor(targetItem.colorRes), 1.6,
|
||||||
|
)
|
||||||
|
|
||||||
|
when (val tag = itemView.tag) {
|
||||||
|
!is ValueAnimator -> {
|
||||||
|
startAnimateForSetBackgroundColor(itemView, originalColor, highlightColor, 300, true)
|
||||||
|
}
|
||||||
|
else -> tag.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startAnimateForSetBackgroundColor(view: View, fromColor: Int, toColor: Int, duration: Long, reverse: Boolean = false) {
|
||||||
|
val alpha = 0.3
|
||||||
|
val animator = ValueAnimator.ofObject(
|
||||||
|
ArgbEvaluator(),
|
||||||
|
fromColor.let { AndroidColorUtils.setAlphaComponent(it, (alpha * 255).toInt()) },
|
||||||
|
toColor.let { AndroidColorUtils.setAlphaComponent(it, (alpha * 255).toInt()) },
|
||||||
|
)
|
||||||
|
animator.duration = duration
|
||||||
|
animator.addUpdateListener { animation ->
|
||||||
|
val animatedValue = animation.animatedValue as Int
|
||||||
|
view.setBackgroundColor(animatedValue)
|
||||||
|
}
|
||||||
|
animator.addListener(object : AnimatorListenerAdapter() {
|
||||||
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
|
if (reverse) {
|
||||||
|
view.postDelayed({
|
||||||
|
if (view.tag == null) return@postDelayed
|
||||||
|
startAnimateForSetBackgroundColor(view, toColor, fromColor, 1300)
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
view.tag = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationCancel(animation: Animator) {
|
||||||
|
view.tag = null
|
||||||
|
view.setBackgroundColor(getColor(R.color.window_background))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
view.tag = animator
|
||||||
|
|
||||||
|
animator.start()
|
||||||
|
}
|
||||||
|
|
||||||
private fun savePrefsForLibraries(library: ColorLibrary?, colorItem: ColorItem) {
|
private fun savePrefsForLibraries(library: ColorLibrary?, colorItem: ColorItem) {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, library?.id ?: -1)
|
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ID, library?.id ?: -1)
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, colorItem.id)
|
Pref.putInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, colorItem.id)
|
||||||
@@ -131,25 +238,25 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
when (library?.id) {
|
when (library?.id) {
|
||||||
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
COLOR_LIBRARY_DEFAULT_COLORS_ID -> {
|
||||||
if (getColor(colorItem.colorRes) == getColor(R.color.theme_color_default)) {
|
if (getColor(colorItem.colorRes) == getColor(R.color.theme_color_default)) {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, defaultColorPosition)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, defaultColorPosition)
|
||||||
} else {
|
} else {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
COLOR_LIBRARY_MATERIAL_COLORS_ID -> {
|
COLOR_LIBRARY_MATERIAL_COLORS_ID -> {
|
||||||
val index = colorItem.id
|
val index = colorItem.id
|
||||||
if (index !in ColorItems.MATERIAL_COLORS.indices) {
|
if (index !in ColorItems.MATERIAL_COLORS.indices) {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||||
} else {
|
} else {
|
||||||
val fixedIndex = maxOf(
|
val fixedIndex = maxOf(
|
||||||
defaultColorPosition,
|
defaultColorPosition,
|
||||||
customColorPosition,
|
customColorPosition,
|
||||||
) + 1 + index
|
) + 1 + index
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, fixedIndex)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, fixedIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,12 +303,40 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_locate_current_theme_color -> {
|
R.id.action_locate_current_theme_color -> {
|
||||||
// locateCurrentColorLibrary()
|
locateCurrentThemeColor()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun locateCurrentThemeColor() {
|
||||||
|
val target = checkAndGetTargetInfoForThemeColorLocate() ?: return
|
||||||
|
val targetLibraryId = target.libraryId
|
||||||
|
val targetIndex = target.libraryItemId
|
||||||
|
when (targetLibraryId) {
|
||||||
|
mLibrary.id -> {
|
||||||
|
val recyclerView = binding.colorLibraryRecyclerView
|
||||||
|
val viewHolder = recyclerView.findViewHolderForAdapterPosition(targetIndex)
|
||||||
|
|
||||||
|
viewHolder?.itemView?.let { itemView ->
|
||||||
|
(itemView.tag as? ValueAnimator)?.cancel()
|
||||||
|
itemView.setBackgroundColor(getColor(R.color.window_background))
|
||||||
|
}
|
||||||
|
|
||||||
|
mInitiallyIdScrollTo = targetIndex
|
||||||
|
scrollToPositionOnceIfNeeded(recyclerView)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val intent = Intent(this, ColorLibraryActivity::class.java).apply {
|
||||||
|
putExtra(INTENT_IDENTIFIER_LIBRARY_ID, targetLibraryId)
|
||||||
|
putExtra(INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO, targetIndex)
|
||||||
|
}
|
||||||
|
startActivity(intent)
|
||||||
|
this.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class ColorItemAdapter(
|
inner class ColorItemAdapter(
|
||||||
private var items: List<ColorItem>,
|
private var items: List<ColorItem>,
|
||||||
private val onItemClick: (ColorItem, View) -> Unit,
|
private val onItemClick: (ColorItem, View) -> Unit,
|
||||||
@@ -220,6 +355,15 @@ class ColorLibraryActivity : ColorSelectBaseActivity() {
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: ColorViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ColorViewHolder, position: Int) {
|
||||||
val item = items[position]
|
val item = items[position]
|
||||||
|
|
||||||
|
when (val tag = holder.itemView.tag) {
|
||||||
|
is ValueAnimator -> {
|
||||||
|
tag.cancel()
|
||||||
|
holder.itemView.tag = null
|
||||||
|
holder.itemView.setBackgroundColor(getColor(R.color.window_background))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
holder.bind(item, position)
|
holder.bind(item, position)
|
||||||
holder.itemView.setOnClickListener { onItemClick(item, holder.itemView) }
|
holder.itemView.setOnClickListener { onItemClick(item, holder.itemView) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.view.ViewAnimationUtils
|
|||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import io.codetail.widget.RevealFrameLayout
|
import io.codetail.widget.RevealFrameLayout
|
||||||
|
import org.autojs.autojs.annotation.ReservedForCompatibility
|
||||||
import org.autojs.autojs.core.image.ColorItems
|
import org.autojs.autojs.core.image.ColorItems
|
||||||
import org.autojs.autojs.core.pref.Pref
|
import org.autojs.autojs.core.pref.Pref
|
||||||
import org.autojs.autojs.theme.ThemeColorManager
|
import org.autojs.autojs.theme.ThemeColorManager
|
||||||
@@ -107,18 +108,67 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
|||||||
mAppBarContainer = appBarContainer
|
mAppBarContainer = appBarContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun checkAndGetTargetInfoForThemeColorLocate(): TargetInfoForLocate? {
|
||||||
|
val targetLibraryId = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, -1)
|
||||||
|
if (targetLibraryId == COLOR_LIBRARY_CUSTOM_COLOR_ID) {
|
||||||
|
ViewUtils.showToast(this, "当前主题色为自定义颜色", true)
|
||||||
|
// 提示
|
||||||
|
// 当前主题色为自定义颜色
|
||||||
|
//
|
||||||
|
// HEX: #FF3300
|
||||||
|
// RGB: 255, 0, 0
|
||||||
|
// HSL: 0, 0, 0.14
|
||||||
|
//
|
||||||
|
// 使用调色盘可查看或修改自定义主题颜色
|
||||||
|
// 调色盘 关闭
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val targetLibrary = colorLibraries.find { it.id == targetLibraryId }
|
||||||
|
if (targetLibrary == null) {
|
||||||
|
ViewUtils.showToast(this, "主题色库定位失败", true)
|
||||||
|
// 定位失败
|
||||||
|
// 无法定位主题色所在颜色库
|
||||||
|
//
|
||||||
|
// Target lib ID: targetLibraryId
|
||||||
|
// Color libs IDs: [ colorLibraries.sorted().joinToString(", ") { "${it.id}" } ]
|
||||||
|
// 复制信息 关闭
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val targetIndex = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ITEM_ID, -1)
|
||||||
|
if (targetIndex !in targetLibrary.colors.indices) {
|
||||||
|
ViewUtils.showToast(this, "主题色条目定位失败", true)
|
||||||
|
// 定位失败
|
||||||
|
// 无法确定主题色条目的索引值
|
||||||
|
//
|
||||||
|
// Target index: targetLibraryId
|
||||||
|
// Color indicies: [ 0..90 ] (注意 90 为 size - 1)
|
||||||
|
// 复制信息 关闭
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return TargetInfoForLocate(targetLibraryId, targetIndex)
|
||||||
|
}
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
fun onItemClick(v: View?, position: Int)
|
fun onItemClick(v: View?, position: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class TargetInfoForLocate(val libraryId: Int, val libraryItemId: Int)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val SELECT_NONE = -1
|
const val SELECT_NONE = -1
|
||||||
|
|
||||||
val KEY_CUSTOM_COLOR = "${ColorSettingRecyclerView::class.java.name}.COLOR_SETTING_CUSTOM_COLOR"
|
@ReservedForCompatibility
|
||||||
val KEY_SELECTED_COLOR_INDEX = "${ColorSettingRecyclerView::class.java.name}.SELECTED_COLOR_INDEX"
|
const val KEY_CUSTOM_COLOR = "org.autojs.autojs.theme.app.ColorSettingRecyclerView.COLOR_SETTING_CUSTOM_COLOR"
|
||||||
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"
|
@ReservedForCompatibility
|
||||||
|
const val KEY_LEGACY_SELECTED_COLOR_INDEX = "org.autojs.autojs.theme.app.ColorSettingRecyclerView.SELECTED_COLOR_INDEX"
|
||||||
|
|
||||||
|
const val KEY_SELECTED_COLOR_LIBRARY_ID = "SELECTED_COLOR_LIBRARY_ID"
|
||||||
|
const val KEY_SELECTED_COLOR_LIBRARY_ITEM_ID = "SELECTED_COLOR_LIBRARY_ITEM_ID"
|
||||||
|
|
||||||
|
const val INTENT_IDENTIFIER_LIBRARY_ID = "LIBRARY_ID"
|
||||||
|
const val INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO = "INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO"
|
||||||
|
|
||||||
val customColorPosition: Int
|
val customColorPosition: Int
|
||||||
get() = /* return mColors.size() - 1; */ 0
|
get() = /* return mColors.size() - 1; */ 0
|
||||||
@@ -130,7 +180,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
|||||||
get() = Pref.getBoolean(R.string.key_color_select_activity_legacy_layout, false)
|
get() = Pref.getBoolean(R.string.key_color_select_activity_legacy_layout, false)
|
||||||
set(value) = Pref.putBoolean(R.string.key_color_select_activity_legacy_layout, value)
|
set(value) = Pref.putBoolean(R.string.key_color_select_activity_legacy_layout, value)
|
||||||
|
|
||||||
val colorItems by lazy {
|
val colorItemsLegacy by lazy {
|
||||||
mutableListOf<Pair</* colorRes */ Int, /* nameRes */ Int>>().apply {
|
mutableListOf<Pair</* colorRes */ Int, /* nameRes */ Int>>().apply {
|
||||||
add(customColorPosition, R.color.custom_color_default 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)
|
add(defaultColorPosition, R.color.theme_color_default to R.string.theme_color_default)
|
||||||
@@ -160,13 +210,13 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getCurrentColorSummary(context: Context, isBrief: Boolean = false): String = when {
|
fun getCurrentColorSummary(context: Context, isBrief: Boolean = false): String = when {
|
||||||
isLegacyLayout -> when (val index = Pref.getInt(KEY_SELECTED_COLOR_INDEX, defaultColorPosition)) {
|
isLegacyLayout -> when (val index = Pref.getInt(KEY_LEGACY_SELECTED_COLOR_INDEX, defaultColorPosition)) {
|
||||||
SELECT_NONE -> {
|
SELECT_NONE -> {
|
||||||
val colorInt = ThemeColorManager.colorPrimary
|
val colorInt = ThemeColorManager.colorPrimary
|
||||||
ColorUtils.toString(colorInt).uppercase()
|
ColorUtils.toString(colorInt).uppercase()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val colorItem = colorItems[index]
|
val colorItem = colorItemsLegacy[index]
|
||||||
val (colorRes, nameRes) = colorItem
|
val (colorRes, nameRes) = colorItem
|
||||||
val name = context.getString(nameRes)
|
val name = context.getString(nameRes)
|
||||||
val colorInt = when (index) {
|
val colorInt = when (index) {
|
||||||
@@ -187,7 +237,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
|||||||
identifier = context.getString(R.string.mt_custom)
|
identifier = context.getString(R.string.mt_custom)
|
||||||
}
|
}
|
||||||
SELECT_NONE -> {
|
SELECT_NONE -> {
|
||||||
val legacyIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
val legacyIndex = Pref.getInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||||
when (legacyIndex) {
|
when (legacyIndex) {
|
||||||
customColorPosition -> identifier = context.getString(R.string.color_library_identifier_custom)
|
customColorPosition -> identifier = context.getString(R.string.color_library_identifier_custom)
|
||||||
SELECT_NONE, defaultColorPosition -> identifier = context.getString(R.string.color_library_identifier_default_colors)
|
SELECT_NONE, defaultColorPosition -> identifier = context.getString(R.string.color_library_identifier_default_colors)
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRAR
|
|||||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_DEFAULT_COLORS_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.COLOR_LIBRARY_MATERIAL_COLORS_ID
|
||||||
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.colorLibraries
|
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_LEGACY_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_ID
|
||||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.KEY_SELECTED_COLOR_LIBRARY_ITEM_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.SELECT_NONE
|
||||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.colorItems
|
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.colorItemsLegacy
|
||||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.customColorPosition
|
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.customColorPosition
|
||||||
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.defaultColorPosition
|
import org.autojs.autojs.theme.app.ColorSelectBaseActivity.Companion.defaultColorPosition
|
||||||
import org.autojs.autojs.util.ViewUtils
|
import org.autojs.autojs.util.ViewUtils
|
||||||
@@ -50,7 +50,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
|||||||
get() = when {
|
get() = when {
|
||||||
mSelectedPosition < 0 -> null
|
mSelectedPosition < 0 -> null
|
||||||
mSelectedPosition == customColorPosition -> customColor
|
mSelectedPosition == customColorPosition -> customColor
|
||||||
else -> context.getColor(colorItems[mSelectedPosition].first)
|
else -> context.getColor(colorItemsLegacy[mSelectedPosition].first)
|
||||||
}?.let { ThemeColor(it) }
|
}?.let { ThemeColor(it) }
|
||||||
|
|
||||||
private val customColor: Int
|
private val customColor: Int
|
||||||
@@ -93,7 +93,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun savePrefsForLegacy() {
|
private fun savePrefsForLegacy() {
|
||||||
Pref.putInt(KEY_SELECTED_COLOR_INDEX, mSelectedPosition)
|
Pref.putInt(KEY_LEGACY_SELECTED_COLOR_INDEX, mSelectedPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun savePrefsForLibraries() {
|
private fun savePrefsForLibraries() {
|
||||||
@@ -122,8 +122,8 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setUpSelectedPosition(currentColor: Int) {
|
fun setUpSelectedPosition(currentColor: Int) {
|
||||||
val selectedIndex = Pref.getInt(KEY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
val selectedIndex = Pref.getInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)
|
||||||
colorItems.getOrNull(selectedIndex)?.let {
|
colorItemsLegacy.getOrNull(selectedIndex)?.let {
|
||||||
setSelectedPosition(selectedIndex)
|
setSelectedPosition(selectedIndex)
|
||||||
} ?: when (currentColor) {
|
} ?: when (currentColor) {
|
||||||
context.getColor(R.color.theme_color_default) -> {
|
context.getColor(R.color.theme_color_default) -> {
|
||||||
@@ -162,7 +162,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val colorItem = colorItems[position]
|
val colorItem = colorItemsLegacy[position]
|
||||||
val (colorRes, nameRes) = colorItem
|
val (colorRes, nameRes) = colorItem
|
||||||
val color = when (position) {
|
val color = when (position) {
|
||||||
customColorPosition -> customColor
|
customColorPosition -> customColor
|
||||||
@@ -176,7 +176,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount() = colorItems.size
|
override fun getItemCount() = colorItemsLegacy.size
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class SearchViewItem implements MenuItemCompat.OnActionExpandListener, Se
|
|||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private EditText mTextview;
|
private EditText mTextview;
|
||||||
private ImageView mCloseButtonView;
|
private ImageView mCloseButtonView;
|
||||||
|
private ImageView mSearchGoButtonView;
|
||||||
|
|
||||||
public SearchViewItem(Activity activity, MenuItem searchMenuItem) {
|
public SearchViewItem(Activity activity, MenuItem searchMenuItem) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
@@ -34,9 +35,11 @@ public class SearchViewItem implements MenuItemCompat.OnActionExpandListener, Se
|
|||||||
if (searchView == null) {
|
if (searchView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
searchView.setSubmitButtonEnabled(true);
|
||||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
|
||||||
mTextview = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
|
mTextview = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
|
||||||
mCloseButtonView = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
|
mCloseButtonView = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
|
||||||
|
mSearchGoButtonView = searchView.findViewById(androidx.appcompat.R.id.search_go_btn);
|
||||||
initThemeColors();
|
initThemeColors();
|
||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, this);
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem, this);
|
||||||
searchView.setOnQueryTextListener(this);
|
searchView.setOnQueryTextListener(this);
|
||||||
@@ -54,6 +57,9 @@ public class SearchViewItem implements MenuItemCompat.OnActionExpandListener, Se
|
|||||||
if (mCloseButtonView != null) {
|
if (mCloseButtonView != null) {
|
||||||
mCloseButtonView.setColorFilter(fullColor);
|
mCloseButtonView.setColorFilter(fullColor);
|
||||||
}
|
}
|
||||||
|
if (mSearchGoButtonView != null) {
|
||||||
|
mSearchGoButtonView.setColorFilter(fullColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryCallback(QueryCallback queryCallback) {
|
public void setQueryCallback(QueryCallback queryCallback) {
|
||||||
|
|||||||
@@ -32,10 +32,13 @@
|
|||||||
|
|
||||||
</io.codetail.widget.RevealFrameLayout>
|
</io.codetail.widget.RevealFrameLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.ThemeColorRecyclerView
|
||||||
android:id="@+id/color_libraries_recycler_view"
|
android:id="@+id/color_libraries_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:fadeScrollbars="true"
|
||||||
|
android:scrollbarDefaultDelayBeforeFade="600"
|
||||||
|
android:scrollbarFadeDuration="500"
|
||||||
android:scrollbars="vertical" />
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -36,6 +36,9 @@
|
|||||||
android:id="@+id/color_library_recycler_view"
|
android:id="@+id/color_library_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:fadeScrollbars="true"
|
||||||
|
android:scrollbarDefaultDelayBeforeFade="600"
|
||||||
|
android:scrollbarFadeDuration="500"
|
||||||
android:scrollbars="vertical" />
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#Fri Mar 28 10:17:08 CST 2025
|
#Fri Mar 28 21:05:28 CST 2025
|
||||||
BUILD_TIME=1743128228067
|
BUILD_TIME=1743167128518
|
||||||
COMPILE_SDK_VERSION=35
|
COMPILE_SDK_VERSION=35
|
||||||
JAVA_VERSION=23
|
JAVA_VERSION=23
|
||||||
JAVA_VERSION_MIN_RADICAL=0
|
JAVA_VERSION_MIN_RADICAL=0
|
||||||
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
|
|||||||
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
||||||
TARGET_SDK_VERSION=35
|
TARGET_SDK_VERSION=35
|
||||||
TARGET_SDK_VERSION_INRT=29
|
TARGET_SDK_VERSION_INRT=29
|
||||||
VERSION_BUILD=3066
|
VERSION_BUILD=3070
|
||||||
VERSION_NAME=6.6.2 Alpha5
|
VERSION_NAME=6.6.2 Alpha5
|
||||||
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
||||||
|
|||||||
Reference in New Issue
Block a user