From 59d086c3ce5d9c3d800abca73762e82f2489cbec Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 7 May 2018 17:31:40 -0700 Subject: 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 +++++++++++++++++++++ .../src/com/android/quickstep/RecentsActivity.java | 6 +++ .../quickstep/WindowTransformSwipeHandler.java | 2 + src/com/android/launcher3/BaseActivity.java | 13 ------ .../android/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 398bd3c46..11d56949d 100644 Binary files a/quickstep/libs/sysui_shared.jar and b/quickstep/libs/sysui_shared.jar differ diff --git a/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java b/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java new file mode 100644 index 000000000..2d9a16147 --- /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 1359b3a1e..20ecde972 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 614ba6e68..9594b9f4e 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 a41edc08b..bd38bf00d 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 1400432c9..e47dbe535 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 4deed73b6..4f9920c5b 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 9a9e001c3..ca6e97ea0 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 000000000..b1a67e9f2 --- /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(); + } +} -- cgit v1.2.3