liuyuqi-dellpc 6 years ago
parent
commit
5951791abd

+ 2 - 2
app/build.gradle

@@ -4,14 +4,14 @@ android {
     compileSdkVersion 26
     defaultConfig {
         applicationId "me.yoqi.app.wxredpacket"
-        minSdkVersion 15
+        minSdkVersion 16
         targetSdkVersion 26
         versionCode 1
         versionName "1.0"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         ndk {
             // 设置支持的SO库架构
-            abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
+            abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
         }
     }
     useLibrary 'org.apache.http.legacy'

+ 6 - 1
app/src/main/AndroidManifest.xml

@@ -4,6 +4,7 @@
 
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WAKE_LOCK"/>
 
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
@@ -42,13 +43,17 @@
         </service>
         <provider
             android:name="android.support.v4.content.FileProvider"
-            android:authorities="xyz.monkeytong.hongbao.fileProvider"
+            android:authorities="me.yoqi.app.hongbao.fileProvider"
             android:exported="false"
             android:grantUriPermissions="true">
             <meta-data
                 android:name="android.support.FILE_PROVIDER_PATHS"
                 android:resource="@xml/provider_paths"/>
         </provider>
+
+        <activity
+            android:name="com.tencent.bugly.beta.ui.BetaActivity"
+            android:theme="@android:style/Theme.Translucent" />
     </application>
 
 </manifest>

+ 2 - 5
app/src/main/java/me/yoqi/app/wxredpacket/activities/MainActivity.java

@@ -22,8 +22,6 @@ import com.tencent.bugly.Bugly;
 import java.util.List;
 
 import me.yoqi.app.wxredpacket.R;
-import me.yoqi.app.wxredpacket.utils.ConnectivityUtil;
-import me.yoqi.app.wxredpacket.utils.UpdateTask;
 
 public class MainActivity extends Activity implements AccessibilityManager.AccessibilityStateChangeListener {
 
@@ -41,7 +39,6 @@ public class MainActivity extends Activity implements AccessibilityManager.Acces
         pluginStatusIcon = findViewById(R.id.layout_control_accessibility_icon);
 
         handleMaterialStatusBar();
-
         explicitlyLoadPreferences();
 
         //监听AccessibilityService 变化
@@ -86,8 +83,8 @@ public class MainActivity extends Activity implements AccessibilityManager.Acces
 
         updateServiceStatus();
         // Check for update when WIFI is connected or on first time.
-        if (ConnectivityUtil.isWifi(this) || UpdateTask.count == 0)
-            new UpdateTask(this, false).update();
+//        if (ConnectivityUtil.isWifi(this) || UpdateTask.count == 0)
+//            new UpdateTask(this, false).update();
     }
 
     @Override

+ 2 - 2
app/src/main/java/me/yoqi/app/wxredpacket/fragments/CommentSettingsFragment.java

@@ -10,7 +10,7 @@ import android.widget.Toast;
 import me.yoqi.app.wxredpacket.R;
 
 /**
- *
+ *接收红包后自动回复设置
  */
 public class CommentSettingsFragment extends PreferenceFragment {
     private Bundle savedInstanceState;
@@ -24,7 +24,7 @@ public class CommentSettingsFragment extends PreferenceFragment {
     }
 
     /**
-     *
+     *监听事件
      */
     private void setPrefListeners() {
         Preference updatePref = findPreference("pref_comment_switch");

+ 2 - 17
app/src/main/java/me/yoqi/app/wxredpacket/fragments/GeneralSettingsFragment.java

@@ -1,17 +1,15 @@
 package me.yoqi.app.wxredpacket.fragments;
 
-import android.content.Intent;
 import android.os.Bundle;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceManager;
 
 import me.yoqi.app.wxredpacket.R;
-import me.yoqi.app.wxredpacket.activities.WebViewActivity;
 import me.yoqi.app.wxredpacket.utils.UpdateTask;
 
 /**
- *
+ *偏好设置Fragment
  */
 public class GeneralSettingsFragment extends PreferenceFragment {
     @Override
@@ -22,7 +20,7 @@ public class GeneralSettingsFragment extends PreferenceFragment {
     }
 
     /**
-     *
+     *设置Pref的监听事件
      */
     private void setPrefListeners() {
         // Check for updates
@@ -34,19 +32,6 @@ public class GeneralSettingsFragment extends PreferenceFragment {
             }
         });
 
-        // Open issue
-        Preference issuePref = findPreference("pref_etc_issue");
-        issuePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
-            public boolean onPreferenceClick(Preference preference) {
-                Intent webViewIntent = new Intent(getActivity(), WebViewActivity.class);
-                webViewIntent.putExtra("title", "GitHub Issues");
-                webViewIntent.putExtra("url", getString(R.string.url_github_issues));
-                webViewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                startActivity(webViewIntent);
-                return false;
-            }
-        });
-
         Preference excludeWordsPref = findPreference("pref_watch_exclude_words");
         String summary = getResources().getString(R.string.pref_watch_exclude_words_summary);
         String value = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_watch_exclude_words", "");

+ 65 - 5
app/src/main/java/me/yoqi/app/wxredpacket/services/HongbaoService.java

@@ -5,6 +5,7 @@ import android.accessibilityservice.GestureDescription;
 import android.app.Notification;
 import android.app.PendingIntent;
 import android.content.ComponentName;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.graphics.Path;
@@ -22,6 +23,9 @@ import java.util.List;
 import me.yoqi.app.wxredpacket.utils.HongbaoSignature;
 import me.yoqi.app.wxredpacket.utils.PowerUtil;
 
+/**
+ * 红包服务,后台监听微信消息,出现红包关键词就打开微信抢红包。
+ */
 public class HongbaoService extends AccessibilityService implements SharedPreferences.OnSharedPreferenceChangeListener {
     private static final String WECHAT_DETAILS_EN = "Details";
     private static final String WECHAT_DETAILS_CH = "红包详情";
@@ -45,9 +49,8 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
 
     private PowerUtil powerUtil;
     private SharedPreferences sharedPreferences;
-
     /**
-     * AccessibilityEvent
+     * AccessibilityEvent,收到event,过滤红包信息
      *
      * @param event 事件
      */
@@ -72,7 +75,12 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         }
     }
 
