fix(target O): floating window cannot be shown

This commit is contained in:
hyb1996
2018-10-06 11:16:27 +08:00
parent 0ff7b1c208
commit 54cbb78d8e
6 changed files with 37 additions and 8 deletions

View File

@@ -291,14 +291,14 @@ public class ScriptOperations {
} }
public void delete(final ScriptFile scriptFile) { 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())) .title(mContext.getString(R.string.text_are_you_sure_to_delete, scriptFile.getName()))
.positiveText(R.string.cancel) .positiveText(R.string.cancel)
.negativeText(R.string.ok) .negativeText(R.string.ok)
.onNegative((dialog, which) -> { .onNegative((dialog, which) -> {
deleteWithoutConfirm(scriptFile); deleteWithoutConfirm(scriptFile);
}) })
.show(); .build());
} }

View File

@@ -3,6 +3,7 @@ package org.autojs.autojs.ui.floating;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.Gravity;
import android.view.OrientationEventListener; import android.view.OrientationEventListener;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
@@ -94,8 +95,10 @@ public class CircularMenuWindow implements FloatyWindow {
} }
private WindowManager.LayoutParams createWindowLayoutParams() { private WindowManager.LayoutParams createWindowLayoutParams() {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(-2, -2, 2003, 520, -3); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
layoutParams.gravity = 51; WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
FloatyWindowManger.getWindowType(), 520, -3);
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
return layoutParams; return layoutParams;
} }

View File

@@ -2,6 +2,8 @@ package org.autojs.autojs.ui.floating;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
import com.stardust.app.GlobalAppContext; import com.stardust.app.GlobalAppContext;
@@ -9,9 +11,11 @@ import com.stardust.autojs.util.FloatingPermission;
import com.stardust.enhancedfloaty.FloatyService; import com.stardust.enhancedfloaty.FloatyService;
import com.stardust.enhancedfloaty.FloatyWindow; import com.stardust.enhancedfloaty.FloatyWindow;
import com.stardust.enhancedfloaty.util.FloatingWindowPermissionUtil; import com.stardust.enhancedfloaty.util.FloatingWindowPermissionUtil;
import org.autojs.autojs.App; import org.autojs.autojs.App;
import org.autojs.autojs.R; import org.autojs.autojs.R;
import org.autojs.autojs.ui.floating.CircularMenu; import org.autojs.autojs.ui.floating.CircularMenu;
import com.stardust.util.IntentUtil; import com.stardust.util.IntentUtil;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@@ -74,4 +78,12 @@ public class FloatyWindowManger {
menu.close(); menu.close();
sCircularMenu = null; 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;
}
}
} }

View File

@@ -80,7 +80,7 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
} }
private void initConsoleTitle(View view) { private void initConsoleTitle(View view) {
mTitleView = (TextView) view.findViewById(R.id.title); mTitleView = view.findViewById(R.id.title);
if (mTitle != null) { if (mTitle != null) {
mTitleView.setText(mTitle); mTitleView.setText(mTitle);
} }
@@ -91,7 +91,7 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
} }
private void setUpConsole(View view, ResizableExpandableFloatyWindow window) { 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.setConsole(mConsole);
consoleView.setWindow(window); consoleView.setWindow(window);
initConsoleTitle(view); initConsoleTitle(view);

View File

@@ -66,10 +66,16 @@ public class RawWindow implements FloatyWindow {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 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 layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, type,
flags, flags,
PixelFormat.TRANSLUCENT); PixelFormat.TRANSLUCENT);
layoutParams.gravity = Gravity.TOP | Gravity.START; layoutParams.gravity = Gravity.TOP | Gravity.START;

View File

@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.os.Build;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
@@ -15,10 +16,17 @@ public class DialogUtils {
public static <T extends Dialog> T showDialog(T dialog) { public static <T extends Dialog> T showDialog(T dialog) {
Context context = dialog.getContext(); Context context = dialog.getContext();
if (!isActivityContext(context)) { if (!isActivityContext(context)) {
Window window = dialog.getWindow(); 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) if (window != null)
window.setType(WindowManager.LayoutParams.TYPE_PHONE); window.setType(type);
} }
dialog.show(); dialog.show();
return dialog; return dialog;