From f5c9900686d280669bc16c0bd81c7cc4c7b3094d Mon Sep 17 00:00:00 2001 From: Cyrus Boadway Date: Wed, 5 May 2021 13:21:54 +0000 Subject: [PATCH] Add OnGlobalLayout listener to WidgetFloatingView This mirrors the FloatingIconView implementation. Bug: 169042867 Test: manual Change-Id: Ic5531dd847af66b9b17f6806dc7fc04c00c42f06 --- .../quickstep/LauncherSwipeHandlerV2.java | 1 + .../quickstep/views/FloatingWidgetView.java | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java index 9398277032..46cd8a2cf9 100644 --- a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java +++ b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java @@ -260,6 +260,7 @@ public class LauncherSwipeHandlerV2 extends @Override public void setAnimation(RectFSpringAnim anim) { anim.addAnimatorListener(floatingWidgetView); + floatingWidgetView.setOnTargetChangeListener(anim::onTargetPositionChanged); floatingWidgetView.setFastFinishRunnable(anim::end); } diff --git a/quickstep/src/com/android/quickstep/views/FloatingWidgetView.java b/quickstep/src/com/android/quickstep/views/FloatingWidgetView.java index 8499902f23..ed54f1007e 100644 --- a/quickstep/src/com/android/quickstep/views/FloatingWidgetView.java +++ b/quickstep/src/com/android/quickstep/views/FloatingWidgetView.java @@ -27,6 +27,7 @@ import android.util.Size; import android.view.GhostView; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.widget.FrameLayout; import com.android.launcher3.Launcher; @@ -39,7 +40,8 @@ import com.android.launcher3.widget.RoundedCornerEnforcement; /** A view that mimics an App Widget through a launch animation. */ @TargetApi(Build.VERSION_CODES.S) -public class FloatingWidgetView extends FrameLayout implements AnimatorListener { +public class FloatingWidgetView extends FrameLayout implements AnimatorListener, + OnGlobalLayoutListener { private static final Matrix sTmpMatrix = new Matrix(); private final Launcher mLauncher; @@ -54,6 +56,7 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener private Runnable mEndRunnable; private Runnable mFastFinishRunnable; + private Runnable mOnTargetChangeRunnable; public FloatingWidgetView(Context context) { this(context, null); @@ -93,6 +96,32 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener public void onAnimationRepeat(Animator animator) { } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + getViewTreeObserver().addOnGlobalLayoutListener(this); + } + + @Override + protected void onDetachedFromWindow() { + getViewTreeObserver().removeOnGlobalLayoutListener(this); + super.onDetachedFromWindow(); + } + + @Override + public void onGlobalLayout() { + if (isUninitialized()) return; + positionViews(); + if (mOnTargetChangeRunnable != null) { + mOnTargetChangeRunnable.run(); + } + } + + /** Sets a runnable that is called on global layout change. */ + public void setOnTargetChangeListener(Runnable onTargetChangeListener) { + mOnTargetChangeRunnable = onTargetChangeListener; + } + /** Sets a runnable that is called after a call to {@link #fastFinish()}. */ public void setFastFinishRunnable(Runnable runnable) { mFastFinishRunnable = runnable; @@ -205,6 +234,7 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener private void recycle() { mEndRunnable = null; mFastFinishRunnable = null; + mOnTargetChangeRunnable = null; mBackgroundPosition = null; mListenerView.setListener(null); mAppWidgetView = null;