Last active
March 5, 2017 14:41
-
-
Save suzp1984/c778faee57722239c541881b3fad30ef to your computer and use it in GitHub Desktop.
FlipAnimation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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