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

Commit 9f30165b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set default launcher orientation to portrait" into ub-launcher3-master

parents a9673f4b 5fcf061c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
@@ -275,6 +276,9 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        }
    };

    private RotationHelper.ForcedRotationChangedListener mForcedRotationChangedListener =
        isForcedRotation -> RecentsView.this.disableMultipleLayoutRotations(!isForcedRotation);

    private final PinnedStackAnimationListener mIPinnedStackAnimationListener =
            new PinnedStackAnimationListener();

@@ -467,6 +471,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        mIPinnedStackAnimationListener.setActivity(mActivity);
        SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(
                mIPinnedStackAnimationListener);
        Launcher launcher = Launcher.getLauncher(getContext());
        launcher.getRotationHelper().addForcedRotationCallback(mForcedRotationChangedListener);
    }

    @Override
@@ -481,6 +487,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        mIdp.removeOnChangeListener(this);
        SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(null);
        mIPinnedStackAnimationListener.setActivity(null);
        Launcher launcher = Launcher.getLauncher(getContext());
        launcher.getRotationHelper().removeForcedRotationCallback(mForcedRotationChangedListener);
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ import java.io.PrintWriter;
class OrientationTouchTransformer {

    private static final String TAG = "OrientationTouchTransformer";
    private static final boolean DEBUG = true;
    private static final boolean DEBUG = false;
    private static final int MAX_ORIENTATIONS = 4;

    private SparseArray<OrientationRectF> mSwipeTouchRegions = new SparseArray<>(MAX_ORIENTATIONS);
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.PagedViewOrientedState;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.touch.PortraitPagedViewHandler;
import com.android.launcher3.touch.OverScroll;
import com.android.launcher3.touch.PagedOrientationHandler;
+58 −13
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@ package com.android.launcher3.states;

import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import android.content.ContentResolver;
@@ -41,6 +43,9 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.UiThreadHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Utility class to manage launcher rotation
 */
@@ -49,16 +54,38 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
    public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";

    public static final String FIXED_ROTATION_TRANSFORM_SETTING_NAME = "fixed_rotation_transform";
    private final ContentResolver mContentResolver;

    /**
     * Listener to receive changes when {@link #FIXED_ROTATION_TRANSFORM_SETTING_NAME} flag changes.
     */
    public interface ForcedRotationChangedListener {
        void onForcedRotationChanged(boolean isForcedRotation);
    }

    public static boolean getAllowRotationDefaultValue() {
        // If the device was scaled, used the original dimensions to determine if rotation
        // is allowed of not.
        // 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.
        Resources res = Resources.getSystem();
        int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
                * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
        return originalSmallestWidth >= 600;
    }


    private final ContentObserver mContentObserver =
        new ContentObserver(MAIN_EXECUTOR.getHandler()) {
            @Override
            public void onChange(boolean selfChange) {
                boolean forcedRotation = Utilities.isForcedRotation(mLauncher);
                PagedView.sFlagForcedRotation = forcedRotation;
                updateForcedRotation();
                for (ForcedRotationChangedListener listener : mForcedRotationChangedListeners) {
                    listener.onForcedRotationChanged(forcedRotation);
                }
            }
        };

    public static final int REQUEST_NONE = 0;
    public static final int REQUEST_ROTATE = 1;
    public static final int REQUEST_LOCK = 2;
@@ -68,6 +95,8 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {

    private boolean mIgnoreAutoRotateSettings;
    private boolean mAutoRotateEnabled;
    private boolean mForcedRotation;
    private List<ForcedRotationChangedListener> mForcedRotationChangedListeners = new ArrayList<>();

    /**
     * Rotation request made by
@@ -96,6 +125,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {

        // On large devices we do not handle auto-rotate differently.
        mIgnoreAutoRotateSettings = mLauncher.getResources().getBoolean(R.bool.allow_rotation);
        updateForcedRotation();
        if (!mIgnoreAutoRotateSettings) {
            mPrefs = Utilities.getPrefs(mLauncher);
            mPrefs.registerOnSharedPreferenceChangeListener(this);
@@ -106,16 +136,24 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
        }

        // TODO(b/150260456) Add this in home settings as well
        final ContentResolver resolver = launcher.getContentResolver();
        final ContentObserver observer = new ContentObserver(MAIN_EXECUTOR.getHandler()) {
            @Override
            public void onChange(boolean selfChange) {
                PagedView.sFlagForcedRotation = Utilities.isForcedRotation(mLauncher);
        mContentResolver = launcher.getContentResolver();
        mContentResolver.registerContentObserver(Settings.Global.getUriFor(
            FIXED_ROTATION_TRANSFORM_SETTING_NAME), false, mContentObserver);
    }
        };
        resolver.registerContentObserver(Settings.Global.getUriFor(
            FIXED_ROTATION_TRANSFORM_SETTING_NAME),
            false, observer);

    private void updateForcedRotation() {
        mForcedRotation = !getAllowRotationDefaultValue() && Utilities.isForcedRotation(mLauncher);
    }

    /**
     * will not be called when first registering the listener.
     */
    public void addForcedRotationCallback(ForcedRotationChangedListener listener) {
        mForcedRotationChangedListeners.add(listener);
    }

    public void removeForcedRotationCallback(ForcedRotationChangedListener listener) {
        mForcedRotationChangedListeners.remove(listener);
    }

    public void setRotationHadDifferentUI(boolean rotationHasDifferentUI) {
@@ -197,6 +235,10 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
            if (mPrefs != null) {
                mPrefs.unregisterOnSharedPreferenceChangeListener(this);
            }
            if (mContentResolver != null) {
                mContentResolver.unregisterContentObserver(mContentObserver);
            }
            mForcedRotationChangedListeners.clear();
        }
    }

@@ -206,7 +248,10 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
        }

        final int activityFlags;
        if (mStateHandlerRequest != REQUEST_NONE) {
        if (mForcedRotation) {
            // TODO(b/150214193) Properly address this
            activityFlags = SCREEN_ORIENTATION_PORTRAIT;
        } else if (mStateHandlerRequest != REQUEST_NONE) {
            activityFlags = mStateHandlerRequest == REQUEST_LOCK ?
                    SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED;
        } else if (mCurrentTransitionRequest != REQUEST_NONE) {