• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 /** The standard interface to Easing functions */
19 public abstract class Easing {
20     int mType;
21 
22     /**
23      * get the value at point x
24      *
25      * @param x the position at which to get the slope
26      * @return the value at the point
27      */
get(float x)28     public abstract float get(float x);
29 
30     /**
31      * get the slope of the easing function at at x
32      *
33      * @param x the position at which to get the slope
34      * @return the slope
35      */
getDiff(float x)36     public abstract float getDiff(float x);
37 
38     /**
39      * get the type of easing function
40      *
41      * @return the type of easing function
42      */
getType()43     public int getType() {
44         return mType;
45     }
46 
47     /** cubic Easing function that accelerates and decelerates */
48     public static final int CUBIC_STANDARD = 1;
49 
50     /** cubic Easing function that accelerates */
51     public static final int CUBIC_ACCELERATE = 2;
52 
53     /** cubic Easing function that decelerates */
54     public static final int CUBIC_DECELERATE = 3;
55 
56     /** cubic Easing function that just linearly interpolates */
57     public static final int CUBIC_LINEAR = 4;
58 
59     /** cubic Easing function that goes bacwards and then accelerates */
60     public static final int CUBIC_ANTICIPATE = 5;
61 
62     /** cubic Easing function that overshoots and then goes back */
63     public static final int CUBIC_OVERSHOOT = 6;
64 
65     /** cubic Easing function that you customize */
66     public static final int CUBIC_CUSTOM = 11;
67 
68     /** a monotonic spline Easing function that you customize */
69     public static final int SPLINE_CUSTOM = 12;
70 
71     /** a bouncing Easing function */
72     public static final int EASE_OUT_BOUNCE = 13;
73 
74     /** a elastic Easing function */
75     public static final int EASE_OUT_ELASTIC = 14;
76 
77     /**
78      * Returns a string representation for the given value. Used during serialization.
79      *
80      * @param value
81      * @return
82      */
getString(int value)83     public static String getString(int value) {
84         switch (value) {
85             case CUBIC_STANDARD:
86                 return "CUBIC_STANDARD";
87             case CUBIC_ACCELERATE:
88                 return "CUBIC_ACCELERATE";
89             case CUBIC_DECELERATE:
90                 return "CUBIC_DECELERATE";
91             case CUBIC_LINEAR:
92                 return "CUBIC_LINEAR";
93             case CUBIC_ANTICIPATE:
94                 return "CUBIC_ANTICIPATE";
95             case CUBIC_OVERSHOOT:
96                 return "CUBIC_OVERSHOOT";
97             case CUBIC_CUSTOM:
98                 return "CUBIC_CUSTOM";
99             case SPLINE_CUSTOM:
100                 return "SPLINE_CUSTOM";
101             case EASE_OUT_BOUNCE:
102                 return "EASE_OUT_BOUNCE";
103             case EASE_OUT_ELASTIC:
104                 return "EASE_OUT_ELASTIC";
105             default:
106                 return "INVALID_CURVE_TYPE[" + value + "]";
107         }
108     }
109 }
110