Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 532764a

Browse files
author
walter
committed
fix can't open packet
1 parent 54a5201 commit 532764a

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "26.0.2"
4+
compileSdkVersion 26
5+
buildToolsVersion "26.0.3"
66
useLibrary 'org.apache.http.legacy'
77
defaultConfig {
88
applicationId "xyz.monkeytong.hongbao"
99
minSdkVersion 19
10-
targetSdkVersion 25
11-
versionCode 7
12-
versionName "v5.0.0"
10+
targetSdkVersion 26
11+
versionCode 8
12+
versionName "v5.0.1"
1313
ndk {
1414
//设置支持的SO库架构
1515
abiFilters 'armeabi', 'armeabi-v7a' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
@@ -40,6 +40,6 @@ android {
4040
//其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.0.1
4141
compile 'com.tencent.bugly:nativecrashreport:latest.release'
4242
//其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.2.0
43-
compile 'com.android.support:support-v4:25.4.0'
44-
compile 'com.android.support:appcompat-v7:25.4.0'
43+
compile 'com.android.support:support-v4:26.1.0'
44+
compile 'com.android.support:appcompat-v7:26.1.0'
4545
}

app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
import android.accessibilityservice.AccessibilityService;
44
import android.accessibilityservice.GestureDescription;
5+
import android.annotation.SuppressLint;
56
import android.app.Notification;
67
import android.app.PendingIntent;
78
import android.content.ComponentName;
89
import android.content.SharedPreferences;
910
import android.content.pm.PackageManager;
11+
import android.graphics.Path;
1012
import android.graphics.Rect;
1113
import android.os.Bundle;
1214
import android.os.Parcelable;
13-
import android.graphics.Path;
1415
import android.preference.PreferenceManager;
16+
import android.util.DisplayMetrics;
1517
import android.util.Log;
1618
import android.view.accessibility.AccessibilityEvent;
1719
import android.view.accessibility.AccessibilityNodeInfo;
18-
import android.util.DisplayMetrics;
19-
import xyz.monkeytong.hongbao.utils.HongbaoSignature;
20-
import xyz.monkeytong.hongbao.utils.PowerUtil;
2120

2221
import java.util.List;
2322

23+
import xyz.monkeytong.hongbao.utils.HongbaoSignature;
24+
import xyz.monkeytong.hongbao.utils.PowerUtil;
25+
2426
public class HongbaoService extends AccessibilityService implements SharedPreferences.OnSharedPreferenceChangeListener {
2527
private static final String TAG = "HongbaoService";
2628
private static final String WECHAT_DETAILS_EN = "Details";
@@ -35,6 +37,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
3537
private static final String WECHAT_LUCKMONEY_DETAIL_ACTIVITY = "LuckyMoneyDetailUI";
3638
private static final String WECHAT_LUCKMONEY_GENERAL_ACTIVITY = "LauncherUI";
3739
private static final String WECHAT_LUCKMONEY_CHATTING_ACTIVITY = "ChattingUI";
40+
private static final String WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY = "LuckyMoneyReceiveUI";
3841
private String currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY;
3942

4043
private AccessibilityNodeInfo rootNodeInfo, mReceiveNode, mUnpackNode;
@@ -74,8 +77,6 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
7477
private void watchChat(AccessibilityEvent event) {
7578
this.rootNodeInfo = getRootInActiveWindow();
7679

77-
if (rootNodeInfo == null) return;
78-
7980
mReceiveNode = null;
8081
mUnpackNode = null;
8182

@@ -92,7 +93,7 @@ private void watchChat(AccessibilityEvent event) {
9293
}
9394
/* 如果戳开但还未领取 */
9495
Log.d(TAG, "戳开红包!" + " mUnpackCount: " + mUnpackCount + " mUnpackNode: " + mUnpackNode);
95-
if (mUnpackCount >= 1 && (mUnpackNode != null)) {
96+
if (canOpen(event)) {
9697
int delayFlag = sharedPreferences.getInt("pref_open_delay", 0) * 1000;
9798
new android.os.Handler().postDelayed(
9899
new Runnable() {
@@ -110,41 +111,41 @@ public void run() {
110111
}
111112
}
112113

114+
private boolean canOpen(AccessibilityEvent event) {
115+
return event.getClassName() != null
116+
&& event.getClassName().toString().contains(WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY)
117+
&& event.isFullScreen()
118+
&& event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
119+
}
120+
113121
private void openPacket() {
114-
DisplayMetrics metrics = getResources().getDisplayMetrics();
115-
float dpi = metrics.densityDpi;
116-
Log.d(TAG, "openPacket!" + dpi);
117122
if (android.os.Build.VERSION.SDK_INT <= 23) {
118-
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
119-
} else {
120-
if (android.os.Build.VERSION.SDK_INT > 23) {
121-
Path path = new Path();
122-
if (640 == dpi) { //1440
123-
path.moveTo(720, 1575);
124-
} else if(320 == dpi){//720p
125-
path.moveTo(355, 780);
126-
}else if(480 == dpi){//1080p
127-
path.moveTo(533, 1115);
123+
if (mUnpackCount >= 1 && (mUnpackNode != null)) {
124+
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
125+
}
126+
}else{
127+
DisplayMetrics metrics = getResources().getDisplayMetrics();
128+
float dpi = metrics.densityDpi;
129+
Log.d(TAG, "openPacket!" + dpi);
130+
Path path = new Path();
131+
path.moveTo(metrics.widthPixels * 0.5f, metrics.heightPixels * 0.6f);
132+
GestureDescription.Builder builder = new GestureDescription.Builder();
133+
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build();
134+
dispatchGesture(gestureDescription, new GestureResultCallback() {
135+
@Override
136+
public void onCompleted(GestureDescription gestureDescription) {
137+
Log.d(TAG, "onCompleted");
138+
mMutex = false;
139+
super.onCompleted(gestureDescription);
128140
}
129-
GestureDescription.Builder builder = new GestureDescription.Builder();
130-
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build();
131-
dispatchGesture(gestureDescription, new GestureResultCallback() {
132-
@Override
133-
public void onCompleted(GestureDescription gestureDescription) {
134-
Log.d(TAG, "onCompleted");
135-
mMutex = false;
136-
super.onCompleted(gestureDescription);
137-
}
138-
139-
@Override
140-
public void onCancelled(GestureDescription gestureDescription) {
141-
Log.d(TAG, "onCancelled");
142-
mMutex = false;
143-
super.onCancelled(gestureDescription);
144-
}
145-
}, null);
146141

147-
}
142+
@Override
143+
public void onCancelled(GestureDescription gestureDescription) {
144+
Log.d(TAG, "onCancelled");
145+
mMutex = false;
146+
super.onCancelled(gestureDescription);
147+
}
148+
}, null);
148149
}
149150
}
150151

app/src/main/res/xml/accessible_service_config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
android:accessibilityFeedbackType="feedbackAllMask"
77
android:packageNames="com.tencent.mm"
88
android:notificationTimeout="10"
9+
android:canPerformGestures="true"
910
android:settingsActivity="xyz.monkeytong.hongbao.activities.SettingsActivity"
1011
android:accessibilityFlags="flagDefault"
1112
android:canRetrieveWindowContent="true"/>

0 commit comments

Comments
 (0)