6.6.2 - Alpha6 - 主题色颜色详情支持使用调色盘直接引用

This commit is contained in:
SuperMonster003
2025-04-13 20:33:03 +08:00
parent bd02228600
commit 1cd5281446
23 changed files with 133 additions and 57 deletions

View File

@@ -28,6 +28,7 @@ class ScreenCapturerForegroundService : Service() {
override fun onBind(intent: Intent): IBinder = Binder()
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
instance = this
mForegroundServiceCreator = ForegroundServiceCreator.Builder(this)
.setClassName(ScreenCapturerForegroundService::class.java)
.setIntent(
@@ -51,11 +52,20 @@ class ScreenCapturerForegroundService : Service() {
override fun onDestroy() {
mForegroundServiceCreator?.stopForeground(STOP_FOREGROUND_REMOVE)
instance = null
super.onDestroy()
}
companion object {
const val NOTIFICATION_ID = 0xCF
var instance: ScreenCapturerForegroundService? = null
fun stopService() {
instance?.stopSelf()
}
}
}

View File

@@ -7,6 +7,7 @@ import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -22,7 +23,12 @@ import org.autojs.autojs6.databinding.ColorInfoDialogListItemBinding
object ColorInfoDialogManager {
@JvmStatic
fun showColorInfoDialog(context: Context, @ColorInt color: Int?, title: String? = null) {
fun showColorInfoDialog(
context: Context,
@ColorInt color: Int?,
title: String? = null,
customNeutral: CustomColorInfoDialogNeutral? = null,
) {
if (color == null) {
MaterialDialog.Builder(context)
.title(R.string.text_prompt)
@@ -36,12 +42,21 @@ object ColorInfoDialogManager {
val colorWithoutAlpha = color or -0x1000000
val dialog = MaterialDialog.Builder(context)
.title(title ?: context.getString(R.string.dialog_title_color_details))
.customView(binding.root, false)
.positiveText(R.string.dialog_button_dismiss)
.positiveColorRes(R.color.dialog_button_default)
.show()
val dialog = MaterialDialog.Builder(context).apply {
title(title ?: context.getString(R.string.dialog_title_color_details))
customView(binding.root, false)
customNeutral?.let { neutral ->
neutral.textRes?.let(::neutralText)
neutral.colorRes?.let(::neutralColorRes)
neutral.onNeutralCallback?.let {
onNeutral { dialog, which ->
it.onClick(dialog, which, colorWithoutAlpha)
}
}
}
positiveText(R.string.dialog_button_dismiss)
positiveColorRes(R.color.dialog_button_default)
}.show()
title?.run { dialog.makeTextCopyable { it.titleView } }
@@ -98,4 +113,14 @@ object ColorInfoDialogManager {
}
}
data class CustomColorInfoDialogNeutral(
val textRes: Int? = null,
val colorRes: Int? = null,
val onNeutralCallback: NeutralButtonCallback? = null,
) {
interface NeutralButtonCallback {
fun onClick(dialog: MaterialDialog, which: DialogAction, @ColorInt color: Int)
}
}
}

View File

@@ -52,24 +52,17 @@ class ColorItemAdapter(
}
private fun updateSelectedPosition(item: PresetColorItem, positionOfCurrentSelection: Int) {
when (selectedItemId) {
SELECT_NONE -> {
selectedLibraryId = item.libraryId
selectedItemId = item.itemId
notifyItemChanged(positionOfCurrentSelection)
if (selectedItemId != SELECT_NONE) {
val positionBeforeSelection = items.indexOfFirst {
it.libraryId == selectedLibraryId && it.itemId == selectedItemId
}
else -> {
val positionBeforeSelection = items.indexOfFirst {
it.libraryId == selectedLibraryId && it.itemId == selectedItemId
}
if (positionBeforeSelection != positionOfCurrentSelection && positionBeforeSelection >= 0) {
notifyItemChanged(positionBeforeSelection)
}
selectedLibraryId = item.libraryId
selectedItemId = item.itemId
notifyItemChanged(positionOfCurrentSelection)
if (positionBeforeSelection != positionOfCurrentSelection && positionBeforeSelection >= 0) {
notifyItemChanged(positionBeforeSelection)
}
}
selectedLibraryId = item.libraryId
selectedItemId = item.itemId
notifyItemChanged(positionOfCurrentSelection)
}
private fun savePrefsAndDatabase(context: Context, item: PresetColorItem) {

View File

@@ -7,6 +7,7 @@ import androidx.annotation.ColorInt
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import org.autojs.autojs.theme.ThemeColorHelper
import org.autojs.autojs.theme.ThemeColorManager
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.PresetColorItem
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.presetColorLibraries
import org.autojs.autojs.util.ViewUtils
@@ -37,13 +38,17 @@ class ColorItemViewHolder(itemViewBinding: MtColorLibraryRecyclerViewItemBinding
}
}
subtitleSplitLineView.isVisible = !colorLibraryIdentifierView.text.isNullOrBlank()
setChecked(color, selectedLibraryId == item.libraryId && selectedItemId == item.itemId)
setChecked(selectedLibraryId == item.libraryId && selectedItemId == item.itemId, color)
}
fun setChecked(@ColorInt color: Int, checked: Boolean) {
fun setChecked(checked: Boolean, @ColorInt refColor: Int? = null) {
if (checked) {
val niceRefColor = refColor ?: ThemeColorManager.colorPrimary
val tintRes = when (ViewUtils.isLuminanceLight(niceRefColor)) {
true -> R.color.day
else -> R.color.night
}
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(context.getColor(tintRes))
} else {
colorView.setImageDrawable(null)

View File

@@ -52,15 +52,24 @@ class ColorItemsActivity : ColorSelectBaseActivity() {
super.onCreate(savedInstanceState)
ThemeChangeNotifier.themeChanged.observe(this) {
mAdapter.apply {
val positionBeforeSelection = items.indexOfFirst {
it.libraryId == selectedLibraryId && it.itemId == selectedItemId
}
setUpSelectedPosition(this)
if (positionBeforeSelection in items.indices) {
notifyItemChanged(positionBeforeSelection)
}
}
updateClickListener(binding.toolbar)
}
val libraryId = intent.getIntExtra(INTENT_IDENTIFIER_LIBRARY_ID, -1)
val libraryId = intent.getIntExtra(INTENT_IDENTIFIER_LIBRARY_ID, SELECT_NONE)
val library = presetColorLibraries.find { it.id == libraryId }?.also { lib ->
mLibrary = lib
} ?: throw RuntimeException("Unknown library id: $libraryId")
mInitiallyItemIdScrollTo = intent.getIntExtra(INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO, -1)
mInitiallyItemIdScrollTo = intent.getIntExtra(INTENT_IDENTIFIER_COLOR_ITEM_ID_SCROLL_TO, SELECT_NONE)
MtActivityColorItemsBinding.inflate(layoutInflater).let {
binding = it
@@ -76,9 +85,7 @@ class ColorItemsActivity : ColorSelectBaseActivity() {
binding.colorItemsRecyclerView.let { it ->
it.layoutManager = LinearLayoutManager(this)
it.adapter = ColorItemAdapter(library.colors) {
updateAppBarColorContent(ThemeColorManager.colorPrimary)
}.also { mAdapter = it }
it.adapter = ColorItemAdapter(library.colors).also { mAdapter = it }
it.addItemDecoration(DividerItemDecoration(this, VERTICAL))
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
@@ -110,7 +117,7 @@ class ColorItemsActivity : ColorSelectBaseActivity() {
}
private fun setUpSelectedPosition(adapter: ColorItemAdapter) {
when (Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
when (val prefLibraryId = Pref.getInt(KEY_SELECTED_COLOR_LIBRARY_ID, SELECT_NONE)) {
SELECT_NONE -> when (val legacyIndex = Pref.getInt(KEY_LEGACY_SELECTED_COLOR_INDEX, SELECT_NONE)) {
customColorPosition -> Unit
SELECT_NONE, defaultColorPosition -> when (mLibrary.id) {
@@ -131,6 +138,10 @@ class ColorItemsActivity : ColorSelectBaseActivity() {
adapter.selectedLibraryId = mLibrary.id
adapter.selectedItemId = Pref.getInt(KEY_SELECTED_COLOR_ITEM_ID, SELECT_NONE)
}
else -> {
adapter.selectedLibraryId = prefLibraryId
adapter.selectedItemId = SELECT_NONE
}
}
}

View File

@@ -42,7 +42,6 @@ class ColorLibrariesActivity : ColorSelectBaseActivity() {
super.onCreate(savedInstanceState)
ThemeChangeNotifier.themeChanged.observe(this) {
updateAppBarColorContent(ThemeColorManager.colorPrimary)
libraryAdapter.notifyDataSetChanged()
colorItemAdapter.notifyDataSetChanged()
}

View File

@@ -21,9 +21,11 @@ class ColorSelectActivity : ColorSelectBaseActivity() {
private val mOnItemClickListener = object : OnItemClickListener {
override fun onItemClick(v: View?, position: Int) {
mColorSettingRecyclerView.selectedThemeColor?.let {
mColorSettingRecyclerView.selectedColor?.let {
mSelectedPosition = position
updateAppBarColorContent(it.colorPrimary)
if (position == customColorPosition) {
isForciblyEnableAppBarColorTransition = true
}
}
}
}

View File

@@ -16,6 +16,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView.VERTICAL
import androidx.recyclerview.widget.ThemeColorRecyclerView
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.appbar.AppBarLayout
import com.jaredrummler.android.colorpicker.ColorPickerDialog
@@ -34,6 +35,7 @@ import org.autojs.autojs.theme.app.ColorEntities.ColorHistory
import org.autojs.autojs.theme.app.ColorEntities.ColorInfo
import org.autojs.autojs.theme.app.ColorEntities.PaletteHistory
import org.autojs.autojs.theme.app.ColorHistoryItemViewHolder.Companion.ColorHistoryItem
import org.autojs.autojs.theme.app.ColorInfoDialogManager.CustomColorInfoDialogNeutral.NeutralButtonCallback
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_ID_DEFAULT
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_ID_MATERIAL
import org.autojs.autojs.theme.app.ColorLibrariesActivity.Companion.COLOR_LIBRARY_ID_PALETTE
@@ -83,6 +85,10 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeChangeNotifier.themeChanged.observe(this) {
updateAppBarColorContent(ThemeColorManager.colorPrimary)
}
mTitle = intent.getStringExtra("title") ?: getString(R.string.text_theme_color)
currentColor = intent.getIntExtra("currentColor", ThemeColorManager.colorPrimary)
@@ -238,7 +244,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
return TargetInfoForLocate(targetLibraryId, targetItemIndex)
}
protected fun showColorPicker() {
protected fun showColorPicker(initialColor: Int? = null) {
ColorPickerDialog.newBuilder()
.setUseLegacyMode(isLegacyLayout)
.setAllowCustom(true)
@@ -246,7 +252,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setShowAlphaSlider(false)
.setDialogTitle(R.string.dialog_title_color_palette)
.setColor(customColor)
.setColor(initialColor ?: customColor)
.setOldColorPanelOnClickListener { showColorDetails(it.tag as? Int) }
.setNewColorPanelOnClickListener { showColorDetails(it.tag as? Int) }
.setColorHistoriesHandler { showColorPickerHistories(it) }
@@ -489,7 +495,17 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
}
protected fun showColorDetails(color: Int?, title: String? = null) {
ColorInfoDialogManager.showColorInfoDialog(this, color, title)
val customNeutral = ColorInfoDialogManager.CustomColorInfoDialogNeutral(
textRes = R.string.dialog_button_use_palette,
colorRes = R.color.dialog_button_hint,
onNeutralCallback = object: NeutralButtonCallback{
override fun onClick(dialog: MaterialDialog, which: DialogAction, color: Int) {
dialog.dismiss()
showColorPicker(color)
}
}
)
ColorInfoDialogManager.showColorInfoDialog(this, color, title, customNeutral)
}
protected fun showThemeColorDetails() {

View File

@@ -18,7 +18,6 @@ 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_ID_PALETTE
@@ -46,16 +45,16 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
private val mAdapter: Adapter
private var mOnItemClickListener: ColorSelectBaseActivity.OnItemClickListener? = null
private var mSelectedPosition = SELECT_NONE
val selectedThemeColor: ThemeColor?
val selectedColor: Int?
get() = when {
mSelectedPosition < 0 -> null
mSelectedPosition == customColorPosition -> customColor
else -> context.getColor(colorItemsLegacy[mSelectedPosition].first)
}?.let { ThemeColor(it) }
}
private val customColor: Int
get() = Pref.getInt(ColorSelectBaseActivity.KEY_CUSTOM_COLOR, context.getColor(R.color.custom_color_default))
@@ -77,13 +76,12 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
itemId = it.itemId,
)
}
}
else -> {
setSelectedPosition(pos)
mOnItemClickListener?.onItemClick(v, pos)
selectedThemeColor?.colorPrimary?.let { c ->
selectedColor?.let { c ->
presetColorLibraries.find { it.isMaterial }!!.colors.find { colorItem ->
context.getColor(colorItem.colorRes) == c
}?.let {
@@ -100,25 +98,25 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
}
init {
adapter = Adapter()
adapter = Adapter().also { mAdapter = it }
layoutManager = LinearLayoutManager(context)
addItemDecoration(DividerItemDecoration(context, VERTICAL))
}
@SuppressLint("NotifyDataSetChanged")
fun setSelectedPosition(currentPosition: Int) {
if (mSelectedPosition != SELECT_NONE) {
adapter!!.notifyItemChanged(mSelectedPosition)
if (mSelectedPosition == SELECT_NONE) {
mSelectedPosition = currentPosition
adapter!!.notifyItemChanged(currentPosition)
mAdapter.notifyDataSetChanged()
} else {
mAdapter.notifyItemChanged(mSelectedPosition)
mSelectedPosition = currentPosition
adapter!!.notifyDataSetChanged()
mAdapter.notifyItemChanged(currentPosition)
}
savePrefsForLegacy()
savePrefsForLibraries()
selectedThemeColor?.let {
ThemeColorManager.setThemeColor(it.colorPrimary)
selectedColor?.let {
ThemeColorManager.setThemeColor(it)
ThemeChangeNotifier.notifyThemeChanged()
}
}
@@ -139,7 +137,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
context.getColor(colorItem.colorRes) == context.getColor(R.color.theme_color_default)
}?.let { Pref.putInt(KEY_SELECTED_COLOR_ITEM_ID, it.itemId) }
}
else -> selectedThemeColor?.colorPrimary?.let { c ->
else -> selectedColor?.let { c ->
presetColorLibraries.find { it.isMaterial }!!.colors.find { colorItem ->
context.getColor(colorItem.colorRes) == c
}?.let {
@@ -224,7 +222,7 @@ class ColorSettingRecyclerView : ThemeColorRecyclerView {
fun setChecked(checked: Boolean) {
if (checked) {
colorView.setImageResource(R.drawable.mt_ic_check_white_36dp)
val selectedThemeColorRes = selectedThemeColor?.colorPrimary?.let {
val selectedThemeColorRes = selectedColor?.let {
if (ViewUtils.isLuminanceLight(it)) R.color.day else R.color.night
} ?: R.color.night_day
colorView.imageTintList = ColorStateList.valueOf(context.getColor(selectedThemeColorRes))

View File

@@ -69,4 +69,10 @@ public class FloatyService extends Service {
}
}
public static void stopService() {
if (instance != null) {
instance.stopSelf();
}
}
}

View File

@@ -313,8 +313,8 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
fun exitCompletely() {
FloatyWindowManger.hideCircularMenuAndSaveState()
stopService(Intent(this, FloatyService::class.java))
stopService(Intent(this, ScreenCapturerForegroundService::class.java))
FloatyService.stopService()
ScreenCapturerForegroundService.stopService()
AutoJs.instance.scriptEngineService.stopAll()

View File

@@ -963,5 +963,6 @@
<string name="summary_all_files_access_inrt">السماح للتطبيق بالوصول إلى جميع الملفات، بما في ذلك التخزين الخارجي</string>
<string name="summary_display_over_other_apps_inrt">السماح للتطبيق بعرض المحتوى فوق التطبيقات الأخرى</string>
<string name="summary_post_notifications_permission_inrt">السماح للتطبيق بإنشاء وإرسال الإشعارات</string>
<string name="dialog_button_use_palette">ستخدام اللوحة</string>
</resources>

View File

@@ -959,5 +959,6 @@
<string name="summary_all_files_access_inrt">Allow the application to access all files, including external storage</string>
<string name="summary_display_over_other_apps_inrt">Allow the application to display content over other apps</string>
<string name="summary_post_notifications_permission_inrt">Allow the application to create and send notifications</string>
<string name="dialog_button_use_palette">Use palette</string>
</resources>

View File

@@ -962,5 +962,6 @@
<string name="summary_all_files_access_inrt">Permitir que la aplicación acceda a todos los archivos, incluido el almacenamiento externo</string>
<string name="summary_display_over_other_apps_inrt">Permitir que la aplicación muestre contenido sobre otras aplicaciones</string>
<string name="summary_post_notifications_permission_inrt">Permitir que la aplicación cree y envíe notificaciones</string>
<string name="dialog_button_use_palette">Usar paleta</string>
</resources>

View File

@@ -962,5 +962,6 @@
<string name="summary_all_files_access_inrt">Autoriser l\'application à accéder à tous les fichiers, y compris le stockage externe</string>
<string name="summary_display_over_other_apps_inrt">Autoriser l\'application à afficher du contenu par-dessus d\'autres applications</string>
<string name="summary_post_notifications_permission_inrt">Autoriser l\'application à créer et envoyer des notifications</string>
<string name="dialog_button_use_palette">Utiliser la palette</string>
</resources>

View File

@@ -962,5 +962,6 @@
<string name="summary_all_files_access_inrt">アプリが外部ストレージを含むすべてのファイルにアクセスすることを許可する</string>
<string name="summary_display_over_other_apps_inrt">アプリが他のアプリの上にコンテンツを表示することを許可する</string>
<string name="summary_post_notifications_permission_inrt">アプリが通知を作成して送信することを許可する</string>
<string name="dialog_button_use_palette">パレットを使う</string>
</resources>

View File

@@ -963,5 +963,6 @@
<string name="summary_all_files_access_inrt">앱이 외부 저장소를 포함한 모든 파일에 접근할 수 있도록 허용합니다</string>
<string name="summary_display_over_other_apps_inrt">앱이 다른 애플리케이션 위에 콘텐츠를 표시할 수 있도록 허용합니다</string>
<string name="summary_post_notifications_permission_inrt">앱이 알림을 생성하고 보낼 수 있도록 허용합니다</string>
<string name="dialog_button_use_palette">팔레트 사용</string>
</resources>

View File

@@ -962,5 +962,6 @@
<string name="summary_all_files_access_inrt">Разрешить приложению доступ ко всем файлам, включая внешнее хранилище</string>
<string name="summary_display_over_other_apps_inrt">Разрешить приложению отображать контент поверх других приложений</string>
<string name="summary_post_notifications_permission_inrt">Разрешить приложению создавать и отправлять уведомления</string>
<string name="dialog_button_use_palette">Использовать палитру</string>
</resources>

View File

@@ -960,5 +960,6 @@
<string name="summary_all_files_access_inrt">允許應用訪問所有文件, 包括外部存儲</string>
<string name="summary_display_over_other_apps_inrt">允許應用在其他應用之上顯示內容</string>
<string name="summary_post_notifications_permission_inrt">允許應用創建併發送通知</string>
<string name="dialog_button_use_palette">使用調色盤</string>
</resources>

View File

@@ -960,5 +960,6 @@
<string name="summary_all_files_access_inrt">允許應用訪問所有檔案, 包括外部儲存</string>
<string name="summary_display_over_other_apps_inrt">允許應用在其他應用之上顯示內容</string>
<string name="summary_post_notifications_permission_inrt">允許應用建立併發送通知</string>
<string name="dialog_button_use_palette">使用調色盤</string>
</resources>

View File

@@ -957,5 +957,6 @@
<string name="summary_all_files_access_inrt">允许应用访问所有文件, 包括外部存储</string>
<string name="summary_display_over_other_apps_inrt">允许应用在其他应用之上显示内容</string>
<string name="summary_post_notifications_permission_inrt">允许应用创建并发送通知</string>
<string name="dialog_button_use_palette">使用调色盘</string>
</resources>

View File

@@ -1207,5 +1207,6 @@
<string name="summary_all_files_access_inrt">Allow the application to access all files, including external storage</string>
<string name="summary_display_over_other_apps_inrt">Allow the application to display content over other apps</string>
<string name="summary_post_notifications_permission_inrt">Allow the application to create and send notifications</string>
<string name="dialog_button_use_palette">Use palette</string>
</resources>

View File

@@ -1,5 +1,5 @@
#Sun Apr 13 14:00:19 CST 2025
BUILD_TIME=1744524019186
#Sun Apr 13 20:26:15 CST 2025
BUILD_TIME=1744547175175
COMPILE_SDK_VERSION=35
JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=35
TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=3133
VERSION_BUILD=3136
VERSION_NAME=6.6.2 Alpha6
VSCODE_EXT_REQUIRED_VERSION=1.0.8