Update BorderAnimator to work with layout updates

1. if a 'ViewScaleTargetProvider' is being used, this can cause a crash
2. otherwise, the old border bounds are reapplied, which is likely no longer correct

Updated BorderAnimator to use 'BorderAnimationParams' rather than 'ViewScaleTargetProvider'. This removes some unnecessary null checks while making the util class simpler to use. It also allows us to listen for specific view events for the border animation.

Flag: ENABLE_KEYBOARD_QUICK_SWITCH
Fixes: 283272516
Test: opened the keyboard quick switch view and highlighted a view in recents view, then rotated the screen several times
Change-Id: I7959d6cd892ebcdd2c68163dd56c358815494af6
This commit is contained in:
Schneider Victor-tulias
2023-05-18 10:35:16 -07:00
parent 6597d5ec3c
commit 7dee27f470
3 changed files with 220 additions and 146 deletions

View File

@@ -27,11 +27,13 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.android.launcher3.R;
import com.android.launcher3.util.Preconditions;
import com.android.quickstep.util.BorderAnimator;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
@@ -43,7 +45,9 @@ import java.util.function.Consumer;
*/
public class KeyboardQuickSwitchTaskView extends ConstraintLayout {
@NonNull private final BorderAnimator mBorderAnimator;
@ColorInt private final int mBorderColor;
@Nullable private BorderAnimator mBorderAnimator;
@Nullable private ImageView mThumbnailView1;
@Nullable private ImageView mThumbnailView2;
@@ -74,29 +78,9 @@ public class KeyboardQuickSwitchTaskView extends ConstraintLayout {
attrs, R.styleable.TaskView, defStyleAttr, defStyleRes);
setWillNotDraw(false);
Resources resources = context.getResources();
mBorderAnimator = new BorderAnimator(
/* borderBoundsBuilder= */ bounds -> bounds.set(0, 0, getWidth(), getHeight()),
/* borderWidthPx= */ resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_border_width),
/* borderRadiusPx= */ resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_task_view_radius),
/* borderColor= */ ta.getColor(
R.styleable.TaskView_borderColor, DEFAULT_BORDER_COLOR),
/* invalidateViewCallback= */ KeyboardQuickSwitchTaskView.this::invalidate,
/* viewScaleTargetProvider= */ new BorderAnimator.ViewScaleTargetProvider() {
@NonNull
@Override
public View getContainerView() {
return KeyboardQuickSwitchTaskView.this;
}
@NonNull
@Override
public View getContentView() {
return mContent;
}
});
mBorderColor = ta.getColor(
R.styleable.TaskView_borderColor, DEFAULT_BORDER_COLOR);
ta.recycle();
}
@@ -108,17 +92,34 @@ public class KeyboardQuickSwitchTaskView extends ConstraintLayout {
mIcon1 = findViewById(R.id.icon1);
mIcon2 = findViewById(R.id.icon2);
mContent = findViewById(R.id.content);
Resources resources = mContext.getResources();
Preconditions.assertNotNull(mContent);
mBorderAnimator = new BorderAnimator(
/* borderRadiusPx= */ resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_task_view_radius),
/* borderColor= */ mBorderColor,
/* borderAnimationParams= */ new BorderAnimator.ScalingParams(
/* borderWidthPx= */ resources.getDimensionPixelSize(
R.dimen.keyboard_quick_switch_border_width),
/* boundsBuilder= */ bounds -> bounds.set(
0, 0, getWidth(), getHeight()),
/* targetView= */ this,
/* contentView= */ mContent));
}
@NonNull
@Nullable
protected Animator getFocusAnimator(boolean focused) {
return mBorderAnimator.buildAnimator(focused);
return mBorderAnimator == null ? null : mBorderAnimator.buildAnimator(focused);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
mBorderAnimator.drawBorder(canvas);
if (mBorderAnimator != null) {
mBorderAnimator.drawBorder(canvas);
}
}
protected void setThumbnails(