Handle config changes in Launcher
- This is practically a revert to http://ag/c/13687966/5 and refactored to use DisplayController.DisplayInfoChangeListener
- Make Launcher handle size and density change so transition is less janky when screen size changes
- Added fix in RecentsView to update state and TaskView when display profile changes
- Removed 720dp specific resoureces
- Removed unused widget_section_indent
- Removed unnecessary all_apps_background_canvas 600dp override that is not needed in AllApps+
- Moved remaining dp specific into DeviceProfile
- Simplified allowRotation logic to use single variable in DeviceProfile to determine if allow rotation is enabled by default
Fixes: 180803696
Test: manual
Change-Id: Iea0a7d1a0e14dc3613152dd3b3887450a2e1fc2f
diff --git a/quickstep/AndroidManifest-launcher.xml b/quickstep/AndroidManifest-launcher.xml
index 7fe9b08..6808222 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 7ab09c5..bf9059f 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 c7e864f..b4740e5 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" />
</PreferenceScreen>
diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
index d164c8c..e983f46 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 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 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 @@
* 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 @@
private int mFlags;
private int mPreviousRotation = ROTATION_0;
+ private boolean mListenersInitialized = false;
// Combined int which encodes the full state.
private int mStateId = 0;
@@ -152,19 +151,32 @@
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 @@
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 @@
* 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 f578ad1..b15bbf3 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -112,6 +112,7 @@
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 5958832..dcef7cf 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1232,13 +1232,51 @@
@Override
public void setInsets(Rect insets) {
mInsets.set(insets);
- resetPaddingFromTaskSize();
+
+ // Update DeviceProfile dependant state.
DeviceProfile dp = mActivity.getDeviceProfile();
+ setOverviewGridEnabled(
+ mActivity.getStateManager().getState().displayOverviewTasksAsGrid(dp));
+
+ // Propagate DeviceProfile change event.
mLiveTileTaskViewSimulator.setDp(dp);
mActionsView.setDp(dp);
+ mOrientationState.setDeviceProfile(dp);
+
+ // Update RecentsView adn TaskView's DeviceProfile dependent layout.
+ updateOrientationHandler();
}
- private void resetPaddingFromTaskSize() {
+ private void updateOrientationHandler() {
+ // Handle orientation changes.
+ mOrientationHandler = mOrientationState.getOrientationHandler();
+ mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
+ setLayoutDirection(mIsRtl
+ ? View.LAYOUT_DIRECTION_RTL
+ : View.LAYOUT_DIRECTION_LTR);
+ mClearAllButton.setLayoutDirection(mIsRtl
+ ? View.LAYOUT_DIRECTION_LTR
+ : View.LAYOUT_DIRECTION_RTL);
+ mClearAllButton.setRotation(mOrientationHandler.getDegreesRotated());
+ mActivity.getDragLayer().recreateControllers();
+ boolean isInLandscape = mOrientationState.getTouchRotation() != ROTATION_0
+ || mOrientationState.getRecentsActivityRotation() != ROTATION_0;
+ mActionsView.updateHiddenFlags(HIDDEN_NON_ZERO_ROTATION,
+ !mOrientationState.canRecentsActivityRotate() && isInLandscape);
+
+ // Update TaskView's DeviceProfile dependent layout.
+ updateChildTaskOrientations();
+
+ // Recalculate DeviceProfile dependent layout.
+ updateSizeAndPadding();
+
+ requestLayout();
+ // Reapply the current page to update page scrolls.
+ setCurrentPage(mCurrentPage);
+ }
+
+ // Update task size and padding that are dependent on DeviceProfile and insets.
+ private void updateSizeAndPadding() {
DeviceProfile dp = mActivity.getDeviceProfile();
getTaskSize(mTempRect);
mTaskWidth = mTempRect.width();
@@ -2554,28 +2592,6 @@
}
}
- private void updateOrientationHandler() {
- mOrientationHandler = mOrientationState.getOrientationHandler();
- mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
- setLayoutDirection(mIsRtl
- ? View.LAYOUT_DIRECTION_RTL
- : View.LAYOUT_DIRECTION_LTR);
- mClearAllButton.setLayoutDirection(mIsRtl
- ? View.LAYOUT_DIRECTION_LTR
- : View.LAYOUT_DIRECTION_RTL);
- mClearAllButton.setRotation(mOrientationHandler.getDegreesRotated());
- mActivity.getDragLayer().recreateControllers();
- boolean isInLandscape = mOrientationState.getTouchRotation() != ROTATION_0
- || mOrientationState.getRecentsActivityRotation() != ROTATION_0;
- mActionsView.updateHiddenFlags(HIDDEN_NON_ZERO_ROTATION,
- !mOrientationState.canRecentsActivityRotate() && isInLandscape);
- updateChildTaskOrientations();
- resetPaddingFromTaskSize();
- requestLayout();
- // Reapply the current page to update page scrolls.
- setCurrentPage(mCurrentPage);
- }
-
public RecentsOrientedState getPagedViewOrientedState() {
return mOrientationState;
}
@@ -3656,7 +3672,6 @@
public void onSecondaryWindowBoundsChanged() {
// Invalidate the task view size
setInsets(mInsets);
- requestLayout();
}
/**