From 6544af68867961e1ab0ce8e4e20c2a144cf073e8 Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Tue, 2 Feb 2016 22:42:11 +0800 Subject: [PATCH 01/12] Update version tag. --- app/build.gradle | 2 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9f4416f0..4fbebb5f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 16 targetSdkVersion 22 versionCode 2 - versionName "v2.1.1" + versionName "v2.2" ndk { //设置支持的SO库架构 abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a30b38fb..3940eb3c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -45,7 +45,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" - android:text="稳定版 v2.1" + android:text="@string/app_version" android:id="@+id/textView3" android:gravity="center" android:onClick="openGithub" android:clickable="true" android:layout_centerInParent="true" android:textColor="#c5a45e" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05cf36ff..cc5061eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ 微信红包 + 测试版 v2.2 ∠( ᐛ 」∠)_使用指南∠( ᐛ 」∠)_\n\n ○ 狠戳插件开关\n ○ 回到微信聊天\n ○ 坐等红包进账\n\n 遇到问题, 欢迎通过Github issue反馈~\n https://github.com/geeeeeeeeek/WeChatLuckyMoney 当前辅助服务状态: 设置抢红包辅助服务 From 6a564f4fa3213961db0300635a0d0d428185382d Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Tue, 2 Feb 2016 23:17:03 +0800 Subject: [PATCH 02/12] Add open in browser button in webview activity. --- .../hongbao/activities/WebViewActivity.java | 11 +++++++++-- app/src/main/res/layout/activity_main.xml | 4 ++-- app/src/main/res/layout/activity_webview.xml | 13 +++++++++++-- .../main/res/mipmap-xxhdpi/ic_open_in_browser.png | Bin 0 -> 629 bytes 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_open_in_browser.png diff --git a/app/src/main/java/xyz/monkeytong/hongbao/activities/WebViewActivity.java b/app/src/main/java/xyz/monkeytong/hongbao/activities/WebViewActivity.java index 8c1e4003..9d90c4a5 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/activities/WebViewActivity.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/activities/WebViewActivity.java @@ -29,6 +29,7 @@ */ public class WebViewActivity extends Activity { private WebView webView; + private String webViewUrl, webViewTitle; @Override protected void onCreate(Bundle savedInstanceState) { @@ -38,8 +39,8 @@ protected void onCreate(Bundle savedInstanceState) { Bundle bundle = getIntent().getExtras(); if (bundle != null && !bundle.isEmpty()) { - String webViewTitle = bundle.getString("title"); - String webViewUrl = bundle.getString("url"); + webViewTitle = bundle.getString("title"); + webViewUrl = bundle.getString("url"); TextView webViewBar = (TextView) findViewById(R.id.webview_bar); webViewBar.setText(webViewTitle); @@ -105,4 +106,10 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { } return super.onKeyDown(keyCode, event); } + + public void openLink(View view) { + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse(this.webViewUrl)); + startActivity(intent); + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3940eb3c..ea3c9511 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,7 +22,7 @@ android:padding="10dp" android:onClick="openNews" android:layout_below="@+id/main_action_bar_placeholder" - android:layout_alignLeft="@+id/textView" android:layout_marginLeft="6dp"/> + android:layout_alignLeft="@+id/textView" android:layout_marginLeft="6dp" android:layout_marginTop="6dp"/> + android:layout_marginRight="6dp" android:layout_marginTop="6dp"/> + vDih+eeMX z)*l{+m1rwH5-N#lU0}>HHQ>u=%+7D)W0(P6*};ao`M zus-?H^zS;ZE}J0n_xTrI@3K={^WBkIe=(=_=}(4<>?Ko Date: Wed, 3 Feb 2016 00:21:47 +0800 Subject: [PATCH 03/12] Change activities launch mode to single task. --- app/src/main/AndroidManifest.xml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 84a01ad1..3e397737 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,11 +4,11 @@ - + - - + + + android:theme="@style/Base.Theme.AppCompat.Light" + android:launchMode="singleTask"> + android:theme="@style/Base.Theme.AppCompat.Light" + android:launchMode="singleTask"> + android:theme="@style/Base.Theme.AppCompat.Light" + android:launchMode="standard"> Date: Wed, 3 Feb 2016 02:03:12 +0800 Subject: [PATCH 04/12] Fix multiple back actions. And won't perform back action on user its own opening a packet. --- .../hongbao/services/HongbaoService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 9e4554d9..61851626 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -33,7 +33,8 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer private String currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY; private AccessibilityNodeInfo rootNodeInfo, mReceiveNode, mUnpackNode; - private boolean mLuckyMoneyPicked, mLuckyMoneyReceived, mNeedUnpack; + private boolean mLuckyMoneyPicked, mLuckyMoneyReceived; + private int mUnpackCount = 0; private boolean mMutex = false; private HongbaoSignature signature = new HongbaoSignature(); @@ -80,10 +81,9 @@ private void watchChat(AccessibilityEvent event) { mLuckyMoneyPicked = true; } /* 如果戳开但还未领取 */ - if (mNeedUnpack && (mUnpackNode != null)) { + if (mUnpackCount == 1 && (mUnpackNode != null)) { AccessibilityNodeInfo cellNode = mUnpackNode; cellNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); - mNeedUnpack = false; } } @@ -156,12 +156,12 @@ public void onInterrupt() { * 递归查找拆红包按钮 */ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { - if (node==null) + if (node == null) return null; //非layout元素 if (node.getChildCount() == 0) { - if("android.widget.Button".equals(node.getClassName())) + if ("android.widget.Button".equals(node.getClassName())) return node; else return null; @@ -170,7 +170,7 @@ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { //layout元素,遍历找button for (int i = 0; i < node.getChildCount(); i++) { AccessibilityNodeInfo button = findOpenButton(node.getChild(i)); - if(button != null) + if (button != null) return button; } return null; @@ -199,7 +199,7 @@ private void checkNodeInfo(int eventType) { AccessibilityNodeInfo node2 = findOpenButton(this.rootNodeInfo); if (node2 != null && "android.widget.Button".equals(node2.getClassName()) && currentActivityName.contains(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY)) { mUnpackNode = node2; - mNeedUnpack = true; + mUnpackCount += 1; return; } @@ -207,11 +207,12 @@ private void checkNodeInfo(int eventType) { boolean hasNodes = this.hasOneOfThoseNodes( WECHAT_BETTER_LUCK_CH, WECHAT_DETAILS_CH, WECHAT_BETTER_LUCK_EN, WECHAT_DETAILS_EN, WECHAT_EXPIRES_CH); - if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && hasNodes + if (mMutex && eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && hasNodes && (currentActivityName.contains(WECHAT_LUCKMONEY_DETAIL_ACTIVITY) || currentActivityName.contains(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY))) { mMutex = false; mLuckyMoneyPicked = false; + mUnpackCount = 0; performGlobalAction(GLOBAL_ACTION_BACK); } } From 6da2e68f3d6e9618d5d575d28b80192dc6484cfb Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Wed, 3 Feb 2016 21:58:49 +0800 Subject: [PATCH 05/12] Add delay preference for opening hongbao. --- .../hongbao/activities/SeekBarPreference.java | 67 +++++++++++++++++++ .../hongbao/services/HongbaoService.java | 13 ++-- .../main/res/layout/preference_seekbar.xml | 17 +++++ app/src/main/res/xml/preferences.xml | 4 ++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java create mode 100644 app/src/main/res/layout/preference_seekbar.xml diff --git a/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java b/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java new file mode 100644 index 00000000..4028220a --- /dev/null +++ b/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java @@ -0,0 +1,67 @@ +package xyz.monkeytong.hongbao.activities; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.DialogPreference; +import android.util.AttributeSet; +import android.view.View; +import android.widget.EditText; +import android.widget.SeekBar; +import android.widget.TextView; +import org.w3c.dom.Text; +import xyz.monkeytong.hongbao.R; + +/** + * Created by Zhongyi on 2/3/16. + */ +public class SeekBarPreference extends DialogPreference { + private SeekBar seekBar; + private TextView textView; + + public SeekBarPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_seekbar); + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + SharedPreferences pref = getSharedPreferences(); + + int delay = pref.getInt("pref_open_delay", 0); + this.seekBar = (SeekBar) view.findViewById(R.id.delay_seekBar); + this.seekBar.setProgress(delay); + + this.textView = (TextView) view.findViewById(R.id.pref_seekbar_textview); + this.textView.setText("延迟" + delay + "秒拆开红包"); + + this.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + textView.setText("延迟" + i + "秒拆开红包"); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + SharedPreferences.Editor editor = getEditor(); + editor.putInt("pref_open_delay", this.seekBar.getProgress()); + editor.commit(); + } + super.onDialogClosed(positiveResult); + } +} diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 61851626..188799d7 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -75,15 +75,20 @@ private void watchChat(AccessibilityEvent event) { if (mLuckyMoneyReceived && !mLuckyMoneyPicked && (mReceiveNode != null)) { mMutex = true; - AccessibilityNodeInfo cellNode = mReceiveNode; - cellNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); + mReceiveNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); mLuckyMoneyReceived = false; mLuckyMoneyPicked = true; } /* 如果戳开但还未领取 */ if (mUnpackCount == 1 && (mUnpackNode != null)) { - AccessibilityNodeInfo cellNode = mUnpackNode; - cellNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + int delayFlag = sharedPreferences.getInt("pref_open_delay", 0) * 1000; + new android.os.Handler().postDelayed( + new Runnable() { + public void run() { + mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + } + }, + delayFlag); } } diff --git a/app/src/main/res/layout/preference_seekbar.xml b/app/src/main/res/layout/preference_seekbar.xml new file mode 100644 index 00000000..fca196ca --- /dev/null +++ b/app/src/main/res/layout/preference_seekbar.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 05a3bd2e..2ab6a133 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -29,6 +29,10 @@ android:title="拆开自己发的红包" android:layout="@layout/preference_checkbox" android:defaultValue="true"/> + Date: Wed, 3 Feb 2016 22:39:48 +0800 Subject: [PATCH 06/12] Update preferences. --- .../hongbao/activities/SettingsActivity.java | 6 ++++- .../main/res/layout/activity_preferences.xml | 4 ++- .../main/res/layout/preference_category.xml | 1 - .../main/res/layout/preference_checkbox.xml | 4 +-- app/src/main/res/xml/preferences.xml | 25 ++++++++++++------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/xyz/monkeytong/hongbao/activities/SettingsActivity.java b/app/src/main/java/xyz/monkeytong/hongbao/activities/SettingsActivity.java index 47107824..f841d5fe 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/activities/SettingsActivity.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/activities/SettingsActivity.java @@ -60,7 +60,11 @@ public boolean onPreferenceClick(Preference preference) { @Override public boolean onPreferenceChange(Preference preference, Object o) { String summary = getResources().getString(R.string.pref_watch_exclude_words_summary); - if (o != null && o.toString().length() > 0) preference.setSummary(summary + ":" + o.toString()); + if (o != null && o.toString().length() > 0) { + preference.setSummary(summary + ":" + o.toString()); + } else { + preference.setSummary(summary); + } return true; } }); diff --git a/app/src/main/res/layout/activity_preferences.xml b/app/src/main/res/layout/activity_preferences.xml index 2fb5a8ac..310afdfc 100644 --- a/app/src/main/res/layout/activity_preferences.xml +++ b/app/src/main/res/layout/activity_preferences.xml @@ -36,7 +36,9 @@ android:layout_alignBottom="@+id/settings_bar"/> + android:id="@android:id/list" android:background="#fffaf6f1" android:paddingLeft="0dp" + android:paddingRight="0dp" android:paddingBottom="0dp" android:paddingTop="10dp" + android:dividerHeight="1dp" android:divider="#22333333"> diff --git a/app/src/main/res/layout/preference_category.xml b/app/src/main/res/layout/preference_category.xml index 776a467d..cb82751a 100644 --- a/app/src/main/res/layout/preference_category.xml +++ b/app/src/main/res/layout/preference_category.xml @@ -9,7 +9,6 @@ android:layout_height="wrap_content" android:paddingTop="10dp" android:layout_marginRight="10dp" - android:layout_marginTop="6dp" android:layout_weight="1"> + + + - + + From 66b76722a67478d6ec82b2a5ac5f1a9828cb1783 Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Thu, 4 Feb 2016 16:24:00 +0800 Subject: [PATCH 07/12] Add auto comment preference. --- app/src/main/AndroidManifest.xml | 2 +- .../hongbao/activities/MainActivity.java | 6 +- .../hongbao/activities/SeekBarPreference.java | 29 ++++++- .../hongbao/activities/SettingsActivity.java | 82 ++++++++----------- .../fragments/CommentSettingsFragment.java | 26 ++++++ .../fragments/GeneralSettingsFragment.java | 64 +++++++++++++++ .../main/res/layout/activity_preferences.xml | 11 ++- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/comment_preferences.xml | 35 ++++++++ ...references.xml => general_preferences.xml} | 12 +++ 10 files changed, 210 insertions(+), 58 deletions(-) create mode 100644 app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java create mode 100644 app/src/main/java/xyz/monkeytong/hongbao/fragments/GeneralSettingsFragment.java create mode 100644 app/src/main/res/xml/comment_preferences.xml rename app/src/main/res/xml/{preferences.xml => general_preferences.xml} (83%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3e397737..846872ea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,7 +25,7 @@ + android:launchMode="standard"> 0) excludeWordsPref.setSummary(summary + ":" + value); - - excludeWordsPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - String summary = getResources().getString(R.string.pref_watch_exclude_words_summary); - if (o != null && o.toString().length() > 0) { - preference.setSummary(summary + ":" + o.toString()); - } else { - preference.setSummary(summary); - } - return true; - } - }); + private void prepareSettings() { + String title, fragId; + Bundle bundle = getIntent().getExtras(); + if (bundle != null) { + title = bundle.getString("title"); + fragId = bundle.getString("frag_id"); + } else { + title = "偏好设置"; + fragId = "GeneralSettingsFragment"; + } + + TextView textView = (TextView) findViewById(R.id.settings_bar); + textView.setText(title); + + FragmentManager fragmentManager = getFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + + if ("GeneralSettingsFragment".equals(fragId)) { + fragmentTransaction.replace(R.id.preferences_fragment, new GeneralSettingsFragment()); + } else if ("CommentSettingsFragment".equals(fragId)) { + fragmentTransaction.replace(R.id.preferences_fragment, new CommentSettingsFragment()); + } + fragmentTransaction.commit(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void loadUI() { - setContentView(R.layout.activity_preferences); - addPreferencesFromResource(R.xml.preferences); - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; Window window = this.getWindow(); @@ -84,7 +75,6 @@ private void loadUI() { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(0xffd84e43); - } @Override diff --git a/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java b/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java new file mode 100644 index 00000000..05149244 --- /dev/null +++ b/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java @@ -0,0 +1,26 @@ +package xyz.monkeytong.hongbao.fragments; + +import android.content.Intent; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import xyz.monkeytong.hongbao.R; +import xyz.monkeytong.hongbao.activities.WebViewActivity; +import xyz.monkeytong.hongbao.utils.UpdateTask; + +/** + * Created by Zhongyi on 2/4/16. + */ +public class CommentSettingsFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.comment_preferences); + setPrefListeners(); + } + + private void setPrefListeners() { + + } +} diff --git a/app/src/main/java/xyz/monkeytong/hongbao/fragments/GeneralSettingsFragment.java b/app/src/main/java/xyz/monkeytong/hongbao/fragments/GeneralSettingsFragment.java new file mode 100644 index 00000000..2e11b4dd --- /dev/null +++ b/app/src/main/java/xyz/monkeytong/hongbao/fragments/GeneralSettingsFragment.java @@ -0,0 +1,64 @@ +package xyz.monkeytong.hongbao.fragments; + +import android.content.Intent; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import xyz.monkeytong.hongbao.R; +import xyz.monkeytong.hongbao.activities.WebViewActivity; +import xyz.monkeytong.hongbao.utils.UpdateTask; + +/** + * Created by Zhongyi on 2/4/16. + */ +public class GeneralSettingsFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.general_preferences); + setPrefListeners(); + } + + private void setPrefListeners() { + // Check for updates + Preference updatePref = findPreference("pref_etc_check_update"); + updatePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + new UpdateTask(getActivity().getApplicationContext(), true).update(); + return false; + } + }); + + // 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", ""); + if (value.length() > 0) excludeWordsPref.setSummary(summary + ":" + value); + + excludeWordsPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object o) { + String summary = getResources().getString(R.string.pref_watch_exclude_words_summary); + if (o != null && o.toString().length() > 0) { + preference.setSummary(summary + ":" + o.toString()); + } else { + preference.setSummary(summary); + } + return true; + } + }); + } +} diff --git a/app/src/main/res/layout/activity_preferences.xml b/app/src/main/res/layout/activity_preferences.xml index 310afdfc..e4d23cc1 100644 --- a/app/src/main/res/layout/activity_preferences.xml +++ b/app/src/main/res/layout/activity_preferences.xml @@ -35,10 +35,9 @@ android:padding="6dp" android:src="@mipmap/ic_refresh" android:layout_alignBottom="@+id/settings_bar"/> - - - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc5061eb..0d2b4b86 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,5 +13,6 @@ 关闭插件 开启插件 不拆开包含这些文字的红包(空格间隔) + 随机选择下列感谢语(空格间隔) https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues \ No newline at end of file diff --git a/app/src/main/res/xml/comment_preferences.xml b/app/src/main/res/xml/comment_preferences.xml new file mode 100644 index 00000000..6728dbff --- /dev/null +++ b/app/src/main/res/xml/comment_preferences.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/general_preferences.xml similarity index 83% rename from app/src/main/res/xml/preferences.xml rename to app/src/main/res/xml/general_preferences.xml index 8cec78d2..4a2f128a 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/general_preferences.xml @@ -30,6 +30,7 @@ + + + + + + Date: Thu, 4 Feb 2016 20:03:09 +0800 Subject: [PATCH 08/12] Add auto comment. --- .../hongbao/activities/SeekBarPreference.java | 8 ++- .../fragments/CommentSettingsFragment.java | 27 ++++++++- .../hongbao/services/HongbaoService.java | 56 ++++++++++++++++++- .../hongbao/utils/HongbaoSignature.java | 5 +- .../main/res/layout/preference_seekbar.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/comment_preferences.xml | 4 +- app/src/main/res/xml/general_preferences.xml | 22 ++++---- 8 files changed, 101 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java b/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java index f356e0db..0561952a 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/activities/SeekBarPreference.java @@ -21,6 +21,7 @@ public class SeekBarPreference extends DialogPreference { public SeekBarPreference(Context context, AttributeSet attrs) { super(context, attrs); + setDialogLayoutResource(R.layout.preference_seekbar); for (int i = 0; i < attrs.getAttributeCount(); i++) { String attr = attrs.getAttributeName(i); @@ -32,9 +33,8 @@ public SeekBarPreference(Context context, AttributeSet attrs) { if (prefKind.equals("pref_open_delay")) { hintText = "拆开红包"; } else if (prefKind.equals("pref_comment_delay")) { - hintText = "发送回复"; + hintText = "发送回复(暂不支持延时)"; } - setDialogLayoutResource(R.layout.preference_seekbar); } @Override @@ -47,6 +47,10 @@ protected void onBindDialogView(View view) { this.seekBar = (SeekBar) view.findViewById(R.id.delay_seekBar); this.seekBar.setProgress(delay); + if (prefKind.equals("pref_comment_delay")) { + this.seekBar.setEnabled(false); + } + this.textView = (TextView) view.findViewById(R.id.pref_seekbar_textview); if (delay == 0) { this.textView.setText("立即" + hintText); diff --git a/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java b/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java index 05149244..2e3488fd 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/fragments/CommentSettingsFragment.java @@ -1,13 +1,12 @@ package xyz.monkeytong.hongbao.fragments; -import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; +import android.widget.Toast; import xyz.monkeytong.hongbao.R; -import xyz.monkeytong.hongbao.activities.WebViewActivity; -import xyz.monkeytong.hongbao.utils.UpdateTask; /** * Created by Zhongyi on 2/4/16. @@ -21,6 +20,28 @@ public void onCreate(Bundle savedInstanceState) { } private void setPrefListeners() { + Preference updatePref = findPreference("pref_comment_switch"); + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + updatePref.setEnabled(false); + } + Toast.makeText(getActivity(), "该功能尚处于实验中,只能自动填充感谢语,无法直接发送.", Toast.LENGTH_LONG).show(); + Preference commentWordsPref = findPreference("pref_comment_words"); + String summary = getResources().getString(R.string.pref_comment_words_summary); + String value = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_comment_words", ""); + if (value.length() > 0) commentWordsPref.setSummary(summary + ":" + value); + + commentWordsPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object o) { + String summary = getResources().getString(R.string.pref_comment_words_summary); + if (o != null && o.toString().length() > 0) { + preference.setSummary(summary + ":" + o.toString()); + } else { + preference.setSummary(summary); + } + return true; + } + }); } } diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 188799d7..7425cca1 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -1,17 +1,22 @@ package xyz.monkeytong.hongbao.services; import android.accessibilityservice.AccessibilityService; +import android.app.Instrumentation; import android.app.Notification; import android.app.PendingIntent; import android.content.ComponentName; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Rect; +import android.os.Bundle; +import android.os.IBinder; import android.os.Parcelable; import android.preference.PreferenceManager; import android.util.Log; +import android.view.KeyEvent; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; +import xyz.monkeytong.hongbao.activities.MainActivity; import xyz.monkeytong.hongbao.utils.HongbaoSignature; import xyz.monkeytong.hongbao.utils.PowerUtil; @@ -42,7 +47,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer private SharedPreferences sharedPreferences; /** - * AccessibilityEvent的回调方法 + * AccessibilityEvent * * @param event 事件 */ @@ -158,7 +163,7 @@ public void onInterrupt() { } /** - * 递归查找拆红包按钮 + * 红包 钮 */ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { if (node == null) @@ -182,11 +187,16 @@ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { } /** - * 检查节点信息 + * 节 信 */ private void checkNodeInfo(int eventType) { if (this.rootNodeInfo == null) return; + if (signature.commentString != null) { + sendComment(); + signature.commentString = null; + } + /* 聊天会话窗口,遍历节点匹配“领取红包”和"查看红包" */ AccessibilityNodeInfo node1 = (sharedPreferences.getBoolean("pref_watch_self", false)) ? this.getTheLastNode(WECHAT_VIEW_OTHERS_CH, WECHAT_VIEW_SELF_CH) : this.getTheLastNode(WECHAT_VIEW_OTHERS_CH); @@ -219,6 +229,24 @@ private void checkNodeInfo(int eventType) { mLuckyMoneyPicked = false; mUnpackCount = 0; performGlobalAction(GLOBAL_ACTION_BACK); + signature.commentString = generateCommentString(); + } + } + + private void sendComment() { + try { + AccessibilityNodeInfo outNode = + getRootInActiveWindow().getChild(0).getChild(0); + AccessibilityNodeInfo nodeToInput = outNode.getChild(outNode.getChildCount() - 1).getChild(0).getChild(1); + + if ("android.widget.EditText".equals(nodeToInput.getClassName())) { + Bundle arguments = new Bundle(); + arguments.putCharSequence(AccessibilityNodeInfo + .ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, signature.commentString); + nodeToInput.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments); + } + } catch (Exception e) { + // Not support } } @@ -250,6 +278,11 @@ private AccessibilityNodeInfo getTheLastNode(String... texts) { if (bounds.bottom > bottom) { bottom = bounds.bottom; lastNode = node; + if (text.equals(WECHAT_VIEW_OTHERS_CH)) { + signature.others = true; + } else { + signature.others = false; + } } } } @@ -284,4 +317,21 @@ public void onDestroy() { this.powerUtil.handleWakeLock(false); super.onDestroy(); } + + private String generateCommentString() { + if (!signature.others) return null; + + Boolean needComment = sharedPreferences.getBoolean("pref_comment_switch", false); + if (!needComment) return null; + + String[] wordsArray = sharedPreferences.getString("pref_comment_words", "").split(" +"); + if (wordsArray.length == 0) return null; + + Boolean atSender = sharedPreferences.getBoolean("pref_comment_at", false); + if (atSender) { + return "@" + signature.sender + " " + wordsArray[(int) (Math.random() * wordsArray.length)]; + } else { + return wordsArray[(int) (Math.random() * wordsArray.length)]; + } + } } diff --git a/app/src/main/java/xyz/monkeytong/hongbao/utils/HongbaoSignature.java b/app/src/main/java/xyz/monkeytong/hongbao/utils/HongbaoSignature.java index 17e1f593..4d7e1889 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/utils/HongbaoSignature.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/utils/HongbaoSignature.java @@ -7,7 +7,8 @@ * Created by Zhongyi on 1/21/16. */ public class HongbaoSignature { - private String sender, content, time, contentDescription = ""; + public String sender, content, time, contentDescription = "", commentString; + public boolean others; public boolean generateSignature(AccessibilityNodeInfo node, String excludeWords) { try { @@ -78,7 +79,7 @@ private String[] getSenderContentDescriptionFromNode(AccessibilityNodeInfo node) AccessibilityNodeInfo thisNode = node.getChild(i); if ("android.widget.ImageView".equals(thisNode.getClassName())) { CharSequence contentDescription = thisNode.getContentDescription(); - if (contentDescription != null) result[0] = contentDescription.toString(); + if (contentDescription != null) result[0] = contentDescription.toString().replaceAll("头像$", ""); } else if ("android.widget.TextView".equals(thisNode.getClassName())) { CharSequence thisNodeText = thisNode.getText(); if (thisNodeText != null) result[1] = thisNodeText.toString(); diff --git a/app/src/main/res/layout/preference_seekbar.xml b/app/src/main/res/layout/preference_seekbar.xml index fca196ca..b3d569ae 100644 --- a/app/src/main/res/layout/preference_seekbar.xml +++ b/app/src/main/res/layout/preference_seekbar.xml @@ -13,5 +13,5 @@ android:layout_height="wrap_content" android:text="延迟0秒拆开红包" android:id="@+id/pref_seekbar_textview" android:textColor="#666666" android:textSize="16sp" - android:layout_marginLeft="32dp" android:layout_marginRight="32dp"/> + android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginBottom="20dp"/> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d2b4b86..232dc58b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,6 @@ 关闭插件 开启插件 不拆开包含这些文字的红包(空格间隔) - 随机选择下列感谢语(空格间隔) + 随机选择下列感谢语(空格间隔) https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues \ No newline at end of file diff --git a/app/src/main/res/xml/comment_preferences.xml b/app/src/main/res/xml/comment_preferences.xml index 6728dbff..6cc602c8 100644 --- a/app/src/main/res/xml/comment_preferences.xml +++ b/app/src/main/res/xml/comment_preferences.xml @@ -4,7 +4,7 @@ tools:context=".SettingsActivity" android:icon="@null"> \ No newline at end of file diff --git a/app/src/main/res/xml/general_preferences.xml b/app/src/main/res/xml/general_preferences.xml index 4a2f128a..6ab0eef9 100644 --- a/app/src/main/res/xml/general_preferences.xml +++ b/app/src/main/res/xml/general_preferences.xml @@ -42,17 +42,6 @@ android:title="屏蔽红包文字" android:summary="@string/pref_watch_exclude_words_summary" android:layout="@layout/preference_checkbox"/> - - - - - - + + + + + + \ No newline at end of file From f12283b440a2404190d8182d8ceb26c86c438a9d Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Thu, 4 Feb 2016 20:04:04 +0800 Subject: [PATCH 09/12] Update version. --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 232dc58b..63078218 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ 微信红包 - 测试版 v2.2 + 稳定版 v2.2 ∠( ᐛ 」∠)_使用指南∠( ᐛ 」∠)_\n\n ○ 狠戳插件开关\n ○ 回到微信聊天\n ○ 坐等红包进账\n\n 遇到问题, 欢迎通过Github issue反馈~\n https://github.com/geeeeeeeeek/WeChatLuckyMoney 当前辅助服务状态: 设置抢红包辅助服务 From 3bb9254f8be5bf62dfc439b34bae028d78c35c5a Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Thu, 4 Feb 2016 20:43:21 +0800 Subject: [PATCH 10/12] Fix crash releated open delay. --- .../xyz/monkeytong/hongbao/services/HongbaoService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 7425cca1..8f50f001 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -90,7 +90,13 @@ private void watchChat(AccessibilityEvent event) { new android.os.Handler().postDelayed( new Runnable() { public void run() { - mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + try { + mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + } catch (Exception e) { + mMutex = false; + mLuckyMoneyPicked = false; + mUnpackCount = 0; + } } }, delayFlag); From 9053f3be1c9b87c7a4f83bcecc87fbeec7508f0b Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Thu, 4 Feb 2016 20:59:30 +0800 Subject: [PATCH 11/12] Fix a wierd bug #11 in bugly. --- .../java/xyz/monkeytong/hongbao/services/HongbaoService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 8f50f001..814759c6 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -122,11 +122,12 @@ private void setCurrentActivityName(AccessibilityEvent event) { } private boolean watchList(AccessibilityEvent event) { + AccessibilityNodeInfo eventSource = event.getSource(); // Not a message - if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || event.getSource() == null) + if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || eventSource == null) return false; - List nodes = event.getSource().findAccessibilityNodeInfosByText(WECHAT_NOTIFICATION_TIP); + List nodes = eventSource.findAccessibilityNodeInfosByText(WECHAT_NOTIFICATION_TIP); if (!nodes.isEmpty()) { AccessibilityNodeInfo nodeToClick = nodes.get(0); CharSequence contentDescription = nodeToClick.getContentDescription(); From d709c3895d209e31e9086e3394196c45b262ad85 Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Thu, 4 Feb 2016 21:15:56 +0800 Subject: [PATCH 12/12] Update README. --- CHANGELOG.md | 22 +++++++++++++++++++++- README.md | 6 ++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 493d93f8..ee27d9f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,26 @@ # 更新日志 -**[v2.1 (2016.01.30)](https://github.com/geeeeeeeeek/WeChatLuckyMoney/releases/tag/v2.1)** +**[v2.2 (2016.02.04)](https://github.com/geeeeeeeeek/WeChatLuckyMoney/releases/tag/v2.2)** + +- 新增 延时拆开红包的可选项 + + +- 新增 跳转至浏览器打开的入口 +- 新增 接入腾讯Bugly +- 新增 自动回复的可选项(实验中) + + +- 优化 手动拆开的红包不返回 + + +- 优化 适配三星等坑爹机型 (感谢 [@firesunCN](https://github.com/firesunCN) 对这项修改的贡献) + + +- 修复 拆开红包后的多次返回问题 + + + +**[v2.1 (2016.01.30)](https://github.com/geeeeeeeeek/WeChatLuckyMoney/releases/tag/v2.1.1)** - 新增 屏蔽指定红包文字的可选项 diff --git a/README.md b/README.md index ed91a537..e2ee2d43 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # 微信红包 -[![forthebadge](http://forthebadge.com/images/badges/designed-in-ms-paint.svg)](http://forthebadge.com)[![forthebadge](http://forthebadge.com/images/badges/powered-by-electricity.svg)](http://forthebadge.com) - -[![Gitter](https://badges.gitter.im/geeeeeeeeek/WeChatLuckyMoney.svg)](https://gitter.im/geeeeeeeeek/WeChatLuckyMoney?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge) [![Build Status](https://travis-ci.org/geeeeeeeeek/WeChatLuckyMoney.svg?branch=stable)](https://travis-ci.org/geeeeeeeeek/WeChatLuckyMoney) [**README IN ENGLISH**](https://github.com/geeeeeeeeek/WeChatLuckyMoney/blob/stable/README_EN.md) +[![Gitter](https://badges.gitter.im/geeeeeeeeek/WeChatLuckyMoney.svg)](https://gitter.im/geeeeeeeeek/WeChatLuckyMoney?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge) [![Build Status](https://travis-ci.org/geeeeeeeeek/WeChatLuckyMoney.svg?branch=stable)](https://travis-ci.org/geeeeeeeeek/WeChatLuckyMoney) [**ENGLISH**](https://github.com/geeeeeeeeek/WeChatLuckyMoney/blob/stable/README_EN.md) 一个帮助你在微信抢红包时战无不胜的Android应用。自动检测并且拆开红包,速度超乎你的想象。 @@ -16,7 +14,7 @@ - **不仅快人一步,红包识别更加智能** - 多种特征标识,聊天时不再重复点击红包。智能过滤红包关键字[[?]](https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues/97),避免落入“专属红包”、“抢到翻倍”的陷阱。 + 多种特征标识,聊天时不再重复点击红包。智能过滤红包关键字[[?]](https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues/97),避免落入“专属红包”、“抢到翻倍”的陷阱。还可以设置延时抢红包和自动回复感谢语[[?]](https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues/118)。 - **紧跟微信更新,内置最新春节红包资讯**