Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert animation package to Kotlin #13509

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

@@ -0,0 +1,16 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.animation

import android.animation.Animator

abstract class AnimationCompleteListener : Animator.AnimatorListener {
abstract override fun onAnimationEnd(animation: Animator)

override fun onAnimationStart(animation: Animator) = Unit
override fun onAnimationCancel(animation: Animator) = Unit
override fun onAnimationRepeat(animation: Animator) = Unit
}

This file was deleted.

@@ -0,0 +1,19 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.animation

import android.animation.Animator
import java.util.function.Consumer

class AnimationRepeatListener(private val animationConsumer: Consumer<Animator>) : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) = Unit
override fun onAnimationEnd(animation: Animator) = Unit
override fun onAnimationCancel(animation: Animator) = Unit

override fun onAnimationRepeat(animation: Animator) {
animationConsumer.accept(animation)
}
}

This file was deleted.

@@ -0,0 +1,47 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.animation

import android.graphics.Point
import android.view.View
import android.view.animation.Animation
import android.view.animation.Transformation

class ResizeAnimation : Animation {
private val target: View
private val targetWidthPx: Int
private val targetHeightPx: Int

private var startWidth: Int = 0
private var startHeight: Int = 0

constructor(target: View, dimension: Point) : this(target, dimension.x, dimension.y)

constructor(target: View, targetWidthPx: Int, targetHeightPx: Int) {
this.target = target
this.targetWidthPx = targetWidthPx
this.targetHeightPx = targetHeightPx
}

override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
val newWidth = (startWidth + (targetWidthPx - startWidth) * interpolatedTime).toInt()
val newHeight = (startHeight + (targetHeightPx - startHeight) * interpolatedTime).toInt()

target.layoutParams.apply {
width = newWidth
height = newHeight
}
}

override fun initialize(width: Int, height: Int, parentWidth: Int, parentHeight: Int) {
super.initialize(width, height, parentWidth, parentHeight)

startWidth = width
startHeight = height
}

override fun willChangeBounds(): Boolean = true
}

This file was deleted.

@@ -0,0 +1,63 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.animation.transitions

import android.animation.Animator
import android.animation.ObjectAnimator
import android.util.Property
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.graphics.drawable.RoundedBitmapDrawable
import androidx.transition.Transition
import androidx.transition.TransitionValues
import kotlin.math.min

abstract class CircleSquareImageViewTransition(private val toCircle: Boolean) : Transition() {
companion object {
private const val CIRCLE_RATIO = "CIRCLE_RATIO"

class RadiusRatioProperty : Property<ImageView, Float>(Float::class.java, "circle_ratio") {
private var ratio: Float = 0.0f

override fun set(imageView: ImageView?, ratio: Float) {
this.ratio = ratio

imageView ?: return
val drawable = imageView.drawable as? RoundedBitmapDrawable ?: return
if (ratio > 0.95) {
drawable.isCircular = true
} else {
drawable.cornerRadius = min(drawable.intrinsicWidth, drawable.intrinsicHeight) * ratio * 0.5f
}
}

override fun get(imageView: ImageView?): Float = ratio
}
}

override fun captureStartValues(transitionValues: TransitionValues) {
if (transitionValues.view is ImageView) {
transitionValues.values[CIRCLE_RATIO] = if (toCircle) 0f else 1f
}
}

override fun captureEndValues(transitionValues: TransitionValues) {
if (transitionValues.view is ImageView) {
transitionValues.values[CIRCLE_RATIO] = if (toCircle) 1f else 0f
}
}

override fun createAnimator(sceneRoot: ViewGroup, startValues: TransitionValues?, endValues: TransitionValues?): Animator? {
startValues ?: return null
endValues ?: return null

val endImageView = endValues.view as ImageView
val start = startValues.values[CIRCLE_RATIO] as Float
val end = startValues.values[CIRCLE_RATIO] as Float

return ObjectAnimator.ofFloat(endImageView, RadiusRatioProperty(), start, end)
}
}

This file was deleted.

@@ -0,0 +1,17 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.animation.transitions

import android.content.Context
import android.util.AttributeSet

/**
* Will only transition [android.widget.ImageView]s that contain a [androidx.core.graphics.drawable.RoundedBitmapDrawable].
*/
class CircleToSquareImageViewTransition(
context: Context,
attrs: AttributeSet
) : CircleSquareImageViewTransition(false)

This file was deleted.