Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt +4 −4 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "hh", ), Loading @@ -173,7 +173,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "hh", ), Loading @@ -192,7 +192,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "mm", ), Loading @@ -211,7 +211,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "mm", ), Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt +45 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.shared.clocks.view import android.graphics.Canvas import android.graphics.Point import android.icu.text.NumberFormat import android.util.MathUtils.constrainedMap import android.view.View import android.view.ViewGroup Loading @@ -26,6 +27,7 @@ import com.android.app.animation.Interpolators import com.android.systemui.customization.R import com.android.systemui.shared.clocks.ClockContext import com.android.systemui.shared.clocks.DigitTranslateAnimator import java.util.Locale import kotlin.math.abs import kotlin.math.max import kotlin.math.min Loading @@ -34,10 +36,14 @@ fun clamp(value: Float, minVal: Float, maxVal: Float): Float = max(min(value, ma class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { override var digitalClockTextViewMap = mutableMapOf<Int, SimpleDigitalClockTextView>() val digitLeftTopMap = mutableMapOf<Int, Point>() var maxSingleDigitSize = Point(-1, -1) val lockscreenTranslate = Point(0, 0) var aodTranslate = Point(0, 0) private val digitLeftTopMap = mutableMapOf<Int, Point>() private var maxSingleDigitSize = Point(-1, -1) private val lockscreenTranslate = Point(0, 0) private var aodTranslate = Point(0, 0) // Does the current language have mono vertical size when displaying numerals private var isMonoVerticalNumericLineSpacing = true init { setWillNotDraw(false) Loading @@ -46,6 +52,7 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, ) updateLocale(Locale.getDefault()) } private val digitOffsets = mutableMapOf<Int, Float>() Loading @@ -58,12 +65,19 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { protected override fun calculateSize(widthMeasureSpec: Int, heightMeasureSpec: Int): Point { maxSingleDigitSize = Point(-1, -1) val bottomLocation: (textView: SimpleDigitalClockTextView) -> Int = { textView -> if (isMonoVerticalNumericLineSpacing) { maxSingleDigitSize.y } else { (textView.paint.fontMetrics.descent - textView.paint.fontMetrics.ascent).toInt() } } digitalClockTextViewMap.forEach { (_, textView) -> textView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) maxSingleDigitSize.x = max(maxSingleDigitSize.x, textView.measuredWidth) maxSingleDigitSize.y = max(maxSingleDigitSize.y, textView.measuredHeight) maxSingleDigitSize.y = max(bottomLocation(textView), textView.measuredHeight) } val textView = digitalClockTextViewMap[R.id.HOUR_FIRST_DIGIT]!! aodTranslate = Point(0, 0) return Point( ((maxSingleDigitSize.x + abs(aodTranslate.x)) * 2), Loading Loading @@ -103,6 +117,11 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { } } override fun onLocaleChanged(locale: Locale) { updateLocale(locale) requestLayout() } override fun animateDoze(isDozing: Boolean, isAnimated: Boolean) { dozeControlState.animateDoze = { super.animateDoze(isDozing, isAnimated) Loading Loading @@ -163,6 +182,18 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { } } private fun updateLocale(locale: Locale) { isMonoVerticalNumericLineSpacing = !NON_MONO_VERTICAL_NUMERIC_LINE_SPACING_LANGUAGES.any { val newLocaleNumberFormat = NumberFormat.getInstance(locale).format(FORMAT_NUMBER.toLong()) val nonMonoVerticalNumericLineSpaceNumberFormat = NumberFormat.getInstance(Locale.forLanguageTag(it)) .format(FORMAT_NUMBER.toLong()) newLocaleNumberFormat == nonMonoVerticalNumericLineSpaceNumberFormat } } /** * Offsets the textViews of the clock for the step clock animation. * Loading Loading @@ -261,10 +292,18 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { // Constants for the animation private val MOVE_INTERPOLATOR = Interpolators.EMPHASIZED private const val FORMAT_NUMBER = 1234567890 // Total available transition time for each digit, taking into account the step. If step is // 0.1, then digit 0 would animate over 0.0 - 0.7, making availableTime 0.7. private const val AVAILABLE_ANIMATION_TIME = 1.0f - MOVE_DIGIT_STEP * (NUM_DIGITS - 1) // Add language tags below that do not have vertically mono spaced numerals private val NON_MONO_VERTICAL_NUMERIC_LINE_SPACING_LANGUAGES = setOf( "my", // Burmese ) // Use the sign of targetTranslation to control the direction of digit translation fun updateDirectionalTargetTranslate(id: Int, targetTranslation: Point): Point { val outPoint = Point(targetTranslation) Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt +9 −5 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe } } override var verticalAlignment: VerticalAlignment = VerticalAlignment.CENTER override var verticalAlignment: VerticalAlignment = VerticalAlignment.BASELINE override var horizontalAlignment: HorizontalAlignment = HorizontalAlignment.LEFT override var isAnimationEnabled = true override var dozeFraction: Float = 0F Loading Loading @@ -242,7 +242,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe -translation.y.toFloat(), (-translation.x + measuredWidth).toFloat(), (-translation.y + measuredHeight).toFloat(), Paint().also { it.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT) }, PORTER_DUFF_XFER_MODE_PAINT, ) canvas.restore() canvas.restore() Loading Loading @@ -387,7 +387,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe // translation of reference point of text // used for translation when calling textInterpolator fun getLocalTranslation(): Point { private fun getLocalTranslation(): Point { val viewHeight = if (isVertical) measuredWidth else measuredHeight val interpolatedTextBounds = updateInterpolatedTextBounds() val localTranslation = Point(0, 0) Loading @@ -413,7 +413,9 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe correctedBaseline } VerticalAlignment.BASELINE -> { localTranslation.y = -lockScreenPaint.strokeWidth.toInt() // account for max bottom distance of font, so clock doesn't collide with elements localTranslation.y = -lockScreenPaint.strokeWidth.toInt() - paint.fontMetrics.descent.toInt() } } Loading Loading @@ -533,7 +535,9 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe } companion object { val AOD_STROKE_WIDTH = "2dp" private val PORTER_DUFF_XFER_MODE_PAINT = Paint().also { it.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT) } val AOD_COLOR = Color.WHITE val OPTICAL_SIZE_AXIS = ClockFontAxisSetting("opsz", 144f) val DEFAULT_LS_VARIATION = Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt +4 −4 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "hh", ), Loading @@ -173,7 +173,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "hh", ), Loading @@ -192,7 +192,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "mm", ), Loading @@ -211,7 +211,7 @@ class DefaultClockProvider( alignment = DigitalAlignment( HorizontalAlignment.CENTER, VerticalAlignment.CENTER, VerticalAlignment.BASELINE, ), dateTimeFormat = "mm", ), Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt +45 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.shared.clocks.view import android.graphics.Canvas import android.graphics.Point import android.icu.text.NumberFormat import android.util.MathUtils.constrainedMap import android.view.View import android.view.ViewGroup Loading @@ -26,6 +27,7 @@ import com.android.app.animation.Interpolators import com.android.systemui.customization.R import com.android.systemui.shared.clocks.ClockContext import com.android.systemui.shared.clocks.DigitTranslateAnimator import java.util.Locale import kotlin.math.abs import kotlin.math.max import kotlin.math.min Loading @@ -34,10 +36,14 @@ fun clamp(value: Float, minVal: Float, maxVal: Float): Float = max(min(value, ma class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { override var digitalClockTextViewMap = mutableMapOf<Int, SimpleDigitalClockTextView>() val digitLeftTopMap = mutableMapOf<Int, Point>() var maxSingleDigitSize = Point(-1, -1) val lockscreenTranslate = Point(0, 0) var aodTranslate = Point(0, 0) private val digitLeftTopMap = mutableMapOf<Int, Point>() private var maxSingleDigitSize = Point(-1, -1) private val lockscreenTranslate = Point(0, 0) private var aodTranslate = Point(0, 0) // Does the current language have mono vertical size when displaying numerals private var isMonoVerticalNumericLineSpacing = true init { setWillNotDraw(false) Loading @@ -46,6 +52,7 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, ) updateLocale(Locale.getDefault()) } private val digitOffsets = mutableMapOf<Int, Float>() Loading @@ -58,12 +65,19 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { protected override fun calculateSize(widthMeasureSpec: Int, heightMeasureSpec: Int): Point { maxSingleDigitSize = Point(-1, -1) val bottomLocation: (textView: SimpleDigitalClockTextView) -> Int = { textView -> if (isMonoVerticalNumericLineSpacing) { maxSingleDigitSize.y } else { (textView.paint.fontMetrics.descent - textView.paint.fontMetrics.ascent).toInt() } } digitalClockTextViewMap.forEach { (_, textView) -> textView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) maxSingleDigitSize.x = max(maxSingleDigitSize.x, textView.measuredWidth) maxSingleDigitSize.y = max(maxSingleDigitSize.y, textView.measuredHeight) maxSingleDigitSize.y = max(bottomLocation(textView), textView.measuredHeight) } val textView = digitalClockTextViewMap[R.id.HOUR_FIRST_DIGIT]!! aodTranslate = Point(0, 0) return Point( ((maxSingleDigitSize.x + abs(aodTranslate.x)) * 2), Loading Loading @@ -103,6 +117,11 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { } } override fun onLocaleChanged(locale: Locale) { updateLocale(locale) requestLayout() } override fun animateDoze(isDozing: Boolean, isAnimated: Boolean) { dozeControlState.animateDoze = { super.animateDoze(isDozing, isAnimated) Loading Loading @@ -163,6 +182,18 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { } } private fun updateLocale(locale: Locale) { isMonoVerticalNumericLineSpacing = !NON_MONO_VERTICAL_NUMERIC_LINE_SPACING_LANGUAGES.any { val newLocaleNumberFormat = NumberFormat.getInstance(locale).format(FORMAT_NUMBER.toLong()) val nonMonoVerticalNumericLineSpaceNumberFormat = NumberFormat.getInstance(Locale.forLanguageTag(it)) .format(FORMAT_NUMBER.toLong()) newLocaleNumberFormat == nonMonoVerticalNumericLineSpaceNumberFormat } } /** * Offsets the textViews of the clock for the step clock animation. * Loading Loading @@ -261,10 +292,18 @@ class FlexClockView(clockCtx: ClockContext) : DigitalClockFaceView(clockCtx) { // Constants for the animation private val MOVE_INTERPOLATOR = Interpolators.EMPHASIZED private const val FORMAT_NUMBER = 1234567890 // Total available transition time for each digit, taking into account the step. If step is // 0.1, then digit 0 would animate over 0.0 - 0.7, making availableTime 0.7. private const val AVAILABLE_ANIMATION_TIME = 1.0f - MOVE_DIGIT_STEP * (NUM_DIGITS - 1) // Add language tags below that do not have vertically mono spaced numerals private val NON_MONO_VERTICAL_NUMERIC_LINE_SPACING_LANGUAGES = setOf( "my", // Burmese ) // Use the sign of targetTranslation to control the direction of digit translation fun updateDirectionalTargetTranslate(id: Int, targetTranslation: Point): Point { val outPoint = Point(targetTranslation) Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt +9 −5 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe } } override var verticalAlignment: VerticalAlignment = VerticalAlignment.CENTER override var verticalAlignment: VerticalAlignment = VerticalAlignment.BASELINE override var horizontalAlignment: HorizontalAlignment = HorizontalAlignment.LEFT override var isAnimationEnabled = true override var dozeFraction: Float = 0F Loading Loading @@ -242,7 +242,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe -translation.y.toFloat(), (-translation.x + measuredWidth).toFloat(), (-translation.y + measuredHeight).toFloat(), Paint().also { it.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT) }, PORTER_DUFF_XFER_MODE_PAINT, ) canvas.restore() canvas.restore() Loading Loading @@ -387,7 +387,7 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe // translation of reference point of text // used for translation when calling textInterpolator fun getLocalTranslation(): Point { private fun getLocalTranslation(): Point { val viewHeight = if (isVertical) measuredWidth else measuredHeight val interpolatedTextBounds = updateInterpolatedTextBounds() val localTranslation = Point(0, 0) Loading @@ -413,7 +413,9 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe correctedBaseline } VerticalAlignment.BASELINE -> { localTranslation.y = -lockScreenPaint.strokeWidth.toInt() // account for max bottom distance of font, so clock doesn't collide with elements localTranslation.y = -lockScreenPaint.strokeWidth.toInt() - paint.fontMetrics.descent.toInt() } } Loading Loading @@ -533,7 +535,9 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe } companion object { val AOD_STROKE_WIDTH = "2dp" private val PORTER_DUFF_XFER_MODE_PAINT = Paint().also { it.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT) } val AOD_COLOR = Color.WHITE val OPTICAL_SIZE_AXIS = ClockFontAxisSetting("opsz", 144f) val DEFAULT_LS_VARIATION = Loading