Loading res/layout/clock_host_view.xml +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <com.android.customization.picker.clock.ui.view.ClockHostView2 <com.android.customization.picker.clock.ui.view.ClockConstraintLayoutHostView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/clock_host_view" android:importantForAccessibility="noHideDescendants" Loading src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt +8 −4 Original line number Diff line number Diff line Loading @@ -41,10 +41,10 @@ import androidx.recyclerview.widget.RecyclerView import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.ui.adapter.ClockSettingsTabAdapter import com.android.customization.picker.clock.ui.view.ClockCarouselView import com.android.customization.picker.clock.ui.view.ClockHostView import com.android.customization.picker.clock.ui.view.ClockViewFactory import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel import com.android.customization.picker.color.ui.binder.ColorOptionIconBinder import com.android.systemui.shared.Flags import com.android.themepicker.R import com.android.wallpaper.picker.common.ui.view.ItemSpacing import com.android.wallpaper.picker.option.ui.binder.OptionItemBinder Loading @@ -64,7 +64,10 @@ object ClockSettingsBinder { clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ) { val clockHostView: ClockHostView = view.requireViewById(R.id.clock_host_view) if (Flags.newCustomizationPickerUi()) { return } val clockHostView: ViewGroup = view.requireViewById(R.id.clock_host_view) val tabView: RecyclerView = view.requireViewById(R.id.tabs) val tabAdapter = ClockSettingsTabAdapter() tabView.adapter = tabAdapter Loading Loading @@ -204,10 +207,11 @@ object ClockSettingsBinder { ClockSize.DYNAMIC -> clockViewFactory.getLargeView(clockId) ClockSize.SMALL -> clockViewFactory.getSmallView(clockId) } // The clock view might still be attached to an existing parent. Detach // before adding to another parent. // The clock view might still be attached to an existing parent. // Detach before adding to another parent. (clockView.parent as? ViewGroup)?.removeView(clockView) clockHostView.addView(clockView) when (size) { ClockSize.DYNAMIC -> { // When clock size data flow emits clock size signal, we want Loading src/com/android/customization/picker/clock/ui/view/ClockHostView2.kt→src/com/android/customization/picker/clock/ui/view/ClockConstraintLayoutHostView.kt +74 −0 Original line number Diff line number Diff line Loading @@ -19,66 +19,56 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.view.View.MeasureSpec.EXACTLY import android.widget.FrameLayout import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout import com.android.customization.picker.clock.shared.ClockSize import com.android.systemui.plugins.clocks.ClockController import com.android.wallpaper.util.ScreenSizeCalculator /** * Parent view for the clock view. We will calculate the current display size and the preview size * and scale down the clock view to fit in the preview. */ class ClockHostView2(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { var clockSize: ClockSize = ClockSize.DYNAMIC set(value) { if (field != value) { field = value updatePivotAndScale() invalidate() } } override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { super.onLayout(changed, left, top, right, bottom) updatePivotAndScale() } override fun measureChildWithMargins( child: View?, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int, ) { class ClockConstraintLayoutHostView(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) super.measureChildWithMargins( child, super.onMeasure( MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), widthUsed, MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), heightUsed, ) val ratio = MeasureSpec.getSize(widthMeasureSpec) / screenSize.x.toFloat() scaleX = ratio scaleY = ratio } private fun updatePivotAndScale() { when (clockSize) { companion object { fun addClockViews( clockController: ClockController, rootView: ClockConstraintLayoutHostView, size: ClockSize, ) { clockController.let { clock -> when (size) { ClockSize.DYNAMIC -> { resetPivot() clock.largeClock.layout.views.forEach { if (it.parent != null) { (it.parent as ViewGroup).removeView(it) } rootView.addView(it).apply { it.visibility = View.VISIBLE } } } ClockSize.SMALL -> { pivotX = getCenteredHostViewPivotX(this) pivotY = 0F clock.smallClock.layout.views.forEach { if (it.parent != null) { (it.parent as ViewGroup).removeView(it) } rootView.addView(it).apply { it.visibility = View.VISIBLE } } } } val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) val ratio = measuredWidth / screenSize.x.toFloat() scaleX = ratio scaleY = ratio } companion object { fun getCenteredHostViewPivotX(hostView: View): Float { return if (hostView.isLayoutRtl) hostView.width.toFloat() else 0F } } } src/com/android/customization/picker/clock/ui/view/ClockHostView.kt +4 −6 Original line number Diff line number Diff line Loading @@ -12,10 +12,7 @@ import com.android.wallpaper.util.ScreenSizeCalculator * same size of lockscreen to layout clock and scale down it to the size in picker carousel * according to ratio of preview to LS */ class ClockHostView( context: Context, attrs: AttributeSet?, ) : FrameLayout(context, attrs) { class ClockHostView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { private var previewRatio: Float = 1F set(value) { if (field != value) { Loading @@ -41,15 +38,16 @@ class ClockHostView( parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int heightUsed: Int, ) { val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) super.measureChildWithMargins( child, MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), widthUsed, MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), heightUsed heightUsed, ) } } src/com/android/customization/picker/clock/ui/view/ThemePickerClockViewFactory.kt +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import com.android.internal.policy.SystemBarUtils import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.shared.Flags import com.android.systemui.shared.clocks.ClockRegistry import com.android.wallpaper.util.ScreenSizeCalculator import com.android.wallpaper.util.TimeUtils.TimeTicker Loading Loading @@ -64,6 +65,7 @@ constructor( * configs, e.g. animation state, might change during the reuse of the clock view in the app. */ override fun getLargeView(clockId: String): View { assert(!Flags.newCustomizationPickerUi()) return getController(clockId).largeClock.let { it.animations.onPickerCarouselSwiping(1F) it.view Loading @@ -75,6 +77,7 @@ constructor( * configs, e.g. translation X, might change during the reuse of the clock view in the app. */ override fun getSmallView(clockId: String): View { assert(!Flags.newCustomizationPickerUi()) val smallClockFrame = smallClockFrames[clockId] ?: createSmallClockFrame().also { Loading Loading
res/layout/clock_host_view.xml +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <com.android.customization.picker.clock.ui.view.ClockHostView2 <com.android.customization.picker.clock.ui.view.ClockConstraintLayoutHostView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/clock_host_view" android:importantForAccessibility="noHideDescendants" Loading
src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt +8 −4 Original line number Diff line number Diff line Loading @@ -41,10 +41,10 @@ import androidx.recyclerview.widget.RecyclerView import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.ui.adapter.ClockSettingsTabAdapter import com.android.customization.picker.clock.ui.view.ClockCarouselView import com.android.customization.picker.clock.ui.view.ClockHostView import com.android.customization.picker.clock.ui.view.ClockViewFactory import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel import com.android.customization.picker.color.ui.binder.ColorOptionIconBinder import com.android.systemui.shared.Flags import com.android.themepicker.R import com.android.wallpaper.picker.common.ui.view.ItemSpacing import com.android.wallpaper.picker.option.ui.binder.OptionItemBinder Loading @@ -64,7 +64,10 @@ object ClockSettingsBinder { clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ) { val clockHostView: ClockHostView = view.requireViewById(R.id.clock_host_view) if (Flags.newCustomizationPickerUi()) { return } val clockHostView: ViewGroup = view.requireViewById(R.id.clock_host_view) val tabView: RecyclerView = view.requireViewById(R.id.tabs) val tabAdapter = ClockSettingsTabAdapter() tabView.adapter = tabAdapter Loading Loading @@ -204,10 +207,11 @@ object ClockSettingsBinder { ClockSize.DYNAMIC -> clockViewFactory.getLargeView(clockId) ClockSize.SMALL -> clockViewFactory.getSmallView(clockId) } // The clock view might still be attached to an existing parent. Detach // before adding to another parent. // The clock view might still be attached to an existing parent. // Detach before adding to another parent. (clockView.parent as? ViewGroup)?.removeView(clockView) clockHostView.addView(clockView) when (size) { ClockSize.DYNAMIC -> { // When clock size data flow emits clock size signal, we want Loading
src/com/android/customization/picker/clock/ui/view/ClockHostView2.kt→src/com/android/customization/picker/clock/ui/view/ClockConstraintLayoutHostView.kt +74 −0 Original line number Diff line number Diff line Loading @@ -19,66 +19,56 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.view.View.MeasureSpec.EXACTLY import android.widget.FrameLayout import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout import com.android.customization.picker.clock.shared.ClockSize import com.android.systemui.plugins.clocks.ClockController import com.android.wallpaper.util.ScreenSizeCalculator /** * Parent view for the clock view. We will calculate the current display size and the preview size * and scale down the clock view to fit in the preview. */ class ClockHostView2(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { var clockSize: ClockSize = ClockSize.DYNAMIC set(value) { if (field != value) { field = value updatePivotAndScale() invalidate() } } override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { super.onLayout(changed, left, top, right, bottom) updatePivotAndScale() } override fun measureChildWithMargins( child: View?, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int, ) { class ClockConstraintLayoutHostView(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) super.measureChildWithMargins( child, super.onMeasure( MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), widthUsed, MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), heightUsed, ) val ratio = MeasureSpec.getSize(widthMeasureSpec) / screenSize.x.toFloat() scaleX = ratio scaleY = ratio } private fun updatePivotAndScale() { when (clockSize) { companion object { fun addClockViews( clockController: ClockController, rootView: ClockConstraintLayoutHostView, size: ClockSize, ) { clockController.let { clock -> when (size) { ClockSize.DYNAMIC -> { resetPivot() clock.largeClock.layout.views.forEach { if (it.parent != null) { (it.parent as ViewGroup).removeView(it) } rootView.addView(it).apply { it.visibility = View.VISIBLE } } } ClockSize.SMALL -> { pivotX = getCenteredHostViewPivotX(this) pivotY = 0F clock.smallClock.layout.views.forEach { if (it.parent != null) { (it.parent as ViewGroup).removeView(it) } rootView.addView(it).apply { it.visibility = View.VISIBLE } } } } val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) val ratio = measuredWidth / screenSize.x.toFloat() scaleX = ratio scaleY = ratio } companion object { fun getCenteredHostViewPivotX(hostView: View): Float { return if (hostView.isLayoutRtl) hostView.width.toFloat() else 0F } } }
src/com/android/customization/picker/clock/ui/view/ClockHostView.kt +4 −6 Original line number Diff line number Diff line Loading @@ -12,10 +12,7 @@ import com.android.wallpaper.util.ScreenSizeCalculator * same size of lockscreen to layout clock and scale down it to the size in picker carousel * according to ratio of preview to LS */ class ClockHostView( context: Context, attrs: AttributeSet?, ) : FrameLayout(context, attrs) { class ClockHostView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { private var previewRatio: Float = 1F set(value) { if (field != value) { Loading @@ -41,15 +38,16 @@ class ClockHostView( parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int heightUsed: Int, ) { val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display) super.measureChildWithMargins( child, MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY), widthUsed, MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY), heightUsed heightUsed, ) } }
src/com/android/customization/picker/clock/ui/view/ThemePickerClockViewFactory.kt +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import com.android.internal.policy.SystemBarUtils import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.shared.Flags import com.android.systemui.shared.clocks.ClockRegistry import com.android.wallpaper.util.ScreenSizeCalculator import com.android.wallpaper.util.TimeUtils.TimeTicker Loading Loading @@ -64,6 +65,7 @@ constructor( * configs, e.g. animation state, might change during the reuse of the clock view in the app. */ override fun getLargeView(clockId: String): View { assert(!Flags.newCustomizationPickerUi()) return getController(clockId).largeClock.let { it.animations.onPickerCarouselSwiping(1F) it.view Loading @@ -75,6 +77,7 @@ constructor( * configs, e.g. translation X, might change during the reuse of the clock view in the app. */ override fun getSmallView(clockId: String): View { assert(!Flags.newCustomizationPickerUi()) val smallClockFrame = smallClockFrames[clockId] ?: createSmallClockFrame().also { Loading