Files
Lawnchair/src/com/android/launcher3/model/PagedViewOrientedState.java
T
Vinit Nayak acaf0749b3 Adjust target and src rects for swipe to home animation
Floating icon animation runs entirely in portrait
since that's what orienation launcher starts in.
Current app window target rects are in landscape to
be able animate to Overview correctly (which is not
in portrait since the leash from WM is in the same
orientation as that of foreground app).
Invert that rect as the animation from app window
to floating icon progresses.

Fixes: 148528795
Change-Id: Ie1149a1a8904afc80bd1986f8d67b6f2d88c49f2
2020-03-02 18:02:52 -08:00

105 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();
}
}
public int getDisplayRotation() {
return mDisplayRotation;
}
/**
* 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;
}
}