diff options
author | Tobias Haamel <haamel@google.com> | 2010-02-18 16:15:43 -0800 |
---|---|---|
committer | Tobias Haamel <haamel@google.com> | 2010-02-22 21:42:39 +0100 |
commit | 53332883543868fb83e111a07306368b7772b340 (patch) | |
tree | 39fe760618d617d4e28d08e2bd00dbd33f055926 /core/java/android/app/UiModeManager.java | |
parent | 7e31e0c351a3b2bb70ee5507b34f1c72d62b56d7 (diff) | |
download | frameworks_base-53332883543868fb83e111a07306368b7772b340.zip frameworks_base-53332883543868fb83e111a07306368b7772b340.tar.gz frameworks_base-53332883543868fb83e111a07306368b7772b340.tar.bz2 |
Manager for controlling the UI modes.
The ui modes can be controlled with the UiModeManager class, which
is can be retrieved as a system service via getSytemService(Context.UIMODE_SERVICE).
The class is necessary so that CarHome can be unbundled and other apps can
disable the car mode. Its currently a hidden class, since I'm not sure if this
is the best way to provide this functionality to the user.
Diffstat (limited to 'core/java/android/app/UiModeManager.java')
-rw-r--r-- | core/java/android/app/UiModeManager.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/core/java/android/app/UiModeManager.java b/core/java/android/app/UiModeManager.java new file mode 100644 index 0000000..eea9257 --- /dev/null +++ b/core/java/android/app/UiModeManager.java @@ -0,0 +1,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.UIMODE_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; + } +} |