From bdcc6f2cdcabdeeb48e7cc4747565743eef803fc Mon Sep 17 00:00:00 2001 From: leon Date: Sat, 16 Jan 2016 15:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E2=80=9C=E7=9C=8B=E7=9C=8B?= =?UTF-8?q?=E5=A4=A7=E5=AE=B6=E7=9A=84=E6=89=8B=E6=B0=94=E2=80=9D=E8=BF=99?= =?UTF-8?q?=E4=B8=AA=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codeboy/qianghongbao/Config.java | 14 ++++++++++ .../codeboy/qianghongbao/MainActivity.java | 19 +++++++++++-- .../job/WechatAccessbilityJob.java | 28 +++++++++++++++---- app/src/main/res/values/arrays.xml | 11 ++++++++ app/src/main/res/xml/main.xml | 12 ++++++-- 5 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/values/arrays.xml diff --git a/app/src/main/java/com/codeboy/qianghongbao/Config.java b/app/src/main/java/com/codeboy/qianghongbao/Config.java index f62a6ab..6a4f0dd 100644 --- a/app/src/main/java/com/codeboy/qianghongbao/Config.java +++ b/app/src/main/java/com/codeboy/qianghongbao/Config.java @@ -14,6 +14,10 @@ public class Config { public static final String PREFERENCE_NAME = "config"; public static final String KEY_ENABLE_WECHAT = "KEY_ENABLE_WECHAT"; + public static final String KEY_WECHAT_AFTER_OPEN_HONGBAO = "KEY_WECHAT_AFTER_OPEN_HONGBAO"; + + public static final int WX_AFTER_OPEN_HONGBAO = 0; + public static final int WX_AFTER_OPEN_SEE = 1; //看大家手气 SharedPreferences preferences; @@ -25,4 +29,14 @@ public Config(Context context) { public boolean isEnableWechat() { return preferences.getBoolean(KEY_ENABLE_WECHAT, true); } + + /** 微信打开红包后的事件*/ + public int getWechatAfterOpenHongBaoEvent() { + int defaultValue = 0; + String result = preferences.getString(KEY_WECHAT_AFTER_OPEN_HONGBAO, String.valueOf(defaultValue)); + try { + return Integer.parseInt(result); + } catch (Exception e) {} + return defaultValue; + } } diff --git a/app/src/main/java/com/codeboy/qianghongbao/MainActivity.java b/app/src/main/java/com/codeboy/qianghongbao/MainActivity.java index 80fd25e..34979a4 100644 --- a/app/src/main/java/com/codeboy/qianghongbao/MainActivity.java +++ b/app/src/main/java/com/codeboy/qianghongbao/MainActivity.java @@ -4,9 +4,9 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; -import android.preference.SwitchPreference; import android.support.v7.app.AlertDialog; import android.view.Menu; import android.view.MenuItem; @@ -110,8 +110,8 @@ public void onCreate(Bundle savedInstanceState) { getPreferenceManager().setSharedPreferencesName(Config.PREFERENCE_NAME); addPreferencesFromResource(R.xml.main); - SwitchPreference switchPreference = (SwitchPreference) findPreference(Config.KEY_ENABLE_WECHAT); - switchPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + //微信红包开关 + findPreference(Config.KEY_ENABLE_WECHAT).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if((Boolean) newValue && !QiangHongBaoService.isRunning()) { @@ -120,6 +120,19 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { return true; } }); + + //打开微信红包后 + final ListPreference wxAfterOpenPre = (ListPreference) findPreference(Config.KEY_WECHAT_AFTER_OPEN_HONGBAO); + wxAfterOpenPre.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + int value = Integer.parseInt(String.valueOf(newValue)); + preference.setSummary(wxAfterOpenPre.getEntries()[value]); + return true; + } + }); + int value = Integer.parseInt(wxAfterOpenPre.getValue()); + wxAfterOpenPre.setSummary(wxAfterOpenPre.getEntries()[value]); } } } diff --git a/app/src/main/java/com/codeboy/qianghongbao/job/WechatAccessbilityJob.java b/app/src/main/java/com/codeboy/qianghongbao/job/WechatAccessbilityJob.java index 74bcfdb..5fed7ad 100644 --- a/app/src/main/java/com/codeboy/qianghongbao/job/WechatAccessbilityJob.java +++ b/app/src/main/java/com/codeboy/qianghongbao/job/WechatAccessbilityJob.java @@ -18,6 +18,7 @@ import android.view.accessibility.AccessibilityNodeInfo; import com.codeboy.qianghongbao.BuildConfig; +import com.codeboy.qianghongbao.Config; import com.codeboy.qianghongbao.QiangHongBaoService; import java.util.List; @@ -60,6 +61,9 @@ public class WechatAccessbilityJob extends BaseAccessbilityJob { /** 点开红包资源文字*/ private static final String TEXT_OPEN_HONGBAO = "拆红包"; + /** 点击看看大家的手气*/ + private static final String TEXT_OPEN_SEE = "看看大家的手气"; + private boolean isFirstChecked ; private PackageInfo mWechatPackageInfo = null; @@ -193,10 +197,17 @@ private void handleLuckyMoneyReceive() { } List list = null; - if(isEnableUseText()) { - list = nodeInfo.findAccessibilityNodeInfosByText(TEXT_OPEN_HONGBAO); - } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - list = nodeInfo.findAccessibilityNodeInfosByViewId(ID_OPEN_HONGBAO); + int event = getConfig().getWechatAfterOpenHongBaoEvent(); + if(event == Config.WX_AFTER_OPEN_HONGBAO) { //拆红包 + if (isEnableUseText()) { + list = nodeInfo.findAccessibilityNodeInfosByText(TEXT_OPEN_HONGBAO); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + list = nodeInfo.findAccessibilityNodeInfosByViewId(ID_OPEN_HONGBAO); + } + } else if(event == Config.WX_AFTER_OPEN_SEE) { //看一看 + if(isEnableUseText()) { //低版本才有 看大家手气的功能 + list = nodeInfo.findAccessibilityNodeInfosByText(TEXT_OPEN_SEE); + } } if(list != null && !list.isEmpty()) { @@ -261,10 +272,15 @@ private void handleChatListHongBao() { /** 是否可以通过使用文本方式进行抢红包*/ private boolean isEnableUseText() { + return getWechatVersion() < USE_ID_MIN_VERSION; + } + + /** 获取微信的版本*/ + private int getWechatVersion() { if(mWechatPackageInfo == null) { - return true; + return 0; } - return mWechatPackageInfo.versionCode < USE_ID_MIN_VERSION; + return mWechatPackageInfo.versionCode; } /** 更新微信包信息*/ diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..4822260 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,11 @@ + + + + 拆红包 + 看看大家的手气 + + + 0 + 1 + + \ No newline at end of file diff --git a/app/src/main/res/xml/main.xml b/app/src/main/res/xml/main.xml index cf66624..66333fb 100644 --- a/app/src/main/res/xml/main.xml +++ b/app/src/main/res/xml/main.xml @@ -5,8 +5,14 @@ - - + android:key="KEY_ENABLE_WECHAT"/> + \ No newline at end of file