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(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { 16 private var previewRatio: Float = 1F 17 set(value) { 18 if (field != value) { 19 field = value 20 scaleX = previewRatio 21 scaleY = previewRatio 22 invalidate() 23 } 24 } 25 onMeasurenull26 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 27 super.onMeasure(widthMeasureSpec, heightMeasureSpec) 28 val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) 29 previewRatio = measuredWidth / screenSize.x.toFloat() 30 } 31 32 /** 33 * In clock picker, we want to clock layout and render at lockscreen size and scale down so that 34 * the preview in clock carousel will be the same as lockscreen 35 */ measureChildWithMarginsnull36 override fun measureChildWithMargins( 37 child: View?, 38 parentWidthMeasureSpec: Int, 39 widthUsed: Int, 40 parentHeightMeasureSpec: Int, 41 heightUsed: Int, 42 ) { 43 44 val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) 45 super.measureChildWithMargins( 46 child, 47 MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), 48 widthUsed, 49 MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), 50 heightUsed, 51 ) 52 } 53 } 54