+    /** 监听是否进入微信红包消息界面
+     * @param event
+     */
     private void watchChat(AccessibilityEvent event) {
+        Log.i("hongbaoservice","watchChat");
+
         this.rootNodeInfo = getRootInActiveWindow();
 
         if (rootNodeInfo == null) return;
@@ -109,7 +117,11 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         }
     }
 
+    /**
+     * 点击“打开”,收红包
+     */
     private void openPacket() {
+        Log.i("hongbaoservice","openPacket");
         DisplayMetrics metrics = getResources().getDisplayMetrics();
         float dpi = metrics.density;
         if (android.os.Build.VERSION.SDK_INT <= 23) {
@@ -144,7 +156,19 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
             }
         }
     }
+    /**
+     * 返回桌面
+     */
+    private void back2Home() {
+        Intent home=new Intent(Intent.ACTION_MAIN);
+        home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        home.addCategory(Intent.CATEGORY_HOME);
+        startActivity(home);
+    }
 
+    /**
+     * @param event
+     */
     private void setCurrentActivityName(AccessibilityEvent event) {
         if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
             return;
@@ -163,7 +187,12 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         }
     }
 
+    /** 监视进入微信app聊天列表:case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
+     * @param event
+     * @return
+     */
     private boolean watchList(AccessibilityEvent event) {
+        Log.i("hongbaoservice","watchList");
         if (mListMutex) return false;
         mListMutex = true;
         AccessibilityNodeInfo eventSource = event.getSource();
@@ -172,8 +201,8 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
             return false;
 
         List<AccessibilityNodeInfo> nodes = eventSource.findAccessibilityNodeInfosByText(WECHAT_NOTIFICATION_TIP);
-        //增加条件判断currentActivityName.contains(WECHAT_LUCKMONEY_GENERAL_ACTIVITY)
         //避免当订阅号中出现标题为“[微信红包]拜年红包”(其实并非红包)的信息时误判
+        //判断是否是微信聊天界面com.tencent.mm.ui.LauncherUI
         if (!nodes.isEmpty() && currentActivityName.contains(WECHAT_LUCKMONEY_GENERAL_ACTIVITY)) {
             AccessibilityNodeInfo nodeToClick = nodes.get(0);
             if (nodeToClick == null) return false;
@@ -187,7 +216,13 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         return false;
     }
 
+    /** 监听通知栏消息,判断红包
+     * @param event
+     * @return
+     */
     private boolean watchNotifications(AccessibilityEvent event) {
+        Log.i("hongbaoservice","watchNotifications");
+
         // Not a notification
         if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
             return false;
@@ -202,7 +237,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
             try {
                 /* 清除signature,避免进入会话后误判 */
                 signature.cleanSignature();
-
+//                模拟打开通知栏消息
                 notification.contentIntent.send();
             } catch (PendingIntent.CanceledException e) {
                 e.printStackTrace();
@@ -213,9 +248,13 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
 
     @Override
     public void onInterrupt() {
-
+        Log.d("HongbaoService", "抢红包服务快被终结了");
     }
 
+    /** 找到红包节点按钮
+     * @param node 输入的根节点
+     * @return
+     */
     private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) {
         if (node == null)
             return null;
@@ -238,6 +277,9 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         return null;
     }
 
+    /** 检测红包节点,mReceiveNode
+     * @param eventType
+     */
     private void checkNodeInfo(int eventType) {
         if (this.rootNodeInfo == null) return;
 
@@ -273,6 +315,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         boolean hasNodes = this.hasOneOfThoseNodes(
                 WECHAT_BETTER_LUCK_CH, WECHAT_DETAILS_CH,
                 WECHAT_BETTER_LUCK_EN, WECHAT_DETAILS_EN, WECHAT_EXPIRES_CH);
+        //判断是否是红包领取后的详情界面 //判断是否是显示‘开'的那个红包界面com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI
         if (mMutex && eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && hasNodes
                 && (currentActivityName.contains(WECHAT_LUCKMONEY_DETAIL_ACTIVITY)
                 || currentActivityName.contains(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY))) {
@@ -284,6 +327,9 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         }
     }
 
+    /**
+     * 发送回复
+     */
     private void sendComment() {
         try {
             AccessibilityNodeInfo outNode =
@@ -302,6 +348,10 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
     }
 
 
+    /**
+     * @param texts
+     * @return
+     */
     private boolean hasOneOfThoseNodes(String... texts) {
         List<AccessibilityNodeInfo> nodes;
         for (String text : texts) {
@@ -314,6 +364,10 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         return false;
     }
 
+    /**
+     * @param texts
+     * @return
+     */
     private AccessibilityNodeInfo getTheLastNode(String... texts) {
         int bottom = 0;
         AccessibilityNodeInfo lastNode = null, tempNode;
@@ -345,6 +399,9 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         this.watchFlagsFromPreference();
     }
 
+    /**
+     * 如果设置了锁屏抢则,解锁屏幕
+     */
     private void watchFlagsFromPreference() {
         sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
         sharedPreferences.registerOnSharedPreferenceChangeListener(this);
@@ -368,6 +425,9 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer
         super.onDestroy();
     }
 
+    /** 获取回复字符串
+     * @return 返回回复字符串
+     */
     private String generateCommentString() {
         if (!signature.others) return null;
 

+ 8 - 5
app/src/main/java/me/yoqi/app/wxredpacket/utils/DownloadUtil.java

@@ -9,19 +9,22 @@ import static android.content.Context.DOWNLOAD_SERVICE;
 
 
 /**
- *下载工具
+ * 下载工具
  */
 public class DownloadUtil {
 
-    /**下载队列
-     * @param url 下载链接
+    /**
+     * 下载队列
+     *
+     * @param url     下载链接
      * @param context 全局Context
      */
     public void enqueue(String url, Context context) {
-            DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));
+        DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));
         r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Uber.apk");
         r.allowScanningByMediaScanner();
         r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
         DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
         dm.enqueue(r);
-    }}
+    }
+}

