6.6.2 - Alpha4 - 修复主页抽屉滑动可能出现的卡顿问题; 避免部分受限 API

This commit is contained in:
SuperMonster003
2025-03-19 00:42:15 +08:00
parent 3fda91cbda
commit 603eef9243
8 changed files with 112 additions and 77 deletions

View File

@@ -1,5 +1,7 @@
package org.autojs.autojs.extension
import java.text.Normalizer
object StringExtensions {
fun String.toDoubleOrNaN() = this.toDoubleOrNull() ?: Double.NaN
@@ -20,4 +22,16 @@ object StringExtensions {
return padStr.repeat(repeatTimes) + remainderStr
}
fun CharSequence.looseMatches(reference: CharSequence): Boolean {
return this.toString().normalizeForMatch() == reference.toString().normalizeForMatch()
}
private fun String.normalizeForMatch(): String {
return Normalizer.normalize(this, Normalizer.Form.NFD)
.trim()
.replace(Regex("\\p{M}"), "") // 移除组合符号, 如上标符号
.replace(Regex("[^\\p{L}\\p{N}@.|]+"), "") // 只保留 [字母/数字/特定符号]
.lowercase()
}
}

View File

@@ -2,25 +2,40 @@ package org.autojs.autojs.theme.preference
import android.content.Context
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import com.afollestad.materialdialogs.MaterialDialog
import org.autojs.autojs6.R
open class MaterialDialogPreference : MaterialPreference {
private val mBuilder: MaterialDialog.Builder
private val mContext: Context
private var mBuilder: MaterialDialog.Builder? = null
private var mContext: Context? = null
private lateinit var mDialog: MaterialDialog
protected var dialogTitle: CharSequence?
protected var dialogContent: CharSequence?
protected var neutralText: CharSequence?
protected var negativeText: CharSequence?
protected var neutralTextShort: CharSequence?
protected var positiveText: CharSequence?
protected var dialogTitle: CharSequence? = null
protected var dialogContent: CharSequence? = null
protected var neutralText: CharSequence? = null
protected var negativeText: CharSequence? = null
protected var neutralTextShort: CharSequence? = null
protected var positiveText: CharSequence? = null
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init(context, attrs, defStyleAttr, defStyleRes)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(context, attrs, defStyleAttr, 0)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs, 0, 0)
}
constructor(context: Context) : super(context) {
init(context, null, 0, 0)
}
private fun init(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) {
mContext = context
mBuilder = MaterialDialog.Builder(context)
@@ -36,17 +51,6 @@ open class MaterialDialogPreference : MaterialPreference {
}
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context, attrs: AttributeSet?) : this(
context, attrs, TypedArrayUtils.getAttr(
context, android.R.attr.dialogPreferenceStyle,
android.R.attr.dialogPreferenceStyle,
)
)
constructor(context: Context) : this(context, null)
override fun onClick() {
getBuilder().build().also { mDialog = it }.show()
super.onClick()
@@ -54,7 +58,7 @@ open class MaterialDialogPreference : MaterialPreference {
protected fun getDialog() = mDialog
protected open fun getBuilder(): MaterialDialog.Builder = mBuilder
protected open fun getBuilder(): MaterialDialog.Builder = mBuilder!!
.neutralColorRes(R.color.dialog_button_hint)
.dismissListener { mDialog.recyclerView?.layoutManager = null }
.onNeutral { _, _ -> onNeutral() }

View File

@@ -4,7 +4,6 @@ import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import androidx.preference.Preference.SummaryProvider
import com.afollestad.materialdialogs.MaterialDialog
import org.autojs.autojs.core.pref.Pref
@@ -34,6 +33,22 @@ open class MaterialListPreference : MaterialDialogPreference {
get() = mItemValues.takeIf { it.isNotEmpty() }?.toList()?.get(itemPrefIndex ?: mItemDefaultIndex)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int, bundle: Bundle) : super(context, attrs, defStyleAttr, defStyleRes) {
init(context, attrs, defStyleAttr, defStyleRes, bundle)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init(context, attrs, defStyleAttr, defStyleRes, Bundle())
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(context, attrs, defStyleAttr, 0, Bundle())
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs, 0, 0, Bundle())
}
private fun init(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int, bundle: Bundle) {
obtainStyledAttrs(context, attrs, R.styleable.MaterialListPreference, defStyleAttr, defStyleRes)
.let { a ->
getAttrString(a, R.styleable.MaterialListPreference_dialogTitle)?.also { dialogTitle = it }
@@ -56,17 +71,6 @@ open class MaterialListPreference : MaterialDialogPreference {
}
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : this(context, attrs, defStyleAttr, defStyleRes, Bundle())
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context, attrs: AttributeSet?) : this(
context, attrs, TypedArrayUtils.getAttr(
context, android.R.attr.dialogPreferenceStyle,
android.R.attr.dialogPreferenceStyle,
)
)
constructor(context: Context) : this(context, null)
override fun getBuilder(): MaterialDialog.Builder = super.getBuilder().also { builder ->

View File

@@ -3,7 +3,6 @@ package org.autojs.autojs.theme.preference
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import androidx.preference.PreferenceViewHolder
import org.autojs.autojs.app.DialogUtils
import org.autojs.autojs6.R
@@ -16,23 +15,28 @@ open class MaterialPreference : androidx.preference.Preference, LongClickablePre
override var longClickPromptMore: CharSequence? = null
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
obtainStyledAttrs(context, attrs, R.styleable.MaterialPreference, defStyleAttr, defStyleRes)
.let { a ->
getAttrString(a, R.styleable.MaterialPreference_longClickPrompt)?.also { longClickPrompt = it }
getAttrString(a, R.styleable.MaterialPreference_longClickPromptMore)?.also { longClickPromptMore = it }
a.recycle()
}
init(context, attrs, defStyleAttr, defStyleRes)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(context, attrs, defStyleAttr, 0)
}
constructor(context: Context, attrs: AttributeSet?) : this(
context, attrs, TypedArrayUtils.getAttr(
context, androidx.preference.R.attr.preferenceStyle, android.R.attr.preferenceStyle
)
)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs, 0, 0)
}
constructor(context: Context) : this(context, null)
constructor(context: Context) : super(context) {
init(context, null, 0, 0)
}
private fun init(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) {
obtainStyledAttrs(context, attrs, R.styleable.MaterialPreference, defStyleAttr, defStyleRes).let { a ->
getAttrString(a, R.styleable.MaterialPreference_longClickPrompt)?.also { longClickPrompt = it }
getAttrString(a, R.styleable.MaterialPreference_longClickPromptMore)?.also { longClickPromptMore = it }
a.recycle()
}
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
@@ -43,8 +47,8 @@ open class MaterialPreference : androidx.preference.Preference, LongClickablePre
return context.obtainStyledAttributes(set, styleableRes, defStyleAttr, defStyleRes)
}
protected fun getAttrString(a: TypedArray, index: Int): String? = TypedArrayUtils.getString(a, index, index)
protected fun getAttrString(a: TypedArray, index: Int): String? = a.getString(index)
protected fun getAttrTextArray(a: TypedArray, index: Int): Array<CharSequence>? = TypedArrayUtils.getTextArray(a, index, index)
protected fun getAttrTextArray(a: TypedArray, index: Int): Array<CharSequence>? = a.getTextArray(index)
}

