diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/data/ConfigData.kt b/module-app/src/main/java/com/fankes/apperrorstracking/data/ConfigData.kt index e9d3326..5f5cb01 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/data/ConfigData.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/data/ConfigData.kt @@ -53,6 +53,9 @@ object ConfigData { /** 启用应用配置模板 */ val ENABLE_APP_CONFIG_TEMPLATE = PrefsData("_enable_app_config_template", false) + /** 启用对话框防误触 */ + val ENABLE_PREVENT_MISOPERATION_FOR_DIALOG = PrefsData("_enable_prevent_misoperation_for_dialog", false) + /** 禁止异常堆栈内容自动换行 */ val DISABLE_AUTO_WRAP_ERROR_STACK_TRACE = PrefsData("_disable_auto_wrap_error_stack_trace", false) @@ -194,6 +197,16 @@ object ConfigData { putBoolean(ENABLE_APP_CONFIG_TEMPLATE, value) } + /** + * 是否启用对话框防误触 + * @return [Boolean] + */ + var isEnablePreventMisoperation + get() = getBoolean(ENABLE_PREVENT_MISOPERATION_FOR_DIALOG) + set(value) { + putBoolean(ENABLE_PREVENT_MISOPERATION_FOR_DIALOG, value) + } + /** * 是否启用 Material 3 风格的错误对话框 * @return [Boolean] diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/MainActivity.kt b/module-app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/MainActivity.kt index c4ca306..b060a9a 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/MainActivity.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/MainActivity.kt @@ -103,6 +103,7 @@ class MainActivity : BaseActivity() { onInitialize { binding.mgrAppsConfigsTemplateButton.isVisible = it } onChanged { reinitialize() } } + binding.errorsDialogPreventMisoperationSwitch.bind(ConfigData.ENABLE_PREVENT_MISOPERATION_FOR_DIALOG) binding.enableMaterial3AppErrorsDialogSwitch.bind(ConfigData.ENABLE_MATERIAL3_STYLE_APP_ERRORS_DIALOG) /** 设置匿名统计 */ binding.appAnalyticsConfigItem.isVisible = AppAnalyticsTool.isAvailable diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/DialogBuilderFactory.kt b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/DialogBuilderFactory.kt index 981cd98..9dbfd3a 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/DialogBuilderFactory.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/DialogBuilderFactory.kt @@ -25,14 +25,19 @@ package com.fankes.apperrorstracking.utils.factory import android.app.Dialog import android.content.Context +import android.os.Handler +import android.os.Looper import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.WindowManager import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.app.AlertDialog +import androidx.core.os.postDelayed import androidx.viewbinding.ViewBinding +import com.fankes.apperrorstracking.data.ConfigData import com.fankes.apperrorstracking.locale.locale import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.progressindicator.CircularProgressIndicator @@ -82,6 +87,8 @@ class DialogBuilder( /** 自定义布局 */ private var customLayoutView: View? = null + private val mainHandler = Handler(Looper.getMainLooper()) + /** * 获取 [DialogBuilder] 绑定布局对象 * @return [VB] @@ -191,6 +198,16 @@ class DialogBuilder( customLayoutView?.let { setView(it) } dialogInstance = this setOnCancelListener { onCancel?.invoke() } + if (ConfigData.isEnablePreventMisoperation) { + setOnShowListener { + window?.run { + addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) + mainHandler.postDelayed(1000) { + clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) + } + } + } + } }?.show() } } diff --git a/module-app/src/main/res/layout/activity_main.xml b/module-app/src/main/res/layout/activity_main.xml index cea83da..36439ac 100644 --- a/module-app/src/main/res/layout/activity_main.xml +++ b/module-app/src/main/res/layout/activity_main.xml @@ -338,6 +338,30 @@ android:text="@string/apps_config_template_tip" android:textColor="@color/colorTextDark" android:textSize="12sp" /> + + + + - \ No newline at end of file + diff --git a/module-app/src/main/res/values-zh-rCN/strings.xml b/module-app/src/main/res/values-zh-rCN/strings.xml index 549c695..e75b425 100644 --- a/module-app/src/main/res/values-zh-rCN/strings.xml +++ b/module-app/src/main/res/values-zh-rCN/strings.xml @@ -115,6 +115,8 @@ 你确定要一次性应用设置给 %1$s 个应用吗? 错误对话框始终显示“重新打开”选项 启用后,在使用对话框显示应用异常时,非首次异常时也将显示“重新打开”选项,若当前异常非主进程或应用无法打开则依然不会显示此选项。 + 错误对话框防误触 + 启用后,错误对话框弹出前 1s 内不会响应点击事件 此模块专为 Android 开发者而打造。\n\n在可能的无法连接电脑,不能进行 ADB 调试的时候,可通过此模块来快速捕获任意已安装应用的任意异常,以便快速定位问题。\n\n应用发生崩溃的错误日志对开发者来说是无价的财富,若你不是开发者,你依然可以安装此模块,以便给开发者提供更多异常信息快速解决问题。 使用说明 部分定制系统使用快速重启后可能会发生错误,仍然要继续吗? diff --git a/module-app/src/main/res/values/strings.xml b/module-app/src/main/res/values/strings.xml index 24742dc..3c08692 100644 --- a/module-app/src/main/res/values/strings.xml +++ b/module-app/src/main/res/values/strings.xml @@ -113,6 +113,8 @@ Are you sure you want to apply settings to %1$s apps at once? Error dialog always shows \"Reopen App\" After enabling, when using the dialog to display application exceptions, the \"Reopen App\" option will also be displayed when the errors is not the first time. If the current errors is not the main process or the application cannot be opened, this option will still not be displayed. + Prevent misoperation of error dialog + After enabling, the error dialog will not respond to click events within 1s after popping up This module is specially designed for Android developers.\n\nWhen it is possible that the computer cannot be connected and ADB cannot be performed, this module can be used to quickly capture any exception of any installed apps, so as to quickly locate the problem.\n\nThe error log of apps crashing is an invaluable asset for developers. If you are not a developer, you can still install this module to provide developers with more exception information to quickly solve problems. Instructions Warning @@ -158,4 +160,4 @@ System Build ID App Package Name Other Requirement - \ No newline at end of file +