diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1fad72db77..8066816e89 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -49,7 +49,7 @@ android:stateNotNeeded="true" android:windowSoftInputMode="adjustPan" android:screenOrientation="unspecified" - android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout" + android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize|density" android:resizeableActivity="true" android:resumeWhilePausing="true" android:taskAffinity="" diff --git a/go/AndroidManifest-launcher.xml b/go/AndroidManifest-launcher.xml index d2575b6c68..6a8f715bb2 100644 --- a/go/AndroidManifest-launcher.xml +++ b/go/AndroidManifest-launcher.xml @@ -49,7 +49,7 @@ android:stateNotNeeded="true" android:windowSoftInputMode="adjustPan" android:screenOrientation="unspecified" - android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|uiMode" + android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize|density|uiMode" android:resizeableActivity="true" android:resumeWhilePausing="true" android:taskAffinity="" diff --git a/quickstep/AndroidManifest-launcher.xml b/quickstep/AndroidManifest-launcher.xml index 7fe9b08f28..6808222258 100644 --- a/quickstep/AndroidManifest-launcher.xml +++ b/quickstep/AndroidManifest-launcher.xml @@ -49,7 +49,7 @@ android:stateNotNeeded="true" android:windowSoftInputMode="adjustPan" android:screenOrientation="unspecified" - android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout" + android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize|density" android:resizeableActivity="true" android:resumeWhilePausing="true" android:taskAffinity="" diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml index 7ab09c5ce9..bf9059f1c4 100644 --- a/quickstep/AndroidManifest.xml +++ b/quickstep/AndroidManifest.xml @@ -71,7 +71,7 @@ android:stateNotNeeded="true" android:theme="@style/LauncherTheme" android:screenOrientation="unspecified" - android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout" + android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize|density" android:resizeableActivity="true" android:resumeWhilePausing="true" android:taskAffinity=""/> diff --git a/quickstep/res/xml/indexable_launcher_prefs.xml b/quickstep/res/xml/indexable_launcher_prefs.xml index c7e864fe00..b4740e5b51 100644 --- a/quickstep/res/xml/indexable_launcher_prefs.xml +++ b/quickstep/res/xml/indexable_launcher_prefs.xml @@ -26,7 +26,7 @@ android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:summary="@string/allow_rotation_desc" - android:defaultValue="@bool/allow_rotation" + android:defaultValue="false" android:persistent="true" /> diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java index d164c8ce3e..e983f461ee 100644 --- a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java +++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java @@ -16,7 +16,6 @@ package com.android.quickstep.util; -import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; import static android.view.OrientationEventListener.ORIENTATION_UNKNOWN; import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_180; @@ -31,7 +30,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Resources; import android.graphics.Matrix; import android.graphics.Point; import android.graphics.PointF; @@ -46,7 +44,6 @@ import androidx.annotation.NonNull; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.PagedOrientationHandler; @@ -67,7 +64,8 @@ import java.util.function.IntConsumer; * This class has initial default state assuming the device and foreground app have * no ({@link Surface#ROTATION_0} rotation. */ -public final class RecentsOrientedState implements SharedPreferences.OnSharedPreferenceChangeListener { +public final class RecentsOrientedState implements + SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = "RecentsOrientedState"; private static final boolean DEBUG = false; @@ -125,6 +123,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre private int mFlags; private int mPreviousRotation = ROTATION_0; + private boolean mListenersInitialized = false; // Combined int which encodes the full state. private int mStateId = 0; @@ -152,18 +151,31 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre mFlags = sizeStrategy.rotationSupportedByActivity ? FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_ACTIVITY : 0; - Resources res = context.getResources(); - int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp - * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE; - if (originalSmallestWidth < 600 && !mContext.getResources().getBoolean( - R.bool.allow_rotation)) { - mFlags |= FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY; - } mFlags |= FLAG_SWIPE_UP_NOT_RUNNING; mSettingsCache = SettingsCache.INSTANCE.get(mContext); initFlags(); } + /** + * Sets the device profile for the current state. + */ + public void setDeviceProfile(DeviceProfile deviceProfile) { + boolean oldMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice(); + setFlag(FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY, !deviceProfile.allowRotation); + if (mListenersInitialized) { + boolean newMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice(); + // If isMultipleOrientationSupportedByDevice is changed, init or destroy listeners + // accordingly. + if (newMultipleOrientationsSupported != oldMultipleOrientationsSupported) { + if (newMultipleOrientationsSupported) { + initMultipleOrientationListeners(); + } else { + destroyMultipleOrientationListeners(); + } + } + } + } + /** * Sets the rotation for the recents activity, which could affect the appearance of task view. * @see #update(int, int) @@ -287,14 +299,24 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre updateHomeRotationSetting(); } + private void initMultipleOrientationListeners() { + mSharedPrefs.registerOnSharedPreferenceChangeListener(this); + mSettingsCache.register(ROTATION_SETTING_URI, mRotationChangeListener); + } + + private void destroyMultipleOrientationListeners() { + mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); + mSettingsCache.unregister(ROTATION_SETTING_URI, mRotationChangeListener); + } + /** * Initializes any system values and registers corresponding change listeners. It must be * paired with {@link #destroyListeners()} call */ public void initListeners() { + mListenersInitialized = true; if (isMultipleOrientationSupportedByDevice()) { - mSharedPrefs.registerOnSharedPreferenceChangeListener(this); - mSettingsCache.register(ROTATION_SETTING_URI, mRotationChangeListener); + initMultipleOrientationListeners(); } initFlags(); } @@ -303,9 +325,9 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre * Unregisters any previously registered listeners. */ public void destroyListeners() { + mListenersInitialized = false; if (isMultipleOrientationSupportedByDevice()) { - mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); - mSettingsCache.unregister(ROTATION_SETTING_URI, mRotationChangeListener); + destroyMultipleOrientationListeners(); } setRotationWatcherEnabled(false); } diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java index f578ad1741..b15bbf3ed2 100644 --- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java +++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java @@ -112,6 +112,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy { public void setDp(DeviceProfile dp) { mDp = dp; mLayoutValid = false; + mOrientationState.setDeviceProfile(dp); } /** diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 385612c9c4..5a58a827b5 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -1244,13 +1244,51 @@ public abstract class RecentsView - true - diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml index ead666cf7a..47a88f2263 100644 --- a/res/values-sw600dp/dimens.xml +++ b/res/values-sw600dp/dimens.xml @@ -3,7 +3,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. - You may obtain a copy of the License at + You may obtain a copy of the License at` http://www.apache.org/licenses/LICENSE-2.0 @@ -15,13 +15,6 @@ --> - - 850dp - 525dp - - - 56dp - -1000dp diff --git a/res/values-sw720dp/config.xml b/res/values-sw720dp/config.xml deleted file mode 100644 index 33fc553a84..0000000000 --- a/res/values-sw720dp/config.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - 90 - diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml deleted file mode 100644 index 691219af63..0000000000 --- a/res/values-sw720dp/dimens.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - 64dp - 180dp - - - 75dp - 62dp - 13dp - 32dp - - diff --git a/res/values-sw720dp/styles.xml b/res/values-sw720dp/styles.xml deleted file mode 100644 index c1e6ecace7..0000000000 --- a/res/values-sw720dp/styles.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/res/values/config.xml b/res/values/config.xml index 0a4549e387..e65c65277e 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -1,7 +1,6 @@ false - false 153 diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 0adafaf7fb..3267a5d246 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -138,7 +138,6 @@ 40dp 8dp 16dp - 0dp 8dp 2dp diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 8195cc1997..90de4987f5 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -45,7 +45,7 @@ android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:summary="@string/allow_rotation_desc" - android:defaultValue="@bool/allow_rotation" + android:defaultValue="false" android:persistent="true" launcher:logIdOn="615" launcher:logIdOff="616" /> diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index 00317f7010..af77bf882a 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -74,7 +74,6 @@ public abstract class ButtonDropTarget extends TextView protected final Launcher mLauncher; - private int mBottomDragPadding; protected DropTargetBar mDropTargetBar; /** Whether this drop target is active for the current drag */ @@ -103,7 +102,6 @@ public abstract class ButtonDropTarget extends TextView mLauncher = Launcher.getLauncher(context); Resources resources = getResources(); - mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding); mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold); } @@ -276,7 +274,7 @@ public abstract class ButtonDropTarget extends TextView @Override public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) { super.getHitRect(outRect); - outRect.bottom += mBottomDragPadding; + outRect.bottom += mLauncher.getDeviceProfile().dropTargetDragPaddingPx; sTempCords[0] = sTempCords[1] = 0; mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords); diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index d5860dc57d..e5ad24341b 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -16,10 +16,12 @@ package com.android.launcher3; +import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static com.android.launcher3.ResourceUtils.pxFromDp; import static com.android.launcher3.Utilities.dpiFromPx; +import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH; import android.annotation.SuppressLint; import android.content.Context; @@ -61,6 +63,7 @@ public class DeviceProfile { public final boolean isPhone; public final boolean transposeLayoutWithOrientation; public final boolean isTwoPanels; + public final boolean allowRotation; // Device properties in current orientation public final boolean isLandscape; @@ -172,6 +175,8 @@ public class DeviceProfile { // Drop Target public int dropTargetBarSizePx; + public int dropTargetDragPaddingPx; + public int dropTargetTextSizePx; // Insets private final Rect mInsets = new Rect(); @@ -190,6 +195,9 @@ public class DeviceProfile { // How much of the bottom inset is due to Taskbar rather than other system elements. public int nonOverlappingTaskbarInset; + // DragController + public int flingToDeleteThresholdVelocity; + DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds, boolean isMultiWindowMode, boolean transposeLayoutWithOrientation, boolean useTwoPanels) { @@ -210,7 +218,12 @@ public class DeviceProfile { int nonFinalAvailableHeightPx = windowBounds.availableSize.y; mInfo = info; - isTablet = info.isTablet(windowBounds); + // 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. + float originalSmallestWidth = dpiFromPx(Math.min(widthPx, heightPx), DENSITY_DEVICE_STABLE); + allowRotation = originalSmallestWidth >= MIN_TABLET_WIDTH; + // Tablet UI does not support emulated landscape. + isTablet = allowRotation && info.isTablet(windowBounds); isPhone = !isTablet; isTwoPanels = isTablet && useTwoPanels; @@ -287,7 +300,11 @@ public class DeviceProfile { iconDrawablePaddingOriginalPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); + dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); + dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding); + dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size); + workspaceSpringLoadedBottomSpace = res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); @@ -354,6 +371,9 @@ public class DeviceProfile { } updateWorkspacePadding(); + flingToDeleteThresholdVelocity = res.getDimensionPixelSize( + R.dimen.drag_flingToDeleteMinVelocity); + // This is done last, after iconSizePx is calculated above. Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE); mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE); @@ -821,6 +841,7 @@ public class DeviceProfile { writer.println(prefix + "DeviceProfile:"); writer.println(prefix + "\t1 dp = " + mMetrics.density + " px"); + writer.println(prefix + "\tallowRotation:" + allowRotation); writer.println(prefix + "\tisTablet:" + isTablet); writer.println(prefix + "\tisPhone:" + isPhone); writer.println(prefix + "\ttransposeLayoutWithOrientation:" diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java index c7684939db..4a1b08460b 100644 --- a/src/com/android/launcher3/DropTargetBar.java +++ b/src/com/android/launcher3/DropTargetBar.java @@ -25,6 +25,7 @@ import android.animation.TimeInterpolator; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.view.ViewDebug; @@ -114,6 +115,7 @@ public class DropTargetBar extends FrameLayout } setLayoutParams(lp); for (ButtonDropTarget button : mDropTargets) { + button.setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.dropTargetTextSizePx); button.setToolTipLocation(tooltipLocation); } } diff --git a/src/com/android/launcher3/dragndrop/FlingToDeleteHelper.java b/src/com/android/launcher3/dragndrop/FlingToDeleteHelper.java index 0a1aba12b5..336fced41f 100644 --- a/src/com/android/launcher3/dragndrop/FlingToDeleteHelper.java +++ b/src/com/android/launcher3/dragndrop/FlingToDeleteHelper.java @@ -22,6 +22,7 @@ import android.view.VelocityTracker; import android.view.ViewConfiguration; import com.android.launcher3.ButtonDropTarget; +import com.android.launcher3.DeviceProfile; import com.android.launcher3.DropTarget; import com.android.launcher3.Launcher; import com.android.launcher3.R; @@ -35,15 +36,12 @@ public class FlingToDeleteHelper { private static final float MAX_FLING_DEGREES = 35f; private final Launcher mLauncher; - private final int mFlingToDeleteThresholdVelocity; private ButtonDropTarget mDropTarget; private VelocityTracker mVelocityTracker; public FlingToDeleteHelper(Launcher launcher) { mLauncher = launcher; - mFlingToDeleteThresholdVelocity = launcher.getResources() - .getDimensionPixelSize(R.dimen.drag_flingToDeleteMinVelocity); } public void recordMotionEvent(MotionEvent ev) { @@ -91,12 +89,13 @@ public class FlingToDeleteHelper { mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity()); PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); float theta = MAX_FLING_DEGREES + 1; - if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) { + DeviceProfile deviceProfile = mLauncher.getDeviceProfile(); + if (mVelocityTracker.getYVelocity() < deviceProfile.flingToDeleteThresholdVelocity) { // Do a quick dot product test to ensure that we are flinging upwards PointF upVec = new PointF(0f, -1f); theta = getAngleBetweenVectors(vel, upVec); } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() && - mVelocityTracker.getXVelocity() < mFlingToDeleteThresholdVelocity) { + mVelocityTracker.getXVelocity() < deviceProfile.flingToDeleteThresholdVelocity) { // Remove icon is on left side instead of top, so check if we are flinging to the left. PointF leftVec = new PointF(-1f, 0f); theta = getAngleBetweenVectors(vel, leftVec); diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 216510beb1..883ff75e37 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -19,7 +19,6 @@ package com.android.launcher3.settings; import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS; import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; -import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue; import android.content.SharedPreferences; import android.os.Bundle; @@ -38,6 +37,8 @@ import androidx.preference.PreferenceGroup.PreferencePositionCallback; import androidx.preference.PreferenceScreen; import androidx.recyclerview.widget.RecyclerView; +import com.android.launcher3.DeviceProfile; +import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherFiles; import com.android.launcher3.R; import com.android.launcher3.Utilities; @@ -169,12 +170,14 @@ public class SettingsActivity extends FragmentActivity return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS; case ALLOW_ROTATION_PREFERENCE_KEY: - if (getResources().getBoolean(R.bool.allow_rotation)) { + DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get( + getContext()).getDeviceProfile(getContext()); + if (deviceProfile.allowRotation) { // Launcher supports rotation by default. No need to show this setting. return false; } // Initialize the UI once - preference.setDefaultValue(getAllowRotationDefaultValue()); + preference.setDefaultValue(false); return true; case FLAGS_PREFERENCE_KEY: diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java index 2da06e939e..5832711f11 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -18,43 +18,34 @@ 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_UNSPECIFIED; -import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; -import android.app.Activity; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.res.Resources; -import com.android.launcher3.R; +import com.android.launcher3.BaseActivity; +import com.android.launcher3.DeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.util.UiThreadHelper; /** * Utility class to manage launcher rotation */ -public class RotationHelper implements OnSharedPreferenceChangeListener { +public class RotationHelper implements OnSharedPreferenceChangeListener, + DeviceProfile.OnDeviceProfileChangeListener { private static final String TAG = "RotationHelper"; public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; - public static boolean getAllowRotationDefaultValue() { - // 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; - } - public static final int REQUEST_NONE = 0; public static final int REQUEST_ROTATE = 1; public static final int REQUEST_LOCK = 2; - private Activity mActivity; - private final SharedPreferences mSharedPrefs; + private BaseActivity mActivity; + private SharedPreferences mSharedPrefs = null; private boolean mIgnoreAutoRotateSettings; + private boolean mForceAllowRotationForTesting; private boolean mHomeRotationEnabled; /** @@ -79,18 +70,25 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { // Initialize mLastActivityFlags to a value not used by SCREEN_ORIENTATION flags private int mLastActivityFlags = -999; - public RotationHelper(Activity activity) { + public RotationHelper(BaseActivity activity) { mActivity = activity; + } + private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) { // On large devices we do not handle auto-rotate differently. - mIgnoreAutoRotateSettings = mActivity.getResources().getBoolean(R.bool.allow_rotation); + mIgnoreAutoRotateSettings = ignoreAutoRotateSettings; if (!mIgnoreAutoRotateSettings) { - mSharedPrefs = Utilities.getPrefs(mActivity); - mSharedPrefs.registerOnSharedPreferenceChangeListener(this); + if (mSharedPrefs == null) { + mSharedPrefs = Utilities.getPrefs(mActivity); + mSharedPrefs.registerOnSharedPreferenceChangeListener(this); + } mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, - getAllowRotationDefaultValue()); + mActivity.getDeviceProfile().allowRotation); } else { - mSharedPrefs = null; + if (mSharedPrefs != null) { + mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); + mSharedPrefs = null; + } } } @@ -99,12 +97,21 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { if (mDestroyed) return; boolean wasRotationEnabled = mHomeRotationEnabled; mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, - getAllowRotationDefaultValue()); + mActivity.getDeviceProfile().allowRotation); if (mHomeRotationEnabled != wasRotationEnabled) { notifyChange(); } } + @Override + public void onDeviceProfileChanged(DeviceProfile dp) { + boolean ignoreAutoRotateSettings = dp.allowRotation; + if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) { + setIgnoreAutoRotateSettings(ignoreAutoRotateSettings); + notifyChange(); + } + } + public void setStateHandlerRequest(int request) { if (mStateHandlerRequest != request) { mStateHandlerRequest = request; @@ -128,14 +135,15 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { // Used by tests only. public void forceAllowRotationForTesting(boolean allowRotation) { - mIgnoreAutoRotateSettings = - allowRotation || mActivity.getResources().getBoolean(R.bool.allow_rotation); + mForceAllowRotationForTesting = allowRotation; notifyChange(); } public void initialize() { if (!mInitialized) { mInitialized = true; + setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().allowRotation); + mActivity.addOnDeviceProfileChangeListener(this); notifyChange(); } } @@ -143,6 +151,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { public void destroy() { if (!mDestroyed) { mDestroyed = true; + mActivity.removeOnDeviceProfileChangeListener(this); mActivity = null; if (mSharedPrefs != null) { mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); @@ -165,7 +174,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { } else if (mCurrentStateRequest == REQUEST_LOCK) { activityFlags = SCREEN_ORIENTATION_LOCKED; } else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE - || mHomeRotationEnabled) { + || mHomeRotationEnabled || mForceAllowRotationForTesting) { activityFlags = SCREEN_ORIENTATION_UNSPECIFIED; } else { // If auto rotation is off, allow rotation on the activity, in case the user is using @@ -191,9 +200,10 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { @Override public String toString() { - return String.format("[mStateHandlerRequest=%d, mCurrentStateRequest=%d," - + " mLastActivityFlags=%d, mIgnoreAutoRotateSettings=%b, mHomeRotationEnabled=%b]", + return String.format("[mStateHandlerRequest=%d, mCurrentStateRequest=%d, " + + "mLastActivityFlags=%d, mIgnoreAutoRotateSettings=%b, " + + "mHomeRotationEnabled=%b, mForceAllowRotationForTesting=%b]", mStateHandlerRequest, mCurrentStateRequest, mLastActivityFlags, - mIgnoreAutoRotateSettings, mHomeRotationEnabled); + mIgnoreAutoRotateSettings, mHomeRotationEnabled, mForceAllowRotationForTesting); } } diff --git a/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java b/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java index 1524ab34e8..c3eda13c3f 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java +++ b/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java @@ -47,7 +47,6 @@ public final class WidgetsListTableViewHolderBinder private int mMaxSpansPerRow = 4; private final LayoutInflater mLayoutInflater; - private final int mIndent; private final OnClickListener mIconClickListener; private final OnLongClickListener mIconLongClickListener; private final WidgetPreviewLoader mWidgetPreviewLoader; @@ -62,7 +61,6 @@ public final class WidgetsListTableViewHolderBinder WidgetPreviewLoader widgetPreviewLoader, WidgetsListAdapter listAdapter) { mLayoutInflater = layoutInflater; - mIndent = context.getResources().getDimensionPixelSize(R.dimen.widget_section_indent); mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; mWidgetPreviewLoader = widgetPreviewLoader; @@ -90,11 +88,6 @@ public final class WidgetsListTableViewHolderBinder ViewGroup container = (ViewGroup) mLayoutInflater.inflate( R.layout.widgets_table_container, parent, false); - - // if the end padding is 0, then container view (horizontal scroll view) doesn't respect - // the end of the linear layout width + the start padding and doesn't allow scrolling. - container.findViewById(R.id.widgets_table).setPaddingRelative(mIndent, 0, 1, 0); - return new WidgetsRowViewHolder(container); } diff --git a/tests/AndroidManifest-common.xml b/tests/AndroidManifest-common.xml index 7f6c8f8a87..918ec4af1a 100644 --- a/tests/AndroidManifest-common.xml +++ b/tests/AndroidManifest-common.xml @@ -109,7 +109,7 @@