View File

@@ -9,7 +9,6 @@ import android.util.AttributeSet
import android.view.View
import android.widget.Switch
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.res.TypedArrayUtils
import androidx.preference.PreferenceViewHolder
import androidx.preference.SwitchPreference
import org.autojs.autojs.app.DialogUtils
@@ -54,12 +53,11 @@ class ThemeColorSwitchPreference : SwitchPreference, ThemeColorMutable, LongClic
}
private fun init(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) {
obtainStyledAttrs(context, attrs, R.styleable.MaterialPreference, defStyleAttr, defStyleRes)
.let { a ->
getAttrString(a, R.styleable.MaterialPreference_longClickPrompt)?.also { longClickPrompt = it }
getAttrString(a, R.styleable.MaterialPreference_longClickPromptMore)?.also { longClickPromptMore = it }
a.recycle()
}
obtainStyledAttrs(context, attrs, R.styleable.MaterialPreference, defStyleAttr, defStyleRes).let { a ->
getAttrString(a, R.styleable.MaterialPreference_longClickPrompt)?.also { longClickPrompt = it }
getAttrString(a, R.styleable.MaterialPreference_longClickPromptMore)?.also { longClickPromptMore = it }
a.recycle()
}
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
@@ -90,6 +88,6 @@ class ThemeColorSwitchPreference : SwitchPreference, ThemeColorMutable, LongClic
}
@SuppressLint("RestrictedApi")
private fun getAttrString(a: TypedArray, index: Int): String? = TypedArrayUtils.getString(a, index, index)
private fun getAttrString(a: TypedArray, index: Int): String? = a.getString(index)
}

