├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── leo │ │ └── wxautomanager │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── leo │ │ │ ├── common │ │ │ ├── Config.java │ │ │ ├── UI.java │ │ │ └── util │ │ │ │ ├── DensityUtils.java │ │ │ │ ├── PhoneController.java │ │ │ │ └── SPHelper.java │ │ │ ├── main │ │ │ └── MainActivity.java │ │ │ └── service │ │ │ ├── AutoOpenLuckyMoneyService.java │ │ │ └── AutoReplyService.java │ └── res │ │ ├── drawable │ │ ├── btn_cancel.xml │ │ └── btn_ok.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── dialog_view.xml │ │ └── listview_item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── cancel_normal.png │ │ ├── cancel_press.png │ │ ├── ic_launcher.png │ │ ├── ok_normal.png │ │ └── ok_press.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ ├── auto_open_lucky_money.xml │ │ └── auto_reply_service_config.xml │ └── test │ └── java │ └── com │ └── leo │ └── wxautomanager │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | WXAutoManager -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.leo.wxautomanager" 9 | minSdkVersion 18 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 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 | compile 'com.android.support:appcompat-v7:23.4.0' 25 | compile 'com.android.support:design:23.4.0' 26 | testCompile 'junit:junit:4.12' 27 | } 28 | -------------------------------------------------------------------------------- /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 E:\android-sdk-windows/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/src/androidTest/java/com/leo/wxautomanager/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.leo.wxautomanager; 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/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/common/Config.java: -------------------------------------------------------------------------------- 1 | package com.leo.common; 2 | 3 | /** 4 | * Created by leo on 2016/8/5. 5 | * 保存全局变量 6 | */ 7 | public class Config { 8 | 9 | /** 10 | * 微信包名 11 | */ 12 | public final static String WX_PACKAGE_NAME = "com.tencent.mm"; 13 | 14 | /** 15 | * 是否打开自动回复 16 | */ 17 | public static boolean isOpenAutoReply = false; 18 | 19 | /** 20 | * 是否打开自动抢红包 21 | */ 22 | public static boolean isOpenAutoOpenLuckyMoney = false; 23 | 24 | /** 25 | * 自动回复文本 26 | */ 27 | public static String AutoReplyText = "我现在没空, 稍后回复哈~"; 28 | 29 | /** 30 | * 选择ID 31 | */ 32 | public static int SelectId = 0; 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/common/UI.java: -------------------------------------------------------------------------------- 1 | package com.leo.common; 2 | 3 | /** 4 | * Created by lenovo on 2016/8/7. 5 | * UI控件 6 | */ 7 | public class UI { 8 | 9 | public final static String BUTTON = "android.widget.Button"; 10 | public final static String EDITTEXT = "android.widget.EditText"; 11 | public final static String LUCKY_MONEY_RECEIVE_UI = "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI"; 12 | public final static String LUCKY_MONEY_DETAIL_UI = "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI"; 13 | public final static String OPEN_LUCKY_MONEY_BUTTON_ID = "com.tencent.mm:id/b_b"; 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/common/util/DensityUtils.java: -------------------------------------------------------------------------------- 1 | package com.leo.common.util; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by Leo on 2017/1/22. 7 | */ 8 | 9 | public class DensityUtils { 10 | 11 | public static int dp2px(Context context, float val) { 12 | float f = context.getResources().getDisplayMetrics().density; 13 | return (int) (val * f + 0.5F); 14 | } 15 | 16 | public static int px2dp(Context context, float val) { 17 | float f = context.getResources().getDisplayMetrics().density; 18 | return (int) (val / f + 0.5F); 19 | } 20 | 21 | public static int sp2px(Context context, float val) { 22 | float f = context.getResources().getDisplayMetrics().scaledDensity; 23 | return (int) (val * f + 0.5F); 24 | } 25 | 26 | public static int px2sp(Context context, float val) { 27 | float f = context.getResources().getDisplayMetrics().scaledDensity; 28 | return (int) (val / f + 0.5F); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/common/util/PhoneController.java: -------------------------------------------------------------------------------- 1 | package com.leo.common.util; 2 | 3 | import android.app.KeyguardManager; 4 | import android.content.Context; 5 | import android.os.PowerManager; 6 | 7 | /** 8 | * Created by leo on 2016/8/4. 9 | * 手机控制相关工具类 10 | */ 11 | public class PhoneController { 12 | 13 | private final static String TAG = PhoneController.class.getSimpleName(); 14 | 15 | /** 16 | * 判断是否锁屏 17 | * @param context 18 | * @return 19 | */ 20 | public static boolean isLockScreen(Context context) { 21 | KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); 22 | return km.inKeyguardRestrictedInputMode(); 23 | } 24 | 25 | /** 26 | * 唤醒手机并解锁(不能有锁屏密码) 27 | * @param context 28 | */ 29 | public static void wakeAndUnlockScreen(Context context) { 30 | PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 31 | PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP 32 | | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); 33 | wakeLock.acquire(1000); // 点亮屏幕 34 | wakeLock.release(); 35 | 36 | KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); 37 | KeyguardManager.KeyguardLock lock = km.newKeyguardLock("unlock"); 38 | lock.disableKeyguard(); // 解锁 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/common/util/SPHelper.java: -------------------------------------------------------------------------------- 1 | package com.leo.common.util; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by leo on 2017/1/14. 8 | */ 9 | 10 | public class SPHelper { 11 | 12 | private static final String DATA_NAME = "MySharePre"; 13 | 14 | private SharedPreferences mSharedPre; 15 | 16 | private static SPHelper instance = null; 17 | 18 | private SPHelper() { 19 | } 20 | 21 | public static SPHelper getInstance() { 22 | if(instance == null) { 23 | synchronized (SPHelper.class) { 24 | if (instance == null) { 25 | instance = new SPHelper(); 26 | } 27 | } 28 | } 29 | return instance; 30 | } 31 | 32 | public void init(Context context) { 33 | mSharedPre = context.getSharedPreferences(DATA_NAME, Context.MODE_PRIVATE); 34 | } 35 | 36 | public Boolean getBoolean(String key) { 37 | if(!isInit()) { 38 | return false; 39 | } 40 | return mSharedPre.getBoolean(key, false); 41 | } 42 | 43 | public void putBoolean(String key, boolean value) { 44 | if(!isInit()) { 45 | return; 46 | } 47 | SharedPreferences.Editor editor = mSharedPre.edit(); 48 | editor.putBoolean(key, value); 49 | editor.apply(); 50 | } 51 | 52 | public int getInt(String key) { 53 | if(!isInit()) { 54 | return 0; 55 | } 56 | return mSharedPre.getInt(key, 0); 57 | } 58 | 59 | public void putInt(String key, int value) { 60 | if(!isInit()) { 61 | return; 62 | } 63 | SharedPreferences.Editor editor = mSharedPre.edit(); 64 | editor.putInt(key, value); 65 | editor.apply(); 66 | } 67 | 68 | public String getString(String key) { 69 | if(!isInit()) { 70 | return ""; 71 | } 72 | return mSharedPre.getString(key, ""); 73 | } 74 | 75 | public void putString(String key, String value) { 76 | if(!isInit()) { 77 | return; 78 | } 79 | SharedPreferences.Editor editor = mSharedPre.edit(); 80 | editor.putString(key, value); 81 | editor.apply(); 82 | } 83 | 84 | private boolean isInit() { 85 | return mSharedPre != null; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/main/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.leo.main; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.design.widget.FloatingActionButton; 9 | import android.support.design.widget.Snackbar; 10 | import android.support.v7.app.AlertDialog; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.AppCompatCheckBox; 13 | import android.support.v7.widget.SwitchCompat; 14 | import android.support.v7.widget.Toolbar; 15 | import android.view.LayoutInflater; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.widget.BaseAdapter; 19 | import android.widget.CompoundButton; 20 | import android.widget.EditText; 21 | import android.widget.ListView; 22 | import android.widget.RelativeLayout; 23 | import android.widget.TextView; 24 | 25 | import com.leo.common.Config; 26 | import com.leo.common.util.DensityUtils; 27 | import com.leo.common.util.SPHelper; 28 | import com.leo.service.AutoOpenLuckyMoneyService; 29 | import com.leo.service.AutoReplyService; 30 | import com.leo.wxautomanager.R; 31 | 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | public class MainActivity extends AppCompatActivity { 36 | 37 | private static final String KEY_REPLY = "reply"; 38 | private static final String KEY_LUCKY_MONEY = "lucky_money"; 39 | private static final String KEY_SELECT_ID = "select_id"; 40 | private static final String KEY_AUTO_REPLY_TEXT = "reply_text"; 41 | 42 | private MyAdapter mAdapter; 43 | 44 | private final List mData = new ArrayList<>(); 45 | 46 | 47 | @Override 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.activity_main); 51 | 52 | SPHelper.getInstance().init(this); 53 | initData(); 54 | initView(); 55 | } 56 | 57 | private void initData() { 58 | Config.isOpenAutoReply = SPHelper.getInstance().getBoolean(KEY_REPLY); 59 | Config.isOpenAutoOpenLuckyMoney = SPHelper.getInstance().getBoolean(KEY_LUCKY_MONEY); 60 | int selectId = SPHelper.getInstance().getInt(KEY_SELECT_ID); 61 | if (selectId < 0 || selectId > 2) { 62 | selectId = 0; 63 | } 64 | Config.SelectId = selectId; 65 | Config.AutoReplyText = SPHelper.getInstance().getString(KEY_AUTO_REPLY_TEXT); 66 | 67 | // 自动回复默认文本 68 | mData.add("Hey~"); 69 | mData.add("你已被拉进黑名单"); 70 | mData.add("忙碌.jpg"); 71 | } 72 | 73 | 74 | private void initView() { 75 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 76 | setSupportActionBar(toolbar); 77 | 78 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 79 | fab.setOnClickListener(new View.OnClickListener() { 80 | @Override 81 | public void onClick(View view) { 82 | showAddReplyView(MainActivity.this); 83 | } 84 | }); 85 | 86 | SwitchCompat swReply = (SwitchCompat) findViewById(R.id.sw_auto_reply); 87 | swReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 88 | @Override 89 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 90 | if(isChecked) { 91 | checkAutoReplyService(MainActivity.this); 92 | Config.isOpenAutoReply = true; 93 | SPHelper.getInstance().putBoolean(KEY_REPLY, true); 94 | } else { 95 | Config.isOpenAutoReply = false; 96 | SPHelper.getInstance().putBoolean(KEY_REPLY, false); 97 | } 98 | } 99 | }); 100 | swReply.setChecked(Config.isOpenAutoReply); 101 | 102 | SwitchCompat swLuckyMoney = (SwitchCompat) findViewById(R.id.sw_auto_open_lucky_money); 103 | swLuckyMoney.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 104 | @Override 105 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 106 | if(isChecked) { 107 | checkAutoOpenLuckyMoneyService(MainActivity.this); 108 | Config.isOpenAutoOpenLuckyMoney = true; 109 | SPHelper.getInstance().putBoolean(KEY_LUCKY_MONEY, true); 110 | } else { 111 | Config.isOpenAutoOpenLuckyMoney = false; 112 | SPHelper.getInstance().putBoolean(KEY_LUCKY_MONEY, false); 113 | } 114 | } 115 | }); 116 | swLuckyMoney.setChecked(Config.isOpenAutoOpenLuckyMoney); 117 | 118 | 119 | mAdapter = new MyAdapter(this, mData, Config.SelectId); 120 | ListView lvContents = (ListView) findViewById(R.id.lv_reply_content); 121 | lvContents.setAdapter(mAdapter); 122 | } 123 | 124 | 125 | private final int ADD_TEXT_LIMIT = 8; 126 | private void showAddReplyView(final Context context) { 127 | final RelativeLayout contentView = new RelativeLayout(context); 128 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( 129 | RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 130 | params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); 131 | params.setMargins(DensityUtils.dp2px(context, 30), 0, 132 | DensityUtils.dp2px(context, 20), 0); 133 | final EditText editText = new EditText(context); 134 | contentView.addView(editText, params); 135 | 136 | final Dialog dialog = new AlertDialog.Builder(context) 137 | .setTitle("添加自动回复文本") 138 | .setView(contentView) 139 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 140 | @Override 141 | public void onClick(DialogInterface dialog, int which) { 142 | String text = editText.getText().toString(); 143 | if (text.length() > 0) { 144 | if (mData.size() < ADD_TEXT_LIMIT) { 145 | addText(text); 146 | Snackbar.make(contentView, "添加文本成功", Snackbar.LENGTH_SHORT) 147 | .setAction("Action", null).show(); 148 | } else { 149 | Snackbar.make(contentView, "添加文本已到上限", Snackbar.LENGTH_SHORT) 150 | .setAction("Action", null).show(); 151 | } 152 | } 153 | dialog.dismiss(); 154 | } 155 | }) 156 | .setNegativeButton("取消", null) 157 | .create(); 158 | dialog.setCancelable(true); 159 | dialog.show(); 160 | } 161 | 162 | private void addText(String text) { 163 | mData.add(text); 164 | mAdapter.notifyDataSetChanged(); 165 | } 166 | 167 | private void checkAutoReplyService(Context context) { 168 | if (!AutoReplyService.isConnected()) { 169 | showAccessibilityServiceSettings(context); 170 | } 171 | } 172 | 173 | private void checkAutoOpenLuckyMoneyService(Context context) { 174 | if (!AutoOpenLuckyMoneyService.isConnected()) { 175 | showAccessibilityServiceSettings(context); 176 | } 177 | } 178 | 179 | private Dialog mDialog = null; 180 | private void showAccessibilityServiceSettings(Context context) { 181 | if (mDialog != null && mDialog.isShowing()) { 182 | mDialog.dismiss(); 183 | mDialog = null; 184 | } 185 | mDialog = new AlertDialog.Builder(context) 186 | .setMessage("使用微信自动服务需要打开辅助服务, 去设置?") 187 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 188 | @Override 189 | public void onClick(DialogInterface dialog, int which) { 190 | Intent intent = new Intent(); 191 | intent.setAction("android.settings.ACCESSIBILITY_SETTINGS"); 192 | startActivity(intent); 193 | } 194 | }) 195 | .setNegativeButton("取消", null) 196 | .create(); 197 | mDialog.show(); 198 | } 199 | 200 | 201 | /* ==== Adapter ==== */ 202 | private class MyAdapter extends BaseAdapter { 203 | 204 | List mData; 205 | LayoutInflater mInflater; 206 | int mSelectId; 207 | 208 | MyAdapter(Context context, List data, int selectId) { 209 | mData = data; 210 | mInflater = LayoutInflater.from(context); 211 | mSelectId = selectId; 212 | } 213 | 214 | @Override 215 | public int getCount() { 216 | return mData.size(); 217 | } 218 | 219 | @Override 220 | public Object getItem(int position) { 221 | return mData.get(position); 222 | } 223 | 224 | @Override 225 | public long getItemId(int position) { 226 | return position; 227 | } 228 | 229 | @Override 230 | public View getView(final int position, View convertView, ViewGroup parent) { 231 | ViewHolder viewHolder; 232 | if(convertView == null) { 233 | viewHolder = new ViewHolder(); 234 | convertView = mInflater.inflate(R.layout.listview_item, parent, false); 235 | viewHolder.textView = (TextView) convertView.findViewById(R.id.tv_content); 236 | viewHolder.checkBox = (AppCompatCheckBox) convertView.findViewById(R.id.cb_select); 237 | convertView.setTag(viewHolder); 238 | } else { 239 | viewHolder = (ViewHolder) convertView.getTag(); 240 | } 241 | 242 | viewHolder.textView.setText(mData.get(position)); 243 | viewHolder.checkBox.setChecked((mSelectId == position)); 244 | viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 245 | @Override 246 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 247 | if(isChecked) { 248 | mSelectId = position; 249 | notifyDataSetChanged(); 250 | // 保存数据 251 | SPHelper.getInstance().putInt(KEY_SELECT_ID, mSelectId); 252 | String text = mData.get(position); 253 | Config.AutoReplyText = text; 254 | SPHelper.getInstance().putString(KEY_AUTO_REPLY_TEXT, text); 255 | } 256 | } 257 | }); 258 | 259 | return convertView; 260 | } 261 | 262 | class ViewHolder { 263 | TextView textView; 264 | AppCompatCheckBox checkBox; 265 | } 266 | } 267 | 268 | @Override 269 | public void onBackPressed() { 270 | Intent i = new Intent(Intent.ACTION_MAIN); 271 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 272 | i.addCategory(Intent.CATEGORY_HOME); 273 | startActivity(i); 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/service/AutoOpenLuckyMoneyService.java: -------------------------------------------------------------------------------- 1 | package com.leo.service; 2 | 3 | import android.accessibilityservice.AccessibilityService; 4 | import android.app.Notification; 5 | import android.app.PendingIntent; 6 | import android.content.Intent; 7 | import android.os.Handler; 8 | import android.os.Message; 9 | import android.util.Log; 10 | import android.view.accessibility.AccessibilityEvent; 11 | import android.view.accessibility.AccessibilityNodeInfo; 12 | 13 | import com.leo.common.Config; 14 | import com.leo.common.UI; 15 | import com.leo.common.util.PhoneController; 16 | 17 | import java.util.List; 18 | 19 | /** 20 | * Created by leo on 2016/8/7. 21 | * 自动抢红包服务 22 | */ 23 | public class AutoOpenLuckyMoneyService extends AccessibilityService { 24 | 25 | private static final String TAG = AutoOpenLuckyMoneyService.class.getSimpleName(); 26 | 27 | private static final int MSG_BACK_HOME = 0; 28 | private static final int MSG_BACK_ONCE = 1; 29 | boolean hasNotify = false; 30 | boolean hasLuckyMoney = true; 31 | private static boolean sIsBound = false; 32 | 33 | 34 | @Override 35 | public void onAccessibilityEvent(AccessibilityEvent event) { 36 | if(!Config.isOpenAutoOpenLuckyMoney) { 37 | Log.i(TAG, "interrupt auto open lucky money service"); 38 | return; 39 | } 40 | 41 | int eventType = event.getEventType(); // 事件类型 42 | switch (eventType) { 43 | case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: // 通知栏事件 44 | Log.i(TAG, "TYPE_NOTIFICATION_STATE_CHANGED"); 45 | if(PhoneController.isLockScreen(this)) { // 锁屏 46 | PhoneController.wakeAndUnlockScreen(this); // 唤醒点亮屏幕 47 | } 48 | 49 | openAppByNotification(event); 50 | hasNotify = true; 51 | break; 52 | 53 | default: 54 | Log.i(TAG, "DEFAULT"); 55 | if(hasNotify) { 56 | AccessibilityNodeInfo rootNode = getRootInActiveWindow(); 57 | clickLuckyMoney(rootNode); 58 | 59 | String className = event.getClassName().toString(); 60 | if (className.equals(UI.LUCKY_MONEY_RECEIVE_UI)) { 61 | if(!openLuckyMoney()) { 62 | backToHome(); 63 | hasNotify = false; 64 | } 65 | hasLuckyMoney = true; 66 | } else if (className.equals(UI.LUCKY_MONEY_DETAIL_UI)) { 67 | backToHome(); 68 | hasNotify = false; 69 | hasLuckyMoney = true; 70 | } else { 71 | if(!hasLuckyMoney) { 72 | handler.sendEmptyMessage(MSG_BACK_ONCE); 73 | hasLuckyMoney = true; // 防止后退多次 74 | } 75 | } 76 | } 77 | break; 78 | } 79 | } 80 | 81 | @Override 82 | public void onInterrupt() { 83 | 84 | } 85 | 86 | @Override 87 | protected void onServiceConnected() { 88 | Log.i(TAG, "connect auto open lucky money service"); 89 | sIsBound = true; 90 | super.onServiceConnected(); 91 | } 92 | 93 | @Override 94 | public boolean onUnbind(Intent intent) { 95 | Log.i(TAG, "disconnect auto open lucky money service"); 96 | sIsBound = false; 97 | return super.onUnbind(intent); 98 | } 99 | 100 | public static boolean isConnected() { 101 | return sIsBound; 102 | } 103 | 104 | /** 105 | * 打开微信 106 | * @param event 事件 107 | */ 108 | private void openAppByNotification(AccessibilityEvent event) { 109 | if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) { 110 | Notification notification = (Notification) event.getParcelableData(); 111 | try { 112 | PendingIntent pendingIntent = notification.contentIntent; 113 | pendingIntent.send(); 114 | } catch (PendingIntent.CanceledException e) { 115 | e.printStackTrace(); 116 | } 117 | } 118 | } 119 | 120 | 121 | private void clickLuckyMoney(AccessibilityNodeInfo rootNode) { 122 | if(rootNode != null) { 123 | int count = rootNode.getChildCount(); 124 | for (int i = count - 1; i >= 0; i--) { // 倒序查找最新的红包 125 | AccessibilityNodeInfo node = rootNode.getChild(i); 126 | if (node == null) 127 | continue; 128 | 129 | CharSequence text = node.getText(); 130 | if (text != null && text.toString().equals("领取红包")) { 131 | AccessibilityNodeInfo parent = node.getParent(); 132 | while (parent != null) { 133 | if (parent.isClickable()) { 134 | parent.performAction(AccessibilityNodeInfo.ACTION_CLICK); 135 | break; 136 | } 137 | parent = parent.getParent(); 138 | } 139 | } 140 | 141 | clickLuckyMoney(node); 142 | } 143 | } 144 | } 145 | 146 | 147 | private boolean openLuckyMoney() { 148 | AccessibilityNodeInfo rootNode = getRootInActiveWindow(); 149 | if(rootNode != null) { 150 | List nodes = 151 | rootNode.findAccessibilityNodeInfosByViewId(UI.OPEN_LUCKY_MONEY_BUTTON_ID); 152 | for(AccessibilityNodeInfo node : nodes) { 153 | if(node.isClickable()) { 154 | Log.i(TAG, "open LuckyMoney"); 155 | node.performAction(AccessibilityNodeInfo.ACTION_CLICK); 156 | return true; 157 | } 158 | } 159 | } 160 | 161 | return false; 162 | } 163 | 164 | 165 | private void backToHome() { 166 | if(handler.hasMessages(MSG_BACK_HOME)) { 167 | handler.removeMessages(MSG_BACK_HOME); 168 | } 169 | handler.sendEmptyMessage(MSG_BACK_HOME); 170 | } 171 | 172 | 173 | Handler handler = new Handler() { 174 | @Override 175 | public void handleMessage(Message msg) { 176 | if(msg.what == MSG_BACK_HOME) { 177 | performGlobalAction(GLOBAL_ACTION_BACK); 178 | postDelayed(new Runnable() { 179 | @Override 180 | public void run() { 181 | performGlobalAction(GLOBAL_ACTION_BACK); 182 | hasLuckyMoney = false; 183 | } 184 | }, 1500); 185 | } else if(msg.what == MSG_BACK_ONCE) { 186 | postDelayed(new Runnable() { 187 | @Override 188 | public void run() { 189 | Log.i(TAG, "click back"); 190 | performGlobalAction(GLOBAL_ACTION_BACK); 191 | hasLuckyMoney = false; 192 | hasNotify = false; 193 | } 194 | }, 1500); 195 | } 196 | } 197 | }; 198 | } 199 | -------------------------------------------------------------------------------- /app/src/main/java/com/leo/service/AutoReplyService.java: -------------------------------------------------------------------------------- 1 | package com.leo.service; 2 | 3 | import android.accessibilityservice.AccessibilityService; 4 | import android.app.Notification; 5 | import android.app.PendingIntent; 6 | import android.content.ClipData; 7 | import android.content.ClipboardManager; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.os.Build; 11 | import android.os.Bundle; 12 | import android.os.Handler; 13 | import android.util.Log; 14 | import android.view.accessibility.AccessibilityEvent; 15 | import android.view.accessibility.AccessibilityNodeInfo; 16 | 17 | import com.leo.common.Config; 18 | import com.leo.common.UI; 19 | import com.leo.common.util.PhoneController; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Created by leo on 2016/8/4. 25 | * 自动回复服务 26 | */ 27 | public class AutoReplyService extends AccessibilityService { 28 | 29 | private static final String TAG = AutoReplyService.class.getSimpleName(); 30 | 31 | private Handler handler = new Handler(); 32 | private boolean hasNotify = false; 33 | private static boolean sIsBound = false; 34 | 35 | /** 36 | * 必须重写的方法,响应各种事件。 37 | */ 38 | @Override 39 | public void onAccessibilityEvent(final AccessibilityEvent event) { 40 | if(!Config.isOpenAutoReply) { 41 | Log.i(TAG, "interrupt auto reply service"); 42 | return; 43 | } 44 | 45 | int eventType = event.getEventType(); // 事件类型 46 | switch (eventType) { 47 | case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: // 通知栏事件 48 | // Log.i(TAG, "TYPE_NOTIFICATION_STATE_CHANGED"); 49 | if(PhoneController.isLockScreen(this)) { // 锁屏 50 | PhoneController.wakeAndUnlockScreen(this); // 唤醒点亮屏幕 51 | } 52 | openAppByNotification(event); 53 | hasNotify = true; 54 | break; 55 | 56 | default: 57 | // Log.i(TAG, "DEFAULT"); 58 | if (hasNotify) { 59 | try { 60 | Thread.sleep(1000); // 停1秒, 否则在微信主界面没进入聊天界面就执行了fillInputBar 61 | } catch (InterruptedException e) { 62 | e.printStackTrace(); 63 | } 64 | if (fillInputBar(Config.AutoReplyText)) { 65 | findAndPerformAction(UI.BUTTON, "发送"); 66 | handler.postDelayed(new Runnable() { 67 | @Override 68 | public void run() { 69 | performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); // 返回 70 | } 71 | }, 1500); 72 | 73 | } 74 | hasNotify = false; 75 | } 76 | break; 77 | } 78 | } 79 | 80 | 81 | @Override 82 | public void onInterrupt() { 83 | Log.i(TAG, "onInterrupt"); 84 | } 85 | 86 | 87 | @Override 88 | protected void onServiceConnected() { 89 | // mainfest 配置了这里无需配置 90 | // AccessibilityServiceInfo info = new AccessibilityServiceInfo(); 91 | // info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; 92 | // info.packageNames = new String[]{Config.WX_PACKAGE_NAME}; 93 | // info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN; 94 | // info.notificationTimeout = 100; 95 | // this.setServiceInfo(info); 96 | 97 | Log.i(TAG, "connect auto reply service"); 98 | sIsBound = true; 99 | super.onServiceConnected(); 100 | } 101 | 102 | @Override 103 | public boolean onUnbind(Intent intent) { 104 | Log.i(TAG, "disconnect auto reply service"); 105 | sIsBound = false; 106 | return super.onUnbind(intent); 107 | } 108 | 109 | public static boolean isConnected() { 110 | return sIsBound; 111 | } 112 | 113 | /** 114 | * 查找UI控件并点击 115 | * @param widget 控件完整名称, 如android.widget.Button, android.widget.TextView 116 | * @param text 控件文本 117 | */ 118 | private void findAndPerformAction(String widget, String text) { 119 | // 取得当前激活窗体的根节点 120 | if (getRootInActiveWindow() == null) { 121 | return; 122 | } 123 | 124 | // 通过文本找到当前的节点 125 | List nodes = getRootInActiveWindow().findAccessibilityNodeInfosByText(text); 126 | if(nodes != null) { 127 | for (AccessibilityNodeInfo node : nodes) { 128 | if (node.getClassName().equals(widget) && node.isEnabled()) { 129 | node.performAction(AccessibilityNodeInfo.ACTION_CLICK); // 执行点击 130 | break; 131 | } 132 | } 133 | } 134 | } 135 | 136 | 137 | 138 | /** 139 | * 打开微信 140 | * @param event 事件 141 | */ 142 | private void openAppByNotification(AccessibilityEvent event) { 143 | if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) { 144 | Notification notification = (Notification) event.getParcelableData(); 145 | try { 146 | PendingIntent pendingIntent = notification.contentIntent; 147 | pendingIntent.send(); 148 | } catch (PendingIntent.CanceledException e) { 149 | e.printStackTrace(); 150 | } 151 | } 152 | } 153 | 154 | 155 | 156 | /** 157 | * 填充输入框 158 | */ 159 | private boolean fillInputBar(String reply) { 160 | AccessibilityNodeInfo rootNode = getRootInActiveWindow(); 161 | if (rootNode != null) { 162 | return findInputBar(rootNode, reply); 163 | } 164 | return false; 165 | } 166 | 167 | 168 | 169 | /** 170 | * 查找EditText控件 171 | * @param rootNode 根结点 172 | * @param reply 回复内容 173 | * @return 找到返回true, 否则返回false 174 | */ 175 | private boolean findInputBar(AccessibilityNodeInfo rootNode, String reply) { 176 | int count = rootNode.getChildCount(); 177 | Log.i(TAG, "root class=" + rootNode.getClassName() + ", " + rootNode.getText() + ", child: " + count); 178 | for (int i = 0; i < count; i++) { 179 | AccessibilityNodeInfo node = rootNode.getChild(i); 180 | if (UI.EDITTEXT.equals(node.getClassName())) { // 找到输入框并输入文本 181 | Log.i(TAG, "****found the EditText"); 182 | fillText(node, reply); 183 | return true; 184 | } 185 | 186 | if (findInputBar(node, reply)) { // 递归查找 187 | return true; 188 | } 189 | } 190 | return false; 191 | } 192 | 193 | 194 | /** 195 | * 填充文本 196 | */ 197 | private void fillText(AccessibilityNodeInfo node, String reply) { 198 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 199 | Log.i(TAG, "set text"); 200 | Bundle args = new Bundle(); 201 | args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, 202 | reply); 203 | node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args); 204 | } else { 205 | ClipData data = ClipData.newPlainText("reply", reply); 206 | ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 207 | clipboardManager.setPrimaryClip(data); 208 | node.performAction(AccessibilityNodeInfo.ACTION_FOCUS); // 获取焦点 209 | node.performAction(AccessibilityNodeInfo.ACTION_PASTE); // 执行粘贴 210 | } 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_cancel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_ok.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 40 | 41 | 49 | 50 | 57 | 58 | 59 | 64 | 65 | 73 | 74 | 81 | 82 | 83 | 90 | 91 | 97 | 98 | 99 | 100 | 101 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 22 | 23 | 31 | 32 | 39 | 40 | 48 | 49 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/listview_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/cancel_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxhdpi/cancel_normal.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/cancel_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxhdpi/cancel_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ok_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxhdpi/ok_normal.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ok_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxhdpi/ok_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeoExer/WXAutoManager/06620a423fb25946438b10a0e490c63ad2edc37f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 8dp 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WXAutoManager 3 | 4 | 5 | 自动回复信息服务\n 6 | 1.取消手机锁屏密码\n 7 | 2.进去app选择自动回复文本\n 8 | 9 | 10 | 自动抢红包服务\n 11 | 1.取消手机锁屏密码\n 12 | 2.取消所有微信群"消息免打扰"\n 13 | 3.把手机调成静音\n 14 | 4.坐等收红包\n 15 | 16 | AutoOpenLuckyMoneyService 17 | AutoReplyService 18 | MainActivity 19 | Settings 20 | Hello World from section: %1$d 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |