Merge "Separate callbacks for dismiss start and end" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
94fdf4049d
@@ -166,7 +166,7 @@ public class ClipboardOverlayController {
|
|||||||
mRemoteCopyChip = requireNonNull(mView.findViewById(R.id.remote_copy_chip));
|
mRemoteCopyChip = requireNonNull(mView.findViewById(R.id.remote_copy_chip));
|
||||||
mDismissButton = requireNonNull(mView.findViewById(R.id.dismiss_button));
|
mDismissButton = requireNonNull(mView.findViewById(R.id.dismiss_button));
|
||||||
|
|
||||||
mView.setOnDismissCallback(this::hideImmediate);
|
mView.setOnDismissEndCallback(this::hideImmediate);
|
||||||
mView.setOnInteractionCallback(mTimeoutHandler::resetTimeout);
|
mView.setOnInteractionCallback(mTimeoutHandler::resetTimeout);
|
||||||
|
|
||||||
mDismissButton.setOnClickListener(view -> animateOut());
|
mDismissButton.setOnClickListener(view -> animateOut());
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.systemui.clipboardoverlay;
|
package com.android.systemui.clipboardoverlay;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -28,13 +29,16 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
|||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.screenshot.SwipeDismissHandler;
|
import com.android.systemui.screenshot.SwipeDismissHandler;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConstraintLayout that is draggable when touched in a specific region
|
* ConstraintLayout that is draggable when touched in a specific region
|
||||||
*/
|
*/
|
||||||
public class DraggableConstraintLayout extends ConstraintLayout {
|
public class DraggableConstraintLayout extends ConstraintLayout {
|
||||||
private final SwipeDismissHandler mSwipeDismissHandler;
|
private final SwipeDismissHandler mSwipeDismissHandler;
|
||||||
private final GestureDetector mSwipeDetector;
|
private final GestureDetector mSwipeDetector;
|
||||||
private Runnable mOnDismiss;
|
private Consumer<Animator> mOnDismissInitiated;
|
||||||
|
private Runnable mOnDismissComplete;
|
||||||
private Runnable mOnInteraction;
|
private Runnable mOnInteraction;
|
||||||
|
|
||||||
public DraggableConstraintLayout(Context context) {
|
public DraggableConstraintLayout(Context context) {
|
||||||
@@ -58,9 +62,16 @@ public class DraggableConstraintLayout extends ConstraintLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss() {
|
public void onSwipeDismissInitiated(Animator animator) {
|
||||||
if (mOnDismiss != null) {
|
if (mOnDismissInitiated != null) {
|
||||||
mOnDismiss.run();
|
mOnDismissInitiated.accept(animator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismissComplete() {
|
||||||
|
if (mOnDismissComplete != null) {
|
||||||
|
mOnDismissComplete.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -105,11 +116,19 @@ public class DraggableConstraintLayout extends ConstraintLayout {
|
|||||||
mSwipeDismissHandler.dismiss();
|
mSwipeDismissHandler.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the callback to be run after view is dismissed (before animation; receives animator as
|
||||||
|
* input)
|
||||||
|
*/
|
||||||
|
public void setOnDismissStartCallback(Consumer<Animator> callback) {
|
||||||
|
mOnDismissInitiated = callback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the callback to be run after view is dismissed
|
* Set the callback to be run after view is dismissed
|
||||||
*/
|
*/
|
||||||
public void setOnDismissCallback(Runnable callback) {
|
public void setOnDismissEndCallback(Runnable callback) {
|
||||||
mOnDismiss = callback;
|
mOnDismissComplete = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -403,12 +403,16 @@ public class ScreenshotView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss() {
|
public void onSwipeDismissInitiated(Animator animator) {
|
||||||
if (DEBUG_DISMISS) {
|
if (DEBUG_DISMISS) {
|
||||||
Log.d(ScreenshotView.TAG, "dismiss triggered via swipe gesture");
|
Log.d(ScreenshotView.TAG, "dismiss triggered via swipe gesture");
|
||||||
}
|
}
|
||||||
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SWIPE_DISMISSED, 0,
|
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SWIPE_DISMISSED, 0,
|
||||||
mPackageName);
|
mPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismissComplete() {
|
||||||
mCallbacks.onDismiss();
|
mCallbacks.onDismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,10 +48,15 @@ public class SwipeDismissHandler implements View.OnTouchListener {
|
|||||||
*/
|
*/
|
||||||
void onInteraction();
|
void onInteraction();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run when the view is dismissed (the distance threshold is met), pre-dismissal animation
|
||||||
|
*/
|
||||||
|
void onSwipeDismissInitiated(Animator animator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run when the view is dismissed (the distance threshold is met), post-dismissal animation
|
* Run when the view is dismissed (the distance threshold is met), post-dismissal animation
|
||||||
*/
|
*/
|
||||||
void onDismiss();
|
void onDismissComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final View mView;
|
private final View mView;
|
||||||
@@ -89,7 +94,9 @@ public class SwipeDismissHandler implements View.OnTouchListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isPastDismissThreshold()) {
|
if (isPastDismissThreshold()) {
|
||||||
dismiss();
|
ValueAnimator dismissAnimator = createSwipeDismissAnimation(1);
|
||||||
|
mCallbacks.onSwipeDismissInitiated(dismissAnimator);
|
||||||
|
dismiss(dismissAnimator);
|
||||||
} else {
|
} else {
|
||||||
// if we've moved, but not past the threshold, start the return animation
|
// if we've moved, but not past the threshold, start the return animation
|
||||||
if (DEBUG_DISMISS) {
|
if (DEBUG_DISMISS) {
|
||||||
@@ -117,7 +124,10 @@ public class SwipeDismissHandler implements View.OnTouchListener {
|
|||||||
float velocityY) {
|
float velocityY) {
|
||||||
if (mView.getTranslationX() * velocityX > 0
|
if (mView.getTranslationX() * velocityX > 0
|
||||||
&& (mDismissAnimation == null || !mDismissAnimation.isRunning())) {
|
&& (mDismissAnimation == null || !mDismissAnimation.isRunning())) {
|
||||||
dismiss(velocityX / (float) 1000);
|
ValueAnimator dismissAnimator =
|
||||||
|
createSwipeDismissAnimation(velocityX / (float) 1000);
|
||||||
|
mCallbacks.onSwipeDismissInitiated(dismissAnimator);
|
||||||
|
dismiss(dismissAnimator);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -160,11 +170,11 @@ public class SwipeDismissHandler implements View.OnTouchListener {
|
|||||||
* Start dismissal animation (will run onDismiss callback when animation complete)
|
* Start dismissal animation (will run onDismiss callback when animation complete)
|
||||||
*/
|
*/
|
||||||
public void dismiss() {
|
public void dismiss() {
|
||||||
dismiss(1);
|
dismiss(createSwipeDismissAnimation(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismiss(float velocity) {
|
private void dismiss(ValueAnimator animator) {
|
||||||
mDismissAnimation = createSwipeDismissAnimation(velocity);
|
mDismissAnimation = animator;
|
||||||
mDismissAnimation.addListener(new AnimatorListenerAdapter() {
|
mDismissAnimation.addListener(new AnimatorListenerAdapter() {
|
||||||
private boolean mCancelled;
|
private boolean mCancelled;
|
||||||
|
|
||||||
@@ -178,7 +188,7 @@ public class SwipeDismissHandler implements View.OnTouchListener {
|
|||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
super.onAnimationEnd(animation);
|
super.onAnimationEnd(animation);
|
||||||
if (!mCancelled) {
|
if (!mCancelled) {
|
||||||
mCallbacks.onDismiss();
|
mCallbacks.onDismissComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user