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 4a366f3 commit 0374fa7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:theme="@style/Theme.AppCompat.Light">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
android:label="@string/main_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/codeboy/qianghongbao/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
public class Config {

public static final String PREFERENCE_NAME = "config";
public static final String KEY_ENABLE_QIANG_HONG_BAO = "KEY_ENABLE_QIANG_HONG_BAO";
public static final String KEY_ENABLE_WECHAT = "KEY_ENABLE_WECHAT";

SharedPreferences preferences;

public Config(Context context) {
preferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
}

public boolean isEnableQiangHongBao() {
return preferences.getBoolean(KEY_ENABLE_QIANG_HONG_BAO, true);
/** 是否启动微信抢红包*/
public boolean isEnableWechat() {
return preferences.getBoolean(KEY_ENABLE_WECHAT, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void onCreate(Bundle savedInstanceState) {
getPreferenceManager().setSharedPreferencesName(Config.PREFERENCE_NAME);
addPreferencesFromResource(R.xml.main);

SwitchPreference switchPreference = (SwitchPreference) findPreference(Config.KEY_ENABLE_QIANG_HONG_BAO);
SwitchPreference switchPreference = (SwitchPreference) findPreference(Config.KEY_ENABLE_WECHAT);
switchPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,14 @@ protected void onServiceConnected() {

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if(!mConfig.isEnableQiangHongBao()) { //没开启,则不处理事件
return;
}
if(BuildConfig.DEBUG) {
Log.d(TAG, "事件--->" + event);
}
String pkn = String.valueOf(event.getPackageName());
if(mAccessbilityJobs != null && !mAccessbilityJobs.isEmpty()) {

for (AccessbilityJob job : mAccessbilityJobs) {
if(pkn.equals(job.getTargetPackageName())) {
if(pkn.equals(job.getTargetPackageName()) && job.isEnable()) {
job.onReceiveJob(event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface AccessbilityJob {
void onCreateJob(QiangHongBaoService service);
void onReceiveJob(AccessibilityEvent event);
void onStopJob();
boolean isEnable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public void onStopJob() {
} catch (Exception e) {}
}

@Override
public boolean isEnable() {
return getConfig().isEnableWechat();
}

@Override
public String getTargetPackageName() {
return WECHAT_PACKAGENAME;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>

<string name="app_name">CodeBoy抢红包</string>
<string name="main_name">抢红包</string>
<string name="accessibility_description">启动抢红包服务,仅支持微信。</string>
<string name="service_name">CodeBoy抢红包</string>
<string name="open_service_title">需要开启辅助服务正常使用</string>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/xml/main.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="设置">
<PreferenceCategory android:title="微信红包设置">
<SwitchPreference
android:defaultValue="true"
android:title="开启抢红包"
android:key="KEY_ENABLE_QIANG_HONG_BAO">
android:title="开启抢微信红包"
android:key="KEY_ENABLE_WECHAT">

</SwitchPreference>
</PreferenceCategory>
Expand Down

0 comments on commit 0374fa7

Please sign in to comment.