Methods Summary |
---|
private static boolean | areAllRotationsAllowed(android.content.Context context)
return context.getResources().getBoolean(R.bool.config_allowAllRotations);
|
public static int | getRotationLockOrientation(android.content.Context context)Returns the orientation that will be used when locking the orientation from system UI
with {@link #setRotationLock}.
If the device only supports locking to its natural orientation, this will be either
Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE,
otherwise Configuration.ORIENTATION_UNDEFINED if any orientation is lockable.
if (!areAllRotationsAllowed(context)) {
final Point size = new Point();
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
try {
wm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, size);
return size.x < size.y ?
Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
} catch (RemoteException e) {
Log.w(TAG, "Unable to get the display size");
}
}
return Configuration.ORIENTATION_UNDEFINED;
|
public static boolean | isRotationLockToggleVisible(android.content.Context context)Returns true if the rotation-lock toggle should be shown in system UI.
return isRotationSupported(context) &&
Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
UserHandle.USER_CURRENT) == 0;
|
public static boolean | isRotationLocked(android.content.Context context)Returns true if rotation lock is enabled.
return Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) == 0;
|
public static boolean | isRotationSupported(android.content.Context context)Gets whether the device supports rotation. In general such a
device has an accelerometer and has the portrait and landscape
features.
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)
&& pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT)
&& pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE)
&& context.getResources().getBoolean(
com.android.internal.R.bool.config_supportAutoRotation);
|
public static void | registerRotationPolicyListener(android.content.Context context, com.android.internal.view.RotationPolicy$RotationPolicyListener listener)Registers a listener for rotation policy changes affecting the caller's user
registerRotationPolicyListener(context, listener, UserHandle.getCallingUserId());
|
public static void | registerRotationPolicyListener(android.content.Context context, com.android.internal.view.RotationPolicy$RotationPolicyListener listener, int userHandle)Registers a listener for rotation policy changes affecting a specific user,
or USER_ALL for all users.
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
Settings.System.ACCELEROMETER_ROTATION),
false, listener.mObserver, userHandle);
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY),
false, listener.mObserver, userHandle);
|
public static void | setRotationLock(android.content.Context context, boolean enabled)Enables or disables rotation lock from the system UI toggle.
Settings.System.putIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
UserHandle.USER_CURRENT);
final int rotation = areAllRotationsAllowed(context) ? CURRENT_ROTATION : NATURAL_ROTATION;
setRotationLock(enabled, rotation);
|
private static void | setRotationLock(boolean enabled, int rotation)
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
if (enabled) {
wm.freezeRotation(rotation);
} else {
wm.thawRotation();
}
} catch (RemoteException exc) {
Log.w(TAG, "Unable to save auto-rotate setting");
}
}
});
|
public static void | setRotationLockForAccessibility(android.content.Context context, boolean enabled)Enables or disables natural rotation lock from Accessibility settings.
If rotation is locked for accessibility, the system UI toggle is hidden to avoid confusion.
Settings.System.putIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0,
UserHandle.USER_CURRENT);
setRotationLock(enabled, NATURAL_ROTATION);
|
public static void | unregisterRotationPolicyListener(android.content.Context context, com.android.internal.view.RotationPolicy$RotationPolicyListener listener)Unregisters a listener for rotation policy changes.
context.getContentResolver().unregisterContentObserver(listener.mObserver);
|