+ 3 - 4
app/src/main/java/me/yoqi/app/wxredpacket/utils/HongbaoSignature.java

@@ -4,7 +4,7 @@ import android.graphics.Rect;
 import android.view.accessibility.AccessibilityNodeInfo;
 
 /**
- * 红包标志
+ * 红包对象,发送者,接收者,发送时间,红包内容
  */
 public class HongbaoSignature {
     public String sender, content, time, contentDescription = "", commentString;
@@ -77,8 +77,8 @@ public class HongbaoSignature {
         return signature.substring(0, signature.length() - 1);
     }
 
-    /**
-     * @return
+    /** 获取ContentDescription
+     * @return contentDescription
      */
     public String getContentDescription() {
         return this.contentDescription;
@@ -120,5 +120,4 @@ public class HongbaoSignature {
         this.time = "";
         this.sender = "";
     }
-
 }

+ 4 - 1
app/src/main/java/me/yoqi/app/wxredpacket/utils/PowerUtil.java

@@ -15,9 +15,12 @@ public class PowerUtil {
      * @param context 全局Context对象
      */
     public PowerUtil(Context context) {
+        //获取电源管理器对象
         PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
         wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                 "HongbaoWakelock");
+        //得到键盘锁管理器对象
         KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
         keyguardLock = km.newKeyguardLock("HongbaoKeyguardLock");
     }
@@ -40,7 +43,7 @@ public class PowerUtil {
         }
     }
 
