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

Commit

Permalink
fix can't open packet
Browse files Browse the repository at this point in the history
  • Loading branch information
walter committed Dec 17, 2018
1 parent 54a5201 commit 64bc802
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
8 changes: 0 additions & 8 deletions WeChatLuckyMoney.iml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="WeChatLuckyMoney" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
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,42 +111,43 @@ 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;
}

@SuppressLint("NewApi")
private void openPacket() {
if (android.os.Build.VERSION.SDK_INT <= 23) {
if (mUnpackCount >= 1 && (mUnpackNode != null)) {
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return;
}
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);
}
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);
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);
}

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

private void setCurrentActivityName(AccessibilityEvent event) {
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"/>

0 comments on commit 64bc802

Please sign in to comment.