DO NOT MERGE Split BackEvent into an internal BackMotionEvent and public BackEvent.
The constructor of BackEvent has diverged on QPR and master, which will create merge conflicts for all subsequent SysUI back animations to be added from QPR. This cherry-picks ag/20445076 minus the public API changes to solve this problem. Test: atest BackAnimationControllerTest Test: atest BackNavigationControllerTests Test: atest WindowOnBackInvokedDispatcherTest Test: atest TouchTrackerTest Test: m -j Bug: 238475284 Change-Id: Ib9100a9d667a9a17e8f357a1bfc3ee2b52ec17c7
This commit is contained in:
@@ -18,10 +18,8 @@ package android.window;
|
|||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.view.RemoteAnimationTarget;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -52,8 +50,6 @@ public class BackEvent implements Parcelable {
|
|||||||
|
|
||||||
@SwipeEdge
|
@SwipeEdge
|
||||||
private final int mSwipeEdge;
|
private final int mSwipeEdge;
|
||||||
@Nullable
|
|
||||||
private final RemoteAnimationTarget mDepartingAnimationTarget;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link BackEvent} instance.
|
* Creates a new {@link BackEvent} instance.
|
||||||
@@ -62,16 +58,12 @@ public class BackEvent implements Parcelable {
|
|||||||
* @param touchY Absolute Y location of the touch point of this event.
|
* @param touchY Absolute Y location of the touch point of this event.
|
||||||
* @param progress Value between 0 and 1 on how far along the back gesture is.
|
* @param progress Value between 0 and 1 on how far along the back gesture is.
|
||||||
* @param swipeEdge Indicates which edge the swipe starts from.
|
* @param swipeEdge Indicates which edge the swipe starts from.
|
||||||
* @param departingAnimationTarget The remote animation target of the departing application
|
|
||||||
* window.
|
|
||||||
*/
|
*/
|
||||||
public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge,
|
public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge) {
|
||||||
@Nullable RemoteAnimationTarget departingAnimationTarget) {
|
|
||||||
mTouchX = touchX;
|
mTouchX = touchX;
|
||||||
mTouchY = touchY;
|
mTouchY = touchY;
|
||||||
mProgress = progress;
|
mProgress = progress;
|
||||||
mSwipeEdge = swipeEdge;
|
mSwipeEdge = swipeEdge;
|
||||||
mDepartingAnimationTarget = departingAnimationTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BackEvent(@NonNull Parcel in) {
|
private BackEvent(@NonNull Parcel in) {
|
||||||
@@ -79,7 +71,6 @@ public class BackEvent implements Parcelable {
|
|||||||
mTouchY = in.readFloat();
|
mTouchY = in.readFloat();
|
||||||
mProgress = in.readFloat();
|
mProgress = in.readFloat();
|
||||||
mSwipeEdge = in.readInt();
|
mSwipeEdge = in.readInt();
|
||||||
mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<BackEvent> CREATOR = new Creator<BackEvent>() {
|
public static final Creator<BackEvent> CREATOR = new Creator<BackEvent>() {
|
||||||
@@ -105,7 +96,6 @@ public class BackEvent implements Parcelable {
|
|||||||
dest.writeFloat(mTouchY);
|
dest.writeFloat(mTouchY);
|
||||||
dest.writeFloat(mProgress);
|
dest.writeFloat(mProgress);
|
||||||
dest.writeInt(mSwipeEdge);
|
dest.writeInt(mSwipeEdge);
|
||||||
dest.writeTypedObject(mDepartingAnimationTarget, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,16 +126,6 @@ public class BackEvent implements Parcelable {
|
|||||||
return mSwipeEdge;
|
return mSwipeEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link RemoteAnimationTarget} of the top departing application window,
|
|
||||||
* or {@code null} if the top window should not be moved for the current type of back
|
|
||||||
* destination.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public RemoteAnimationTarget getDepartingAnimationTarget() {
|
|
||||||
return mDepartingAnimationTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "BackEvent{"
|
return "BackEvent{"
|
||||||
@@ -153,7 +133,6 @@ public class BackEvent implements Parcelable {
|
|||||||
+ ", mTouchY=" + mTouchY
|
+ ", mTouchY=" + mTouchY
|
||||||
+ ", mProgress=" + mProgress
|
+ ", mProgress=" + mProgress
|
||||||
+ ", mSwipeEdge" + mSwipeEdge
|
+ ", mSwipeEdge" + mSwipeEdge
|
||||||
+ ", mDepartingAnimationTarget" + mDepartingAnimationTarget
|
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
core/java/android/window/BackMotionEvent.aidl
Normal file
22
core/java/android/window/BackMotionEvent.aidl
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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 android.window;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
parcelable BackMotionEvent;
|
||||||
150
core/java/android/window/BackMotionEvent.java
Normal file
150
core/java/android/window/BackMotionEvent.java
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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 android.window;
|
||||||
|
|
||||||
|
import android.annotation.FloatRange;
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.view.RemoteAnimationTarget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object used to report back gesture progress. Holds information about a {@link BackEvent} plus
|
||||||
|
* any {@link RemoteAnimationTarget} the gesture manipulates.
|
||||||
|
*
|
||||||
|
* @see BackEvent
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public final class BackMotionEvent implements Parcelable {
|
||||||
|
private final float mTouchX;
|
||||||
|
private final float mTouchY;
|
||||||
|
private final float mProgress;
|
||||||
|
|
||||||
|
@BackEvent.SwipeEdge
|
||||||
|
private final int mSwipeEdge;
|
||||||
|
@Nullable
|
||||||
|
private final RemoteAnimationTarget mDepartingAnimationTarget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link BackMotionEvent} instance.
|
||||||
|
*
|
||||||
|
* @param touchX Absolute X location of the touch point of this event.
|
||||||
|
* @param touchY Absolute Y location of the touch point of this event.
|
||||||
|
* @param progress Value between 0 and 1 on how far along the back gesture is.
|
||||||
|
* @param swipeEdge Indicates which edge the swipe starts from.
|
||||||
|
* @param departingAnimationTarget The remote animation target of the departing
|
||||||
|
* application window.
|
||||||
|
*/
|
||||||
|
public BackMotionEvent(float touchX, float touchY, float progress,
|
||||||
|
@BackEvent.SwipeEdge int swipeEdge,
|
||||||
|
@Nullable RemoteAnimationTarget departingAnimationTarget) {
|
||||||
|
mTouchX = touchX;
|
||||||
|
mTouchY = touchY;
|
||||||
|
mProgress = progress;
|
||||||
|
mSwipeEdge = swipeEdge;
|
||||||
|
mDepartingAnimationTarget = departingAnimationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BackMotionEvent(@NonNull Parcel in) {
|
||||||
|
mTouchX = in.readFloat();
|
||||||
|
mTouchY = in.readFloat();
|
||||||
|
mProgress = in.readFloat();
|
||||||
|
mSwipeEdge = in.readInt();
|
||||||
|
mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static final Creator<BackMotionEvent> CREATOR = new Creator<BackMotionEvent>() {
|
||||||
|
@Override
|
||||||
|
public BackMotionEvent createFromParcel(Parcel in) {
|
||||||
|
return new BackMotionEvent(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BackMotionEvent[] newArray(int size) {
|
||||||
|
return new BackMotionEvent[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||||
|
dest.writeFloat(mTouchX);
|
||||||
|
dest.writeFloat(mTouchY);
|
||||||
|
dest.writeFloat(mProgress);
|
||||||
|
dest.writeInt(mSwipeEdge);
|
||||||
|
dest.writeTypedObject(mDepartingAnimationTarget, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the progress of a {@link BackEvent}.
|
||||||
|
*
|
||||||
|
* @see BackEvent#getProgress()
|
||||||
|
*/
|
||||||
|
@FloatRange(from = 0, to = 1)
|
||||||
|
public float getProgress() {
|
||||||
|
return mProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the absolute X location of the touch point.
|
||||||
|
*/
|
||||||
|
public float getTouchX() {
|
||||||
|
return mTouchX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the absolute Y location of the touch point.
|
||||||
|
*/
|
||||||
|
public float getTouchY() {
|
||||||
|
return mTouchY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the screen edge that the swipe starts from.
|
||||||
|
*/
|
||||||
|
@BackEvent.SwipeEdge
|
||||||
|
public int getSwipeEdge() {
|
||||||
|
return mSwipeEdge;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link RemoteAnimationTarget} of the top departing application window,
|
||||||
|
* or {@code null} if the top window should not be moved for the current type of back
|
||||||
|
* destination.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public RemoteAnimationTarget getDepartingAnimationTarget() {
|
||||||
|
return mDepartingAnimationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BackMotionEvent{"
|
||||||
|
+ "mTouchX=" + mTouchX
|
||||||
|
+ ", mTouchY=" + mTouchY
|
||||||
|
+ ", mProgress=" + mProgress
|
||||||
|
+ ", mSwipeEdge" + mSwipeEdge
|
||||||
|
+ ", mDepartingAnimationTarget" + mDepartingAnimationTarget
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ public class BackProgressAnimator {
|
|||||||
private final SpringAnimation mSpring;
|
private final SpringAnimation mSpring;
|
||||||
private ProgressCallback mCallback;
|
private ProgressCallback mCallback;
|
||||||
private float mProgress = 0;
|
private float mProgress = 0;
|
||||||
private BackEvent mLastBackEvent;
|
private BackMotionEvent mLastBackEvent;
|
||||||
private boolean mStarted = false;
|
private boolean mStarted = false;
|
||||||
|
|
||||||
private void setProgress(float progress) {
|
private void setProgress(float progress) {
|
||||||
@@ -82,9 +82,9 @@ public class BackProgressAnimator {
|
|||||||
/**
|
/**
|
||||||
* Sets a new target position for the back progress.
|
* Sets a new target position for the back progress.
|
||||||
*
|
*
|
||||||
* @param event the {@link BackEvent} containing the latest target progress.
|
* @param event the {@link BackMotionEvent} containing the latest target progress.
|
||||||
*/
|
*/
|
||||||
public void onBackProgressed(BackEvent event) {
|
public void onBackProgressed(BackMotionEvent event) {
|
||||||
if (!mStarted) {
|
if (!mStarted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -95,11 +95,11 @@ public class BackProgressAnimator {
|
|||||||
/**
|
/**
|
||||||
* Starts the back progress animation.
|
* Starts the back progress animation.
|
||||||
*
|
*
|
||||||
* @param event the {@link BackEvent} that started the gesture.
|
* @param event the {@link BackMotionEvent} that started the gesture.
|
||||||
* @param callback the back callback to invoke for the gesture. It will receive back progress
|
* @param callback the back callback to invoke for the gesture. It will receive back progress
|
||||||
* dispatches as the progress animation updates.
|
* dispatches as the progress animation updates.
|
||||||
*/
|
*/
|
||||||
public void onBackStarted(BackEvent event, ProgressCallback callback) {
|
public void onBackStarted(BackMotionEvent event, ProgressCallback callback) {
|
||||||
reset();
|
reset();
|
||||||
mLastBackEvent = event;
|
mLastBackEvent = event;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
@@ -129,8 +129,7 @@ public class BackProgressAnimator {
|
|||||||
}
|
}
|
||||||
mCallback.onProgressUpdate(
|
mCallback.onProgressUpdate(
|
||||||
new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(),
|
new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(),
|
||||||
progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge(),
|
progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge()));
|
||||||
mLastBackEvent.getDepartingAnimationTarget()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package android.window;
|
package android.window;
|
||||||
|
|
||||||
import android.window.BackEvent;
|
import android.window.BackMotionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that wraps a {@link OnBackInvokedCallback} object, to be stored in window manager
|
* Interface that wraps a {@link OnBackInvokedCallback} object, to be stored in window manager
|
||||||
@@ -30,18 +30,19 @@ oneway interface IOnBackInvokedCallback {
|
|||||||
* Called when a back gesture has been started, or back button has been pressed down.
|
* Called when a back gesture has been started, or back button has been pressed down.
|
||||||
* Wraps {@link OnBackInvokedCallback#onBackStarted(BackEvent)}.
|
* Wraps {@link OnBackInvokedCallback#onBackStarted(BackEvent)}.
|
||||||
*
|
*
|
||||||
* @param backEvent The {@link BackEvent} containing information about the touch or button press.
|
* @param backMotionEvent The {@link BackMotionEvent} containing information about the touch
|
||||||
|
* or button press.
|
||||||
*/
|
*/
|
||||||
void onBackStarted(in BackEvent backEvent);
|
void onBackStarted(in BackMotionEvent backMotionEvent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on back gesture progress.
|
* Called on back gesture progress.
|
||||||
* Wraps {@link OnBackInvokedCallback#onBackProgressed(BackEvent)}.
|
* Wraps {@link OnBackInvokedCallback#onBackProgressed(BackEvent)}.
|
||||||
*
|
*
|
||||||
* @param backEvent The {@link BackEvent} containing information about the latest touch point
|
* @param backMotionEvent The {@link BackMotionEvent} containing information about the latest
|
||||||
* and the progress that the back animation should seek to.
|
* touch point and the progress that the back animation should seek to.
|
||||||
*/
|
*/
|
||||||
void onBackProgressed(in BackEvent backEvent);
|
void onBackProgressed(in BackMotionEvent backMotionEvent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a back gesture or back button press has been cancelled.
|
* Called when a back gesture or back button press has been cancelled.
|
||||||
|
|||||||
@@ -229,19 +229,21 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackStarted(BackEvent backEvent) {
|
public void onBackStarted(BackMotionEvent backEvent) {
|
||||||
Handler.getMain().post(() -> {
|
Handler.getMain().post(() -> {
|
||||||
final OnBackAnimationCallback callback = getBackAnimationCallback();
|
final OnBackAnimationCallback callback = getBackAnimationCallback();
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
mProgressAnimator.onBackStarted(backEvent, event ->
|
mProgressAnimator.onBackStarted(backEvent, event ->
|
||||||
callback.onBackProgressed(event));
|
callback.onBackProgressed(event));
|
||||||
callback.onBackStarted(backEvent);
|
callback.onBackStarted(new BackEvent(
|
||||||
|
backEvent.getTouchX(), backEvent.getTouchY(),
|
||||||
|
backEvent.getProgress(), backEvent.getSwipeEdge()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackProgressed(BackEvent backEvent) {
|
public void onBackProgressed(BackMotionEvent backEvent) {
|
||||||
Handler.getMain().post(() -> {
|
Handler.getMain().post(() -> {
|
||||||
final OnBackAnimationCallback callback = getBackAnimationCallback();
|
final OnBackAnimationCallback callback = getBackAnimationCallback();
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package android.window;
|
package android.window;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.isNull;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -60,8 +61,8 @@ public class WindowOnBackInvokedDispatcherTest {
|
|||||||
private OnBackAnimationCallback mCallback1;
|
private OnBackAnimationCallback mCallback1;
|
||||||
@Mock
|
@Mock
|
||||||
private OnBackAnimationCallback mCallback2;
|
private OnBackAnimationCallback mCallback2;
|
||||||
@Mock
|
private final BackMotionEvent mBackEvent = new BackMotionEvent(
|
||||||
private BackEvent mBackEvent;
|
0, 0, 0, BackEvent.EDGE_LEFT, null);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -89,12 +90,12 @@ public class WindowOnBackInvokedDispatcherTest {
|
|||||||
captor.capture());
|
captor.capture());
|
||||||
captor.getAllValues().get(0).getCallback().onBackStarted(mBackEvent);
|
captor.getAllValues().get(0).getCallback().onBackStarted(mBackEvent);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mCallback1).onBackStarted(mBackEvent);
|
verify(mCallback1).onBackStarted(any(BackEvent.class));
|
||||||
verifyZeroInteractions(mCallback2);
|
verifyZeroInteractions(mCallback2);
|
||||||
|
|
||||||
captor.getAllValues().get(1).getCallback().onBackStarted(mBackEvent);
|
captor.getAllValues().get(1).getCallback().onBackStarted(mBackEvent);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mCallback2).onBackStarted(mBackEvent);
|
verify(mCallback2).onBackStarted(any(BackEvent.class));
|
||||||
verifyNoMoreInteractions(mCallback1);
|
verifyNoMoreInteractions(mCallback1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ public class WindowOnBackInvokedDispatcherTest {
|
|||||||
assertEquals(captor.getValue().getPriority(), OnBackInvokedDispatcher.PRIORITY_OVERLAY);
|
assertEquals(captor.getValue().getPriority(), OnBackInvokedDispatcher.PRIORITY_OVERLAY);
|
||||||
captor.getValue().getCallback().onBackStarted(mBackEvent);
|
captor.getValue().getCallback().onBackStarted(mBackEvent);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mCallback1).onBackStarted(mBackEvent);
|
verify(mCallback1).onBackStarted(any(BackEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,6 +153,6 @@ public class WindowOnBackInvokedDispatcherTest {
|
|||||||
verify(mWindowSession).setOnBackInvokedCallbackInfo(Mockito.eq(mWindow), captor.capture());
|
verify(mWindowSession).setOnBackInvokedCallbackInfo(Mockito.eq(mWindow), captor.capture());
|
||||||
captor.getValue().getCallback().onBackStarted(mBackEvent);
|
captor.getValue().getCallback().onBackStarted(mBackEvent);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mCallback2).onBackStarted(mBackEvent);
|
verify(mCallback2).onBackStarted(any(BackEvent.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import android.view.RemoteAnimationTarget;
|
|||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
import android.window.BackAnimationAdaptor;
|
import android.window.BackAnimationAdaptor;
|
||||||
import android.window.BackEvent;
|
import android.window.BackEvent;
|
||||||
|
import android.window.BackMotionEvent;
|
||||||
import android.window.BackNavigationInfo;
|
import android.window.BackNavigationInfo;
|
||||||
import android.window.IBackAnimationRunner;
|
import android.window.IBackAnimationRunner;
|
||||||
import android.window.IBackNaviAnimationController;
|
import android.window.IBackNaviAnimationController;
|
||||||
@@ -173,11 +174,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
|
|||||||
boolean consumed = false;
|
boolean consumed = false;
|
||||||
if (mWaitingAnimation && mOnBackCallback != null) {
|
if (mWaitingAnimation && mOnBackCallback != null) {
|
||||||
if (mTriggerBack) {
|
if (mTriggerBack) {
|
||||||
final BackEvent backFinish = mTouchTracker.createProgressEvent(1);
|
final BackMotionEvent backFinish = mTouchTracker.createProgressEvent(1);
|
||||||
dispatchOnBackProgressed(mBackToLauncherCallback, backFinish);
|
dispatchOnBackProgressed(mBackToLauncherCallback, backFinish);
|
||||||
dispatchOnBackInvoked(mOnBackCallback);
|
dispatchOnBackInvoked(mOnBackCallback);
|
||||||
} else {
|
} else {
|
||||||
final BackEvent backFinish = mTouchTracker.createProgressEvent(0);
|
final BackMotionEvent backFinish = mTouchTracker.createProgressEvent(0);
|
||||||
dispatchOnBackProgressed(mBackToLauncherCallback, backFinish);
|
dispatchOnBackProgressed(mBackToLauncherCallback, backFinish);
|
||||||
dispatchOnBackCancelled(mOnBackCallback);
|
dispatchOnBackCancelled(mOnBackCallback);
|
||||||
}
|
}
|
||||||
@@ -480,7 +481,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
|
|||||||
if (!mBackGestureStarted || mBackNavigationInfo == null) {
|
if (!mBackGestureStarted || mBackNavigationInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BackEvent backEvent = mTouchTracker.createProgressEvent();
|
final BackMotionEvent backEvent = mTouchTracker.createProgressEvent();
|
||||||
if (USE_TRANSITION && mBackAnimationController != null && mAnimationTarget != null) {
|
if (USE_TRANSITION && mBackAnimationController != null && mAnimationTarget != null) {
|
||||||
dispatchOnBackProgressed(mBackToLauncherCallback, backEvent);
|
dispatchOnBackProgressed(mBackToLauncherCallback, backEvent);
|
||||||
} else if (mEnableAnimations.get()) {
|
} else if (mEnableAnimations.get()) {
|
||||||
@@ -573,7 +574,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dispatchOnBackStarted(IOnBackInvokedCallback callback,
|
private void dispatchOnBackStarted(IOnBackInvokedCallback callback,
|
||||||
BackEvent backEvent) {
|
BackMotionEvent backEvent) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -611,7 +612,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dispatchOnBackProgressed(IOnBackInvokedCallback callback,
|
private void dispatchOnBackProgressed(IOnBackInvokedCallback callback,
|
||||||
BackEvent backEvent) {
|
BackMotionEvent backEvent) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -730,7 +731,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
|
|||||||
}
|
}
|
||||||
dispatchOnBackStarted(mBackToLauncherCallback,
|
dispatchOnBackStarted(mBackToLauncherCallback,
|
||||||
mTouchTracker.createStartEvent(mAnimationTarget));
|
mTouchTracker.createStartEvent(mAnimationTarget));
|
||||||
final BackEvent backInit = mTouchTracker.createProgressEvent();
|
final BackMotionEvent backInit = mTouchTracker.createProgressEvent();
|
||||||
if (!mCachingBackDispatcher.consume()) {
|
if (!mCachingBackDispatcher.consume()) {
|
||||||
dispatchOnBackProgressed(mBackToLauncherCallback, backInit);
|
dispatchOnBackProgressed(mBackToLauncherCallback, backInit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.wm.shell.back;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.view.RemoteAnimationTarget;
|
import android.view.RemoteAnimationTarget;
|
||||||
import android.window.BackEvent;
|
import android.window.BackEvent;
|
||||||
|
import android.window.BackMotionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to record the touch location for gesture and generate back events.
|
* Helper class to record the touch location for gesture and generate back events.
|
||||||
@@ -82,11 +83,11 @@ class TouchTracker {
|
|||||||
mSwipeEdge = BackEvent.EDGE_LEFT;
|
mSwipeEdge = BackEvent.EDGE_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackEvent createStartEvent(RemoteAnimationTarget target) {
|
BackMotionEvent createStartEvent(RemoteAnimationTarget target) {
|
||||||
return new BackEvent(mInitTouchX, mInitTouchY, 0, mSwipeEdge, target);
|
return new BackMotionEvent(mInitTouchX, mInitTouchY, 0, mSwipeEdge, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
BackEvent createProgressEvent() {
|
BackMotionEvent createProgressEvent() {
|
||||||
float progressThreshold = PROGRESS_THRESHOLD >= 0
|
float progressThreshold = PROGRESS_THRESHOLD >= 0
|
||||||
? PROGRESS_THRESHOLD : mProgressThreshold;
|
? PROGRESS_THRESHOLD : mProgressThreshold;
|
||||||
progressThreshold = progressThreshold == 0 ? 1 : progressThreshold;
|
progressThreshold = progressThreshold == 0 ? 1 : progressThreshold;
|
||||||
@@ -109,8 +110,8 @@ class TouchTracker {
|
|||||||
return createProgressEvent(progress);
|
return createProgressEvent(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
BackEvent createProgressEvent(float progress) {
|
BackMotionEvent createProgressEvent(float progress) {
|
||||||
return new BackEvent(mLatestTouchX, mLatestTouchY, progress, mSwipeEdge, null);
|
return new BackMotionEvent(mLatestTouchX, mLatestTouchY, progress, mSwipeEdge, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressThreshold(float progressThreshold) {
|
public void setProgressThreshold(float progressThreshold) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.RemoteAnimationTarget;
|
import android.view.RemoteAnimationTarget;
|
||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
import android.window.BackEvent;
|
import android.window.BackEvent;
|
||||||
|
import android.window.BackMotionEvent;
|
||||||
import android.window.BackNavigationInfo;
|
import android.window.BackNavigationInfo;
|
||||||
import android.window.IBackNaviAnimationController;
|
import android.window.IBackNaviAnimationController;
|
||||||
import android.window.IOnBackInvokedCallback;
|
import android.window.IOnBackInvokedCallback;
|
||||||
@@ -246,10 +247,11 @@ public class BackAnimationControllerTest extends ShellTestCase {
|
|||||||
// Check that back start and progress is dispatched when first move.
|
// Check that back start and progress is dispatched when first move.
|
||||||
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
||||||
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
||||||
ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class);
|
ArgumentCaptor<BackMotionEvent> backEventCaptor =
|
||||||
|
ArgumentCaptor.forClass(BackMotionEvent.class);
|
||||||
verify(mIOnBackInvokedCallback).onBackStarted(backEventCaptor.capture());
|
verify(mIOnBackInvokedCallback).onBackStarted(backEventCaptor.capture());
|
||||||
assertEquals(animationTarget, backEventCaptor.getValue().getDepartingAnimationTarget());
|
assertEquals(animationTarget, backEventCaptor.getValue().getDepartingAnimationTarget());
|
||||||
verify(mIOnBackInvokedCallback, atLeastOnce()).onBackProgressed(any(BackEvent.class));
|
verify(mIOnBackInvokedCallback, atLeastOnce()).onBackProgressed(any(BackMotionEvent.class));
|
||||||
|
|
||||||
// Check that back invocation is dispatched.
|
// Check that back invocation is dispatched.
|
||||||
mController.setTriggerBack(true); // Fake trigger back
|
mController.setTriggerBack(true); // Fake trigger back
|
||||||
@@ -271,17 +273,18 @@ public class BackAnimationControllerTest extends ShellTestCase {
|
|||||||
|
|
||||||
RemoteAnimationTarget animationTarget = createAnimationTarget();
|
RemoteAnimationTarget animationTarget = createAnimationTarget();
|
||||||
IOnBackInvokedCallback appCallback = mock(IOnBackInvokedCallback.class);
|
IOnBackInvokedCallback appCallback = mock(IOnBackInvokedCallback.class);
|
||||||
ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class);
|
ArgumentCaptor<BackMotionEvent> backEventCaptor =
|
||||||
|
ArgumentCaptor.forClass(BackMotionEvent.class);
|
||||||
createNavigationInfo(animationTarget, null, null,
|
createNavigationInfo(animationTarget, null, null,
|
||||||
BackNavigationInfo.TYPE_RETURN_TO_HOME, appCallback, false);
|
BackNavigationInfo.TYPE_RETURN_TO_HOME, appCallback, false);
|
||||||
|
|
||||||
triggerBackGesture();
|
triggerBackGesture();
|
||||||
|
|
||||||
verify(appCallback, never()).onBackStarted(any(BackEvent.class));
|
verify(appCallback, never()).onBackStarted(any(BackMotionEvent.class));
|
||||||
verify(appCallback, never()).onBackProgressed(backEventCaptor.capture());
|
verify(appCallback, never()).onBackProgressed(backEventCaptor.capture());
|
||||||
verify(appCallback, times(1)).onBackInvoked();
|
verify(appCallback, times(1)).onBackInvoked();
|
||||||
|
|
||||||
verify(mIOnBackInvokedCallback, never()).onBackStarted(any(BackEvent.class));
|
verify(mIOnBackInvokedCallback, never()).onBackStarted(any(BackMotionEvent.class));
|
||||||
verify(mIOnBackInvokedCallback, never()).onBackProgressed(backEventCaptor.capture());
|
verify(mIOnBackInvokedCallback, never()).onBackProgressed(backEventCaptor.capture());
|
||||||
verify(mIOnBackInvokedCallback, never()).onBackInvoked();
|
verify(mIOnBackInvokedCallback, never()).onBackInvoked();
|
||||||
}
|
}
|
||||||
@@ -314,7 +317,7 @@ public class BackAnimationControllerTest extends ShellTestCase {
|
|||||||
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
|
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
|
||||||
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
||||||
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
||||||
verify(mIOnBackInvokedCallback).onBackStarted(any(BackEvent.class));
|
verify(mIOnBackInvokedCallback).onBackStarted(any(BackMotionEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -333,7 +336,7 @@ public class BackAnimationControllerTest extends ShellTestCase {
|
|||||||
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
|
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
|
||||||
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
||||||
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
||||||
verify(mIOnBackInvokedCallback).onBackStarted(any(BackEvent.class));
|
verify(mIOnBackInvokedCallback).onBackStarted(any(BackMotionEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -349,7 +352,7 @@ public class BackAnimationControllerTest extends ShellTestCase {
|
|||||||
// Check that back start and progress is dispatched when first move.
|
// Check that back start and progress is dispatched when first move.
|
||||||
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
|
||||||
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME, animationTarget);
|
||||||
verify(mIOnBackInvokedCallback).onBackStarted(any(BackEvent.class));
|
verify(mIOnBackInvokedCallback).onBackStarted(any(BackMotionEvent.class));
|
||||||
|
|
||||||
// Check that back invocation is dispatched.
|
// Check that back invocation is dispatched.
|
||||||
mController.setTriggerBack(true); // Fake trigger back
|
mController.setTriggerBack(true); // Fake trigger back
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.wm.shell.back;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import android.window.BackEvent;
|
import android.window.BackEvent;
|
||||||
|
import android.window.BackMotionEvent;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -38,7 +39,7 @@ public class TouchTrackerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generatesProgress_onStart() {
|
public void generatesProgress_onStart() {
|
||||||
mTouchTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0, BackEvent.EDGE_LEFT);
|
mTouchTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0, BackEvent.EDGE_LEFT);
|
||||||
BackEvent event = mTouchTracker.createStartEvent(null);
|
BackMotionEvent event = mTouchTracker.createStartEvent(null);
|
||||||
assertEquals(event.getProgress(), 0f, 0f);
|
assertEquals(event.getProgress(), 0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import android.hardware.HardwareBuffer;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.window.BackEvent;
|
import android.window.BackMotionEvent;
|
||||||
import android.window.BackNavigationInfo;
|
import android.window.BackNavigationInfo;
|
||||||
import android.window.IOnBackInvokedCallback;
|
import android.window.IOnBackInvokedCallback;
|
||||||
import android.window.OnBackInvokedCallback;
|
import android.window.OnBackInvokedCallback;
|
||||||
@@ -242,11 +242,11 @@ public class BackNavigationControllerTests extends WindowTestsBase {
|
|||||||
private IOnBackInvokedCallback createOnBackInvokedCallback() {
|
private IOnBackInvokedCallback createOnBackInvokedCallback() {
|
||||||
return new IOnBackInvokedCallback.Stub() {
|
return new IOnBackInvokedCallback.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void onBackStarted(BackEvent backEvent) {
|
public void onBackStarted(BackMotionEvent backEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackProgressed(BackEvent backEvent) {
|
public void onBackProgressed(BackMotionEvent backEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user