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

Commit

Permalink
Merge release/2.1 into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhongyi Tong committed Feb 2, 2016
2 parents d8ae618 + 3fc45db commit b7bcccf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/im.fir/fir-sdk/1.3.7/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.tencent.bugly/crashreport/1.2.9/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
Expand All @@ -93,7 +93,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="fir-sdk-1.3.7" level="project" />
<orderEntry type="library" exported="" name="crashreport-1.2.9" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
</component>
</module>
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ android {
targetSdkVersion 22
versionCode 2
versionName "v2.1.1"
ndk {
//设置支持的SO库架构
abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
}

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -22,4 +27,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.2.8
}
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep public class com.tencent.bugly.**{*;}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,38 @@
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.utils.ConnectivityUtil;
import xyz.monkeytong.hongbao.utils.UpdateTask;

import java.lang.reflect.Method;
import java.util.List;

import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.utils.ConnectivityUtil;
import xyz.monkeytong.hongbao.utils.UpdateTask;

import com.tencent.bugly.crashreport.CrashReport;


public class MainActivity extends Activity {
private final Intent mAccessibleIntent =
new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
public class MainActivity extends Activity implements AccessibilityManager.AccessibilityStateChangeListener {

//开关切换按钮
private Button switchPlugin;
//AccessibilityService 管理
private AccessibilityManager accessibilityManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CrashReport.initCrashReport(getApplicationContext(), "900019352", false);
setContentView(R.layout.activity_main);
switchPlugin = (Button) findViewById(R.id.button_accessible);

handleMaterialStatusBar();
updateServiceStatus();

explicitlyLoadPreferences();

//监听AccessibilityService 变化
accessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
accessibilityManager.addAccessibilityStateChangeListener(this);
updateServiceStatus();
}

private void explicitlyLoadPreferences() {
Expand Down Expand Up @@ -67,40 +73,22 @@ private void handleMaterialStatusBar() {
@Override
protected void onResume() {
super.onResume();
updateServiceStatus();

// Check for update when WIFI is connected or on first time.
if (ConnectivityUtil.isWifi(this) || UpdateTask.count == 0) new UpdateTask(this, false).update();
if (ConnectivityUtil.isWifi(this) || UpdateTask.count == 0)
new UpdateTask(this, false).update();
}

@Override
protected void onDestroy() {
//移除监听服务
accessibilityManager.removeAccessibilityStateChangeListener(this);
super.onDestroy();
}

private void updateServiceStatus() {
boolean serviceEnabled = false;

AccessibilityManager accessibilityManager =
(AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
List<AccessibilityServiceInfo> accessibilityServices =
accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);
for (AccessibilityServiceInfo info : accessibilityServices) {
if (info.getId().equals(getPackageName() + "/.services.HongbaoService")) {
serviceEnabled = true;
break;
}
}

if (serviceEnabled) {
switchPlugin.setText(R.string.service_off);
} else {
switchPlugin.setText(R.string.service_on);
}
}

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

public void openGithub(View view) {
Expand Down Expand Up @@ -129,4 +117,35 @@ public void openNews(View view) {
startActivity(webViewIntent);
}

@Override
public void onAccessibilityStateChanged(boolean enabled) {
updateServiceStatus();
}

/**
* 更新当前 HongbaoService 显示状态
*/
private void updateServiceStatus() {
if (isServiceEnabled()) {
switchPlugin.setText(R.string.service_off);
} else {
switchPlugin.setText(R.string.service_on);
}
}

/**
* 获取 HongbaoService 是否启用状态
*
* @return
*/
private boolean isServiceEnabled() {
List<AccessibilityServiceInfo> accessibilityServices =
accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);
for (AccessibilityServiceInfo info : accessibilityServices) {
if (info.getId().equals(getPackageName() + "/.services.HongbaoService")) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ public void onInterrupt() {

}

/**
* 递归查找拆红包按钮
*/
private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) {
if (node==null)
return null;

//非layout元素
if (node.getChildCount() == 0) {
if("android.widget.Button".equals(node.getClassName()))
return node;
else
return null;
}

//layout元素,遍历找button
for (int i = 0; i < node.getChildCount(); i++) {
AccessibilityNodeInfo button = findOpenButton(node.getChild(i));
if(button != null)
return button;
}
return null;
}

/**
* 检查节点信息
*/
Expand All @@ -172,7 +196,7 @@ private void checkNodeInfo(int eventType) {
}

/* 戳开红包,红包还没抢完,遍历节点匹配“拆红包” */
AccessibilityNodeInfo node2 = (this.rootNodeInfo.getChildCount() > 3) ? this.rootNodeInfo.getChild(3) : null;
AccessibilityNodeInfo node2 = findOpenButton(this.rootNodeInfo);
if (node2 != null && "android.widget.Button".equals(node2.getClassName()) && currentActivityName.contains(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY)) {
mUnpackNode = node2;
mNeedUnpack = true;
Expand Down

0 comments on commit b7bcccf

Please sign in to comment.