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

修复红包无法自动点击开启的问题 #260

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "xyz.monkeytong.hongbao"
minSdkVersion 19
targetSdkVersion 25
versionCode 7
versionName "v5.0.0"
targetSdkVersion 26
versionCode 8
versionName "v5.0.1"
ndk {
//设置支持的SO库架构
abiFilters 'armeabi', 'armeabi-v7a' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
Expand Down Expand Up @@ -40,6 +40,6 @@ android {
//其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.0.1
compile 'com.tencent.bugly:nativecrashreport:latest.release'
//其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.2.0
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.graphics.Path;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.util.DisplayMetrics;
import xyz.monkeytong.hongbao.utils.HongbaoSignature;
import xyz.monkeytong.hongbao.utils.PowerUtil;

import java.util.List;

import xyz.monkeytong.hongbao.utils.HongbaoSignature;
import xyz.monkeytong.hongbao.utils.PowerUtil;

public class HongbaoService extends AccessibilityService implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "HongbaoService";
private static final String WECHAT_DETAILS_EN = "Details";
Expand All @@ -35,6 +37,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
private static final String WECHAT_LUCKMONEY_DETAIL_ACTIVITY = "LuckyMoneyDetailUI";
private static final String WECHAT_LUCKMONEY_GENERAL_ACTIVITY = "LauncherUI";
private static final String WECHAT_LUCKMONEY_CHATTING_ACTIVITY = "ChattingUI";
private static final String WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY = "LuckyMoneyReceiveUI";
private String currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY;

private AccessibilityNodeInfo rootNodeInfo, mReceiveNode, mUnpackNode;
Expand Down Expand Up @@ -74,8 +77,6 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
private void watchChat(AccessibilityEvent event) {
this.rootNodeInfo = getRootInActiveWindow();

if (rootNodeInfo == null) return;

mReceiveNode = null;
mUnpackNode = null;

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

private boolean canOpen(AccessibilityEvent event) {
return event.getClassName() != null
&& event.getClassName().toString().contains(WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY)
&& event.isFullScreen()
&& event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
}

private void openPacket() {
DisplayMetrics metrics = getResources().getDisplayMetrics();
float dpi = metrics.densityDpi;
Log.d(TAG, "openPacket!" + dpi);
if (android.os.Build.VERSION.SDK_INT <= 23) {
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
} else {
if (android.os.Build.VERSION.SDK_INT > 23) {
Path path = new Path();
if (640 == dpi) { //1440
path.moveTo(720, 1575);
} else if(320 == dpi){//720p
path.moveTo(355, 780);
}else if(480 == dpi){//1080p
path.moveTo(533, 1115);
if (mUnpackCount >= 1 && (mUnpackNode != null)) {
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}else{
DisplayMetrics metrics = getResources().getDisplayMetrics();
float dpi = metrics.densityDpi;
Log.d(TAG, "openPacket!" + dpi);
Path path = new Path();
path.moveTo(metrics.widthPixels * 0.5f, metrics.heightPixels * 0.6f);
GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build();
dispatchGesture(gestureDescription, new GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
Log.d(TAG, "onCompleted");
mMutex = false;
super.onCompleted(gestureDescription);
}
GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build();
dispatchGesture(gestureDescription, new GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
Log.d(TAG, "onCompleted");
mMutex = false;
super.onCompleted(gestureDescription);
}

@Override
public void onCancelled(GestureDescription gestureDescription) {
Log.d(TAG, "onCancelled");
mMutex = false;
super.onCancelled(gestureDescription);
}
}, null);

}
@Override
public void onCancelled(GestureDescription gestureDescription) {
Log.d(TAG, "onCancelled");
mMutex = false;
super.onCancelled(gestureDescription);
}
}, null);
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/accessible_service_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:accessibilityFeedbackType="feedbackAllMask"
android:packageNames="com.tencent.mm"
android:notificationTimeout="10"
android:canPerformGestures="true"
android:settingsActivity="xyz.monkeytong.hongbao.activities.SettingsActivity"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"/>