Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17e32cd6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implement Placeholder Clock Fidget Animation" into main

parents 237f274d 36e4b1b8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package com.android.systemui.shared.clocks
import android.content.Context
import android.content.res.Resources
import android.graphics.Typeface
import android.os.Vibrator
import android.view.LayoutInflater
import com.android.systemui.customization.R
import com.android.systemui.log.core.MessageBuffer
@@ -40,6 +41,7 @@ data class ClockContext(
    val typefaceCache: TypefaceCache,
    val messageBuffers: ClockMessageBuffers,
    val messageBuffer: MessageBuffer,
    val vibrator: Vibrator?,
)

/** Provides the default system clock */
@@ -48,6 +50,7 @@ class DefaultClockProvider(
    val layoutInflater: LayoutInflater,
    val resources: Resources,
    private val isClockReactiveVariantsEnabled: Boolean = false,
    private val vibrator: Vibrator?,
) : ClockProvider {
    private var messageBuffers: ClockMessageBuffers? = null

@@ -82,6 +85,7 @@ class DefaultClockProvider(
                    typefaceCache,
                    buffers,
                    buffers.infraMessageBuffer,
                    vibrator,
                )
            )
        } else {
+41 −10
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Point
import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode
import android.graphics.Rect
import android.os.VibrationEffect
import android.text.Layout
import android.text.TextPaint
import android.util.AttributeSet
@@ -67,7 +68,7 @@ enum class HorizontalAlignment {

@SuppressLint("AppCompatCustomView")
open class SimpleDigitalClockTextView(
    clockCtx: ClockContext,
    val clockCtx: ClockContext,
    isLargeClock: Boolean,
    attrs: AttributeSet? = null,
) : TextView(clockCtx.context, attrs) {
@@ -92,6 +93,9 @@ open class SimpleDigitalClockTextView(
        (fixedAodAxes + listOf(roundAxis, SLANT_AXIS)).toFVar()
    }

    // TODO(b/374306512): Fidget endpoint to spec
    private var fidgetFontVariation = aodFontVariation

    private val parser = DimensionParser(clockCtx.context)
    var maxSingleDigitHeight = -1
    var maxSingleDigitWidth = -1
@@ -289,24 +293,45 @@ open class SimpleDigitalClockTextView(
            return
        }
        logger.d("animateCharge()")
        val startAnimPhase2 = Runnable {
        textAnimator.setTextStyle(
            fvar = if (dozeFraction == 0F) aodFontVariation else lsFontVariation,
            animate = isAnimationEnabled,
            onAnimationEnd =
                Runnable {
                    textAnimator.setTextStyle(
                        fvar = if (dozeFraction == 0F) lsFontVariation else aodFontVariation,
                        animate = isAnimationEnabled,
                    )
                    updateTextBoundsForTextAnimator()
        }
        textAnimator.setTextStyle(
            fvar = if (dozeFraction == 0F) aodFontVariation else lsFontVariation,
            animate = isAnimationEnabled,
            onAnimationEnd = startAnimPhase2,
                },
        )
        updateTextBoundsForTextAnimator()
    }

    fun animateFidget(x: Float, y: Float) {
        // TODO(b/374306512): Implement Fidget Animation
        if (!this::textAnimator.isInitialized || textAnimator.isRunning()) {
            // Skip fidget animation if other animation is already playing.
            return
        }

        logger.animateFidget(x, y)
        clockCtx.vibrator?.vibrate(FIDGET_HAPTICS)

        // TODO(b/374306512): Duplicated charge animation as placeholder. Implement final version
        // when we have a complete spec. May require additional code to animate individual digits.
        textAnimator.setTextStyle(
            fvar = fidgetFontVariation,
            animate = isAnimationEnabled,
            onAnimationEnd =
                Runnable {
                    textAnimator.setTextStyle(
                        fvar = if (dozeFraction == 0F) lsFontVariation else aodFontVariation,
                        animate = isAnimationEnabled,
                    )
                    updateTextBoundsForTextAnimator()
                },
        )
        updateTextBoundsForTextAnimator()
    }

    fun refreshText() {
@@ -533,6 +558,12 @@ open class SimpleDigitalClockTextView(
        private val PORTER_DUFF_XFER_MODE_PAINT =
            Paint().also { it.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT) }

        val FIDGET_HAPTICS =
            VibrationEffect.startComposition()
                .addPrimitive(VibrationEffect.Composition.PRIMITIVE_THUD, 1.0f, 0)
                .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 1.0f, 43)
                .compose()

        val AOD_COLOR = Color.WHITE
        val LS_WEIGHT_AXIS = ClockFontAxisSetting(GSFAxes.WEIGHT, 400f)
        val AOD_WEIGHT_AXIS = ClockFontAxisSetting(GSFAxes.WEIGHT, 200f)
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ class DefaultClockProviderTest : SysuiTestCase() {
        whenever(mockSmallClockView.getLayoutParams()).thenReturn(FrameLayout.LayoutParams(10, 10))
        whenever(mockLargeClockView.getLayoutParams()).thenReturn(FrameLayout.LayoutParams(10, 10))

        provider = DefaultClockProvider(context, layoutInflater, resources)
        provider = DefaultClockProvider(context, layoutInflater, resources, vibrator = null)
    }

    @Test
+7 −2
Original line number Diff line number Diff line
@@ -18,8 +18,11 @@ package com.android.keyguard.dagger;

import android.content.Context;
import android.content.res.Resources;
import android.os.Vibrator;
import android.view.LayoutInflater;

import androidx.annotation.Nullable;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Background;
@@ -55,7 +58,8 @@ public abstract class ClockRegistryModule {
            FeatureFlags featureFlags,
            @Main Resources resources,
            LayoutInflater layoutInflater,
            ClockMessageBuffers clockBuffers) {
            ClockMessageBuffers clockBuffers,
            @Nullable Vibrator vibrator) {
        ClockRegistry registry = new ClockRegistry(
                context,
                pluginManager,
@@ -69,7 +73,8 @@ public abstract class ClockRegistryModule {
                        context,
                        layoutInflater,
                        resources,
                        com.android.systemui.shared.Flags.clockReactiveVariants()
                        com.android.systemui.shared.Flags.clockReactiveVariants(),
                        vibrator
                ),
                context.getString(R.string.lockscreen_clock_id_fallback),
                clockBuffers,
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ class SimpleDigitalClockTextViewTest : SysuiTestCase() {
                    },
                    ClockMessageBuffers(messageBuffer),
                    messageBuffer,
                    vibrator = null,
                ),
                isLargeClock = false,
            )