-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathScreenDim.java
More file actions
47 lines (38 loc) · 1.27 KB
/
ScreenDim.java
File metadata and controls
47 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.phonegap.build.screendim;
import org.json.JSONArray;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.view.WindowManager;
import android.view.Window;
import android.util.Log;
public class ScreenDim extends CordovaPlugin {
public final static String TAG = "ScreenDim";
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
throws JSONException {
if (action.equals("enable")) {
enable();
} else if (action.equals("disable")) {
disable();
} else {
// Returning false results in a "MethodNotFound" error.
return false;
}
return true;
}
public void enable() {
Log.d(TAG, "Enable screen dimmer");
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void disable() {
Log.d(TAG, "Disable screen dimmer");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
protected Window getWindow() {
return cordova.getActivity().getWindow();
}
}