Add OnGlobalLayout listener to WidgetFloatingView
This mirrors the FloatingIconView implementation. Bug: 169042867 Test: manual Change-Id: Ic5531dd847af66b9b17f6806dc7fc04c00c42f06
This commit is contained in:
parent
e80a0caa81
commit
f5c9900686
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue