fix: floaty not working

This commit is contained in:
hyb1996
2018-10-12 23:30:50 +08:00
parent e64afaa88f
commit 4dc37bc4ff
12 changed files with 194 additions and 22 deletions

View File

@@ -37,7 +37,7 @@
<meta-data
android:name="android.max_aspect"
android:value="2.1" />
android:value="2.1"/>
<activity
android:name=".ui.splash.SplashActivity"
@@ -126,6 +126,33 @@
<activity android:name=".external.tasker.TaskPrefEditActivity_"/>
<service
android:name=".external.tile.LayoutBoundsTile"
android:icon="@drawable/ic_circular_menu_bounds"
android:label="@string/text_inspect_layout_bounds"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="false"/>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<service
android:name=".external.tile.LayoutHierarchyTile"
android:icon="@drawable/ic_circular_menu_hierarchy"
android:label="@string/text_inspect_layout_hierarchy"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="false"/>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<activity-alias
android:name=".external.tasker.PluginActivity"
android:exported="true"
@@ -138,10 +165,10 @@
</intent-filter>
</activity-alias>
<receiver android:name="org.autojs.autojs.external.receiver.StaticBroadcastReceiver" >
<receiver android:name="org.autojs.autojs.external.receiver.StaticBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.TIME_SET"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
<action android:name="android.intent.action.UID_REMOVED"/>
@@ -170,6 +197,7 @@
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_RESTARTED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>

View File

@@ -0,0 +1,23 @@
package org.autojs.autojs.external.tile;
import android.os.Build;
import android.support.annotation.RequiresApi;
import com.stardust.view.accessibility.NodeInfo;
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
import org.autojs.autojs.ui.floating.layoutinspector.LayoutBoundsFloatyWindow;
@RequiresApi(api = Build.VERSION_CODES.N)
public class LayoutBoundsTile extends LayoutInspectTileService {
@Override
protected FullScreenFloatyWindow onCreateWindow(NodeInfo capture) {
return new LayoutBoundsFloatyWindow(capture) {
@Override
public void close() {
super.close();
inactive();
}
};
}
}

View File

@@ -0,0 +1,23 @@
package org.autojs.autojs.external.tile;
import android.os.Build;
import android.support.annotation.RequiresApi;
import com.stardust.view.accessibility.NodeInfo;
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
import org.autojs.autojs.ui.floating.layoutinspector.LayoutHierarchyFloatyWindow;
@RequiresApi(api = Build.VERSION_CODES.N)
public class LayoutHierarchyTile extends LayoutInspectTileService {
@Override
protected FullScreenFloatyWindow onCreateWindow(NodeInfo capture) {
return new LayoutHierarchyFloatyWindow(capture) {
@Override
public void close() {
super.close();
inactive();
}
};
}
}

View File

@@ -0,0 +1,90 @@
package org.autojs.autojs.external.tile;
import android.content.Intent;
import android.os.Build;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.widget.Toast;
import com.stardust.app.GlobalAppContext;
import com.stardust.view.accessibility.LayoutInspector;
import com.stardust.view.accessibility.NodeInfo;
import org.autojs.autojs.R;
import org.autojs.autojs.accessibility.AccessibilityService;
import org.autojs.autojs.autojs.AutoJs;
import org.autojs.autojs.tool.AccessibilityServiceTool;
import org.autojs.autojs.ui.floating.FloatyWindowManger;
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
@RequiresApi(api = Build.VERSION_CODES.N)
public abstract class LayoutInspectTileService extends TileService implements LayoutInspector.CaptureAvailableListener {
private boolean mCapturing = false;
@Override
public void onCreate() {
super.onCreate();
Log.d(getClass().getName(), "onCreate");
AutoJs.getInstance().getLayoutInspector().addCaptureAvailableListener(this);
}
@Override
public void onStartListening() {
super.onStartListening();
Log.d(getClass().getName(), "onStartListening");
inactive();
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(getClass().getName(), "onDestroy");
AutoJs.getInstance().getLayoutInspector().removeCaptureAvailableListener(this);
}
@Override
public void onClick() {
super.onClick();
Log.d(getClass().getName(), "onClick");
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
if (AccessibilityService.getInstance() == null) {
Toast.makeText(this, R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
AccessibilityServiceTool.goToAccessibilitySetting();
inactive();
return;
}
mCapturing = true;
GlobalAppContext.postDelayed(() ->
AutoJs.getInstance().getLayoutInspector().captureCurrentWindow()
, 1000);
}
protected void inactive() {
Tile qsTile = getQsTile();
if (qsTile == null)
return;
qsTile.setState(Tile.STATE_INACTIVE);
qsTile.updateTile();
}
@Override
public void onCaptureAvailable(NodeInfo capture) {
Log.d(getClass().getName(), "onCaptureAvailable: capturing = " + mCapturing);
if (!mCapturing) {
return;
}
mCapturing = false;
GlobalAppContext.post(() -> {
FullScreenFloatyWindow window = onCreateWindow(capture);
if (!FloatyWindowManger.addWindow(getApplicationContext(), window)) {
inactive();
}
});
}
protected abstract FullScreenFloatyWindow onCreateWindow(NodeInfo capture);
}

View File

@@ -99,7 +99,7 @@ public class FunctionsKeyboardView extends FrameLayout {
}
private void initPropertiesView() {
WrapContentGridLayoutManger manager = new WrapContentGridLayoutManger(getContext(), 2);
WrapContentGridLayoutManger manager = new WrapContentGridLayoutManger(getContext(), SPAN_COUNT);
manager.setDebugInfo("FunctionsKeyboardView");
mPropertiesView.setLayoutManager(manager);
mPropertiesView.setAdapter(new PropertiesAdapter());

View File

@@ -32,18 +32,21 @@ public class FloatyWindowManger {
private static WeakReference<CircularMenu> sCircularMenu;
public static void addWindow(Context context, FloatyWindow window) {
public static boolean addWindow(Context context, FloatyWindow window) {
context.startService(new Intent(context, FloatyService.class));
FloatingPermission.ensurePermissionGranted(context);
boolean hasPermission = FloatingPermission.ensurePermissionGranted(context);
try {
FloatyService.addWindow(window);
return true;
// SecurityException: https://github.com/hyb1996-guest/AutoJsIssueReport/issues/4781
} catch (Exception e) {
e.printStackTrace();
manageDrawOverlays(context);
Toast.makeText(context, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
if(hasPermission){
manageDrawOverlays(context);
Toast.makeText(context, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
}
}
return false;
}
public static boolean isCircularMenuShowing() {

View File

@@ -1,5 +1,6 @@
package org.autojs.autojs.ui.shortcut;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -58,12 +59,13 @@ public class ShortcutIconSelectActivity extends BaseActivity {
private void setupApps() {
mApps.setAdapter(new AppsAdapter());
WrapContentGridLayoutManger manager = new WrapContentGridLayoutManger(this, 2);
WrapContentGridLayoutManger manager = new WrapContentGridLayoutManger(this, 5);
manager.setDebugInfo("IconSelectView");
mApps.setLayoutManager(manager);
loadApps();
}
@SuppressLint("CheckResult")
private void loadApps() {
List<ApplicationInfo> packages = mPackageManager.getInstalledApplications(PackageManager.GET_META_DATA);
Observable.fromIterable(packages)