diff options
author | Yuri Ufimtsev <yufimtsev@google.com> | 2023-03-02 15:50:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-03-02 15:50:33 +0000 |
commit | a92f796720d9b35d06fd06a433f57af2b48efa29 (patch) | |
tree | ad145e320dd865782b094288c15a44b2085454ab /PermissionController/src/com/android/permissioncontroller/safetycenter | |
parent | 11ceb5a1e3e1f1e73baf2a70efe0758c65855a66 (diff) | |
parent | 0af4732fce0cc4765ef7da670d6adafec7eaa81e (diff) | |
download | Permission-a92f796720d9b35d06fd06a433f57af2b48efa29.tar.gz |
Merge "Animates round corners of More alerts card in Safety Center" into udc-dev
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/safetycenter')
2 files changed, 43 insertions, 15 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/IssueCardPreference.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/IssueCardPreference.java index bf1c05e83..4996402fa 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/IssueCardPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/IssueCardPreference.java @@ -244,6 +244,7 @@ public class IssueCardPreference extends Preference implements ComparablePrefere && Objects.equals( mResolvedIssueActionId, ((IssueCardPreference) preference).mResolvedIssueActionId) + && mIsDismissed == ((IssueCardPreference) preference).mIsDismissed && mPositionInCardList == ((IssueCardPreference) preference).mPositionInCardList; } diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/view/MoreIssuesHeaderView.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/view/MoreIssuesHeaderView.kt index ab4311390..b0483512b 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/view/MoreIssuesHeaderView.kt +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/view/MoreIssuesHeaderView.kt @@ -1,5 +1,7 @@ package com.android.permissioncontroller.safetycenter.ui.view +import android.animation.Animator +import android.animation.ValueAnimator import android.content.Context import android.graphics.drawable.Animatable2 import android.graphics.drawable.AnimatedVectorDrawable @@ -25,6 +27,7 @@ import com.android.permissioncontroller.permission.utils.StringUtils import com.android.permissioncontroller.safetycenter.ui.MoreIssuesCardAnimator import com.android.permissioncontroller.safetycenter.ui.MoreIssuesCardData import java.text.NumberFormat +import java.time.Duration @RequiresApi(Build.VERSION_CODES.TIRAMISU) internal class MoreIssuesHeaderView @@ -50,6 +53,7 @@ constructor( private val expandCollapseIcon: ImageView by lazy { expandCollapseLayout.findViewById(R.id.widget_icon) } + private var cornerAnimator: Animator? = null fun showExpandableHeader( previousData: MoreIssuesCardData?, @@ -66,7 +70,7 @@ constructor( overrideChevronIconResId ) updateIssueCount(previousData?.hiddenIssueCount, nextData.hiddenIssueCount) - updateBackground(nextData.isExpanded) + updateBackground(previousData?.isExpanded, nextData.isExpanded) setOnClickListener { onClick() } val expansionString = @@ -91,7 +95,7 @@ constructor( expandCollapseLayout.isVisible = false setOnClickListener(null) isClickable = false - updateBackground(true) + updateBackground(wasExpanded = null, isExpanded = true) } private fun updateExpandCollapseButton( @@ -171,14 +175,16 @@ constructor( } } - private fun updateBackground(isExpanded: Boolean) { - // changing radius of existing background instead of switching backgrounds - // with PositionInCardList because of two reasons: - // 1) we will need to animate rounding the corners in TODO: b/270036109 - // 2) this particular header has smaller radii than values from PositionInCardList + private fun updateBackground(wasExpanded: Boolean?, isExpanded: Boolean) { (background?.mutate() as? RippleDrawable)?.let { ripple -> val topRadius = context.resources.getDimension(R.dimen.sc_card_corner_radius_medium) - val bottomRadius = + val bottomRadiusStart = + if (wasExpanded ?: isExpanded) { + context.resources.getDimension(R.dimen.sc_card_corner_radius_xsmall) + } else { + topRadius + } + val bottomRadiusEnd = if (isExpanded) { context.resources.getDimension(R.dimen.sc_card_corner_radius_xsmall) } else { @@ -190,15 +196,34 @@ constructor( topRadius, topRadius, topRadius, - bottomRadius, - bottomRadius, - bottomRadius, - bottomRadius + bottomRadiusStart, + bottomRadiusStart, + bottomRadiusStart, + bottomRadiusStart ) - for (index in 0 until ripple.numberOfLayers) { - (ripple.getDrawable(index).mutate() as? GradientDrawable)?.let { - it.cornerRadii = cornerRadii + setCornerRadii(ripple, cornerRadii) + if (bottomRadiusEnd != bottomRadiusStart) { + cornerAnimator?.cancel() + val animator = + ValueAnimator.ofFloat(bottomRadiusStart, bottomRadiusEnd) + .setDuration(CORNER_RADII_ANIMATION_DURATION.toMillis()) + if (isExpanded) { + animator.startDelay = CORNER_RADII_ANIMATION_DELAY.toMillis() } + animator.addUpdateListener { + cornerRadii.fill(it.animatedValue as Float, fromIndex = 4, toIndex = 8) + setCornerRadii(ripple, cornerRadii) + } + animator.start() + cornerAnimator = animator + } + } + } + + private fun setCornerRadii(ripple: RippleDrawable, cornerRadii: FloatArray) { + for (index in 0 until ripple.numberOfLayers) { + (ripple.getDrawable(index).mutate() as? GradientDrawable)?.let { + it.cornerRadii = cornerRadii } } } @@ -220,5 +245,7 @@ constructor( companion object { val TAG: String = MoreIssuesHeaderView::class.java.simpleName + private val CORNER_RADII_ANIMATION_DELAY = Duration.ofMillis(250) + private val CORNER_RADII_ANIMATION_DURATION = Duration.ofMillis(120) } } |