blob: aca8ab4ad613bf1e38fdffbf01c97aad4f9e21f6 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package android.app;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
/**
* This class provides access to the system uimode services. These services
* allow applications to control UI modes of the device.
* It provides functionality to disable the car mode and it gives access to the
* night mode settings.
*
* <p>You do not instantiate this class directly; instead, retrieve it through
* {@link android.content.Context#getSystemService
* Context.getSystemService(Context.UI_MODE_SERVICE)}.
*/
public class UiModeManager {
private static final String TAG = "UiModeManager";
public static final int MODE_NOTNIGHT = 1;
public static final int MODE_NIGHT = 2;
public static final int MODE_AUTO = 3;
private IUiModeManager mService;
/*package*/ UiModeManager() {
mService = IUiModeManager.Stub.asInterface(
ServiceManager.getService("uimode"));
}
/**
* Disables the car mode.
*/
public void disableCarMode() {
if (mService != null) {
try {
mService.disableCarMode();
} catch (RemoteException e) {
Log.e(TAG, "disableCarMode: RemoteException", e);
}
}
}
/**
* Sets the night mode. Changes to the night mode are only effective when
* the car mode is enabled on a device.
*
* <p>The mode can be one of:
* <ul>
* <li><em>{@link #MODE_NOTNIGHT}<em> - sets the device into notnight
* mode.</li>
* <li><em>{@link #MODE_NIGHT}</em> - sets the device into night mode.
* </li>
* <li><em>{@link #MODE_AUTO}</em> - automatic night/notnight switching
* depending on the location and certain other sensors.</li>
*/
public void setNightMode(int mode) {
if (mService != null) {
try {
mService.setNightMode(mode);
} catch (RemoteException e) {
Log.e(TAG, "setNightMode: RemoteException", e);
}
}
}
/**
* Returns the currently configured night mode.
*
* @return {@link #MODE_NOTNIGHT}, {@link #MODE_NIGHT} or {@link #MODE_AUTO}
* When an error occurred -1 is returned.
*/
public int getNightMode() {
if (mService != null) {
try {
return mService.getNightMode();
} catch (RemoteException e) {
Log.e(TAG, "getNightMode: RemoteException", e);
}
}
return -1;
}
}
|