Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from geeeeeeeeek/milestone/2.0
Browse files Browse the repository at this point in the history
Milestone/2.0 Ready to Merge
  • Loading branch information
Zhongyi Tong authored and Zhongyi Tong committed Jan 23, 2016
2 parents 91bcf4b + 00b29b1 commit 828bf1b
Show file tree
Hide file tree
Showing 27 changed files with 611 additions and 137 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions LuckyMoneyTool.iml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

## **版权及免责声明**

本项目源自小米今年秋季发布会时演示的抢红包测试[源码](https://github.com/XiaoMi/LuckyMoneyTool)。stable分支基于此代码继续开发,dev分支重写了几乎所有的逻辑代码。应用的包名com.miui.hongbao未变。
本项目源自小米今年秋季发布会时演示的抢红包测试[源码](https://github.com/XiaoMi/LuckyMoneyTool)。stable分支基于此代码继续开发,dev分支重写了几乎所有的逻辑代码。

由于插件可能会改变自然的微信交互方式,这份代码仅可用于教学目的,不得更改后用于其他用途。对于使用插件时可能发生的任何情形,由使用者自行承担,包括但不限于“禁用红包功能”、“微信封号”。

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ The following doc is targeted at **stable branch**.

## License

The project was heavily inspired by an [app](https://github.com/XiaoMi/LuckyMoneyTool) demonstrated on XiaoMi's news conference for its phone product this autumn. The stable branch is developed after this, while the dev branch rewrites nearly all the code. The package name remains unchanged as `com.miui.hongbao`.
The project was heavily inspired by an [app](https://github.com/XiaoMi/LuckyMoneyTool) demonstrated on XiaoMi's news conference for its phone product this autumn. The stable branch is developed after this, while the dev branch rewrites nearly all the code.

**Note that:** This app might alter the natural way of interactions with WeChat. Thus the code is restricted to educational use only. You are *not* allowed to use it for other purposes. You must understand and be fully responsiable of the potential risks of using the app, including "being forbidden to use WeChat Lucky Money functionality", etc.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ android {
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.miui.hongbao"
minSdkVersion 15
applicationId "xyz.monkeytong.hongbao"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionCode 2
versionName "v2.0"
}
buildTypes {
release {
Expand Down
30 changes: 17 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miui.hongbao" >
<uses-sdk android:minSdkVersion="18"
android:targetSdkVersion="22"/>
package="xyz.monkeytong.hongbao">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Base.Theme.AppCompat.Light">
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/Base.Theme.AppCompat.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.SettingsActivity"
android:theme="@style/Base.Theme.AppCompat.Light">
</activity>
<service
android:name=".HongbaoService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
android:name=".services.HongbaoService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package com.miui.hongbao;
package xyz.monkeytong.hongbao.activities;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.utils.UpdateTask;


import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.*;

public class MainActivity extends Activity {
public static Map<String, Boolean> watchedFlags = new HashMap<>();
private final Intent mAccessibleIntent =
new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);

Expand All @@ -35,6 +38,24 @@ protected void onCreate(Bundle savedInstanceState) {

handleMIUIStatusBar();
updateServiceStatus();

watchFlagsFromPreference();
}

private void watchFlagsFromPreference() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Boolean changedValue = sharedPreferences.getBoolean(key, false);
MainActivity.watchedFlags.put(key, changedValue);
}
});

List<String> flagsList = Arrays.asList("pref_watch_notification", "pref_watch_list", "pref_watch_chat");
for (String flag : flagsList) {
MainActivity.watchedFlags.put(flag, sharedPreferences.getBoolean(flag, false));
}
}

/**
Expand All @@ -53,6 +74,10 @@ private void handleMIUIStatusBar() {

Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
extraFlagField.invoke(window, tranceFlag, tranceFlag);

ImageView placeholder = (ImageView) findViewById(R.id.main_actiob_bar_placeholder);
int placeholderHeight = getStatusBarHeight();
placeholder.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, placeholderHeight));
} catch (Exception e) {
// 考虑到大多数非MIUI ROM都会打印出错误栈,不太优雅,而且一点卵用也没有,于是删了
}
Expand All @@ -62,11 +87,13 @@ private void handleMIUIStatusBar() {
protected void onResume() {
super.onResume();
updateServiceStatus();

// Check for update
new UpdateTask(this, false).update();
}

@Override
protected void onDestroy() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onDestroy();
}

Expand All @@ -85,12 +112,9 @@ private void updateServiceStatus() {
}

if (serviceEnabled) {
switchPlugin.setText("关闭插件");
// Prevent screen from dimming
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
switchPlugin.setText(R.string.service_off);
} else {
switchPlugin.setText("开启插件");
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
switchPlugin.setText(R.string.service_on);
}
}

Expand All @@ -102,4 +126,15 @@ public void openGithub(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/geeeeeeeeek/WeChatLuckyMoney"));
startActivity(browserIntent);
}

public void openSettings(View view) {
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}

public int getStatusBarHeight() {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) return getResources().getDimensionPixelSize(resourceId);
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package xyz.monkeytong.hongbao.activities;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.view.View;
import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.utils.UpdateTask;

/**
* Created by Zhongyi on 1/19/16.
* Settings page.
*/
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

loadUI();
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(getApplicationContext(),true).update();
return false;
}
});

// Open issue
Preference issuePref = findPreference("pref_etc_issue");
issuePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues"));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SettingsActivity.this.startActivity(browserIntent);
return false;
}
});
}

private void loadUI() {
addPreferencesFromResource(R.xml.preferences);

// Get rid of the fucking additional padding
getListView().setPadding(0, 0, 0, 0);
getListView().setBackgroundColor(0xfffaf6f1);
}

@Override
protected void onResume() {
super.onResume();
}

public void performBack(View view) {
super.onBackPressed();
}

public void enterAccessibilityPage(View view) {
Intent mAccessibleIntent =
new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(mAccessibleIntent);
}
}
Loading

0 comments on commit 828bf1b

Please sign in to comment.