-    /**
+    /** 解锁屏幕
      * @param isWake
      */
     public void handleWakeLock(boolean isWake) {

+ 17 - 0
app/src/main/java/me/yoqi/app/wxredpacket/utils/UpdateTask.java

@@ -19,12 +19,19 @@ import java.io.IOException;
 
 import me.yoqi.app.wxredpacket.R;
 
+/**
+ * 更新
+ */
 public class UpdateTask extends AsyncTask<String, String, String> {
     public static int count = 0;
     private Context context;
     private boolean isUpdateOnRelease;
     public static final String updateUrl = "https://api.github.com/repos/geeeeeeeeek/WeChatLuckyMoney/releases/latest";
 
+    /** 构造函数
+     * @param context
+     * @param needUpdate
+     */
     public UpdateTask(Context context, boolean needUpdate) {
         this.context = context;
         this.isUpdateOnRelease = needUpdate;
@@ -32,6 +39,10 @@ public class UpdateTask extends AsyncTask<String, String, String> {
             Toast.makeText(context, context.getString(R.string.checking_new_version), Toast.LENGTH_SHORT).show();
     }
 
+    /** 后台自动下载
+     * @param uri 下载链接
+     * @return
+     */
     @Override
     protected String doInBackground(String... uri) {
         HttpClient httpclient = new DefaultHttpClient();
@@ -56,6 +67,9 @@ public class UpdateTask extends AsyncTask<String, String, String> {
         return responseString;
     }
 
+    /** doInBackground执行完后,会回调此方法,用于更新界面信息
+     * @param result
+     */
     @Override
     protected void onPostExecute(String result) {
         super.onPostExecute(result);
@@ -94,6 +108,9 @@ public class UpdateTask extends AsyncTask<String, String, String> {
         }
     }
 
+    /**
+     * 更新
+     */
     public void update() {
         super.execute(updateUrl);
     }

+ 11 - 9
app/src/main/res/layout/activity_main.xml

@@ -2,7 +2,7 @@
                 xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                tools:context=".MainActivity"
+                tools:context=".activities.MainActivity"
                 android:background="#fff">
     <ImageView
             android:layout_width="fill_parent"
@@ -23,20 +23,22 @@
             android:id="@+id/textView"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="40dp"
+            android:layout_marginTop="80dp"
             android:gravity="center_vertical|center_horizontal"
             android:text="@string/app_name"
             android:textColor="#fff"
             android:textIsSelectable="false"
             android:textSize="28dp"
             tools:text="wxRedPacket" />
-        <TextView android:layout_width="fill_parent"
-                  android:layout_height="wrap_content"
-                  android:id="@+id/textView5"
-                  android:text="@string/app_version"
-                  android:textColor="#fff"
-                  android:gravity="center_vertical|center_horizontal"
-                  android:layout_marginTop="4dp"/>
+
+        <TextView
+            android:id="@+id/textView5"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="4dp"
+            android:gravity="center_vertical|center_horizontal"
+            android:text="@string/app_version"
+            android:textColor="#fff" />
     </LinearLayout>
     <ImageView
             android:layout_width="match_parent"

+ 0 - 2
app/src/main/res/values/styles.xml

@@ -1,5 +1,4 @@
 <resources>
-
     <!-- Base application theme. -->
     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
         <!-- Customize your theme here. -->
@@ -7,5 +6,4 @@
         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
         <item name="colorAccent">@color/colorAccent</item>
     </style>
-
 </resources>

+ 1 - 6
app/src/main/res/xml/general_preferences.xml

@@ -49,12 +49,7 @@
         <Preference
                 android:key="pref_etc_check_update"
                 android:title="@string/check_new_version"
-                android:summary="http://dwz.cn/WeChatLuckyMoney"
-                android:layout="@layout/preference_checkbox"/>
-        <Preference
-                android:key="pref_etc_issue"
-                android:title="@string/help_and_feedback"
-                android:summary="@string/help_hint"
+                android:summary="http://git.yoqi.me:3000/lyq/wxRedPacket"
                 android:layout="@layout/preference_checkbox"/>
     </PreferenceCategory>
     <PreferenceCategory