• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.internal.widget.remotecompose.core.operations.utilities.easing;
17 
18 import android.annotation.NonNull;
19 
20 /** Provides and interface to create easing functions */
21 public class GeneralEasing extends Easing {
22     @NonNull float[] mEasingData = new float[0];
23     @NonNull Easing mEasingCurve = new CubicEasing(CUBIC_STANDARD);
24 
25     /**
26      * Set the curve based on the float encoding of it
27      *
28      * @param data the float encoding of the curve
29      */
setCurveSpecification(@onNull float[] data)30     public void setCurveSpecification(@NonNull float[] data) {
31         mEasingData = data;
32         createEngine();
33     }
34 
35     /**
36      * Get the float encoding of the curve
37      *
38      * @return the float encoding of the curve
39      */
getCurveSpecification()40     public @NonNull float[] getCurveSpecification() {
41         return mEasingData;
42     }
43 
createEngine()44     void createEngine() {
45         int type = Float.floatToRawIntBits(mEasingData[0]);
46         switch (type) {
47             case CUBIC_STANDARD:
48             case CUBIC_ACCELERATE:
49             case CUBIC_DECELERATE:
50             case CUBIC_LINEAR:
51             case CUBIC_ANTICIPATE:
52             case CUBIC_OVERSHOOT:
53                 mEasingCurve = new CubicEasing(type);
54                 break;
55             case CUBIC_CUSTOM:
56                 mEasingCurve =
57                         new CubicEasing(
58                                 mEasingData[1], mEasingData[2], mEasingData[3], mEasingData[5]);
59                 break;
60             case EASE_OUT_BOUNCE:
61                 mEasingCurve = new BounceCurve(type);
62                 break;
63         }
64     }
65 
66     /** get the value at point x */
67     @Override
get(float x)68     public float get(float x) {
69         return mEasingCurve.get(x);
70     }
71 
72     /** get the slope of the easing function at at x */
73     @Override
getDiff(float x)74     public float getDiff(float x) {
75         return mEasingCurve.getDiff(x);
76     }
77 
78     @Override
getType()79     public int getType() {
80         return mEasingCurve.getType();
81     }
82 }
83