Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt +34 −21 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ import android.text.format.DateFormat import android.util.AttributeSet import android.util.MathUtils.constrainedMap import android.util.TypedValue import android.view.View import android.view.View.MeasureSpec.EXACTLY import android.view.View import android.widget.TextView import com.android.app.animation.Interpolators import com.android.internal.annotations.VisibleForTesting Loading Loading @@ -88,6 +88,10 @@ class AnimatableClockView @JvmOverloads constructor( private var textAnimator: TextAnimator? = null private var onTextAnimatorInitialized: Runnable? = null private var translateForCenterAnimation = false private val parentWidth: Int get() = (parent as View).measuredWidth // last text size which is not constrained by view height private var lastUnconstrainedTextSize: Float = Float.MAX_VALUE @VisibleForTesting var textAnimatorFactory: (Layout, () -> Unit) -> TextAnimator = Loading Loading @@ -116,14 +120,14 @@ class AnimatableClockView @JvmOverloads constructor( try { dozingWeightInternal = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_dozeWeight, 100 /* default = */ 100 ) lockScreenWeightInternal = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_lockScreenWeight, 300 /* default = */ 300 ) chargeAnimationDelay = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_chargeAnimationDelay, 200 R.styleable.AnimatableClockView_chargeAnimationDelay, /* default = */ 200 ) } finally { animatableClockViewAttributes.recycle() Loading @@ -134,9 +138,9 @@ class AnimatableClockView @JvmOverloads constructor( defStyleAttr, defStyleRes ) isSingleLineInternal = try { textViewAttributes.getBoolean(android.R.styleable.TextView_singleLine, false) isSingleLineInternal = textViewAttributes.getBoolean( android.R.styleable.TextView_singleLine, /* default = */ false) } finally { textViewAttributes.recycle() } Loading Loading @@ -206,6 +210,7 @@ class AnimatableClockView @JvmOverloads constructor( super.setTextSize(TypedValue.COMPLEX_UNIT_PX, min(lastUnconstrainedTextSize, MeasureSpec.getSize(heightMeasureSpec) / 2F)) } super.onMeasure(widthMeasureSpec, heightMeasureSpec) val animator = textAnimator if (animator == null) { Loading @@ -215,18 +220,27 @@ class AnimatableClockView @JvmOverloads constructor( } else { animator.updateLayout(layout) } if (migratedClocks && hasCustomPositionUpdatedAnimation) { // Expand width to avoid clock being clipped during stepping animation setMeasuredDimension(measuredWidth + MeasureSpec.getSize(widthMeasureSpec) / 2, measuredHeight) val targetWidth = measuredWidth + MeasureSpec.getSize(widthMeasureSpec) / 2 // This comparison is effectively a check if we're in splitshade or not translateForCenterAnimation = parentWidth > targetWidth if (translateForCenterAnimation) { setMeasuredDimension(targetWidth, measuredHeight) } } else { translateForCenterAnimation = false } } override fun onDraw(canvas: Canvas) { if (migratedClocks && hasCustomPositionUpdatedAnimation) { canvas.save() canvas.translate((parent as View).measuredWidth / 4F, 0F) if (translateForCenterAnimation) { canvas.translate(parentWidth / 4f, 0f) } logger.d({ "onDraw($str1)"}) { str1 = text.toString() } // Use textAnimator to render text if animation is enabled. // Otherwise default to using standard draw functions. Loading @@ -236,10 +250,9 @@ class AnimatableClockView @JvmOverloads constructor( } else { super.onDraw(canvas) } if (migratedClocks && hasCustomPositionUpdatedAnimation) { canvas.restore() } } override fun invalidate() { @Suppress("UNNECESSARY_SAFE_CALL") Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt +34 −21 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ import android.text.format.DateFormat import android.util.AttributeSet import android.util.MathUtils.constrainedMap import android.util.TypedValue import android.view.View import android.view.View.MeasureSpec.EXACTLY import android.view.View import android.widget.TextView import com.android.app.animation.Interpolators import com.android.internal.annotations.VisibleForTesting Loading Loading @@ -88,6 +88,10 @@ class AnimatableClockView @JvmOverloads constructor( private var textAnimator: TextAnimator? = null private var onTextAnimatorInitialized: Runnable? = null private var translateForCenterAnimation = false private val parentWidth: Int get() = (parent as View).measuredWidth // last text size which is not constrained by view height private var lastUnconstrainedTextSize: Float = Float.MAX_VALUE @VisibleForTesting var textAnimatorFactory: (Layout, () -> Unit) -> TextAnimator = Loading Loading @@ -116,14 +120,14 @@ class AnimatableClockView @JvmOverloads constructor( try { dozingWeightInternal = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_dozeWeight, 100 /* default = */ 100 ) lockScreenWeightInternal = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_lockScreenWeight, 300 /* default = */ 300 ) chargeAnimationDelay = animatableClockViewAttributes.getInt( R.styleable.AnimatableClockView_chargeAnimationDelay, 200 R.styleable.AnimatableClockView_chargeAnimationDelay, /* default = */ 200 ) } finally { animatableClockViewAttributes.recycle() Loading @@ -134,9 +138,9 @@ class AnimatableClockView @JvmOverloads constructor( defStyleAttr, defStyleRes ) isSingleLineInternal = try { textViewAttributes.getBoolean(android.R.styleable.TextView_singleLine, false) isSingleLineInternal = textViewAttributes.getBoolean( android.R.styleable.TextView_singleLine, /* default = */ false) } finally { textViewAttributes.recycle() } Loading Loading @@ -206,6 +210,7 @@ class AnimatableClockView @JvmOverloads constructor( super.setTextSize(TypedValue.COMPLEX_UNIT_PX, min(lastUnconstrainedTextSize, MeasureSpec.getSize(heightMeasureSpec) / 2F)) } super.onMeasure(widthMeasureSpec, heightMeasureSpec) val animator = textAnimator if (animator == null) { Loading @@ -215,18 +220,27 @@ class AnimatableClockView @JvmOverloads constructor( } else { animator.updateLayout(layout) } if (migratedClocks && hasCustomPositionUpdatedAnimation) { // Expand width to avoid clock being clipped during stepping animation setMeasuredDimension(measuredWidth + MeasureSpec.getSize(widthMeasureSpec) / 2, measuredHeight) val targetWidth = measuredWidth + MeasureSpec.getSize(widthMeasureSpec) / 2 // This comparison is effectively a check if we're in splitshade or not translateForCenterAnimation = parentWidth > targetWidth if (translateForCenterAnimation) { setMeasuredDimension(targetWidth, measuredHeight) } } else { translateForCenterAnimation = false } } override fun onDraw(canvas: Canvas) { if (migratedClocks && hasCustomPositionUpdatedAnimation) { canvas.save() canvas.translate((parent as View).measuredWidth / 4F, 0F) if (translateForCenterAnimation) { canvas.translate(parentWidth / 4f, 0f) } logger.d({ "onDraw($str1)"}) { str1 = text.toString() } // Use textAnimator to render text if animation is enabled. // Otherwise default to using standard draw functions. Loading @@ -236,10 +250,9 @@ class AnimatableClockView @JvmOverloads constructor( } else { super.onDraw(canvas) } if (migratedClocks && hasCustomPositionUpdatedAnimation) { canvas.restore() } } override fun invalidate() { @Suppress("UNNECESSARY_SAFE_CALL") Loading