hc
2023-08-30 862c27fc9920c83318c784bfdadf43a65df1ec8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.rockchip.smart.rockhome.slidemenu.animation;
 
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
 
/**
 * Created by Konstantin on 22.12.2014.
 */
public class FlipAnimation extends Animation {
    private final float mFromDegrees;
    private final float mToDegrees;
    private final float mCenterX;
    private final float mCenterY;
    private Camera mCamera;
 
    public FlipAnimation(float fromDegrees, float toDegrees,
                         float centerX, float centerY) {
        mFromDegrees = fromDegrees;
        mToDegrees = toDegrees;
        mCenterX = centerX;
        mCenterY = centerY;
    }
 
    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        mCamera = new Camera();
    }
 
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final float fromDegrees = mFromDegrees;
        float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
 
        final float centerX = mCenterX;
        final float centerY = mCenterY;
        final Camera camera = mCamera;
 
        final Matrix matrix = t.getMatrix();
 
        camera.save();
 
        camera.rotateY(degrees);
 
        camera.getMatrix(matrix);
        camera.restore();
 
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX, centerY);
 
    }
 
}