1 package com.android.customization.picker.clock.ui.view 2 3 import android.content.Context 4 import android.util.AttributeSet 5 import android.view.View 6 import android.view.View.MeasureSpec.EXACTLY 7 import android.widget.FrameLayout 8 import com.android.wallpaper.util.ScreenSizeCalculator 9 10 /** 11 * The parent view for each clock view in picker carousel This view will give a container with the 12 * same size of lockscreen to layout clock and scale down it to the size in picker carousel 13 * according to ratio of preview to LS 14 */ 15 class ClockHostView( 16 context: Context, 17 attrs: AttributeSet?, 18 ) : FrameLayout(context, attrs) { 19 private var previewRatio: Float = 1F 20 set(value) { 21 if (field != value) { 22 field = value 23 scaleX = previewRatio 24 scaleY = previewRatio 25 invalidate() 26 } 27 } 28 onMeasurenull29 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 30 super.onMeasure(widthMeasureSpec, heightMeasureSpec) 31 val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) 32 previewRatio = measuredWidth / screenSize.x.toFloat() 33 } 34 35 /** 36 * In clock picker, we want to clock layout and render at lockscreen size and scale down so that 37 * the preview in clock carousel will be the same as lockscreen 38 */ measureChildWithMarginsnull39 override fun measureChildWithMargins( 40 child: View?, 41 parentWidthMeasureSpec: Int, 42 widthUsed: Int, 43 parentHeightMeasureSpec: Int, 44 heightUsed: Int 45 ) { 46 val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) 47 super.measureChildWithMargins( 48 child, 49 MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), 50 widthUsed, 51 MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), 52 heightUsed 53 ) 54 } 55 } 56