Snap for 6586161 from c29b122c6f to sc-release

Change-Id: I9074010d07520512effe93bfd78cd698e94309de
This commit is contained in:
android-build-team Robot committed 2020-06-13 02:04:32 +00:00
commit 90dc1bc8a6
4 files changed
+158 -23

No files matched your search

@@ -106,18 +106,16 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer {
} else {
float distance = (float) Math.hypot(mLastPos.x - mStartDragPos.x,
mLastPos.y - mStartDragPos.y);
if (distance > mDragDistThreshold && mPassedSlop
&& mDeviceState.isOneHandedModeActive()) {
SystemUiProxy.INSTANCE.get(mContext).stopOneHandedMode();
if (distance > mDragDistThreshold && mPassedSlop) {
onStopGestureDetected();
}
}
break;
}
case ACTION_UP:
case ACTION_CANCEL: {
if (mLastPos.y >= mStartDragPos.y && mPassedSlop
&& !mDeviceState.isOneHandedModeActive()) {
SystemUiProxy.INSTANCE.get(mContext).startOneHandedMode();
if (mLastPos.y >= mStartDragPos.y && mPassedSlop) {
onStartGestureDetected();
}
mPassedSlop = false;
@@ -131,6 +129,28 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer {
}
}
private void onStartGestureDetected() {
if (mDeviceState.isOneHandedModeActive()) {
return;
}
if (mDeviceState.isOneHandedModeEnabled()) {
SystemUiProxy.INSTANCE.get(mContext).startOneHandedMode();
return;
}
// Hook one-handed gesture to expand notification panel by default
SystemUiProxy.INSTANCE.get(mContext).expandNotificationPanel();
}
private void onStopGestureDetected() {
if (!mDeviceState.isOneHandedModeEnabled() || !mDeviceState.isOneHandedModeActive()) {
return;
}
SystemUiProxy.INSTANCE.get(mContext).stopOneHandedMode();
}
private boolean isValidStartAngle(float deltaX, float deltaY) {
final float angle = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
return angle > -(ANGLE_MAX) && angle < -(ANGLE_MIN);
@@ -16,6 +16,7 @@
package com.android.quickstep;
import static android.content.Intent.ACTION_USER_UNLOCKED;
import static android.view.Surface.ROTATION_0;
import static com.android.launcher3.util.DefaultDisplay.CHANGE_ALL;
import static com.android.launcher3.util.DefaultDisplay.CHANGE_FRAME_DELAY;
@@ -52,15 +53,18 @@ import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.OrientationEventListener;
import androidx.annotation.BinderThread;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.DefaultDisplay;
import com.android.launcher3.util.SecureSettingsObserver;
import com.android.quickstep.SysUINavigationMode.NavigationModeChangeListener;
import com.android.quickstep.util.NavBarPosition;
import com.android.quickstep.util.RecentsOrientedState;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags;
@@ -79,8 +83,6 @@ public class RecentsAnimationDeviceState implements
NavigationModeChangeListener,
DefaultDisplay.DisplayInfoChangeListener {
private static boolean sIsOneHandedEnabled;
private final Context mContext;
private final SysUINavigationMode mSysUiNavMode;
private final DefaultDisplay mDefaultDisplay;
@@ -97,6 +99,7 @@ public class RecentsAnimationDeviceState implements
private final Region mDeferredGestureRegion = new Region();
private boolean mAssistantAvailable;
private float mAssistantVisibility;
private boolean mIsOneHandedModeEnabled;
private boolean mIsUserUnlocked;
private final ArrayList<Runnable> mUserUnlockedActions = new ArrayList<>();
@@ -119,9 +122,53 @@ public class RecentsAnimationDeviceState implements
}
enableMultipleRegions(false);
}
@Override
public void onActivityRotation(int displayId) {
super.onActivityRotation(displayId);
// This always gets called before onDisplayInfoChanged() so we know how to process
// the rotation in that method. This is done to avoid having a race condition between
// the sensor readings and onDisplayInfoChanged() call
if (displayId != mDisplayId) {
return;
}
mPrioritizeDeviceRotation = true;
if (mInOverview) {
// reset, launcher must be rotating
mExitOverviewRunnable.run();
}
}
};
private Runnable mExitOverviewRunnable = new Runnable() {
@Override
public void run() {
mInOverview = false;
enableMultipleRegions(false);
}
};
private OrientationTouchTransformer mOrientationTouchTransformer;
/**
* Used to listen for when the device rotates into the orientation of the current
* foreground app. For example, if a user quickswitches from a portrait to a fixed landscape
* app and then rotates rotates the device to match that orientation, this triggers calls to
* sysui to adjust the navbar.
*/
private OrientationEventListener mOrientationListener;
private int mPreviousRotation = ROTATION_0;
/**
* This is the configuration of the foreground app or the app that will be in the foreground
* once a quickstep gesture finishes.
*/
private int mCurrentAppRotation = -1;
/**
* This flag is set to true when the device physically changes orientations. When true,
* we will always report the current rotation of the foreground app whenever the display
* changes, as it would indicate the user's intention to rotate the foreground app.
*/
private boolean mPrioritizeDeviceRotation = false;
private Region mExclusionRegion;
private SystemGestureExclusionListenerCompat mExclusionListener;
@@ -207,6 +254,26 @@ public class RecentsAnimationDeviceState implements
userSetupObserver.register();
runOnDestroy(userSetupObserver::unregister);
}
mOrientationListener = new OrientationEventListener(context) {
@Override
public void onOrientationChanged(int degrees) {
int newRotation = RecentsOrientedState.getRotationForUserDegreesRotated(degrees,
mPreviousRotation);
if (newRotation == mPreviousRotation) {
return;
}
mPreviousRotation = newRotation;
mPrioritizeDeviceRotation = true;
if (newRotation == mCurrentAppRotation) {
// When user rotates device to the orientation of the foreground app after
// quickstepping
toggleSecondaryNavBarsForRotation(false);
}
}
};
}
private void setupOrientationSwipeHandler() {
@@ -282,6 +349,18 @@ public class RecentsAnimationDeviceState implements
mNavBarPosition = new NavBarPosition(mMode, info);
updateGestureTouchRegions();
mOrientationTouchTransformer.createOrAddTouchRegion(info);
mCurrentAppRotation = mDisplayRotation;
/* Update nav bars on the following:
* a) if we're not expecting quickswitch, this is coming from an activity rotation
* b) we launch an app in the orientation that user is already in
* c) We're not in overview, since overview will always be portrait (w/o home rotation)
*/
if ((mPrioritizeDeviceRotation
|| mCurrentAppRotation == mPreviousRotation) // switch to an app of orientation user is in
&& !mInOverview) {
toggleSecondaryNavBarsForRotation(false);
}
}
/**
@@ -569,10 +648,6 @@ public class RecentsAnimationDeviceState implements
* @return whether the given motion event can trigger the one handed mode.
*/
public boolean canTriggerOneHandedAction(MotionEvent ev) {
if (!sIsOneHandedEnabled) {
return false;
}
final DefaultDisplay.Info displayInfo = mDefaultDisplay.getInfo();
return (mOrientationTouchTransformer.touchInOneHandedModeRegion(ev)
&& displayInfo.rotation != Surface.ROTATION_90
@@ -580,8 +655,12 @@ public class RecentsAnimationDeviceState implements
&& displayInfo.metrics.densityDpi < DisplayMetrics.DENSITY_600);
}
public boolean isOneHandedModeEnabled() {
return mIsOneHandedModeEnabled;
}
private void onOneHandedEnabledSettingsChanged(boolean isOneHandedEnabled) {
sIsOneHandedEnabled = isOneHandedEnabled;
mIsOneHandedModeEnabled = isOneHandedEnabled;
}
/**
@@ -596,9 +675,13 @@ public class RecentsAnimationDeviceState implements
mOrientationTouchTransformer.transform(event);
}
void enableMultipleRegions(boolean enable) {
mOrientationTouchTransformer.enableMultipleRegions(enable, mDefaultDisplay.getInfo());
notifySysuiForRotation(mOrientationTouchTransformer.getQuickStepStartingRotation());
private void enableMultipleRegions(boolean enable) {
toggleSecondaryNavBarsForRotation(enable);
if (enable && !TestProtocol.sDisableSensorRotation) {
mOrientationListener.enable();
} else {
mOrientationListener.disable();
}
}
private void notifySysuiForRotation(int rotation) {
@@ -624,10 +707,7 @@ public class RecentsAnimationDeviceState implements
// If we're in landscape w/o ever quickswitching, show the navbar in landscape
enableMultipleRegions(true);
}
activityInterface.onExitOverview(this, () -> {
mInOverview = false;
enableMultipleRegions(false);
});
activityInterface.onExitOverview(this, mExitOverviewRunnable);
} else if (endTarget == GestureState.GestureEndTarget.HOME) {
enableMultipleRegions(false);
} else if (endTarget == GestureState.GestureEndTarget.NEW_TASK) {
@@ -637,6 +717,11 @@ public class RecentsAnimationDeviceState implements
} else {
notifySysuiForRotation(mOrientationTouchTransformer.getCurrentActiveRotation());
}
// A new gesture is starting, reset the current device rotation
// This is done under the assumption that the user won't rotate the phone and then
// quickswitch in the old orientation.
mPrioritizeDeviceRotation = false;
} else if (endTarget == GestureState.GestureEndTarget.LAST_TASK) {
if (!mTaskListFrozen) {
// touched nav bar but didn't go anywhere and not quickswitching, do nothing
@@ -646,7 +731,24 @@ public class RecentsAnimationDeviceState implements
}
}
int getCurrentActiveRotation() {
private void notifySysuiOfCurrentRotation(int rotation) {
UI_HELPER_EXECUTOR.execute(() -> SystemUiProxy.INSTANCE.get(mContext)
.onQuickSwitchToNewTask(rotation));
}
/**
* Disables/Enables multiple nav bars on {@link OrientationTouchTransformer} and then
* notifies system UI of the primary rotation the user is interacting with
*
* @param enable if {@code true}, this will report to sysUI the navbar of the region the gesture
* started in (during ACTION_DOWN), otherwise will report {@param displayRotation}
*/
private void toggleSecondaryNavBarsForRotation(boolean enable) {
mOrientationTouchTransformer.enableMultipleRegions(enable, mDefaultDisplay.getInfo());
notifySysuiOfCurrentRotation(mOrientationTouchTransformer.getQuickStepStartingRotation());
}
public int getCurrentActiveRotation() {
if (!mMode.hasGestures) {
// touch rotation should always match that of display for 3 button
return mDisplayRotation;
@@ -380,4 +380,15 @@ public class SystemUiProxy implements ISystemUiProxy {
}
}
}
@Override
public void expandNotificationPanel() {
if (mSystemUiProxy != null) {
try {
mSystemUiProxy.expandNotificationPanel();
} catch (RemoteException e) {
Log.w(TAG, "Failed call expandNotificationPanel", e);
}
}
}
}
@@ -445,7 +445,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
}
break;
case ROTATION_270:
if (degrees < (90 - threshold)) {
if (degrees < (90 - threshold) ||
(degrees > (270 + threshold) && degrees < 360)) {
return ROTATION_0;
}
if (degrees > (90 + threshold) && degrees < 180) {
@@ -468,7 +469,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
if (degrees < (270 - threshold) && degrees > 90) {
return ROTATION_180;
}
if (degrees > (270 + threshold) && degrees < 360) {
if (degrees > (270 + threshold) && degrees < 360
|| (degrees >= 0 && degrees < threshold)) {
return ROTATION_0;
}
// flip from landscape to seascape