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

Commit 618df8b3 authored by Pat Manning's avatar Pat Manning Committed by Android (Google) Code Review
Browse files

Merge "Get home rotation default value from DisplayController Info in case...

Merge "Get home rotation default value from DisplayController Info in case DeviceProfile is not updated." into tm-qpr-dev
parents 09fab7ee e95a12c3
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.util.DisplayController;


import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
@@ -267,15 +268,14 @@ public class SettingsActivity extends FragmentActivity
                    return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;
                    return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;


                case ALLOW_ROTATION_PREFERENCE_KEY:
                case ALLOW_ROTATION_PREFERENCE_KEY:
                    DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
                    DisplayController.Info info = InvariantDeviceProfile.INSTANCE.get(
                            getContext()).getDeviceProfile(getContext());
                            getContext()).getDeviceProfile(getContext()).getDisplayInfo();
                    if (deviceProfile.isTablet) {
                    if (info.isTablet(info.realBounds)) {
                        // Launcher supports rotation by default. No need to show this setting.
                        // Launcher supports rotation by default. No need to show this setting.
                        return false;
                        return false;
                    }
                    }
                    // Initialize the UI once
                    // Initialize the UI once
                    preference.setDefaultValue(
                    preference.setDefaultValue(RotationHelper.getAllowRotationDefaultValue(info));
                            RotationHelper.getAllowRotationDefaultValue(deviceProfile));
                    return true;
                    return true;


                case FLAGS_PREFERENCE_KEY:
                case FLAGS_PREFERENCE_KEY:
+9 −9
Original line number Original line Diff line number Diff line
@@ -35,7 +35,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.annotation.WorkerThread;


import com.android.launcher3.BaseActivity;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController;


@@ -50,11 +49,11 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
    /**
    /**
     * Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference.
     * Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference.
     */
     */
    public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
    public static boolean getAllowRotationDefaultValue(DisplayController.Info info) {
        // If the device's pixel density was scaled (usually via settings for A11y), use the
        // If the device's pixel density was scaled (usually via settings for A11y), use the
        // original dimensions to determine if rotation is allowed of not.
        // original dimensions to determine if rotation is allowed of not.
        float originalSmallestWidth = dpiFromPx(
        float originalSmallestWidth = dpiFromPx(Math.min(info.currentSize.x, info.currentSize.y),
                Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
                DENSITY_DEVICE_STABLE);
        return originalSmallestWidth >= MIN_TABLET_WIDTH;
        return originalSmallestWidth >= MIN_TABLET_WIDTH;
    }
    }


@@ -99,7 +98,8 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
                new Handler(UI_HELPER_EXECUTOR.getLooper(), this::setOrientationAsync);
                new Handler(UI_HELPER_EXECUTOR.getLooper(), this::setOrientationAsync);
    }
    }


    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings,
            DisplayController.Info info) {
        // On large devices we do not handle auto-rotate differently.
        // On large devices we do not handle auto-rotate differently.
        mIgnoreAutoRotateSettings = ignoreAutoRotateSettings;
        mIgnoreAutoRotateSettings = ignoreAutoRotateSettings;
        if (!mIgnoreAutoRotateSettings) {
        if (!mIgnoreAutoRotateSettings) {
@@ -108,7 +108,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
                mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
                mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
            }
            }
            mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
            mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
                    getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
                    getAllowRotationDefaultValue(info));
        } else {
        } else {
            if (mSharedPrefs != null) {
            if (mSharedPrefs != null) {
                mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
                mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
@@ -122,7 +122,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
        if (mDestroyed || mIgnoreAutoRotateSettings) return;
        if (mDestroyed || mIgnoreAutoRotateSettings) return;
        boolean wasRotationEnabled = mHomeRotationEnabled;
        boolean wasRotationEnabled = mHomeRotationEnabled;
        mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
        mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
                getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
                getAllowRotationDefaultValue(mActivity.getDeviceProfile().getDisplayInfo()));
        if (mHomeRotationEnabled != wasRotationEnabled) {
        if (mHomeRotationEnabled != wasRotationEnabled) {
            notifyChange();
            notifyChange();
        }
        }
@@ -132,7 +132,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
    public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
    public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
        boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
        boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
        if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
        if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
            setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
            setIgnoreAutoRotateSettings(ignoreAutoRotateSettings, info);
            notifyChange();
            notifyChange();
        }
        }
    }
    }
@@ -169,7 +169,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
            mInitialized = true;
            mInitialized = true;
            DisplayController displayController = DisplayController.INSTANCE.get(mActivity);
            DisplayController displayController = DisplayController.INSTANCE.get(mActivity);
            DisplayController.Info info = displayController.getInfo();
            DisplayController.Info info = displayController.getInfo();
            setIgnoreAutoRotateSettings(info.isTablet(info.realBounds));
            setIgnoreAutoRotateSettings(info.isTablet(info.realBounds), info);
            displayController.addChangeListener(this);
            displayController.addChangeListener(this);
            notifyChange();
            notifyChange();
        }
        }