summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/view/RotationPolicy.java73
-rw-r--r--packages/SystemUI/res/values-sw600dp/config.xml3
-rw-r--r--packages/SystemUI/res/values/config.xml5
-rw-r--r--packages/SystemUI/res/values/strings.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java31
8 files changed, 74 insertions, 64 deletions
diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java
index df4e1a6..9fefd00 100644
--- a/core/java/com/android/internal/view/RotationPolicy.java
+++ b/core/java/com/android/internal/view/RotationPolicy.java
@@ -18,7 +18,9 @@ package com.android.internal.view;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.content.res.Configuration;
import android.database.ContentObserver;
+import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
@@ -26,15 +28,20 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
+import android.view.Display;
import android.view.IWindowManager;
import android.view.Surface;
import android.view.WindowManagerGlobal;
+import com.android.internal.R;
+
/**
* Provides helper functions for configuring the display rotation policy.
*/
public final class RotationPolicy {
private static final String TAG = "RotationPolicy";
+ private static final int CURRENT_ROTATION = -1;
+ private static final int NATURAL_ROTATION = Surface.ROTATION_0;
private RotationPolicy() {
}
@@ -55,23 +62,33 @@ public final class RotationPolicy {
}
/**
- * Returns true if the device supports the rotation-lock toggle feature
- * in the system UI or system bar.
+ * Returns the orientation that will be used when locking the orientation from system UI
+ * with {@link #setRotationLock}.
*
- * When the rotation-lock toggle is supported, the "auto-rotate screen" option in
- * Display settings should be hidden, but it should remain available in Accessibility
- * settings.
+ * 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.
*/
- public static boolean isRotationLockToggleSupported(Context context) {
- return isRotationSupported(context)
- && context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
+ public static int getRotationLockOrientation(Context context) {
+ 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;
}
/**
- * Returns true if the rotation-lock toggle should be shown in the UI.
+ * Returns true if the rotation-lock toggle should be shown in system UI.
*/
public static boolean isRotationLockToggleVisible(Context context) {
- return isRotationLockToggleSupported(context) &&
+ return isRotationSupported(context) &&
Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
UserHandle.USER_CURRENT) == 0;
@@ -86,50 +103,42 @@ public final class RotationPolicy {
}
/**
- * Enables or disables rotation lock.
- *
- * Should be used by the rotation lock toggle.
+ * Enables or disables rotation lock from the system UI toggle.
*/
public static void setRotationLock(Context context, final boolean enabled) {
Settings.System.putIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
UserHandle.USER_CURRENT);
- AsyncTask.execute(new Runnable() {
- @Override
- public void run() {
- try {
- IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
- if (enabled) {
- wm.freezeRotation(-1);
- } else {
- wm.thawRotation();
- }
- } catch (RemoteException exc) {
- Log.w(TAG, "Unable to save auto-rotate setting");
- }
- }
- });
+ final int rotation = areAllRotationsAllowed(context) ? CURRENT_ROTATION : NATURAL_ROTATION;
+ setRotationLock(enabled, rotation);
}
/**
- * Enables or disables rotation lock and adjusts whether the rotation lock toggle
- * should be hidden for accessibility purposes.
+ * Enables or disables natural rotation lock from Accessibility settings.
*
- * Should be used by Display settings and Accessibility settings.
+ * If rotation is locked for accessibility, the system UI toggle is hidden to avoid confusion.
*/
public static void setRotationLockForAccessibility(Context context, final boolean enabled) {
Settings.System.putIntForUser(context.getContentResolver(),
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0,
UserHandle.USER_CURRENT);
+ setRotationLock(enabled, NATURAL_ROTATION);
+ }
+
+ private static boolean areAllRotationsAllowed(Context context) {
+ return context.getResources().getBoolean(R.bool.config_allowAllRotations);
+ }
+
+ private static void setRotationLock(final boolean enabled, final int rotation) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
if (enabled) {
- wm.freezeRotation(Surface.ROTATION_0);
+ wm.freezeRotation(rotation);
} else {
wm.thawRotation();
}
diff --git a/packages/SystemUI/res/values-sw600dp/config.xml b/packages/SystemUI/res/values-sw600dp/config.xml
index 48a02ab..b77f1e0 100644
--- a/packages/SystemUI/res/values-sw600dp/config.xml
+++ b/packages/SystemUI/res/values-sw600dp/config.xml
@@ -29,9 +29,6 @@
<!-- The number of columns that the top level tiles span in the QuickSettings -->
<integer name="quick_settings_user_time_settings_tile_span">1</integer>
- <!-- Whether rotation lock shows up in quick settings or not -->
- <bool name="quick_settings_show_rotation_lock">true</bool>
-
<!-- Enable the "flip settings" panel -->
<bool name="config_hasFlipSettingsPanel">false</bool>
</resources>
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 3869db3..1dd9300 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -50,7 +50,7 @@
<!-- When true, show 1/2G networks as 3G. -->
<bool name="config_showMin3G">false</bool>
- <!-- Show rotation lock button in phone-style notification panel. -->
+ <!-- Show rotation lock toggle in System UI-->
<bool name="config_showRotationLock">true</bool>
<!-- Amount of time to hold off before showing the search panel when the user presses home -->
@@ -84,9 +84,6 @@
<!-- The number of columns that the top level tiles span in the QuickSettings -->
<integer name="quick_settings_user_time_settings_tile_span">1</integer>
- <!-- Whether rotation lock shows up in quick settings or not -->
- <bool name="quick_settings_show_rotation_lock">false</bool>
-
<!-- Whether or not the RSSI tile is capitalized or not. -->
<bool name="quick_settings_rssi_tile_capitalization">true</bool>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 5afd55b..94796af 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -464,6 +464,10 @@
<string name="quick_settings_rotation_unlocked_label">Auto Rotate</string>
<!-- QuickSettings: Rotation Locked [CHAR LIMIT=NONE] -->
<string name="quick_settings_rotation_locked_label">Rotation Locked</string>
+ <!-- QuickSettings: Locked to Portrait [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_rotation_locked_portrait_label">Locked to Portrait</string>
+ <!-- QuickSettings: Locked to Landscape [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_rotation_locked_landscape_label">Locked to Landscape</string>
<!-- QuickSettings: IME [CHAR LIMIT=NONE] -->
<string name="quick_settings_ime_label">Input Method</string>
<!-- QuickSettings: Location [CHAR LIMIT=NONE] -->
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index bbac4ef..b181658 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -534,7 +534,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
mBatteryController = new BatteryController(mContext);
mNetworkController = new NetworkController(mContext);
mBluetoothController = new BluetoothController(mContext);
- mRotationLockController = new RotationLockController(mContext);
+ if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)
+ || QuickSettings.DEBUG_GONE_TILES) {
+ mRotationLockController = new RotationLockController(mContext);
+ }
final SignalClusterView signalCluster =
(SignalClusterView)mStatusBarView.findViewById(R.id.signal_cluster);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
index e6fd7d0..4d7ff5e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
@@ -176,7 +176,9 @@ class QuickSettings {
bluetoothController.addStateChangedCallback(mModel);
batteryController.addStateChangedCallback(mModel);
locationController.addSettingsChangedCallback(mModel);
- rotationLockController.addRotationLockControllerCallback(mModel);
+ if (rotationLockController != null) {
+ rotationLockController.addRotationLockControllerCallback(mModel);
+ }
}
private void queryForSslCaCerts() {
@@ -503,8 +505,7 @@ class QuickSettings {
}
// Rotation Lock
- if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock)
- || DEBUG_GONE_TILES) {
+ if (mRotationLockController != null) {
final QuickSettingsBasicTile rotationLockTile
= new QuickSettingsBasicTile(mContext);
rotationLockTile.setOnClickListener(new View.OnClickListener() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java
index 12e08d0..11cba7b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
@@ -409,6 +410,7 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
private State mSslCaCertWarningState = new State();
private RotationLockController mRotationLockController;
+ private int mRotationLockedLabel;
public QuickSettingsModel(Context context) {
mContext = context;
@@ -919,6 +921,12 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
mRotationLockTile = view;
mRotationLockCallback = cb;
mRotationLockController = rotationLockController;
+ final int lockOrientation = mRotationLockController.getRotationLockOrientation();
+ mRotationLockedLabel = lockOrientation == Configuration.ORIENTATION_PORTRAIT
+ ? R.string.quick_settings_rotation_locked_portrait_label
+ : lockOrientation == Configuration.ORIENTATION_LANDSCAPE
+ ? R.string.quick_settings_rotation_locked_landscape_label
+ : R.string.quick_settings_rotation_locked_label;
onRotationLockChanged();
}
void onRotationLockChanged() {
@@ -933,7 +941,7 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
? R.drawable.ic_qs_rotation_locked
: R.drawable.ic_qs_auto_rotate;
mRotationLockState.label = rotationLocked
- ? mContext.getString(R.string.quick_settings_rotation_locked_label)
+ ? mContext.getString(mRotationLockedLabel)
: mContext.getString(R.string.quick_settings_rotation_unlocked_label);
mRotationLockCallback.refreshView(mRotationLockTile, mRotationLockState);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java
index 6f61ec8..98d205a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockController.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.policy;
import android.content.Context;
+import android.content.res.Configuration;
import android.os.UserHandle;
import com.android.internal.view.RotationPolicy;
@@ -42,42 +43,32 @@ public final class RotationLockController {
public RotationLockController(Context context) {
mContext = context;
- notifyChanged();
- if (RotationPolicy.isRotationLockToggleSupported(mContext)) {
- RotationPolicy.registerRotationPolicyListener(mContext,
- mRotationPolicyListener, UserHandle.USER_ALL);
- }
+ RotationPolicy.registerRotationPolicyListener(mContext,
+ mRotationPolicyListener, UserHandle.USER_ALL);
}
public void addRotationLockControllerCallback(RotationLockControllerCallback callback) {
mCallbacks.add(callback);
}
+ public int getRotationLockOrientation() {
+ return RotationPolicy.getRotationLockOrientation(mContext);
+ }
+
public boolean isRotationLocked() {
- if (RotationPolicy.isRotationLockToggleSupported(mContext)) {
- return RotationPolicy.isRotationLocked(mContext);
- }
- return false;
+ return RotationPolicy.isRotationLocked(mContext);
}
public void setRotationLocked(boolean locked) {
- if (RotationPolicy.isRotationLockToggleSupported(mContext)) {
- RotationPolicy.setRotationLock(mContext, locked);
- }
+ RotationPolicy.setRotationLock(mContext, locked);
}
public boolean isRotationLockAffordanceVisible() {
- if (RotationPolicy.isRotationLockToggleSupported(mContext)) {
- return RotationPolicy.isRotationLockToggleVisible(mContext);
- }
- return false;
+ return RotationPolicy.isRotationLockToggleVisible(mContext);
}
public void release() {
- if (RotationPolicy.isRotationLockToggleSupported(mContext)) {
- RotationPolicy.unregisterRotationPolicyListener(mContext,
- mRotationPolicyListener);
- }
+ RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener);
}
private void notifyChanged() {