blob: 20457334c33c8ddd927b978cdb21d876064c298d [file] [log] [blame]
Sunny Goyalf3ac7032020-03-13 13:01:33 -07001/*
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 */
16package com.android.launcher3.states;
17
18import android.view.animation.Interpolator;
19
20import androidx.annotation.IntDef;
21
22import java.lang.annotation.Retention;
23import java.lang.annotation.RetentionPolicy;
24
25/**
26 * Utility class for building animator set
27 */
28public class StateAnimationConfig {
29
Sunny Goyalf3ac7032020-03-13 13:01:33 -070030 @IntDef(flag = true, value = {
Tony Wickham6cd95cd2021-03-23 17:22:28 -070031 PLAY_ANIMATION,
Sunny Goyalf3ac7032020-03-13 13:01:33 -070032 SKIP_OVERVIEW,
Tony Wickhamd683d982020-12-23 16:12:18 -060033 SKIP_DEPTH_CONTROLLER,
Sunny Goyalf3ac7032020-03-13 13:01:33 -070034 })
35 @Retention(RetentionPolicy.SOURCE)
36 public @interface AnimationFlags {}
Tony Wickham6cd95cd2021-03-23 17:22:28 -070037 // TODO: make this the default; invert this to be SKIP_ALL_ANIMATIONS
38 public static final int PLAY_ANIMATION = 1 << 0;
39 public static final int SKIP_OVERVIEW = 1 << 1;
40 public static final int SKIP_DEPTH_CONTROLLER = 1 << 2;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070041
42 public long duration;
43 public boolean userControlled;
Tony Wickham6cd95cd2021-03-23 17:22:28 -070044 public @AnimationFlags int animFlags = PLAY_ANIMATION;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070045
Sunny Goyalf3ac7032020-03-13 13:01:33 -070046
47 // Various types of animation state transition
48 @IntDef(value = {
49 ANIM_VERTICAL_PROGRESS,
50 ANIM_WORKSPACE_SCALE,
51 ANIM_WORKSPACE_TRANSLATE,
52 ANIM_WORKSPACE_FADE,
53 ANIM_HOTSEAT_SCALE,
54 ANIM_HOTSEAT_TRANSLATE,
55 ANIM_OVERVIEW_SCALE,
56 ANIM_OVERVIEW_TRANSLATE_X,
57 ANIM_OVERVIEW_TRANSLATE_Y,
58 ANIM_OVERVIEW_FADE,
59 ANIM_ALL_APPS_FADE,
60 ANIM_OVERVIEW_SCRIM_FADE,
61 ANIM_ALL_APPS_HEADER_FADE,
Tony Wickham10c2b4f2020-06-01 14:20:30 -050062 ANIM_OVERVIEW_MODAL,
63 ANIM_DEPTH,
Tony Wickham03a4a0c2020-07-17 13:06:57 -070064 ANIM_OVERVIEW_ACTIONS_FADE,
Sunny Goyalf3ac7032020-03-13 13:01:33 -070065 })
66 @Retention(RetentionPolicy.SOURCE)
67 public @interface AnimType {}
68 public static final int ANIM_VERTICAL_PROGRESS = 0;
69 public static final int ANIM_WORKSPACE_SCALE = 1;
70 public static final int ANIM_WORKSPACE_TRANSLATE = 2;
71 public static final int ANIM_WORKSPACE_FADE = 3;
72 public static final int ANIM_HOTSEAT_SCALE = 4;
73 public static final int ANIM_HOTSEAT_TRANSLATE = 5;
74 public static final int ANIM_OVERVIEW_SCALE = 6;
75 public static final int ANIM_OVERVIEW_TRANSLATE_X = 7;
76 public static final int ANIM_OVERVIEW_TRANSLATE_Y = 8;
77 public static final int ANIM_OVERVIEW_FADE = 9;
78 public static final int ANIM_ALL_APPS_FADE = 10;
79 public static final int ANIM_OVERVIEW_SCRIM_FADE = 11;
80 public static final int ANIM_ALL_APPS_HEADER_FADE = 12; // e.g. predictions
Zak Cohena39544d2020-04-27 16:26:55 -070081 public static final int ANIM_OVERVIEW_MODAL = 13;
Tony Wickham10c2b4f2020-06-01 14:20:30 -050082 public static final int ANIM_DEPTH = 14;
Tony Wickham03a4a0c2020-07-17 13:06:57 -070083 public static final int ANIM_OVERVIEW_ACTIONS_FADE = 15;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070084
Tony Wickhame63bd382021-03-22 17:19:41 -070085 private static final int ANIM_TYPES_COUNT = 16;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070086
Tony Wickham03a4a0c2020-07-17 13:06:57 -070087 protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT];
Sunny Goyalf3ac7032020-03-13 13:01:33 -070088
89 public StateAnimationConfig() { }
90
91 /**
92 * Copies the config to target
93 */
94 public void copyTo(StateAnimationConfig target) {
95 target.duration = duration;
96 target.animFlags = animFlags;
97 target.userControlled = userControlled;
98 for (int i = 0; i < ANIM_TYPES_COUNT; i++) {
99 target.mInterpolators[i] = mInterpolators[i];
100 }
101 }
102
103 /**
104 * Returns the interpolator set for animId or fallback if nothing is set
105 *
106 * @see #setInterpolator(int, Interpolator)
107 */
108 public Interpolator getInterpolator(@AnimType int animId, Interpolator fallback) {
109 return mInterpolators[animId] == null ? fallback : mInterpolators[animId];
110 }
111
112 /**
113 * Sets an interpolator for a given animation type
114 */
115 public void setInterpolator(@AnimType int animId, Interpolator interpolator) {
116 mInterpolators[animId] = interpolator;
117 }
118
119 /**
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700120 * Returns true if the config and any of the provided component flags
121 */
122 public boolean hasAnimationFlag(@AnimationFlags int a) {
123 return (animFlags & a) != 0;
124 }
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700125}