From 59d086c3ce5d9c3d800abca73762e82f2489cbec Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 7 May 2018 17:31:40 -0700 Subject: [PATCH] Using surface rotation instead of insets to determine seascape configuration Insets may not correctly indicate seascape configuration in multi-window or when the presence of device-cutouts Bug: 79376298 Change-Id: I8268efca0001fe527a0ffefe48cc71e774fad01c --- quickstep/libs/sysui_shared.jar | Bin 125835 -> 127582 bytes .../uioverrides/DisplayRotationListener.java | 48 ++++++++++++++++++ .../android/quickstep/RecentsActivity.java | 6 +++ .../WindowTransformSwipeHandler.java | 2 + src/com/android/launcher3/BaseActivity.java | 13 ----- .../launcher3/BaseDraggingActivity.java | 23 +++++++++ src/com/android/launcher3/DeviceProfile.java | 20 +++++++- src/com/android/launcher3/Launcher.java | 21 ++++++-- .../uioverrides/DisplayRotationListener.java | 37 ++++++++++++++ 9 files changed, 151 insertions(+), 19 deletions(-) create mode 100644 quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java create mode 100644 src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java diff --git a/quickstep/libs/sysui_shared.jar b/quickstep/libs/sysui_shared.jar index 398bd3c466a889c2e906c0331b5f35f6dd50e6e9..11d56949d2d4c16bae5b2f97dbac27ae5961f611 100644 GIT binary patch delta 4393 zcmZuzd0b7~7eBk(ty`L|CP_+4ijt?2luAgcbQ1|ZB}t?~C845+G(WC7X!>ao9w|po z^b^g}oK#Bll_oMi;U~X+_C1E)?|1*X-_Kg#^<8VPwa?x=rcJn;CoFEijv*+6u~;lD zKRV~MxDkW;vkqnCMd#!{nhU6ZyiXZupJB^!!$p{cp#Ts@MwRWzNQ8@Ukb!$#)c}88 z3d9LH_O)N*M7ZLL(+P3us$b(o2yw+gWFU^Kz5Lo-}EqW$|EP0_oo7>2h!2K%0Y~q{2@5oHJnxu##jc=A7ObX!hukwjpqqU-VcNGvK zZrUyqr8KxURg|bKS9hBrzWyPQAj~$80?I?^Y$-qht(Z!~)%BJnb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cher3/uioverrides/DisplayRotationListener.java b/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java new file mode 100644 index 0000000000..2d9a161475 --- /dev/null +++ b/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.uioverrides; + +import android.content.Context; +import android.os.Handler; + +import com.android.systemui.shared.system.RotationWatcher; + +/** + * Utility class for listening for rotation changes + */ +public class DisplayRotationListener extends RotationWatcher { + + private final Runnable mCallback; + private Handler mHandler; + + public DisplayRotationListener(Context context, Runnable callback) { + super(context); + mCallback = callback; + } + + @Override + public void enable() { + if (mHandler == null) { + mHandler = new Handler(); + } + super.enable(); + } + + @Override + protected void onRotationChanged(int i) { + mHandler.post(mCallback); + } +} diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java index 1359b3a1e0..20ecde9726 100644 --- a/quickstep/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/src/com/android/quickstep/RecentsActivity.java @@ -121,6 +121,11 @@ public class RecentsActivity extends BaseDraggingActivity { dispatchDeviceProfileChanged(); mRecentsRootView.setup(); + reapplyUi(); + } + + @Override + protected void reapplyUi() { mRecentsRootView.dispatchInsets(); } @@ -140,6 +145,7 @@ public class RecentsActivity extends BaseDraggingActivity { ? new InvariantDeviceProfile(this).getDeviceProfile(this) : appState.getInvariantDeviceProfile().getDeviceProfile(this).copy(this); } + onDeviceProfileInitiated(); } @Override diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index 614ba6e685..9594b9f4e3 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -43,6 +43,7 @@ import android.support.annotation.WorkerThread; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver.OnDrawListener; +import android.view.WindowManager; import android.view.animation.Interpolator; import com.android.launcher3.AbstractFloatingView; @@ -541,6 +542,7 @@ public class WindowTransformSwipeHandler { dp = dp.copy(mContext); dp.updateInsets(insets); } + dp.updateIsSeascape(mContext.getSystemService(WindowManager.class)); if (runningTaskTarget != null) { mClipAnimationHelper.updateSource(overviewStackBounds, runningTaskTarget); diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index a41edc08b4..bd38bf00d2 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -213,19 +213,6 @@ public abstract class BaseActivity extends Activity { return mForceInvisible != 0; } - /** - * Sets the device profile, adjusting it accordingly in case of multi-window - */ - protected void setDeviceProfile(DeviceProfile dp) { - mDeviceProfile = dp; - if (isInMultiWindowModeCompat()) { - Display display = getWindowManager().getDefaultDisplay(); - Point mwSize = new Point(); - display.getSize(mwSize); - mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); - } - } - public interface MultiWindowModeChangedListener { void onMultiWindowModeChanged(boolean isInMultiWindowMode); } diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index 1400432c92..e47dbe5358 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -28,12 +28,14 @@ import android.os.StrictMode; import android.os.UserHandle; import android.util.Log; import android.view.ActionMode; +import android.view.Surface; import android.view.View; import android.widget.Toast; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.badge.BadgeInfo; import com.android.launcher3.compat.LauncherAppsCompat; +import com.android.launcher3.uioverrides.DisplayRotationListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.views.BaseDragLayer; @@ -61,10 +63,13 @@ public abstract class BaseDraggingActivity extends BaseActivity private int mThemeRes = R.style.LauncherTheme; + private DisplayRotationListener mRotationListener; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mIsSafeModeEnabled = getPackageManager().isSafeMode(); + mRotationListener = new DisplayRotationListener(this, this::onDeviceRotationChanged); // Update theme WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this); @@ -237,12 +242,30 @@ public abstract class BaseDraggingActivity extends BaseActivity protected void onDestroy() { super.onDestroy(); WallpaperColorInfo.getInstance(this).removeOnChangeListener(this); + mRotationListener.disable(); } public void setOnStartCallback(OnStartCallback callback) { mOnStartCallback = callback; } + protected void onDeviceProfileInitiated() { + if (mDeviceProfile.isVerticalBarLayout()) { + mRotationListener.enable(); + mDeviceProfile.updateIsSeascape(getWindowManager()); + } else { + mRotationListener.disable(); + } + } + + private void onDeviceRotationChanged() { + if (mDeviceProfile.updateIsSeascape(getWindowManager())) { + reapplyUi(); + } + } + + protected abstract void reapplyUi(); + /** * Callback for listening for onStart */ diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 4deed73b69..4f9920c5b0 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -25,6 +25,8 @@ import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.util.DisplayMetrics; +import android.view.Surface; +import android.view.WindowManager; import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.badge.BadgeRenderer; @@ -118,6 +120,7 @@ public class DeviceProfile { private final Rect mInsets = new Rect(); public final Rect workspacePadding = new Rect(); private final Rect mHotseatPadding = new Rect(); + private boolean mIsSeascape; // Icon badges public BadgeRenderer mBadgeRenderer; @@ -519,9 +522,22 @@ public class DeviceProfile { return isLandscape && transposeLayoutWithOrientation; } + /** + * Updates orientation information and returns true if it has changed from the previous value. + */ + public boolean updateIsSeascape(WindowManager wm) { + if (isVerticalBarLayout()) { + boolean isSeascape = wm.getDefaultDisplay().getRotation() == Surface.ROTATION_270; + if (mIsSeascape != isSeascape) { + mIsSeascape = isSeascape; + return true; + } + } + return false; + } + public boolean isSeascape() { - // TODO: This might not hold true for multi window mode, use configuration insead. - return isVerticalBarLayout() && mInsets.left > mInsets.right; + return isVerticalBarLayout() && mIsSeascape; } public boolean shouldFadeAdjacentWorkspaceScreens() { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 9a9e001c3e..ca6e97ea0f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -45,6 +45,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; +import android.graphics.Point; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -57,6 +58,7 @@ import android.text.TextUtils; import android.text.method.TextKeyListener; import android.util.Log; import android.util.SparseArray; +import android.view.Display; import android.view.KeyEvent; import android.view.KeyboardShortcutGroup; import android.view.KeyboardShortcutInfo; @@ -359,9 +361,7 @@ public class Launcher extends BaseDraggingActivity mUserEventDispatcher = null; initDeviceProfile(mDeviceProfile.inv); dispatchDeviceProfileChanged(); - - getRootView().dispatchInsets(); - getStateManager().reapplyState(true /* cancelCurrentAnimation */); + reapplyUi(); // Recreate touch controllers mDragLayer.setup(mDragController); @@ -375,6 +375,12 @@ public class Launcher extends BaseDraggingActivity super.onConfigurationChanged(newConfig); } + @Override + protected void reapplyUi() { + getRootView().dispatchInsets(); + getStateManager().reapplyState(true /* cancelCurrentAnimation */); + } + @Override public void rebindModel() { int currentPage = mWorkspace.getNextPage(); @@ -386,7 +392,14 @@ public class Launcher extends BaseDraggingActivity private void initDeviceProfile(InvariantDeviceProfile idp) { // Load configuration-specific DeviceProfile - setDeviceProfile(idp.getDeviceProfile(this)); + mDeviceProfile = idp.getDeviceProfile(this); + if (isInMultiWindowModeCompat()) { + Display display = getWindowManager().getDefaultDisplay(); + Point mwSize = new Point(); + display.getSize(mwSize); + mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); + } + onDeviceProfileInitiated(); mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout(), true); } diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java b/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java new file mode 100644 index 0000000000..b1a67e9f2f --- /dev/null +++ b/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.uioverrides; + +import android.content.Context; +import android.view.OrientationEventListener; + +/** + * Utility class for listening for rotation changes + */ +public class DisplayRotationListener extends OrientationEventListener { + + private final Runnable mCallback; + + public DisplayRotationListener(Context context, Runnable callback) { + super(context); + mCallback = callback; + } + + @Override + public void onOrientationChanged(int i) { + mCallback.run(); + } +}