|
@@ -0,0 +1,60 @@
|
|
1
|
+package com.github.wusuopu.RNIdle;
|
|
2
|
+
|
|
3
|
+import android.app.Activity;
|
|
4
|
+import android.content.BroadcastReceiver;
|
|
5
|
+import android.content.Context;
|
|
6
|
+import android.content.Intent;
|
|
7
|
+import android.content.IntentFilter;
|
|
8
|
+import android.content.pm.ActivityInfo;
|
|
9
|
+import android.content.res.Configuration;
|
|
10
|
+import android.util.Log;
|
|
11
|
+
|
|
12
|
+import com.facebook.common.logging.FLog;
|
|
13
|
+import com.facebook.react.bridge.Arguments;
|
|
14
|
+import com.facebook.react.bridge.Callback;
|
|
15
|
+import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
|
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
|
+import com.facebook.react.bridge.ReactMethod;
|
|
18
|
+import com.facebook.react.bridge.WritableMap;
|
|
19
|
+import com.facebook.react.common.ReactConstants;
|
|
20
|
+import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
21
|
+
|
|
22
|
+import java.util.HashMap;
|
|
23
|
+import java.util.Map;
|
|
24
|
+
|
|
25
|
+import javax.annotation.Nullable;
|
|
26
|
+
|
|
27
|
+public class RNIdleModule extends ReactContextBaseJavaModule {
|
|
28
|
+ public RNIdleModule(ReactApplicationContext reactContext) {
|
|
29
|
+ super(reactContext);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ @Override
|
|
33
|
+ public String getName() {
|
|
34
|
+ return "RNIdle";
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @ReactMethod
|
|
38
|
+ public void disableIdleTimer() {
|
|
39
|
+ setIdleTimerDisabled(true);
|
|
40
|
+ }
|
|
41
|
+ @ReactMethod
|
|
42
|
+ public void enableIdleTimer() {
|
|
43
|
+ setIdleTimerDisabled(false);
|
|
44
|
+ }
|
|
45
|
+ public void setIdleTimerDisabled(final boolean disabled) {
|
|
46
|
+ final Activity activity = this.getCurrentActivity();
|
|
47
|
+ if (activity != null) {
|
|
48
|
+ activity.runOnUiThread(new Runnable() {
|
|
49
|
+ @Override
|
|
50
|
+ public void run() {
|
|
51
|
+ if (disabled) {
|
|
52
|
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
53
|
+ } else {
|
|
54
|
+ activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+ });
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+}
|