mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-03 17:36:49 +00:00
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
This commit is contained in:
Binary file not shown.
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<T extends BaseDraggingActivity> {
|
||||
dp = dp.copy(mContext);
|
||||
dp.updateInsets(insets);
|
||||
}
|
||||
dp.updateIsSeascape(mContext.getSystemService(WindowManager.class));
|
||||
|
||||
if (runningTaskTarget != null) {
|
||||
mClipAnimationHelper.updateSource(overviewStackBounds, runningTaskTarget);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 <T extends BaseDraggingActivity> void setOnStartCallback(OnStartCallback<T> 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
|
||||
*/
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user