Bring back auto-rotate to settings
Add a dropdown preference to the display settings screen that controls whether auto-rotate is on. Bug: 16636008 Change-Id: I71099a23793aa82b514bd0eebae183695415a92c
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
import com.android.settings.notification.DropDownPreference;
|
||||
import com.android.settings.notification.DropDownPreference.Callback;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
@@ -26,6 +29,7 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
@@ -65,6 +69,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
private static final String KEY_LIFT_TO_WAKE = "lift_to_wake";
|
||||
private static final String KEY_DOZE = "doze";
|
||||
private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
|
||||
private static final String KEY_AUTO_ROTATE = "auto_rotate";
|
||||
|
||||
private static final int DLG_GLOBAL_CHANGE_WARNING = 1;
|
||||
|
||||
@@ -81,7 +86,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final Activity activity = getActivity();
|
||||
final ContentResolver resolver = activity.getContentResolver();
|
||||
|
||||
addPreferencesFromResource(R.xml.display_settings);
|
||||
|
||||
@@ -111,19 +117,59 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
removePreference(KEY_AUTO_BRIGHTNESS);
|
||||
}
|
||||
|
||||
if (isLiftToWakeAvailable(getActivity())) {
|
||||
if (isLiftToWakeAvailable(activity)) {
|
||||
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
|
||||
mLiftToWakePreference.setOnPreferenceChangeListener(this);
|
||||
} else {
|
||||
removePreference(KEY_LIFT_TO_WAKE);
|
||||
}
|
||||
|
||||
if (isDozeAvailable(getActivity())) {
|
||||
if (isDozeAvailable(activity)) {
|
||||
mDozePreference = (SwitchPreference) findPreference(KEY_DOZE);
|
||||
mDozePreference.setOnPreferenceChangeListener(this);
|
||||
} else {
|
||||
removePreference(KEY_DOZE);
|
||||
}
|
||||
|
||||
if (RotationPolicy.isRotationLockToggleVisible(activity)) {
|
||||
DropDownPreference rotatePreference =
|
||||
(DropDownPreference) findPreference(KEY_AUTO_ROTATE);
|
||||
rotatePreference.addItem(activity.getString(R.string.display_auto_rotate_rotate),
|
||||
false);
|
||||
int rotateLockedResourceId;
|
||||
// The following block sets the string used when rotation is locked.
|
||||
// If the device locks specifically to portrait or landscape (rather than current
|
||||
// rotation), then we use a different string to include this information.
|
||||
if (allowAllRotations(activity)) {
|
||||
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
|
||||
} else {
|
||||
if (RotationPolicy.getRotationLockOrientation(activity)
|
||||
== Configuration.ORIENTATION_PORTRAIT) {
|
||||
rotateLockedResourceId =
|
||||
R.string.display_auto_rotate_stay_in_portrait;
|
||||
} else {
|
||||
rotateLockedResourceId =
|
||||
R.string.display_auto_rotate_stay_in_landscape;
|
||||
}
|
||||
}
|
||||
rotatePreference.addItem(activity.getString(rotateLockedResourceId), true);
|
||||
rotatePreference.setSelectedItem(RotationPolicy.isRotationLocked(activity) ?
|
||||
1 : 0);
|
||||
rotatePreference.setCallback(new Callback() {
|
||||
@Override
|
||||
public boolean onItemSelected(int pos, Object value) {
|
||||
RotationPolicy.setRotationLock(activity, (Boolean) value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
removePreference(KEY_AUTO_ROTATE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean allowAllRotations(Context context) {
|
||||
return Resources.getSystem().getBoolean(
|
||||
com.android.internal.R.bool.config_allowAllRotations);
|
||||
}
|
||||
|
||||
private static boolean isLiftToWakeAvailable(Context context) {
|
||||
@@ -382,6 +428,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
if (!isDozeAvailable(context)) {
|
||||
result.add(KEY_DOZE);
|
||||
}
|
||||
if (!RotationPolicy.isRotationLockToggleVisible(context)) {
|
||||
result.add(KEY_AUTO_ROTATE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user