View File

@@ -201,8 +201,15 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
super.onDrawerSlide(drawerView, slideOffset)
when {
slideOffset > 0.5 -> setUpStatusBarAppearanceLightByNightMode()
else -> setUpStatusBarAppearanceLightByThemeColor()
// @Hint by SuperMonster003 on Mar 18, 2025.
// ! Changing this to a middle value (e.g., `slideOffset < 0.5`) would provide
// ! a better visual experience for the light/dark status bar transition,
// ! but it may cause slight stuttering during the drawer view sliding.
// ! zh-CN:
// ! 此处改为中间值 (如 `slideOffset < 0.5`) 会带来更好的通知栏亮暗色转换视觉体验,
// ! 但会造成抽屉视图滑动时出现些微卡顿.
slideOffset < 1 -> setUpStatusBarAppearanceLightByThemeColor()
else -> setUpStatusBarAppearanceLightByNightMode()
}
}

View File

@@ -3,7 +3,6 @@ package org.autojs.autojs.ui.settings
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import com.afollestad.materialdialogs.MaterialDialog
import org.autojs.autojs.core.pref.Pref
import org.autojs.autojs.theme.preference.MaterialListPreference
@@ -13,23 +12,17 @@ import org.autojs.autojs6.R
class NightModePreference : MaterialListPreference {
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes, Bundle().apply {
if (!ViewUtils.AutoNightMode.isFunctional()) {
putString(key(R.string.key_pref_bundle_default_item), context.getString(R.string.key_night_mode_always_off))
putIntegerArrayList(key(R.string.key_pref_bundle_disabled_items), arrayListOf(R.string.key_night_mode_follow_system))
}
})
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
super(context, attrs, defStyleAttr, defStyleRes, createDefaultBundle(context))
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
super(context, attrs, defStyleAttr, 0, createDefaultBundle(context))
constructor(context: Context, attrs: AttributeSet?) : this(
context, attrs, TypedArrayUtils.getAttr(
context, android.R.attr.dialogPreferenceStyle,
android.R.attr.dialogPreferenceStyle,
)
)
constructor(context: Context, attrs: AttributeSet?) :
super(context, attrs, 0, 0, createDefaultBundle(context))
constructor(context: Context) : this(context, null)
constructor(context: Context) :
super(context, null, 0, 0, createDefaultBundle(context))
override fun onChangeConfirmed(dialog: MaterialDialog) {
super.onChangeConfirmed(dialog)
@@ -54,4 +47,15 @@ class NightModePreference : MaterialListPreference {
}
}
companion object {
private fun createDefaultBundle(context: Context) = Bundle().apply {
if (!ViewUtils.AutoNightMode.isFunctional()) {
putString(key(R.string.key_pref_bundle_default_item), context.getString(R.string.key_night_mode_always_off))
putIntegerArrayList(key(R.string.key_pref_bundle_disabled_items), arrayListOf(R.string.key_night_mode_follow_system))
}
}
}
}

View File

@@ -1,5 +1,5 @@
#Sun Mar 16 00:59:16 CST 2025
BUILD_TIME=1742057956511
#Wed Mar 19 00:38:56 CST 2025
BUILD_TIME=1742315936702
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=3032
VERSION_BUILD=3037
VERSION_NAME=6.6.2 Alpha4
VSCODE_EXT_REQUIRED_VERSION=1.0.8