• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.launcher3.states;
17 
18 import android.view.animation.Interpolator;
19 
20 import androidx.annotation.IntDef;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 
25 /**
26  * Utility class for building animator set
27  */
28 public class StateAnimationConfig {
29 
30     @IntDef(flag = true, value = {
31             SKIP_ALL_ANIMATIONS,
32             SKIP_OVERVIEW,
33             SKIP_DEPTH_CONTROLLER,
34             SKIP_SCRIM,
35     })
36     @Retention(RetentionPolicy.SOURCE)
37     public @interface AnimationFlags {}
38     public static final int SKIP_ALL_ANIMATIONS = 1 << 0;
39     public static final int SKIP_OVERVIEW = 1 << 1;
40     public static final int SKIP_DEPTH_CONTROLLER = 1 << 2;
41     public static final int SKIP_SCRIM = 1 << 3;
42 
43     @IntDef(flag = true, value = {
44             USER_CONTROLLED,
45             HANDLE_STATE_APPLY
46     })
47     @Retention(RetentionPolicy.SOURCE)
48     public @interface AnimationPropertyFlags {}
49     // Indicates that the animation is controlled by the user
50     public static final int USER_CONTROLLED = 1 << 0;
51     // Indicates that he animation can survive state UI resets due to inset or config changes
52     public static final int HANDLE_STATE_APPLY = 1 << 1;
53 
54     public long duration;
55     public @AnimationPropertyFlags int animProps = 0;
56     public @AnimationFlags int animFlags = 0;
57 
58 
59     // Various types of animation state transition
60     @IntDef(value = {
61             ANIM_VERTICAL_PROGRESS,
62             ANIM_WORKSPACE_SCALE,
63             ANIM_WORKSPACE_TRANSLATE,
64             ANIM_WORKSPACE_FADE,
65             ANIM_HOTSEAT_SCALE,
66             ANIM_HOTSEAT_TRANSLATE,
67             ANIM_HOTSEAT_FADE,
68             ANIM_OVERVIEW_SCALE,
69             ANIM_OVERVIEW_TRANSLATE_X,
70             ANIM_OVERVIEW_TRANSLATE_Y,
71             ANIM_OVERVIEW_FADE,
72             ANIM_ALL_APPS_FADE,
73             ANIM_SCRIM_FADE,
74             ANIM_OVERVIEW_MODAL,
75             ANIM_DEPTH,
76             ANIM_OVERVIEW_ACTIONS_FADE,
77             ANIM_WORKSPACE_PAGE_TRANSLATE_X,
78             ANIM_OVERVIEW_SPLIT_SELECT_FLOATING_TASK_TRANSLATE_OFFSCREEN,
79             ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE,
80             ANIM_ALL_APPS_KEYBOARD_FADE
81     })
82     @Retention(RetentionPolicy.SOURCE)
83     public @interface AnimType {}
84     public static final int ANIM_VERTICAL_PROGRESS = 0;
85     public static final int ANIM_WORKSPACE_SCALE = 1;
86     public static final int ANIM_WORKSPACE_TRANSLATE = 2;
87     public static final int ANIM_WORKSPACE_FADE = 3;
88     public static final int ANIM_HOTSEAT_SCALE = 4;
89     public static final int ANIM_HOTSEAT_TRANSLATE = 5;
90     public static final int ANIM_HOTSEAT_FADE = 16;
91     public static final int ANIM_OVERVIEW_SCALE = 6;
92     public static final int ANIM_OVERVIEW_TRANSLATE_X = 7;
93     public static final int ANIM_OVERVIEW_TRANSLATE_Y = 8;
94     public static final int ANIM_OVERVIEW_FADE = 9;
95     public static final int ANIM_ALL_APPS_FADE = 10;
96     public static final int ANIM_SCRIM_FADE = 11;
97     public static final int ANIM_OVERVIEW_MODAL = 12;
98     public static final int ANIM_DEPTH = 13;
99     public static final int ANIM_OVERVIEW_ACTIONS_FADE = 14;
100     public static final int ANIM_WORKSPACE_PAGE_TRANSLATE_X = 15;
101     public static final int ANIM_OVERVIEW_SPLIT_SELECT_FLOATING_TASK_TRANSLATE_OFFSCREEN = 17;
102     public static final int ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE = 18;
103     public static final int ANIM_ALL_APPS_KEYBOARD_FADE = 19;
104 
105     private static final int ANIM_TYPES_COUNT = 21;
106 
107     protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT];
108 
StateAnimationConfig()109     public StateAnimationConfig() { }
110 
111     /**
112      * Copies the config to target
113      */
copyTo(StateAnimationConfig target)114     public void copyTo(StateAnimationConfig target) {
115         target.duration = duration;
116         target.animFlags = animFlags;
117         target.animProps = animProps;
118         for (int i = 0; i < ANIM_TYPES_COUNT; i++) {
119             target.mInterpolators[i] = mInterpolators[i];
120         }
121     }
122 
isUserControlled()123     public boolean isUserControlled() {
124         return (animProps & USER_CONTROLLED) != 0;
125     }
126 
127     /**
128      * Returns the interpolator set for animId or fallback if nothing is set
129      *
130      * @see #setInterpolator(int, Interpolator)
131      */
getInterpolator(@nimType int animId, Interpolator fallback)132     public Interpolator getInterpolator(@AnimType int animId, Interpolator fallback) {
133         return mInterpolators[animId] == null ? fallback : mInterpolators[animId];
134     }
135 
136     /**
137      * Sets an interpolator for a given animation type
138      */
setInterpolator(@nimType int animId, Interpolator interpolator)139     public void setInterpolator(@AnimType int animId, Interpolator interpolator) {
140         mInterpolators[animId] = interpolator;
141     }
142 
143     /**
144      * Returns true if the config and any of the provided component flags
145      */
hasAnimationFlag(@nimationFlags int a)146     public boolean hasAnimationFlag(@AnimationFlags int a) {
147         return (animFlags & a) != 0;
148     }
149 }
150