From 914549b48213eaa8ba948409bc1a6af1536546df Mon Sep 17 00:00:00 2001 From: Sihua Ma Date: Fri, 6 Jan 2023 13:47:10 -0800 Subject: [PATCH] Set the original drawable for floating widget view This ensures that the background of the widget will not disappear after cancelling opening the widget activity. Normally, when opening and closing the widget activity, the following procedures are executed: tap on widget -> opening animation initialized -> opening animation finished -> close the activity -> closing animation initialized -> closing animation finished The steps above would work fine. However, a different set of procedures is followed if we try to cancel opening the widget activity: tap on widget -> opening animation initialized -> opening animation started -> swipe back before opening animation is completed -> closing animation initialized -> opening animation finished -> closing animation started -> closing animation finished During the animation initialization process, FloatingWidgetBackgroundView would be initialized. It will then cache the original background and replace with a temporary drawable with alpha set to 0. The background is only restored at the end of the animation. If two FloatingWidgetBackgroundView is initialized on the same app widget view before one of them is finished, the second floating view will treat the temporary drawable as the original background. At the end of the closing animation, the temporary drawable with an alpha value of 0 will be set for the app widget view, causing the background of the widget view to disappear. This CL stores the original drawables into the background view so they could be retrieved during the initialization process of the floating background view. Test: Manual Fix: 259526083 Change-Id: Iefa29b22b690076a4fc3fc77fe6eea4b6316f852 --- .../views/FloatingWidgetBackgroundView.java | 26 ++++++++++++++++--- res/values/id.xml | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/FloatingWidgetBackgroundView.java b/quickstep/src/com/android/quickstep/views/FloatingWidgetBackgroundView.java index adea1a40cf..4ea77532bc 100644 --- a/quickstep/src/com/android/quickstep/views/FloatingWidgetBackgroundView.java +++ b/quickstep/src/com/android/quickstep/views/FloatingWidgetBackgroundView.java @@ -27,8 +27,10 @@ import android.view.View; import android.view.ViewOutlineProvider; import android.widget.RemoteViews.RemoteViewOutlineProvider; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.android.launcher3.R; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.RoundedCornerEnforcement; @@ -65,14 +67,20 @@ final class FloatingWidgetBackgroundView extends View { setClipToOutline(true); } - void init(LauncherAppWidgetHostView hostView, View backgroundView, float finalRadius, - int fallbackBackgroundColor) { + void init(LauncherAppWidgetHostView hostView, @NonNull View backgroundView, + float finalRadius, int fallbackBackgroundColor) { mFinalRadius = finalRadius; mSourceView = backgroundView; mInitialOutlineRadius = getOutlineRadius(hostView, backgroundView); mIsUsingFallback = false; if (isSupportedDrawable(backgroundView.getForeground())) { - mOriginalForeground = backgroundView.getForeground(); + if (backgroundView.getTag(R.id.saved_floating_widget_foreground) == null) { + mOriginalForeground = backgroundView.getForeground(); + backgroundView.setTag(R.id.saved_floating_widget_foreground, mOriginalForeground); + } else { + mOriginalForeground = (Drawable) backgroundView.getTag( + R.id.saved_floating_widget_foreground); + } mForegroundProperties.init( mOriginalForeground.getConstantState().newDrawable().mutate()); setForeground(mForegroundProperties.mDrawable); @@ -82,7 +90,13 @@ final class FloatingWidgetBackgroundView extends View { mSourceView.setForeground(clipPlaceholder); } if (isSupportedDrawable(backgroundView.getBackground())) { - mOriginalBackground = backgroundView.getBackground(); + if (backgroundView.getTag(R.id.saved_floating_widget_background) == null) { + mOriginalBackground = backgroundView.getBackground(); + backgroundView.setTag(R.id.saved_floating_widget_background, mOriginalBackground); + } else { + mOriginalBackground = (Drawable) backgroundView.getTag( + R.id.saved_floating_widget_background); + } mBackgroundProperties.init( mOriginalBackground.getConstantState().newDrawable().mutate()); setBackground(mBackgroundProperties.mDrawable); @@ -115,6 +129,10 @@ final class FloatingWidgetBackgroundView extends View { } void recycle() { + if (mSourceView != null) { + mSourceView.setTag(R.id.saved_floating_widget_foreground, null); + mSourceView.setTag(R.id.saved_floating_widget_background, null); + } mSourceView = null; mOriginalForeground = null; mOriginalBackground = null; diff --git a/res/values/id.xml b/res/values/id.xml index 375750f0d6..dc819443a6 100644 --- a/res/values/id.xml +++ b/res/values/id.xml @@ -38,4 +38,7 @@ + + +