From 9f56a2f55a0ca986f51e5fb897590afc03d35b2d Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 3 Feb 2020 14:22:09 -0800 Subject: [PATCH] Using Display listener for landscape/seascape changes Bug: 146150882 Change-Id: Idd2ef053bd10d9add93a1366e49c0e231f2c391b --- .../uioverrides/DisplayRotationListener.java | 48 ------------------- .../launcher3/BaseDraggingActivity.java | 22 ++++----- .../uioverrides/DisplayRotationListener.java | 37 -------------- 3 files changed, 11 insertions(+), 96 deletions(-) delete mode 100644 quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java delete mode 100644 src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java diff --git a/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java b/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java deleted file mode 100644 index 2d9a161475..0000000000 --- a/quickstep/src/com/android/launcher3/uioverrides/DisplayRotationListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index dda38b308d..0d9126b133 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import static com.android.launcher3.util.DefaultDisplay.CHANGE_ROTATION; + import android.app.ActivityOptions; import android.content.ActivityNotFoundException; import android.content.Intent; @@ -38,8 +40,10 @@ import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.touch.ItemClickHandler; -import com.android.launcher3.uioverrides.DisplayRotationListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; +import com.android.launcher3.util.DefaultDisplay; +import com.android.launcher3.util.DefaultDisplay.DisplayInfoChangeListener; +import com.android.launcher3.util.DefaultDisplay.Info; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Themes; import com.android.launcher3.util.TraceHelper; @@ -48,7 +52,7 @@ import com.android.launcher3.util.TraceHelper; * Extension of BaseActivity allowing support for drag-n-drop */ public abstract class BaseDraggingActivity extends BaseActivity - implements WallpaperColorInfo.OnChangeListener { + implements WallpaperColorInfo.OnChangeListener, DisplayInfoChangeListener { private static final String TAG = "BaseDraggingActivity"; @@ -63,8 +67,6 @@ public abstract class BaseDraggingActivity extends BaseActivity private int mThemeRes = R.style.AppTheme; - private DisplayRotationListener mRotationListener; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -72,7 +74,7 @@ public abstract class BaseDraggingActivity extends BaseActivity mIsSafeModeEnabled = TraceHelper.whitelistIpcs("isSafeMode", () -> getPackageManager().isSafeMode()); - mRotationListener = new DisplayRotationListener(this, this::onDeviceRotationChanged); + DefaultDisplay.INSTANCE.get(this).addChangeListener(this); // Update theme WallpaperColorInfo.INSTANCE.get(this).addOnChangeListener(this); @@ -238,7 +240,7 @@ public abstract class BaseDraggingActivity extends BaseActivity protected void onDestroy() { super.onDestroy(); WallpaperColorInfo.INSTANCE.get(this).removeOnChangeListener(this); - mRotationListener.disable(); + DefaultDisplay.INSTANCE.get(this).removeChangeListener(this); } public void runOnceOnStart(Runnable action) { @@ -251,15 +253,13 @@ public abstract class BaseDraggingActivity extends BaseActivity protected void onDeviceProfileInitiated() { if (mDeviceProfile.isVerticalBarLayout()) { - mRotationListener.enable(); mDeviceProfile.updateIsSeascape(this); - } else { - mRotationListener.disable(); } } - private void onDeviceRotationChanged() { - if (mDeviceProfile.updateIsSeascape(this)) { + @Override + public void onDisplayInfoChanged(Info info, int flags) { + if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.updateIsSeascape(this)) { reapplyUi(); } } diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java b/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java deleted file mode 100644 index b1a67e9f2f..0000000000 --- a/src_ui_overrides/com/android/launcher3/uioverrides/DisplayRotationListener.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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(); - } -}