Skip to content

Instantly share code, notes, and snippets.

@suzp1984
Last active March 5, 2017 14:41
Show Gist options
  • Select an option

  • Save suzp1984/c778faee57722239c541881b3fad30ef to your computer and use it in GitHub Desktop.

Select an option

Save suzp1984/c778faee57722239c541881b3fad30ef to your computer and use it in GitHub Desktop.
FlipAnimation
package suzp1984.github.io.exapidemo.animation
import android.graphics.Camera
import android.view.animation.Animation
import android.view.animation.Transformation
class FlipAnimation(fromDegre: Float, toDegre: Float, centerX : Float, centerY : Float) : Animation() {
var fromDegree : Float = 0.0f
var toDegree : Float = 0.0f
var centerX : Float = 0.0f
var centerY : Float = 0.0f
lateinit var camera : Camera
init {
this.fromDegree = fromDegre
this.toDegree = toDegre
this.centerX = centerX
this.centerY = centerY
}
override
fun initialize(width: Int, height: Int, parentWidth: Int, parentHeight: Int) {
super.initialize(width, height, parentWidth, parentHeight)
camera = Camera()
}
override fun applyTransformation(interpolatedTime: Float, t: Transformation) {
val degrees = fromDegree + (toDegree - fromDegree) * interpolatedTime
val camera = camera
val matrix = t.matrix
camera.save()
camera.rotateY(degrees)
camera.getMatrix(matrix)
camera.restore()
matrix.preTranslate(-centerX, -centerY)
matrix.postTranslate(centerX, centerY)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment