Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3232da7 authored by Jason Monk's avatar Jason Monk
Browse files

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
parent d6cfeba9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -5918,4 +5918,15 @@
    <!-- Summary Title for saying that the preference is experimental and will evolve over time due to User feedback. [CHAR LIMIT=NONE] -->
    <string name="experimental_preference">(Experimental)</string>

    <!-- [CHAR LIMIT=45] Auto-rotate setting title -->
    <string name="display_auto_rotate_title">When device is rotated</string>
    <!-- [CHAR LIMIT=70] Rotate when screen is turned option -->
    <string name="display_auto_rotate_rotate">Rotate the contents of the screen</string>
    <!-- [CHAR LIMIT=70] Keep the screen in portrait when rotated -->
    <string name="display_auto_rotate_stay_in_portrait">Stay in portrait view</string>
    <!-- [CHAR LIMIT=70] Keep the screen in landscape when rotated -->
    <string name="display_auto_rotate_stay_in_landscape">Stay in landscape view</string>
    <!-- [CHAR LIMIT=70] Don't rotate when screen is turned option -->
    <string name="display_auto_rotate_stay_in_current">Stay in current orientation</string>

</resources>
+4 −0
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@
                android:entryValues="@array/entryvalues_font_size"
                android:dialogTitle="@string/dialog_title_font_size" />

        <com.android.settings.notification.DropDownPreference
                android:key="auto_rotate"
                android:title="@string/display_auto_rotate_title" />

        <PreferenceScreen
                android:key="wifi_display"
                android:title="@string/wifi_display_settings_title"
+52 −3
Original line number Diff line number Diff line
@@ -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;
                }
            };