Skip to content

Commit

Permalink
加入延时抢包功能
Browse files Browse the repository at this point in the history
  • Loading branch information
leon committed Jan 16, 2016
1 parent bdcc6f2 commit 64df6c1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/codeboy/qianghongbao/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 String KEY_WECHAT_DELAY_TIME = "KEY_WECHAT_DELAY_TIME";

public static final int WX_AFTER_OPEN_HONGBAO = 0;
public static final int WX_AFTER_OPEN_SEE = 1; //看大家手气
Expand All @@ -39,4 +40,14 @@ public int getWechatAfterOpenHongBaoEvent() {
} catch (Exception e) {}
return defaultValue;
}

/** 微信打开红包后延时时间*/
public int getWechatOpenDelayTime() {
int defaultValue = 0;
String result = preferences.getString(KEY_WECHAT_DELAY_TIME, String.valueOf(defaultValue));
try {
return Integer.parseInt(result);
} catch (Exception e) {}
return defaultValue;
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/codeboy/qianghongbao/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
Expand Down Expand Up @@ -133,6 +134,25 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
});
int value = Integer.parseInt(wxAfterOpenPre.getValue());
wxAfterOpenPre.setSummary(wxAfterOpenPre.getEntries()[value]);

final EditTextPreference delayEditTextPre = (EditTextPreference) findPreference(Config.KEY_WECHAT_DELAY_TIME);
delayEditTextPre.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if("0".equals(String.valueOf(newValue))) {
preference.setSummary("");
} else {
preference.setSummary("已延时" + newValue + "毫秒");
}
return true;
}
});
String delay = delayEditTextPre.getText();
if("0".equals(String.valueOf(delay))) {
delayEditTextPre.setSummary("");
} else {
delayEditTextPre.setSummary("已延时" + delay + "毫秒");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
Expand Down Expand Up @@ -66,6 +68,7 @@ public class WechatAccessbilityJob extends BaseAccessbilityJob {

private boolean isFirstChecked ;
private PackageInfo mWechatPackageInfo = null;
private Handler mHandler = null;

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
Expand Down Expand Up @@ -211,8 +214,18 @@ private void handleLuckyMoneyReceive() {
}

if(list != null && !list.isEmpty()) {
for (AccessibilityNodeInfo n : list) {
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
long sDelayTime = getConfig().getWechatOpenDelayTime();
for (final AccessibilityNodeInfo n : list) {
if(sDelayTime != 0) {
getHandler().postDelayed(new Runnable() {
@Override
public void run() {
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}, sDelayTime);
} else {
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}
}
}
Expand Down Expand Up @@ -250,15 +263,19 @@ private void handleChatListHongBao() {
}

for(AccessibilityNodeInfo n : list) {
Log.i(TAG, "-->微信红包:" + n);
if(BuildConfig.DEBUG) {
Log.i(TAG, "-->微信红包:" + n);
}
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
} else if(list != null) {
//最新的红包领起
for(int i = list.size() - 1; i >= 0; i --) {
AccessibilityNodeInfo parent = list.get(i).getParent();
Log.i(TAG, "-->领取红包:" + parent);
if(BuildConfig.DEBUG) {
Log.i(TAG, "-->领取红包:" + parent);
}
if(parent != null) {
if (isFirstChecked){
parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
Expand All @@ -270,6 +287,13 @@ private void handleChatListHongBao() {
}
}

private Handler getHandler() {
if(mHandler == null) {
mHandler = new Handler(Looper.getMainLooper());
}
return mHandler;
}

/** 是否可以通过使用文本方式进行抢红包*/
private boolean isEnableUseText() {
return getWechatVersion() < USE_ID_MIN_VERSION;
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
android:defaultValue="true"
android:title="开启抢微信红包"
android:key="KEY_ENABLE_WECHAT"/>

<EditTextPreference
android:title="设置延迟拆红包/查看手气时间"
android:defaultValue="0"
android:key="KEY_WECHAT_DELAY_TIME"
android:inputType="number"
android:dialogTitle="设置延迟时间(毫秒)"
android:hint="单位毫秒(1秒=1000毫秒)"/>

<ListPreference
android:title="打开红包后"
android:defaultValue="0"
Expand Down

0 comments on commit 64df6c1

Please sign in to comment.