opt: layout inspector toast
This commit is contained in:
@@ -31,9 +31,12 @@ import com.stardust.scriptdroid.ui.main.scripts.ScriptListView;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
import com.stardust.view.accessibility.LayoutInspector;
|
||||
import com.stardust.view.accessibility.NodeInfo;
|
||||
import com.stericson.RootShell.RootShell;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
@@ -43,7 +46,8 @@ import butterknife.Optional;
|
||||
* Created by Stardust on 2017/10/18.
|
||||
*/
|
||||
|
||||
public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
public class CircularMenu implements Recorder.OnStateChangedListener, LayoutInspector.CaptureAvailableListener {
|
||||
|
||||
|
||||
public static class StateChangeEvent {
|
||||
private int currentState;
|
||||
@@ -76,6 +80,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
private GlobalActionRecorder mRecorder;
|
||||
private MaterialDialog mSettingsDialog;
|
||||
private String mRunningPackage, mRunningActivity;
|
||||
private Deferred<NodeInfo, Void, Void> mCaptureDeferred;
|
||||
|
||||
public CircularMenu(Context context) {
|
||||
mContext = new ContextThemeWrapper(context, R.style.AppTheme);
|
||||
@@ -83,6 +88,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
setupListeners();
|
||||
mRecorder = GlobalActionRecorder.getSingleton(context);
|
||||
mRecorder.addOnStateChangedListener(this);
|
||||
AutoJs.getInstance().getLayoutInspector().addCaptureAvailableListener(this);
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
@@ -92,6 +98,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
} else if (mWindow.isExpanded()) {
|
||||
mWindow.collapse();
|
||||
} else {
|
||||
mCaptureDeferred = new DeferredObject<>();
|
||||
AutoJs.getInstance().getLayoutInspector().captureCurrentWindow();
|
||||
mWindow.expand();
|
||||
}
|
||||
@@ -182,12 +189,14 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
if (!ensureCapture()) {
|
||||
return;
|
||||
}
|
||||
LayoutBoundsFloatyWindow window = new LayoutBoundsFloatyWindow(
|
||||
AutoJs.getInstance().getLayoutInspector().getCapture()
|
||||
);
|
||||
FloatyService.addWindow(window);
|
||||
mCaptureDeferred.promise()
|
||||
.done(capture -> {
|
||||
LayoutBoundsFloatyWindow window = new LayoutBoundsFloatyWindow(capture);
|
||||
mActionViewIcon.post(() -> FloatyService.addWindow(window));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Optional
|
||||
@OnClick(R.id.layout_hierarchy)
|
||||
void showLayoutHierarchy() {
|
||||
@@ -195,20 +204,28 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
if (!ensureCapture()) {
|
||||
return;
|
||||
}
|
||||
LayoutHierarchyFloatyWindow window = new LayoutHierarchyFloatyWindow(
|
||||
AutoJs.getInstance().getLayoutInspector().getCapture()
|
||||
);
|
||||
FloatyService.addWindow(window);
|
||||
mCaptureDeferred.promise()
|
||||
.done(capture -> {
|
||||
LayoutHierarchyFloatyWindow window = new LayoutHierarchyFloatyWindow(capture);
|
||||
mActionViewIcon.post(() -> FloatyService.addWindow(window));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptureAvailable(NodeInfo capture) {
|
||||
mCaptureDeferred.resolve(capture);
|
||||
}
|
||||
|
||||
private boolean ensureCapture() {
|
||||
LayoutInspector inspector = AutoJs.getInstance().getLayoutInspector();
|
||||
if (inspector.isDumping()) {
|
||||
Toast.makeText(mContext, R.string.text_layout_inspector_is_dumping, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (AccessibilityService.getInstance() == null) {
|
||||
Toast.makeText(mContext, R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
return false;
|
||||
}
|
||||
if (inspector.getCapture() == null) {
|
||||
@@ -296,6 +313,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
mState = STATE_CLOSED;
|
||||
}
|
||||
mRecorder.removeOnStateChangedListener(this);
|
||||
AutoJs.getInstance().getLayoutInspector().removeCaptureAvailableListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
<string name="text_guard_mode">保护模式</string>
|
||||
<string name="summary_guard_mode">在本软件界面无法运行自动操作命令以免误触</string>
|
||||
<string name="key_guard_mode">key_guard_mode</string>
|
||||
<string name="text_layout_inspector_is_dumping">布局分析中,请稍后点击</string>
|
||||
<string name="text_layout_inspector_is_dumping">布局分析中</string>
|
||||
<string name="text_force_stop">强制停止</string>
|
||||
<string name="text_execution_finished" formatted="false">\n------------\n[%s]运行结束,用时%f秒</string>
|
||||
<string name="text_again">又</string>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
>
|
||||
<activity
|
||||
android:name=".execution.ScriptExecuteActivity"
|
||||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
|
||||
android:theme="@style/AppTheme"/>
|
||||
|
||||
<activity
|
||||
android:name="com.stardust.autojs.core.image.ScreenCaptureRequestActivity"
|
||||
@@ -22,7 +22,6 @@
|
||||
android:theme="@style/AppTheme.Transparent"/>
|
||||
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -50,7 +50,6 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
mAndroidContext = context;
|
||||
mContext = createContext();
|
||||
mScriptable = createScope(mContext);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@@ -17,29 +19,45 @@ import java.util.concurrent.Executors;
|
||||
|
||||
public class LayoutInspector {
|
||||
|
||||
public interface CaptureAvailableListener {
|
||||
void onCaptureAvailable(NodeInfo capture);
|
||||
}
|
||||
|
||||
private static final String LOG_TAG = LayoutInspector.class.getSimpleName();
|
||||
private volatile NodeInfo mCapture;
|
||||
private volatile boolean mDumping = false;
|
||||
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||
private CopyOnWriteArrayList<CaptureAvailableListener> mCaptureAvailableListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void captureCurrentWindow() {
|
||||
AccessibilityService service = AccessibilityService.getInstance();
|
||||
if (service == null) {
|
||||
Log.d(LOG_TAG, "captureCurrentWindow: service = null");
|
||||
mCapture = null;
|
||||
} else {
|
||||
final AccessibilityNodeInfo root = getRootInActiveWindow(service);
|
||||
if (root == null) {
|
||||
Log.d(LOG_TAG, "captureCurrentWindow: root = null");
|
||||
mCapture = null;
|
||||
} else {
|
||||
mExecutor.execute(() -> {
|
||||
mDumping = true;
|
||||
mCapture = NodeInfo.capture(root);
|
||||
mDumping = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
final AccessibilityNodeInfo root = getRootInActiveWindow(service);
|
||||
if (root == null) {
|
||||
Log.d(LOG_TAG, "captureCurrentWindow: root = null");
|
||||
mCapture = null;
|
||||
return;
|
||||
}
|
||||
mExecutor.execute(() -> {
|
||||
mDumping = true;
|
||||
mCapture = NodeInfo.capture(root);
|
||||
mDumping = false;
|
||||
for (CaptureAvailableListener l : mCaptureAvailableListeners) {
|
||||
l.onCaptureAvailable(mCapture);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addCaptureAvailableListener(CaptureAvailableListener l){
|
||||
mCaptureAvailableListeners.add(l);
|
||||
}
|
||||
|
||||
public boolean removeCaptureAvailableListener(CaptureAvailableListener l){
|
||||
return mCaptureAvailableListeners.remove(l);
|
||||
}
|
||||
|
||||
private AccessibilityNodeInfo getRootInActiveWindow(AccessibilityService service) {
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.stardust.autojs.project.ProjectConfig;
|
||||
import com.stardust.autojs.script.JavaScriptFileSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import org.mozilla.javascript.optimizer.ClassCompiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user