• 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 
17 package com.android.wm.shell.shared.animation;
18 
19 import android.graphics.Path;
20 import android.view.animation.BackGestureInterpolator;
21 import android.view.animation.Interpolator;
22 import android.view.animation.LinearInterpolator;
23 import android.view.animation.PathInterpolator;
24 
25 /**
26  * Common interpolators used in wm shell library.
27  */
28 public class Interpolators {
29 
30     public static final Interpolator LINEAR = new LinearInterpolator();
31 
32     /**
33      * Interpolator for alpha in animation.
34      */
35     public static final Interpolator ALPHA_IN = new PathInterpolator(0.4f, 0f, 1f, 1f);
36 
37     /**
38      * Interpolator for alpha out animation.
39      */
40     public static final Interpolator ALPHA_OUT = new PathInterpolator(0f, 0f, 0.8f, 1f);
41 
42     /**
43      * Interpolator for fast out linear in animation.
44      */
45     public static final Interpolator FAST_OUT_LINEAR_IN = new PathInterpolator(0.4f, 0f, 1f, 1f);
46 
47     /**
48      * Interpolator for fast out slow in animation.
49      */
50     public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
51 
52     /**
53      * Interpolator for linear out slow in animation.
54      */
55     public static final Interpolator LINEAR_OUT_SLOW_IN = new PathInterpolator(0f, 0f, 0.2f, 1f);
56 
57     /**
58      * The default emphasized interpolator. Used for hero / emphasized movement of content.
59      */
60     public static final Interpolator EMPHASIZED = createEmphasizedInterpolator();
61 
62     /**
63      * The accelerated emphasized interpolator. Used for hero / emphasized movement of content that
64      * is disappearing e.g. when moving off screen.
65      */
66     public static final Interpolator EMPHASIZED_ACCELERATE = new PathInterpolator(
67             0.3f, 0f, 0.8f, 0.15f);
68 
69     /**
70      * The decelerating emphasized interpolator. Used for hero / emphasized movement of content that
71      * is appearing e.g. when coming from off screen
72      */
73     public static final Interpolator EMPHASIZED_DECELERATE = new PathInterpolator(
74             0.05f, 0.7f, 0.1f, 1f);
75 
76     /**
77      * The standard accelerating interpolator that should be used on every regular movement of
78      * content that is disappearing e.g. when moving off screen.
79      */
80     public static final Interpolator STANDARD_ACCELERATE = new PathInterpolator(0.3f, 0f, 1f, 1f);
81 
82     /**
83      * The standard decelerating interpolator that should be used on every regular movement of
84      * content that is appearing e.g. when coming from off screen.
85      */
86     public static final Interpolator STANDARD_DECELERATE = new PathInterpolator(0f, 0f, 0f, 1f);
87 
88     /**
89      * Interpolator to be used when animating a move based on a click. Pair with enough duration.
90      */
91     public static final Interpolator TOUCH_RESPONSE = new PathInterpolator(0.3f, 0f, 0.1f, 1f);
92 
93     /**
94      * Interpolator to be used when animating a panel closing.
95      */
96     public static final Interpolator PANEL_CLOSE_ACCELERATED =
97             new PathInterpolator(0.3f, 0, 0.5f, 1);
98 
99     public static final PathInterpolator SLOWDOWN_INTERPOLATOR =
100             new PathInterpolator(0.5f, 1f, 0.5f, 1f);
101 
102     /**
103      * An interpolator used for dimming a task as it travels offscreen, or towards a distant dismiss
104      * point. A sharp rise, followed by a steady middle, and ending with another sharp rise.
105      */
106     public static final PathInterpolator DIM_INTERPOLATOR =
107             new PathInterpolator(.23f, .87f, .52f, -0.11f);
108 
109     /**
110      * An interpolator used for dimming a task very quickly. Roughly approximates one of the "sharp
111      * rises" of {@link #DIM_INTERPOLATOR}.
112      */
113     public static final PathInterpolator FAST_DIM_INTERPOLATOR =
114             new PathInterpolator(0.23f, 0.87f, 0.83f, 0.83f);
115 
116     /**
117      * Use this interpolator for animating progress values coming from the back callback to get
118      * the predictive-back-typical decelerate motion.
119      *
120      * This interpolator is similar to {@link Interpolators#STANDARD_DECELERATE} but has a slight
121      * acceleration phase at the start.
122      */
123     public static final Interpolator BACK_GESTURE = new BackGestureInterpolator();
124 
125     // Create the default emphasized interpolator
createEmphasizedInterpolator()126     private static PathInterpolator createEmphasizedInterpolator() {
127         Path path = new Path();
128         // Doing the same as fast_out_extra_slow_in
129         path.moveTo(0f, 0f);
130         path.cubicTo(0.05f, 0f, 0.133333f, 0.06f, 0.166666f, 0.4f);
131         path.cubicTo(0.208333f, 0.82f, 0.25f, 1f, 1f, 1f);
132         return new PathInterpolator(path);
133     }
134 }
135