This commit is contained in:
hyb1996
2018-04-03 16:09:26 +08:00
parent ebf086af90
commit aeae51bb74
9 changed files with 44 additions and 34 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 23 targetSdkVersion 23
versionCode 260 versionCode 261
versionName "3.1.1 Alpha4" versionName "3.1.1 Alpha5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {

View File

@@ -3,6 +3,7 @@ package com.stardust.scriptdroid.autojs.key;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import com.stardust.app.GlobalAppContext;
import com.stardust.autojs.core.inputevent.InputEventObserver; import com.stardust.autojs.core.inputevent.InputEventObserver;
import com.stardust.autojs.core.inputevent.ShellKeyObserver; import com.stardust.autojs.core.inputevent.ShellKeyObserver;
import com.stardust.event.EventDispatcher; import com.stardust.event.EventDispatcher;
@@ -11,6 +12,8 @@ import com.stardust.scriptdroid.autojs.AutoJs;
import com.stardust.view.accessibility.AccessibilityService; import com.stardust.view.accessibility.AccessibilityService;
import com.stardust.view.accessibility.OnKeyListener; import com.stardust.view.accessibility.OnKeyListener;
import javax.microedition.khronos.opengles.GL;
/** /**
* Created by Stardust on 2017/8/14. * Created by Stardust on 2017/8/14.
*/ */
@@ -35,7 +38,7 @@ public class GlobalKeyObserver implements OnKeyListener, ShellKeyObserver.KeyLis
.addListener(this); .addListener(this);
ShellKeyObserver observer = new ShellKeyObserver(); ShellKeyObserver observer = new ShellKeyObserver();
observer.setKeyListener(this); observer.setKeyListener(this);
InputEventObserver.getGlobal().addListener(observer); InputEventObserver.getGlobal(GlobalAppContext.get()).addListener(observer);
} }
public static GlobalKeyObserver getSingleton() { public static GlobalKeyObserver getSingleton() {

View File

@@ -55,15 +55,12 @@ public class LayoutBoundsFloatyWindow extends FullScreenFloatyWindow {
} }
private void setupView() { private void setupView() {
mLayoutBoundsView.setOnNodeInfoSelectListener(new OnNodeInfoSelectListener() { mLayoutBoundsView.setOnNodeInfoSelectListener(info -> {
@Override mSelectedNode = info;
public void onNodeSelect(NodeInfo info) { ensureOperationPopMenu();
mSelectedNode = info; if (mBubblePopMenu.getContentView().getMeasuredWidth() <= 0)
ensureOperationPopMenu(); mBubblePopMenu.preMeasure();
if (mBubblePopMenu.getContentView().getMeasuredWidth() <= 0) mBubblePopMenu.showAsDropDownAtLocation(mLayoutBoundsView, info.getBoundsInScreen().height(), info.getBoundsInScreen().centerX() - mBubblePopMenu.getContentView().getMeasuredWidth() / 2, info.getBoundsInScreen().bottom - mLayoutBoundsView.getStatusBarHeight());
mBubblePopMenu.preMeasure();
mBubblePopMenu.showAsDropDownAtLocation(mLayoutBoundsView, info.getBoundsInScreen().height(), info.getBoundsInScreen().centerX() - mBubblePopMenu.getContentView().getMeasuredWidth() / 2, info.getBoundsInScreen().bottom - mLayoutBoundsView.getStatusBarHeight());
}
}); });
mLayoutBoundsView.getBoundsPaint().setStrokeWidth(2f); mLayoutBoundsView.getBoundsPaint().setStrokeWidth(2f);
mLayoutBoundsView.setRootNode(mRootNode); mLayoutBoundsView.setRootNode(mRootNode);

View File

@@ -32,12 +32,14 @@ public class LayoutBoundsView extends View {
private NodeInfo mTouchedNode; private NodeInfo mTouchedNode;
private Paint mBoundsPaint; private Paint mBoundsPaint;
private Paint mFillingPaint; private Paint mFillingPaint;
private int mStatusBarHeight;
private OnNodeInfoSelectListener mOnNodeInfoSelectListener; private OnNodeInfoSelectListener mOnNodeInfoSelectListener;
private int mTouchedNodeBoundsColor = Color.RED; private int mTouchedNodeBoundsColor = Color.RED;
private int mNormalNodeBoundsColor = Color.GREEN; private int mNormalNodeBoundsColor = Color.GREEN;
private Rect mTouchedNodeBounds; private Rect mTouchedNodeBounds;
private int[] mBoundsInScreen;
protected int mStatusBarHeight;
public LayoutBoundsView(Context context) { public LayoutBoundsView(Context context) {
super(context); super(context);
init(); init();
@@ -76,14 +78,19 @@ public class LayoutBoundsView extends View {
mFillingPaint = new Paint(); mFillingPaint = new Paint();
mFillingPaint.setStyle(Paint.Style.FILL); mFillingPaint.setStyle(Paint.Style.FILL);
mFillingPaint.setColor(COLOR_SHADOW); mFillingPaint.setColor(COLOR_SHADOW);
mStatusBarHeight = ViewUtil.getStatusBarHeight(getContext());
setWillNotDraw(false); setWillNotDraw(false);
mStatusBarHeight = ViewUtil.getStatusBarHeight(getContext());
} }
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (mBoundsInScreen == null) {
mBoundsInScreen = new int[4];
getLocationOnScreen(mBoundsInScreen);
mStatusBarHeight = mBoundsInScreen[1];
}
if (mTouchedNode != null) { if (mTouchedNode != null) {
canvas.save(); canvas.save();
if (mTouchedNodeBounds == null) { if (mTouchedNodeBounds == null) {
@@ -112,10 +119,6 @@ public class LayoutBoundsView extends View {
return mFillingPaint; return mFillingPaint;
} }
public int getStatusBarHeight() {
return mStatusBarHeight;
}
public void setTouchedNodeBoundsColor(int touchedNodeBoundsColor) { public void setTouchedNodeBoundsColor(int touchedNodeBoundsColor) {
mTouchedNodeBoundsColor = touchedNodeBoundsColor; mTouchedNodeBoundsColor = touchedNodeBoundsColor;
} }
@@ -164,13 +167,9 @@ public class LayoutBoundsView extends View {
if (list.isEmpty()) { if (list.isEmpty()) {
return null; return null;
} }
return Collections.min(list, new Comparator<NodeInfo>() { return Collections.min(list, (o1, o2) ->
@Override o1.getBoundsInScreen().width() * o1.getBoundsInScreen().height() -
public int compare(NodeInfo o1, NodeInfo o2) { o2.getBoundsInScreen().width() * o2.getBoundsInScreen().height());
return o1.getBoundsInScreen().width() * o1.getBoundsInScreen().height() -
o2.getBoundsInScreen().width() * o2.getBoundsInScreen().height();
}
});
} }
@@ -188,4 +187,8 @@ public class LayoutBoundsView extends View {
mTouchedNodeBounds = null; mTouchedNodeBounds = null;
invalidate(); invalidate();
} }
public int getStatusBarHeight() {
return mStatusBarHeight;
}
} }

View File

@@ -56,6 +56,7 @@ public class LayoutHierarchyView extends MultiLevelListView {
}; };
private Paint mPaint; private Paint mPaint;
private int[] mBoundsInScreen;
private int mStatusBarHeight; private int mStatusBarHeight;
private NodeInfo mClickedNodeInfo; private NodeInfo mClickedNodeInfo;
private View mClickedView; private View mClickedView;
@@ -89,10 +90,6 @@ public class LayoutHierarchyView extends MultiLevelListView {
mClickedColor = clickedColor; mClickedColor = clickedColor;
} }
public int getStatusBarHeight() {
return mStatusBarHeight;
}
private void init() { private void init() {
mAdapter = new Adapter(); mAdapter = new Adapter();
setAdapter(mAdapter); setAdapter(mAdapter);
@@ -152,6 +149,11 @@ public class LayoutHierarchyView extends MultiLevelListView {
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (mBoundsInScreen == null) {
mBoundsInScreen = new int[4];
getLocationOnScreen(mBoundsInScreen);
mStatusBarHeight = mBoundsInScreen[1];
}
if (mShowClickedNodeBounds && mClickedNodeInfo != null) { if (mShowClickedNodeBounds && mClickedNodeInfo != null) {
LayoutBoundsView.drawRect(canvas, mClickedNodeInfo.getBoundsInScreen(), mStatusBarHeight, mPaint); LayoutBoundsView.drawRect(canvas, mClickedNodeInfo.getBoundsInScreen(), mStatusBarHeight, mPaint);
} }

View File

@@ -84,7 +84,6 @@ public abstract class AutoJs {
protected void init() { protected void init() {
addAccessibilityServiceDelegates(); addAccessibilityServiceDelegates();
registerActivityLifecycleCallbacks(); registerActivityLifecycleCallbacks();
InputEventObserver.initGlobal(mContext);
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_13, mContext, new BaseLoaderCallback(mContext) { OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_13, mContext, new BaseLoaderCallback(mContext) {
}); });
} }

View File

@@ -75,11 +75,16 @@ public class InputEventObserver {
mContext = context; mContext = context;
} }
public static InputEventObserver getGlobal() { public static InputEventObserver getGlobal(Context context) {
if (sGlobal == null) {
initGlobal(context);
}
return sGlobal; return sGlobal;
} }
public static void initGlobal(Context context) { private static void initGlobal(Context context) {
if (sGlobal != null)
return;
sGlobal = new InputEventObserver(context); sGlobal = new InputEventObserver(context);
sGlobal.observe(); sGlobal.observe();
} }

View File

@@ -106,7 +106,7 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
return; return;
ensureHandler(); ensureHandler();
mLoopers.waitWhenIdle(true); mLoopers.waitWhenIdle(true);
mTouchObserver = new TouchObserver(InputEventObserver.getGlobal()); mTouchObserver = new TouchObserver(InputEventObserver.getGlobal(mContext));
mTouchObserver.setOnTouchEventListener(this); mTouchObserver.setOnTouchEventListener(this);
mTouchObserver.observe(); mTouchObserver.observe();
} }

View File

@@ -3,6 +3,7 @@ package com.stardust.auojs.inrt.autojs;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import com.stardust.app.GlobalAppContext;
import com.stardust.auojs.inrt.Pref; import com.stardust.auojs.inrt.Pref;
import com.stardust.autojs.core.inputevent.InputEventObserver; import com.stardust.autojs.core.inputevent.InputEventObserver;
import com.stardust.autojs.core.inputevent.ShellKeyObserver; import com.stardust.autojs.core.inputevent.ShellKeyObserver;
@@ -26,7 +27,7 @@ public class GlobalKeyObserver implements OnKeyListener, ShellKeyObserver.KeyLis
.addListener(this); .addListener(this);
ShellKeyObserver observer = new ShellKeyObserver(); ShellKeyObserver observer = new ShellKeyObserver();
observer.setKeyListener(this); observer.setKeyListener(this);
InputEventObserver.getGlobal().addListener(observer); InputEventObserver.getGlobal(GlobalAppContext.get()).addListener(observer);
} }
public static void init() { public static void init() {