diff --git a/.gitignore b/.gitignore
index 9c4de582..67b05292 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
.DS_Store
/build
/captures
+/.idea/dictionaries
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 00000000..97626ba4
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 00000000..7f68460d
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/miui/hongbao/HongbaoService.java b/app/src/main/java/com/miui/hongbao/HongbaoService.java
index 82a2a3c5..37d4c3fb 100644
--- a/app/src/main/java/com/miui/hongbao/HongbaoService.java
+++ b/app/src/main/java/com/miui/hongbao/HongbaoService.java
@@ -3,7 +3,9 @@
import android.accessibilityservice.AccessibilityService;
import android.annotation.TargetApi;
import android.os.Build;
+import android.os.PowerManager;
import android.util.Log;
+import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
@@ -168,5 +170,4 @@ private String getHongbaoHash(AccessibilityNodeInfo node) {
return content + "@" + getNodeId(node);
}
-
}
diff --git a/app/src/main/java/com/miui/hongbao/MainActivity.java b/app/src/main/java/com/miui/hongbao/MainActivity.java
index 24b23d6c..930005d3 100644
--- a/app/src/main/java/com/miui/hongbao/MainActivity.java
+++ b/app/src/main/java/com/miui/hongbao/MainActivity.java
@@ -10,6 +10,7 @@
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;
@@ -24,14 +25,12 @@ public class MainActivity extends Activity {
private final Intent mAccessibleIntent =
new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
- private TextView githubLink;
private Button switchPlugin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- githubLink = (TextView) findViewById(R.id.github);
switchPlugin = (Button) findViewById(R.id.button_accessible);
handleMIUIStatusBar();
@@ -63,6 +62,12 @@ protected void onResume() {
updateServiceStatus();
}
+ @Override
+ protected void onDestroy() {
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ super.onDestroy();
+ }
+
private void updateServiceStatus() {
boolean serviceEnabled = false;
@@ -73,10 +78,18 @@ private void updateServiceStatus() {
for (AccessibilityServiceInfo info : accessibilityServices) {
if (info.getId().equals(getPackageName() + "/.HongbaoService")) {
serviceEnabled = true;
+ break;
}
}
- switchPlugin.setText(serviceEnabled ? "关闭插件" : "开启插件");
+ if (serviceEnabled) {
+ switchPlugin.setText("关闭插件");
+ // Prevent screen from dimming
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ } else {
+ switchPlugin.setText("开启插件");
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
}
public void onButtonClicked(View view) {