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"
minSdkVersion 17
targetSdkVersion 23
versionCode 260
versionName "3.1.1 Alpha4"
versionCode 261
versionName "3.1.1 Alpha5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
ndk {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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