Add rotation-lock to Quick Settings on phones.
Make the rotation-lock QS tile available for display on phones.
Devices < sw600dp are only allowed to lock rotation to their
natural orientation (i.e. portrait on most phones), so tweak
the QS tile label to make this clear. e.g. "Locked to Portrait"
instead of "Rotation Locked" on portrait phones.
Simplify RotationLockController now that the sw600 check is no
longer hardcoded in RotationPolicy.
Remove redundant sw600dp check in SystemUI, everything driven
from the RotationPolicy helper, though SystemUI can still
choose not to display the tile at all with a resource config.
Clean up some of the docs in RotationPolicy to make clear the
subtle distinction between the two ways of locking rotation:
- From Accessibility (locks to natural orientation on all devices)
- From System UI (locks to natural < sw600dp, else current rotation)
Bug:11062710
Change-Id: I5caa4485c9501315da9fed964d6667d3012b43cb
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 @@
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 @@
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 @@
}
// 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.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 @@
private State mSslCaCertWarningState = new State();
private RotationLockController mRotationLockController;
+ private int mRotationLockedLabel;
public QuickSettingsModel(Context context) {
mContext = context;
@@ -919,6 +921,12 @@
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 @@
? 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 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() {