Skip to content

Commit

Permalink
Keep screen on when service running.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongyiTong committed Nov 27, 2015
1 parent 0cb2c79 commit b2f0c9d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.DS_Store
/build
/captures
/.idea/dictionaries
6 changes: 6 additions & 0 deletions .idea/encodings.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

3 changes: 2 additions & 1 deletion app/src/main/java/com/miui/hongbao/HongbaoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -168,5 +170,4 @@ private String getHongbaoHash(AccessibilityNodeInfo node) {

return content + "@" + getNodeId(node);
}

}
19 changes: 16 additions & 3 deletions app/src/main/java/com/miui/hongbao/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit b2f0c9d

Please sign in to comment.