diff --git a/tests/SilkFX/src/com/android/test/silkfx/hdr/GainmapImage.kt b/tests/SilkFX/src/com/android/test/silkfx/hdr/GainmapImage.kt index 7cf69b7780d9f..31ea8327c2b37 100644 --- a/tests/SilkFX/src/com/android/test/silkfx/hdr/GainmapImage.kt +++ b/tests/SilkFX/src/com/android/test/silkfx/hdr/GainmapImage.kt @@ -16,6 +16,10 @@ package com.android.test.silkfx.hdr +import android.animation.AnimatorSet +import android.animation.ObjectAnimator +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas @@ -65,15 +69,9 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context findViewById(R.id.output_mode)!!.also { it.check(outputMode) it.setOnCheckedChangeListener { _, checkedId -> - val previousMode = outputMode outputMode = checkedId - if (previousMode == R.id.output_sdr && checkedId == R.id.output_hdr) { - animateToHdr() - } else if (previousMode == R.id.output_hdr && checkedId == R.id.output_sdr) { - animateToSdr() - } else { - updateDisplay() - } + // Intentionally don't do anything fancy so that mode A/B comparisons are easy + updateDisplay() } } @@ -103,10 +101,41 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context imageView.apply { isClickable = true + // Example of animating between SDR and HDR using gainmap params; animates HDR->SDR->HDR + // with a brief pause on SDR. The key thing here is that the gainmap's + // minDisplayRatioForHdrTransition is animated between its original value (for full HDR) + // and displayRatioForFullHdr (for full SDR). The view must also be invalidated during + // the animation for the updates to take effect. setOnClickListener { - animate().alpha(.5f).withEndAction { - animate().alpha(1f).start() - }.start() + if (gainmap != null && (outputMode == R.id.output_hdr || + outputMode == R.id.output_hdr_test)) { + val animationLengthMs: Long = 500 + val updateListener = object : AnimatorUpdateListener { + override fun onAnimationUpdate(animation: ValueAnimator) { + imageView.invalidate() + } + } + val hdrToSdr = ObjectAnimator.ofFloat( + gainmap, "minDisplayRatioForHdrTransition", + gainmap!!.minDisplayRatioForHdrTransition, + gainmap!!.displayRatioForFullHdr).apply { + duration = animationLengthMs + addUpdateListener(updateListener) + } + val sdrToHdr = ObjectAnimator.ofFloat( + gainmap, "minDisplayRatioForHdrTransition", + gainmap!!.displayRatioForFullHdr, + gainmap!!.minDisplayRatioForHdrTransition).apply { + duration = animationLengthMs + addUpdateListener(updateListener) + } + + AnimatorSet().apply { + play(hdrToSdr) + play(sdrToHdr).after(animationLengthMs) + start() + } + } } } } @@ -164,20 +193,6 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context updateDisplay() } - private fun animateToHdr() { - if (bitmap == null || gainmap == null) return - - // TODO: Trigger an animation - updateDisplay() - } - - private fun animateToSdr() { - if (bitmap == null) return - - // TODO: Trigger an animation - updateDisplay() - } - private fun updateDisplay() { if (bitmap == null) return