6.7.0 - Alpha16 - 修复浮动按钮 "运行脚本" 对话框后台操作文件时可能导致应用崩溃的问题

This commit is contained in:
SuperMonster003
2026-01-18 23:16:20 +08:00
parent 3d7b50ec69
commit f28c704148
10 changed files with 98 additions and 39 deletions

View File

@@ -38,8 +38,18 @@ object DialogUtils {
@Suppress("DEPRECATION")
WindowManager.LayoutParams.TYPE_PHONE
}
// Try setting window type before show().
// zh-CN: 尝试在 show() 之前设置窗口类型.
window?.setType(type)
// Ensure window type is applied when window becomes available.
// zh-CN: 当 window 可用时确保窗口类型已正确应用.
dialog.setOnShowListener {
window?.setType(type)
}
}
if (Looper.getMainLooper() == Looper.myLooper()) {
dialog.show()
} else {
@@ -117,7 +127,7 @@ object DialogUtils {
text = text
}
}
.show()
.let { showDialog(it) }
}
}
}
@@ -133,7 +143,7 @@ object DialogUtils {
text = text
}
}
.show()
.let { showDialog(it) }
true
} ?: false
}

View File

@@ -19,6 +19,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
import org.autojs.autojs.app.DialogUtils;
import org.autojs.autojs.app.GlobalAppContext;
import org.autojs.autojs.core.pref.Pref;
import org.autojs.autojs.extension.MaterialDialogExtensions;
@@ -389,15 +390,14 @@ public class ScriptOperations {
}
public void delete(final ScriptFile scriptFile) {
new MaterialDialog.Builder(mContext)
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title(mContext.getString(R.string.text_confirm_to_delete))
.content(scriptFile.getName())
.negativeText(R.string.text_cancel)
.positiveText(R.string.dialog_button_confirm)
.positiveColorRes(R.color.dialog_button_caution)
.onPositive((dialog, which) -> deleteWithoutConfirm(scriptFile))
.build()
.show();
.build());
}
public void setAsWorkingDir(final ScriptFile scriptFile) {
@@ -409,7 +409,7 @@ public class ScriptOperations {
}
String content = mContext.getString(R.string.text_old_path) + ": " + oldPath + "\n"
+ mContext.getString(R.string.text_new_path) + ": " + newPath;
new MaterialDialog.Builder(mContext)
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title(mContext.getString(R.string.text_prompt))
.content(content)
.negativeText(R.string.text_cancel)
@@ -417,8 +417,7 @@ public class ScriptOperations {
.positiveText(R.string.dialog_button_confirm)
.positiveColorRes(R.color.dialog_button_warn)
.onPositive((dialog, which) -> setAsWorkingDirNow(scriptFile))
.build()
.show();
.build());
}
public void deleteWithoutConfirm(final ScriptFile scriptFile) {
@@ -490,14 +489,14 @@ public class ScriptOperations {
}
public void importFile() {
new FileChooserDialogBuilder(mContext)
DialogUtils.showDialog(new FileChooserDialogBuilder(mContext)
.dir(EnvironmentUtils.getExternalStoragePath())
.justScriptFile()
.singleChoice(file -> importFile(file.getPath()).subscribe())
.title(R.string.text_select_file_to_import)
.positiveText(R.string.dialog_button_confirm)
.positiveColorRes(R.color.dialog_button_attraction)
.show();
.build());
}
public void timedTask(ScriptFile scriptFile) {

View File

@@ -1,19 +1,17 @@
package org.autojs.autojs.ui.explorer;
import static org.autojs.autojs.util.ViewUtils.showToast;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.cardview.widget.CardView;
import androidx.core.widget.ImageViewCompat;
import org.autojs.autojs.AutoJs;
import org.autojs.autojs.model.explorer.ExplorerChangeEvent;
import org.autojs.autojs.model.explorer.ExplorerItem;
@@ -27,6 +25,10 @@ import org.autojs.autojs6.R;
import org.autojs.autojs6.databinding.ExplorerProjectToolbarBinding;
import org.greenrobot.eventbus.Subscribe;
import java.util.List;
import static org.autojs.autojs.util.ViewUtils.showToast;
/**
* Modified by SuperMonster003 as of May 26, 2022.
* Transformed by SuperMonster003 on May 12, 2023.
@@ -41,6 +43,10 @@ public class ExplorerProjectToolbar extends CardView {
private OnOperateListener mOnOperateListener;
// Unify action icon tint to match day/night theme, especially for overlay dialogs.
// zh-CN: 统一操作图标着色以匹配日/夜主题, 尤其用于 overlay 对话框场景.
ColorStateList mActionIconTint = ColorStateList.valueOf(getContext().getColor(R.color.project_toolbar_button));
public ExplorerProjectToolbar(Context context) {
super(context);
init();
@@ -61,9 +67,18 @@ public class ExplorerProjectToolbar extends CardView {
binding = ExplorerProjectToolbarBinding.inflate(LayoutInflater.from(getContext()), this, true);
mProjectName = binding.projectName;
binding.projectRun.setOnClickListener(v -> run());
binding.projectBuild.setOnClickListener(v -> build());
binding.projectEdit.setOnClickListener(v -> edit());
ImageView projectRun = binding.projectRun;
ImageView projectBuild = binding.projectBuild;
ImageView projectEdit = binding.projectEdit;
projectRun.setOnClickListener(v -> run());
projectBuild.setOnClickListener(v -> build());
projectEdit.setOnClickListener(v -> edit());
List.of(projectRun, projectBuild, projectEdit).forEach(imageView -> {
ImageViewCompat.setImageTintList(imageView, mActionIconTint);
});
this.setOnClickListener(v -> edit());
}

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.ui.explorer
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.util.Log
import android.view.ContextThemeWrapper
@@ -12,6 +13,7 @@ import android.view.ViewGroup
import android.widget.PopupMenu
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.core.widget.ImageViewCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller
@@ -126,15 +128,21 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
private val mPageStateHistories = Stack<ExplorerPageState>()
private var mDirectorySpanSize = 2
// Unify action icon tint to match day/night theme, especially for overlay dialogs.
// zh-CN: 统一操作图标着色以匹配日/夜主题, 尤其用于 overlay 对话框场景.
private val mActionIconTint by lazy {
ColorStateList.valueOf(context.getColor(R.color.explorer_file_operation_button))
}
constructor(context: Context) : super(context) {
init()
init(context)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
init(context)
}
private fun init() {
private fun init(context: Context) {
ExplorerViewBinding.inflate(LayoutInflater.from(context), this, true).also { binding ->
this.binding = binding
binding.explorerItemList.also {
@@ -703,6 +711,10 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
mOptions = explorerFileBinding.more.apply { setOnClickListener { withItemSelected { showOptionsMenu() } } }
listOf(mRun, mEdit, mInfo, mInstall, mOptions).forEach { view ->
ImageViewCompat.setImageTintList(view, mActionIconTint)
}
explorerFileBinding.item.setOnClickListener { withItemSelected { onItemClick() } }
}
@@ -934,6 +946,12 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
private var mExplorerPage: ExplorerPage? = null
init {
listOf(mOptions).forEach { view ->
ImageViewCompat.setImageTintList(view, mActionIconTint)
}
}
override fun bind(data: Any, position: Int) {
if (data !is ExplorerPage) return
mName.text = ExplorerViewHelper.getDisplayName(context, data)

View File

@@ -86,8 +86,9 @@ public class CircularMenu implements LayoutInspector.CaptureAvailableListener {
};
public CircularMenu(Context context) {
// mContext = new ContextThemeWrapper(context, R.style.AppTheme);
mContext = context;
// Use application context as base to avoid being treated as Activity context.
// zh-CN: 使用 application context 作为 base, 避免被识别为 Activity context.
mContext = new ContextThemeWrapper(context.getApplicationContext(), R.style.AppTheme);
initFloaty();
setupWindowListeners();
mRecorder = GlobalActionRecorder.getSingleton(context);
@@ -137,26 +138,39 @@ public class CircularMenu implements LayoutInspector.CaptureAvailableListener {
ExplorerView explorerView = new ExplorerView(mContext);
explorerView.setExplorer(Explorers.workspace(), ExplorerDirPage.createRoot(WorkingDirectoryUtils.getPath()));
explorerView.setDirectorySpanSize(2);
final MaterialDialog dialog = new AppLevelThemeDialogBuilder(mContext)
.title(mContext.getString(R.string.text_run_script))
final MaterialDialog dialog = new MaterialDialog.Builder(mContext)
.title(R.string.text_run_script)
.titleColorRes(R.color.day_night)
.customView(explorerView, false)
.backgroundColorRes(R.color.window_background)
.positiveText(R.string.dialog_button_dismiss)
.positiveColorRes(R.color.dialog_button_default)
.cancelable(false)
.build();
explorerView.setOnItemOperateListener(item -> dialog.dismiss());
// Only dismiss on clicking the item itself.
// zh-CN: 仅在点击条目本体时关闭对话框.
explorerView.setOnItemClickListener((view, item) -> {
if (item.isExecutable()) {
Scripts.run(mContext, item.toScriptFile());
dialog.dismiss();
Scripts.run(view != null ? view.getContext() : explorerView.getContext(), item.toScriptFile());
} else {
new MaterialDialog.Builder(mContext)
DialogUtils.showDialog(new MaterialDialog.Builder(mContext)
.title(mContext.getString(R.string.error_failed_to_run_script))
.content(mContext.getString(R.string.text_file_with_abs_path_is_not_an_executable_script, item.toScriptFile().getAbsolutePath()))
.content(mContext.getString(
R.string.text_file_with_abs_path_is_not_an_executable_script,
item.toScriptFile().getAbsolutePath()
))
.positiveText(R.string.dialog_button_dismiss)
.positiveColorRes(R.color.dialog_button_failure)
.show();
.build());
}
});
// Do not dismiss on action buttons (run/edit/delete/rename/etc.).
// zh-CN: 点击右侧操作按钮 (运行/编辑/删除/重命名等) 时不关闭对话框.
explorerView.setOnItemOperateListener(null);
explorerView.setOnProjectToolbarOperateListener(toolbar -> dialog.dismiss());
explorerView.setOnProjectToolbarClickListener(toolbar -> toolbar.findViewById(R.id.project_run).performClick());
explorerView.setProjectToolbarRunnableOnly(true);

View File

@@ -108,7 +108,7 @@
android:focusable="true"
android:src="@drawable/ic_install_explorer_btn"
android:visibility="gone"
app:tint="#A9AAAB"
app:tint="@color/explorer_file_operation_button"
tools:visibility="visible" />
<ImageView
@@ -121,7 +121,7 @@
android:focusable="true"
android:src="@drawable/ic_run_explorer_btn"
android:visibility="gone"
app:tint="#A9AAAB"
app:tint="@color/explorer_file_operation_button"
tools:visibility="visible" />
<ImageView
@@ -134,7 +134,7 @@
android:focusable="true"
android:src="@drawable/ic_edit_explorer_btn"
android:visibility="gone"
app:tint="#A9AAAB"
app:tint="@color/explorer_file_operation_button"
tools:visibility="visible" />
<ImageView
@@ -147,7 +147,7 @@
android:focusable="true"
android:src="@drawable/ic_info_explorer_btn"
android:visibility="gone"
app:tint="#A9AAAB"
app:tint="@color/explorer_file_operation_button"
tools:visibility="visible" />
</LinearLayout>
@@ -162,7 +162,7 @@
android:contentDescription="@string/text_more"
android:focusable="true"
android:src="@drawable/ic_more_explorer_btn"
app:tint="#A9AAAB" />
app:tint="@color/explorer_file_operation_button" />
</LinearLayout>

View File

@@ -72,6 +72,7 @@
<color name="prefTextColorPrimary">#9A9A9A</color>
<color name="prefTextColorSecondary">#808080</color>
<color name="explorer_file_operation_button">@color/md_gray_600</color>
<color name="project_toolbar_button">#A9AAAB</color>
<color name="project_toolbar_title">#A9AAAB</color>

View File

@@ -169,6 +169,7 @@
<color name="prefTextColorPrimary">#282C2F</color>
<color name="prefTextColorSecondary">#9DA0A2</color>
<color name="explorer_file_operation_button">#A9AAAB</color>
<color name="project_toolbar_button">#606366</color>
<color name="project_toolbar_title">#606366</color>