mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix(target O): floating window cannot be shown
This commit is contained in:
parent
0ff7b1c208
commit
54cbb78d8e
@ -291,14 +291,14 @@ public class ScriptOperations {
|
||||
}
|
||||
|
||||
public void delete(final ScriptFile scriptFile) {
|
||||
new ThemeColorMaterialDialogBuilder(mContext)
|
||||
DialogUtils.showDialog(new ThemeColorMaterialDialogBuilder(mContext)
|
||||
.title(mContext.getString(R.string.text_are_you_sure_to_delete, scriptFile.getName()))
|
||||
.positiveText(R.string.cancel)
|
||||
.negativeText(R.string.ok)
|
||||
.onNegative((dialog, which) -> {
|
||||
deleteWithoutConfirm(scriptFile);
|
||||
})
|
||||
.show();
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package org.autojs.autojs.ui.floating;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.Gravity;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
@ -94,8 +95,10 @@ public class CircularMenuWindow implements FloatyWindow {
|
||||
}
|
||||
|
||||
private WindowManager.LayoutParams createWindowLayoutParams() {
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(-2, -2, 2003, 520, -3);
|
||||
layoutParams.gravity = 51;
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
FloatyWindowManger.getWindowType(), 520, -3);
|
||||
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
return layoutParams;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ package org.autojs.autojs.ui.floating;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
@ -9,9 +11,11 @@ import com.stardust.autojs.util.FloatingPermission;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
import com.stardust.enhancedfloaty.util.FloatingWindowPermissionUtil;
|
||||
|
||||
import org.autojs.autojs.App;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.ui.floating.CircularMenu;
|
||||
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@ -74,4 +78,12 @@ public class FloatyWindowManger {
|
||||
menu.close();
|
||||
sCircularMenu = null;
|
||||
}
|
||||
|
||||
public static int getWindowType() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
return WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
||||
}
|
||||
|
||||
private void initConsoleTitle(View view) {
|
||||
mTitleView = (TextView) view.findViewById(R.id.title);
|
||||
mTitleView = view.findViewById(R.id.title);
|
||||
if (mTitle != null) {
|
||||
mTitleView.setText(mTitle);
|
||||
}
|
||||
@ -91,7 +91,7 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
||||
}
|
||||
|
||||
private void setUpConsole(View view, ResizableExpandableFloatyWindow window) {
|
||||
ConsoleView consoleView = (ConsoleView) view.findViewById(R.id.console);
|
||||
ConsoleView consoleView = view.findViewById(R.id.console);
|
||||
consoleView.setConsole(mConsole);
|
||||
consoleView.setWindow(window);
|
||||
initConsoleTitle(view);
|
||||
|
||||
@ -66,10 +66,16 @@ public class RawWindow implements FloatyWindow {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
|
||||
}
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
}
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
type,
|
||||
flags,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.START;
|
||||
|
||||
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Build;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@ -15,10 +16,17 @@ public class DialogUtils {
|
||||
|
||||
public static <T extends Dialog> T showDialog(T dialog) {
|
||||
Context context = dialog.getContext();
|
||||
|
||||
if (!isActivityContext(context)) {
|
||||
Window window = dialog.getWindow();
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
if (window != null)
|
||||
window.setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
window.setType(type);
|
||||
}
|
||||
dialog.show();
|
||||
return dialog;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user