WM is making changes which allows apps to maintain their orientation independent of the orientation of the foreground app. This allows recents to always start in portrait even when the app currently running is in landscape. This means we have to give the illusion of a landscape oriented overview when user swipes up in gesterual nav when launcher is started in portrait configuration. PagedOrientationHandler abstracts all coordinate specific logic from Paged/RecentsView primarily, but also all other dynamic calculations throughout launcher. PagedViewOrientationState is the single point of exposure to other classes that depend on those changes. The goal is to also minimize holding state to allow for default implementations of PagedOrientationHandler for all the 3p/Fallback classes. PagedViewOrientationState also holds other data around rotation that isn't specifically tied to view logic. The fake landscape overview can be toggled with: adb shell settings put global forced_rotation [0/1] Fixes: 146176182 Change-Id: I65d8d4e9f92b93931cbe0053ccaf0cda8d2ffd6c
101 lines
3.9 KiB
Java
101 lines
3.9 KiB
Java
/*
|
|
*
|
|
* * Copyright (C) 2020 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.model;
|
|
|
|
import android.view.Surface;
|
|
|
|
import com.android.launcher3.states.RotationHelper;
|
|
import com.android.launcher3.touch.PortraitPagedViewHandler;
|
|
import com.android.launcher3.touch.LandscapePagedViewHandler;
|
|
import com.android.launcher3.touch.PagedOrientationHandler;
|
|
import com.android.launcher3.touch.SeascapePagedViewHandler;
|
|
|
|
/**
|
|
* Container to hold orientation/rotation related information for Launcher.
|
|
* This is not meant to be an abstraction layer for applying different functionality between
|
|
* the different orientation/rotations. For that see {@link PagedOrientationHandler}
|
|
*
|
|
* This class has initial default state assuming the device and foreground app have
|
|
* no ({@link Surface.ROTATION_0} rotation.
|
|
*
|
|
* Currently this class resides in {@link com.android.launcher3.PagedView}, but there's a ticket
|
|
* to disassociate it from Launcher since it's needed before Launcher is instantiated
|
|
* See TODO(b/150300347)
|
|
*/
|
|
public final class PagedViewOrientedState {
|
|
|
|
private PagedOrientationHandler mOrientationHandler = new PortraitPagedViewHandler();
|
|
|
|
private int mTouchRotation = Surface.ROTATION_0;
|
|
private int mDisplayRotation = Surface.ROTATION_0;
|
|
/**
|
|
* If {@code true} we default to {@link PortraitPagedViewHandler} and don't support any fake
|
|
* launcher orientations.
|
|
*/
|
|
private boolean mDisableMultipleOrientations;
|
|
|
|
public void update(int touchRotation, int displayRotation) {
|
|
mDisplayRotation = displayRotation;
|
|
mTouchRotation = touchRotation;
|
|
if (mTouchRotation == Surface.ROTATION_90) {
|
|
mOrientationHandler = new LandscapePagedViewHandler();
|
|
} else if (mTouchRotation == Surface.ROTATION_270) {
|
|
mOrientationHandler = new SeascapePagedViewHandler();
|
|
} else {
|
|
mOrientationHandler = new PortraitPagedViewHandler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return {@code true} if the area where the user touched the nav bar is the expected
|
|
* location for the given display rotation. Ex. bottom of phone in portrait, or left side of
|
|
* phone in landscape, right side in seascape, etc.
|
|
* False otherwise
|
|
*/
|
|
public boolean isTouchRegionNaturalForDisplay() {
|
|
return mTouchRotation == mDisplayRotation;
|
|
}
|
|
|
|
public boolean areMultipleLayoutOrientationsDisabled() {
|
|
return mDisableMultipleOrientations;
|
|
}
|
|
|
|
public void disableMultipleOrientations(boolean disable) {
|
|
mDisableMultipleOrientations = disable;
|
|
if (disable) {
|
|
mOrientationHandler = new PortraitPagedViewHandler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the difference between the rotation of the device/display and which region the
|
|
* user is currently interacting with in factors of 90 degree clockwise rotations.
|
|
* Ex. Display is in portrait -> 0, user touches landscape region -> 1, this
|
|
* method would return 3 because it takes 3 clockwise 90 degree rotations from normal to
|
|
* landscape (portrait -> seascape -> reverse portrait -> landscape)
|
|
*/
|
|
public int getTouchDisplayDelta() {
|
|
return RotationHelper.deltaRotation(mTouchRotation, mDisplayRotation);
|
|
}
|
|
|
|
public PagedOrientationHandler getOrientationHandler() {
|
|
return mOrientationHandler;
|
|
}
|
|
}
|