├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── xml
│ │ │ │ ├── pref_mode.xml
│ │ │ │ └── wallet_service_config.xml
│ │ │ └── layout
│ │ │ │ ├── item_common_title_spinner.xml
│ │ │ │ ├── include_common_toolbar.xml
│ │ │ │ ├── include_common_appbar.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── mysiga
│ │ │ │ └── wallet
│ │ │ │ ├── interfaces
│ │ │ │ ├── IWalletConfigView.java
│ │ │ │ └── IWalletServiceView.java
│ │ │ │ ├── model
│ │ │ │ └── WalletModeModel.java
│ │ │ │ ├── config
│ │ │ │ ├── SharePrefHelper.java
│ │ │ │ ├── WalletServiceSwitch.java
│ │ │ │ └── WalletPrefHelper.java
│ │ │ │ ├── service
│ │ │ │ └── WalletService.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── presenter
│ │ │ │ └── WalletServicePresenter.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── mysiga
│ │ │ └── wallet
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mysiga
│ │ └── wallet
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── RedWalletV1.0.7.apk
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── RebWallet.iml
├── RedWallet.iml
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/RedWalletV1.0.7.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/RedWalletV1.0.7.apk
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mysiga/RedWallet/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | *.iml
9 | .idea/
10 | *.class
11 | bin
12 | */bin
13 | */gen
14 | /output
15 | */output
16 | RedWalletV1.0.6.apk
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 25 08:51:30 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/interfaces/IWalletConfigView.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.interfaces;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * 配置接口类
7 | * @author Wilson milin411@163.com
8 | */
9 | public interface IWalletConfigView {
10 |
11 | void updateWalletServiceState();
12 |
13 | Context getContext();
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/interfaces/IWalletServiceView.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.interfaces;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 |
5 | /**
6 | * 服务接口
7 | *
8 | * @author Wlison milin411@163.com
9 | */
10 | public interface IWalletServiceView {
11 | AccessibilityService getAccessibilityService();
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 | 20dp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #484848
7 |
8 | #D1D1D1
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/mysiga/wallet/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_mode.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_common_title_spinner.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mysiga/wallet/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/model/WalletModeModel.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 模式实体类
7 | *
8 | * @author Wilson milin411@163.com
9 | */
10 | public class WalletModeModel implements Serializable {
11 | public String name;
12 | public String mode;
13 |
14 | public WalletModeModel(String name, String mode) {
15 | this.name = name;
16 | this.mode = mode;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_common_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_common_appbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/config/SharePrefHelper.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.config;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.support.annotation.NonNull;
6 |
7 | /**
8 | * SharedPreferences帮助类
9 | *
10 | * @author Wilson milin411@163.com
11 | */
12 | public class SharePrefHelper {
13 |
14 | public static SharedPreferences getSharePref(@NonNull Context context, String name) {
15 | return context.getSharedPreferences(name, Context.MODE_PRIVATE);
16 | }
17 |
18 | public static SharedPreferences.Editor getSharePrefEditor(@NonNull Context context, String name) {
19 | return getSharePref(context, name).edit();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/mingwu/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.mysiga.wallet"
9 | minSdkVersion 19
10 | targetSdkVersion 24
11 | versionCode 3
12 | versionName "1.0.6"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:24.2.0'
26 | compile 'com.android.support:design:24.2.0'
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 微信助手
3 | 当前模式:
4 | 说明:\n1.微信不要设置自动更新\n2.目前适用微信版本:V6.5.4\n3.请确认系统微信通知信息设置打开\n4.请保持屏幕常亮,不能锁屏\n5.外挂模式为后台自动抢红包模式\n6.窗口模式为抢当前聊天页面窗口红包模式
5 | 外挂模式
6 | 窗口模式
7 | 抢红包服务已启动,默认为外挂模式
8 | 中断抢红包服务
9 | 服务器解绑
10 | 打开微信助手服务
11 | 微信助手服务已开启
12 | 找到微信抢助手,并开启
13 | pref_key_mode
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | !-- app actionbar通用popup主题-->
6 |
7 |
8 |
9 |
10 |
14 |
15 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/config/WalletServiceSwitch.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.config;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 |
8 | /**
9 | * 服务器状态
10 | *
11 | * @author Wilson milin411@163.com
12 | */
13 | public class WalletServiceSwitch {
14 | @IntDef({STATE_NO_START, STATE_NOTIFICATION_SERVICE, STATE_WINDOWS_SERVICE})
15 | @Retention(RetentionPolicy.SOURCE)
16 | public @interface WalletServiceState {
17 | }
18 |
19 | /**
20 | * 未启动服务
21 | */
22 | public static final int STATE_NO_START = 0;
23 | /**
24 | * 外挂模式
25 | */
26 | public static final int STATE_NOTIFICATION_SERVICE = 1;
27 | /**
28 | * 窗口模式
29 | */
30 | public static final int STATE_WINDOWS_SERVICE = 2;
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/RebWallet.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/RedWallet.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/config/WalletPrefHelper.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.config;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 |
6 | /**
7 | * 抢红包配置参数类
8 | *
9 | * @author Wilson milin411@163.com
10 | */
11 | public class WalletPrefHelper {
12 |
13 | public static void setWalletServiceState(@NonNull Context context, @WalletServiceSwitch.WalletServiceState int state) {
14 | SharePrefHelper.getSharePrefEditor(context, WalletConfig.APP_NAME).putInt(WalletConfig.SERVICE_STATE, state).commit();
15 | }
16 |
17 | public static int getWalletServiceState(@NonNull Context context) {
18 | return SharePrefHelper.getSharePref(context, WalletConfig.APP_NAME).getInt(WalletConfig.SERVICE_STATE, WalletServiceSwitch.STATE_NO_START);
19 | }
20 |
21 | private static class WalletConfig {
22 | private static final String APP_NAME = "redwallet";
23 | /**
24 | * 服务状态运行状态
25 | */
26 | private static final String SERVICE_STATE = "serivce_state";
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/wallet_service_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
19 |
23 |
24 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
26 | !-- 通用appbar分割线-->
27 |
28 |
29 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
35 |
36 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/service/WalletService.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.service;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 | import android.accessibilityservice.AccessibilityServiceInfo;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.ServiceConnection;
9 | import android.content.SharedPreferences;
10 | import android.preference.PreferenceManager;
11 | import android.view.accessibility.AccessibilityEvent;
12 |
13 | import com.mysiga.wallet.R;
14 | import com.mysiga.wallet.presenter.WalletServicePresenter;
15 | import com.mysiga.wallet.interfaces.IWalletServiceView;
16 |
17 | /**
18 | * redWallet service
19 | *
20 | * @author Wilson milin411@163.com
21 | */
22 | public class WalletService extends AccessibilityService implements IWalletServiceView,
23 | SharedPreferences.OnSharedPreferenceChangeListener {
24 |
25 | private WalletServicePresenter mWalletServicePresenter;
26 | private SharedPreferences mSharedPreferences;
27 |
28 | @Override
29 | public void onCreate() {
30 | super.onCreate();
31 | mWalletServicePresenter = new WalletServicePresenter(this);
32 | }
33 |
34 | @Override
35 | public void onAccessibilityEvent(AccessibilityEvent event) {
36 | if (mWalletServicePresenter != null) {
37 | mWalletServicePresenter.onAccessibilityEvent(event, this);
38 | }
39 | }
40 |
41 | @Override
42 | public void onInterrupt() {
43 |
44 | }
45 |
46 | @Override
47 | protected void onServiceConnected() {
48 | mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
49 | changeMode(mSharedPreferences);
50 | mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
51 | super.onServiceConnected();
52 | }
53 |
54 | @Override
55 | public void unbindService(ServiceConnection conn) {
56 | if (mSharedPreferences != null) {
57 | mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
58 | }
59 | super.unbindService(conn);
60 | }
61 |
62 | @Override
63 | public AccessibilityService getAccessibilityService() {
64 | return this;
65 | }
66 |
67 | @Override
68 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
69 | changeMode(sharedPreferences);
70 | }
71 |
72 | private void changeMode(SharedPreferences sharedPreferences) {
73 | boolean isMode = sharedPreferences.getBoolean(getString(R.string.pref_key_mode), true);
74 | AccessibilityServiceInfo serviceInfo = getServiceInfo();
75 | if (isMode) {
76 | serviceInfo.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
77 | setServiceInfo(serviceInfo);
78 | } else {
79 | serviceInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_SCROLLED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
80 | setServiceInfo(serviceInfo);
81 | mWalletServicePresenter.setIsFirstChecked(false);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.ActivityManager;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.Build;
8 | import android.os.Bundle;
9 | import android.preference.Preference;
10 | import android.preference.PreferenceActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.view.accessibility.AccessibilityManager;
14 | import android.widget.Button;
15 | import android.widget.Toast;
16 |
17 | import com.mysiga.wallet.interfaces.IWalletConfigView;
18 | import com.mysiga.wallet.service.WalletService;
19 |
20 | /**
21 | * 主页
22 | *
23 | * @author Wilson milin411@163.com
24 | */
25 | public class MainActivity extends PreferenceActivity implements View.OnClickListener, AccessibilityManager.AccessibilityStateChangeListener {
26 | private Button mStartServer;
27 | //AccessibilityService 管理
28 | private AccessibilityManager accessibilityManager;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | mStartServer = (Button) findViewById(R.id.open_red_wallet_service);
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.common_toolbar);
36 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View v) {
39 | onBackPressed();
40 | }
41 | });
42 | addPreferencesFromResource(R.xml.pref_mode);
43 | //监听AccessibilityService 变化
44 | accessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
45 | accessibilityManager.addAccessibilityStateChangeListener(this);
46 | updateServiceStatus();
47 |
48 | findViewById(R.id.open_red_wallet_service).setOnClickListener(this);
49 | }
50 |
51 | @Override
52 | protected void onDestroy() {
53 | if (accessibilityManager != null) {
54 | accessibilityManager.removeAccessibilityStateChangeListener(this);
55 | }
56 | super.onDestroy();
57 | }
58 |
59 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
60 | private boolean isServiceRunning() {
61 | ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
62 | String simpleName = WalletService.class.getName();
63 | for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
64 | if (simpleName.equals(service.service.getClassName())) {
65 | return true;
66 | }
67 | }
68 | return false;
69 | }
70 |
71 | @Override
72 | public void onAccessibilityStateChanged(boolean enabled) {
73 | updateServiceStatus();
74 | }
75 |
76 | private void updateServiceStatus() {
77 | mStartServer.setText(isServiceRunning() ? R.string.service_running : R.string.open_service);
78 | }
79 |
80 | @Override
81 | public void onClick(View v) {
82 | switch (v.getId()) {
83 | case R.id.open_red_wallet_service:
84 | try {
85 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
86 | startActivity(intent);
87 | Toast.makeText(this, R.string.open_wechat_assister, Toast.LENGTH_LONG).show();
88 | } catch (Exception e) {
89 | e.printStackTrace();
90 | }
91 | break;
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RedWallet 微信抢红包
2 |
3 | - 当前抢红包有两种模式
4 | - 外挂模式
5 | 
6 | - 窗口模式
7 | 
8 | - 外挂模式
9 | - 开启服务默认就开启了"外挂抢红包模式"
10 | - 外挂模式就是不在当前聊天界面聊天都可以抢红包
11 | - 添加屏幕在没有设置锁屏下可以在关闭屏幕下唤醒屏幕后台抢红包
12 | - 窗口模式
13 | - 就是只能抢当前聊天界面的模式,
14 | - bug:抢完每个当前聊天界面的红包,必须要把当前聊天界面的红包删掉。自己发的红包要自己点击抢红包才能抢到,不能自动帮你抢。
15 | - 使用心得
16 | - 速度
17 | - 网络:一定要保证手机网络或者本身手机的无线是好的
18 | - 手机:这也是影响抢到红包的重要的,在当前聊天窗口抢红包最能体现,首先手机处理速度快。
19 | - iPhone:这里提到下这个外挂都是基于Android手机写的,但是实际在与iPhone6s抢红包发现问题,在网络和手机都相当好的情况下才能抢的过iPhone6s(测试手机:Nexus6,mx3Nexus6与iPhone6s基本:1:1,mx3与iPhone6s基本:0:n)
20 | - 时间
21 | - 外挂模式:3s(正常)
22 | - 当前聊天窗口抢红包模式:1-2s(正常)
23 | - 代码:可以先参考下[抢红包的鼻祖](https://github.com/lendylongli/qianghongbao.git),我也是基于他的代码修改,优化的
24 | - 代码优化
25 | - switch:jdk使用1.7,如果有if-elseif都采用switch
26 |
27 | ````
28 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
29 | private void switchClickRedWallet(AccessibilityEvent event) {
30 | String eventName = String.valueOf(event.getClassName());
31 | switch (eventName) {
32 | case "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI":
33 | //拆红包
34 | openRedWalletView();
35 | break;
36 | case "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI":
37 | //拆完红包后看详细的纪录界面
38 | break;
39 | case "com.tencent.mm.ui.LauncherUI":
40 | //点中领取红包
41 | clickRedWalletView();
42 | break;
43 | default:
44 | break;
45 | }
46 | }
47 | ````
48 | - synchronized:在使用中发现有多线程安全问题
49 |
50 | ````
51 | public synchronized void onAccessibilityEvent(AccessibilityEvent event) {
52 | ````
53 | - 去掉部分for循环:
54 |
55 | ````
56 | case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
57 | List messages = event.getText();
58 | if (!messages.isEmpty()) {
59 | String message = String.valueOf(messages.get(0));
60 | if (!message.contains(WECHAT_RED_TEXT_KEY)) {
61 | return;
62 | }
63 | openNotification(event);
64 | }
65 | break;
66 | ````
67 | 在抢红包通知中“[微信红包]”判断就取第一个,其他点击'微信红包',点击'抢红包'都取一条。
68 | - 简化逻辑:每次只做一件事
69 | - 外挂抢红包模式:用红包通知-->点击通知-->触发 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED-->点击微信红包-->触发 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED-点击抢红包-->触发 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED-跳转抢红包详情页面,鼻祖的代码中有个一问题,点击完通知就立即获取当前页面是否有“微信红包”这个按钮。实际要触发了AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED这个事件才能有"微信红包"按钮
70 | - 通知延迟都设置为0
71 |
72 | ````
73 |
80 | ````
81 | - 当前聊天窗口抢红包模式:重点说下这个吧这也是别人没有我却有的功能
82 | - 地球人知道:微信当前页面聊天没有通知
83 | - 当前窗口有消息只有三种状态改变:具体tag可以设置这个
84 | ````
85 | android:accessibilityEventTypes="typeAllMask"
86 | ````
87 | - AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
88 | - 微信每个页面跳转都会触发这个
89 | - AccessibilityEvent.TYPE_VIEW_SCROLLED:
90 | - 当前页面有消息发过来都会触发这个,要是自己发信息就不会触发这个,而且一次短信就触发一次,触发对象ListView
91 | - AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
92 | - 有消息就会触发,每次都触发4次
93 | - 最后选择AccessibilityEvent.TYPE_VIEW_SCROLLED这个事件来监听是不是这个页面有消息发送过来的标志,主要发生一次,
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mysiga/wallet/presenter/WalletServicePresenter.java:
--------------------------------------------------------------------------------
1 | package com.mysiga.wallet.presenter;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.KeyguardManager;
5 | import android.app.Notification;
6 | import android.app.PendingIntent;
7 | import android.content.Context;
8 | import android.os.Build;
9 | import android.os.Handler;
10 | import android.os.Looper;
11 | import android.os.Parcelable;
12 | import android.os.PowerManager;
13 | import android.support.annotation.NonNull;
14 | import android.util.Log;
15 | import android.view.accessibility.AccessibilityEvent;
16 | import android.view.accessibility.AccessibilityNodeInfo;
17 |
18 | import java.util.List;
19 |
20 | import com.mysiga.wallet.interfaces.IWalletServiceView;
21 |
22 | /**
23 | * wallet service control
24 | *
25 | * @author Wilson milin411@163.com
26 | */
27 | public class WalletServicePresenter {
28 | /**
29 | * 红包消息的关键字
30 | */
31 | private static final String WECHAT_RED_TEXT_KEY = "[微信红包]";
32 | /**
33 | * 拆红包
34 | */
35 | private static final String RECEIVE_RED_TEXT_KEY = "领取红包";
36 | private static final String LOOK_DETAIL_TEXT_KEY = "查看领取详情";
37 | private static final String LOOK_ALL_TEXT_KEY = "看看大家的手气";
38 | /**
39 | * 抢红包id
40 | */
41 | private static final String WHART_VIEW_ID = "com.tencent.mm:id/bi3";
42 |
43 | /**
44 | * 拆红包界面
45 | */
46 | public static final String LUCKY_MONEY_RECEIVE_UI = "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI";
47 | /**
48 | * //红包详情页面
49 | */
50 | public static final String LUCKY_MONEY_DETAIL_UI = "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI";
51 | /**
52 | * 聊天界面
53 | */
54 | public static final String LAUNCHER_UI = "com.tencent.mm.ui.LauncherUI";
55 | public static final String LIST_VIEW = "android.widget.ListView";
56 | private IWalletServiceView mWalletServiceView;
57 | private boolean mIsFirstChecked;
58 | private Handler mHandler;
59 |
60 | public WalletServicePresenter(IWalletServiceView walletServiceView) {
61 | mWalletServiceView = walletServiceView;
62 | }
63 |
64 | public synchronized void setIsFirstChecked(Boolean isFirstChecked) {
65 | mIsFirstChecked = isFirstChecked;
66 | }
67 |
68 | public void onAccessibilityEvent(AccessibilityEvent event, Context context) {
69 | final int eventType = event.getEventType();
70 | Log.d(this.getClass().getSimpleName(), "事件---->" + event);
71 | //通知栏事件
72 | if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
73 | if (isWeChatRedWallet(event)) {
74 | openRedWalletNotification(event, context);
75 | }
76 | } else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
77 | openRedWalletStep(event, context);
78 | } else if (eventType == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
79 | openListRedView(event);
80 | }
81 | }
82 |
83 | private boolean isWeChatRedWallet(AccessibilityEvent event) {
84 | List messages = event.getText();
85 | if (!messages.isEmpty()) {
86 | String message = String.valueOf(messages.get(0));
87 | if (message.contains(WECHAT_RED_TEXT_KEY)) {
88 | return true;
89 | }
90 | }
91 | return false;
92 | }
93 |
94 | /**
95 | * 打开通知栏消息
96 | */
97 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
98 | private void openRedWalletNotification(AccessibilityEvent event, Context context) {
99 | Parcelable parcelable = event.getParcelableData();
100 | if (parcelable == null || !(parcelable instanceof Notification)) {
101 | return;
102 | }
103 | PendingIntent pendingIntent = ((Notification) parcelable).contentIntent;
104 | setIsFirstChecked(true);
105 | try {
106 | pendingIntent.send();
107 | //解决在微信首页微信红包通知后无法触发AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED事件问题
108 | searchRedWalletView(context);
109 | } catch (PendingIntent.CanceledException e) {
110 | e.printStackTrace();
111 | }
112 | }
113 |
114 | private void openRedWalletStep(AccessibilityEvent event, Context context) {
115 | String eventName = String.valueOf(event.getClassName());
116 | //拆红包界面
117 | if (eventName.equals(LUCKY_MONEY_RECEIVE_UI)) {
118 | //拆红包
119 | clickRedWalletView();
120 | } else if (eventName.equals(LUCKY_MONEY_DETAIL_UI)) {
121 | ////红包详情页面,拆完红包后看详细的纪录界面
122 | } else if (eventName.equals(LAUNCHER_UI)) {
123 | ////红包详情页面,点中领取红包
124 | searchRedWalletView(context);
125 | }
126 |
127 | }
128 |
129 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
130 | private void clickRedWalletView() {
131 | AccessibilityNodeInfo nodeInfo = mWalletServiceView.getAccessibilityService().getRootInActiveWindow();
132 | if (nodeInfo == null) {
133 | return;
134 | }
135 | List list = nodeInfo.findAccessibilityNodeInfosByViewId(WHART_VIEW_ID);
136 | if (list.isEmpty()) {
137 | list = nodeInfo.findAccessibilityNodeInfosByText(LOOK_DETAIL_TEXT_KEY);
138 | if (list.isEmpty()) {
139 | list = nodeInfo.findAccessibilityNodeInfosByText(LOOK_ALL_TEXT_KEY);
140 | }
141 | if (!list.isEmpty()) {
142 | AccessibilityNodeInfo parent = list.get(list.size() - 1).getParent();
143 | if (parent != null) {
144 | parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
145 | }
146 | }
147 | } else {
148 | list.get(list.size() - 1).performAction(AccessibilityNodeInfo.ACTION_CLICK);
149 | //// 延时1s判断是否抢到红包,没有抢到点击"查看领取详情"跳转到红包详情
150 | getHandler().postDelayed(new Runnable() {
151 | @Override
152 | public void run() {
153 | AccessibilityNodeInfo nodeInfo = mWalletServiceView.getAccessibilityService().getRootInActiveWindow();
154 | List list = nodeInfo.findAccessibilityNodeInfosByText(WalletServicePresenter.LOOK_DETAIL_TEXT_KEY);
155 | if (!list.isEmpty()) {
156 | AccessibilityNodeInfo parent = list.get(list.size() - 1).getParent();
157 | if (parent != null) {
158 | parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
159 | }
160 | }
161 | }
162 | }, 1000);
163 | }
164 |
165 | }
166 |
167 | private Handler getHandler() {
168 | if (mHandler == null) {
169 | mHandler = new Handler(Looper.getMainLooper());
170 | }
171 | return mHandler;
172 | }
173 |
174 | /**
175 | * 检查屏幕是否亮着并且唤醒屏幕
176 | */
177 | @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
178 | private void wakeScreen(Context context) {
179 | PowerManager powerManager = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE);
180 | if (!powerManager.isInteractive()) {
181 | KeyguardManager keyguardManager = (KeyguardManager) context.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
182 | KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
183 | // 解锁
184 | keyguardLock.disableKeyguard();
185 | // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
186 | PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
187 | // 点亮屏幕
188 | wakeLock.acquire();
189 | // 释放
190 | wakeLock.release();
191 | }
192 | }
193 |
194 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
195 | private void searchRedWalletView(Context context) {
196 | wakeScreen(context);
197 | AccessibilityNodeInfo nodeInfo = mWalletServiceView.getAccessibilityService().getRootInActiveWindow();
198 | if (nodeInfo == null) {
199 | return;
200 | }
201 | List list = nodeInfo.findAccessibilityNodeInfosByText(WalletServicePresenter.RECEIVE_RED_TEXT_KEY);
202 | if (list != null && !list.isEmpty()) {
203 | //最新的红包领起
204 | AccessibilityNodeInfo parent = list.get(list.size() - 1).getParent();
205 | if (parent != null && mIsFirstChecked) {
206 | parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
207 | setIsFirstChecked(false);
208 | }
209 | }
210 | }
211 |
212 |
213 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
214 | private void openListRedView(AccessibilityEvent event) {
215 | String eventName = String.valueOf(event.getClassName());
216 | if (eventName.equals(LIST_VIEW)) {
217 | //在聊天界面,点击"领取红包"
218 | AccessibilityNodeInfo nodeInfo = mWalletServiceView.getAccessibilityService().getRootInActiveWindow();
219 | if (nodeInfo == null) {
220 | return;
221 | }
222 | List list = nodeInfo.findAccessibilityNodeInfosByText(WalletServicePresenter.RECEIVE_RED_TEXT_KEY);
223 | if (list == null || list.isEmpty()) {
224 | return;
225 | }
226 | //最新的红包领起
227 | AccessibilityNodeInfo parent = list.get(list.size() - 1).getParent();
228 | if (parent != null) {
229 | parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
230 | }
231 | }
232 |
233 | }
234 | }
235 |
--------------------------------------------------------------------------------