Improve clock carousel
1. Middle card should be 0.0 at the initial state
2. Avoid time tick while carousel in transition
3. Make sure time tick when on populate the clock carousel item view
Test: Manually test that it works as expected
Bug: 277623986
Change-Id: I43a356abc80ee4cf1f95bd450fd097c40d7b6d7d
diff --git a/res/layout/clock_carousel.xml b/res/layout/clock_carousel.xml
index f6c408b..25af031 100644
--- a/res/layout/clock_carousel.xml
+++ b/res/layout/clock_carousel.xml
@@ -94,6 +94,7 @@
android:id="@+id/item_card_2"
android:layout_width="@dimen/clock_carousel_item_card_width"
android:layout_height="@dimen/clock_carousel_item_card_height"
+ android:alpha="0.0"
android:layout_gravity="center"
android:background="@drawable/carousel_item_card_background"/>
diff --git a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
index 925e293..30eac55 100644
--- a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
+++ b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
@@ -89,7 +89,9 @@
LifecycleEventObserver { source, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
- clockViewFactory.registerTimeTicker(source)
+ clockViewFactory.registerTimeTicker(source) {
+ !carouselView.isCarouselInTransition
+ }
}
Lifecycle.Event.ON_PAUSE -> {
clockViewFactory.unregisterTimeTicker(source)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
index 48d3de3..a27d019 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
@@ -17,7 +17,6 @@
import android.content.Context
import android.util.AttributeSet
-import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -37,6 +36,8 @@
attrs,
) {
+ var isCarouselInTransition = false
+
private val carousel: Carousel
private val motionLayout: MotionLayout
private lateinit var adapter: ClockCarouselAdapter
@@ -70,7 +71,7 @@
startId: Int,
endId: Int
) {
- Log.d("mmpud", "onTransitionStarted")
+ isCarouselInTransition = true
val scalingDownClockId = adapter.clockIds[carousel.currentIndex]
val scalingUpIdx =
if (endId == R.id.next) (carousel.currentIndex + 1) % adapter.count()
@@ -115,7 +116,9 @@
hidingCardView?.alpha = getHidingAlpha(progress)
}
- override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {}
+ override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
+ isCarouselInTransition = false
+ }
override fun onTransitionTrigger(
motionLayout: MotionLayout?,
@@ -158,6 +161,8 @@
clockHostView.removeAllViews()
val clockView = onGetClockController(clockIds[index]).largeClock.view
+ // Making sure the large clock tick to the correct time
+ onGetClockController(clockIds[index]).largeClock.events.onTimeTick()
// The clock view might still be attached to an existing parent. Detach before adding to
// another parent.
(clockView.parent as? ViewGroup)?.removeView(clockView)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
index 67c7002..6c1e76a 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
@@ -33,7 +33,7 @@
) {
private val timeTickListeners: ConcurrentHashMap<Int, TimeTicker> = ConcurrentHashMap()
private val clockControllers: HashMap<String, ClockController> = HashMap()
- private var ticker: TimeTicker? = null
+
fun getRatio(): Float {
val screenSizeCalculator = ScreenSizeCalculator.getInstance()
val screenSize = screenSizeCalculator.getScreenSize(activity.windowManager.defaultDisplay)
@@ -60,16 +60,27 @@
}
fun registerTimeTicker(owner: LifecycleOwner) {
+ registerTimeTicker(owner, null)
+ }
+
+ fun registerTimeTicker(owner: LifecycleOwner, shouldTimeTick: (() -> Boolean)?) {
val hashCode = owner.hashCode()
if (timeTickListeners.keys.contains(hashCode)) {
return
}
+
timeTickListeners[hashCode] =
TimeTicker.registerNewReceiver(activity.applicationContext) {
- clockControllers.values.forEach { it.largeClock.events.onTimeTick() }
+ if (shouldTimeTick == null || shouldTimeTick()) {
+ onTimeTick()
+ }
}
}
+ private fun onTimeTick() {
+ clockControllers.values.forEach { it.largeClock.events.onTimeTick() }
+ }
+
fun unregisterTimeTicker(owner: LifecycleOwner) {
val hashCode = owner.hashCode()
timeTickListeners[hashCode]?.let {