blob: 0dbfb0b15ffb43f28ceab41c27a3b2cb067f8b0c [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 Wickham52bbcc32021-03-25 11:22:21 -070031 SKIP_ALL_ANIMATIONS,
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 Wickham52bbcc32021-03-25 11:22:21 -070037 public static final int SKIP_ALL_ANIMATIONS = 1 << 0;
Tony Wickham6cd95cd2021-03-23 17:22:28 -070038 public static final int SKIP_OVERVIEW = 1 << 1;
39 public static final int SKIP_DEPTH_CONTROLLER = 1 << 2;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070040
41 public long duration;
42 public boolean userControlled;
Tony Wickham52bbcc32021-03-25 11:22:21 -070043 public @AnimationFlags int animFlags = 0;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070044
Sunny Goyalf3ac7032020-03-13 13:01:33 -070045
46 // Various types of animation state transition
47 @IntDef(value = {
48 ANIM_VERTICAL_PROGRESS,
49 ANIM_WORKSPACE_SCALE,
50 ANIM_WORKSPACE_TRANSLATE,
51 ANIM_WORKSPACE_FADE,
52 ANIM_HOTSEAT_SCALE,
53 ANIM_HOTSEAT_TRANSLATE,
54 ANIM_OVERVIEW_SCALE,
55 ANIM_OVERVIEW_TRANSLATE_X,
56 ANIM_OVERVIEW_TRANSLATE_Y,
57 ANIM_OVERVIEW_FADE,
58 ANIM_ALL_APPS_FADE,
Sunny Goyalc82916f2021-04-06 13:03:54 -070059 ANIM_WORKSPACE_SCRIM_FADE,
Sunny Goyalf3ac7032020-03-13 13:01:33 -070060 ANIM_ALL_APPS_HEADER_FADE,
Tony Wickham10c2b4f2020-06-01 14:20:30 -050061 ANIM_OVERVIEW_MODAL,
62 ANIM_DEPTH,
Tony Wickham03a4a0c2020-07-17 13:06:57 -070063 ANIM_OVERVIEW_ACTIONS_FADE,
Sunny Goyalf3ac7032020-03-13 13:01:33 -070064 })
65 @Retention(RetentionPolicy.SOURCE)
66 public @interface AnimType {}
67 public static final int ANIM_VERTICAL_PROGRESS = 0;
68 public static final int ANIM_WORKSPACE_SCALE = 1;
69 public static final int ANIM_WORKSPACE_TRANSLATE = 2;
70 public static final int ANIM_WORKSPACE_FADE = 3;
71 public static final int ANIM_HOTSEAT_SCALE = 4;
72 public static final int ANIM_HOTSEAT_TRANSLATE = 5;
73 public static final int ANIM_OVERVIEW_SCALE = 6;
74 public static final int ANIM_OVERVIEW_TRANSLATE_X = 7;
75 public static final int ANIM_OVERVIEW_TRANSLATE_Y = 8;
76 public static final int ANIM_OVERVIEW_FADE = 9;
77 public static final int ANIM_ALL_APPS_FADE = 10;
Sunny Goyalc82916f2021-04-06 13:03:54 -070078 public static final int ANIM_WORKSPACE_SCRIM_FADE = 11;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070079 public static final int ANIM_ALL_APPS_HEADER_FADE = 12; // e.g. predictions
Zak Cohena39544d2020-04-27 16:26:55 -070080 public static final int ANIM_OVERVIEW_MODAL = 13;
Tony Wickham10c2b4f2020-06-01 14:20:30 -050081 public static final int ANIM_DEPTH = 14;
Tony Wickham03a4a0c2020-07-17 13:06:57 -070082 public static final int ANIM_OVERVIEW_ACTIONS_FADE = 15;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070083
Tony Wickhame63bd382021-03-22 17:19:41 -070084 private static final int ANIM_TYPES_COUNT = 16;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070085
Tony Wickham03a4a0c2020-07-17 13:06:57 -070086 protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT];
Sunny Goyalf3ac7032020-03-13 13:01:33 -070087
88 public StateAnimationConfig() { }
89
90 /**
91 * Copies the config to target
92 */
93 public void copyTo(StateAnimationConfig target) {
94 target.duration = duration;
95 target.animFlags = animFlags;
96 target.userControlled = userControlled;
97 for (int i = 0; i < ANIM_TYPES_COUNT; i++) {
98 target.mInterpolators[i] = mInterpolators[i];
99 }
100 }
101
102 /**
103 * Returns the interpolator set for animId or fallback if nothing is set
104 *
105 * @see #setInterpolator(int, Interpolator)
106 */
107 public Interpolator getInterpolator(@AnimType int animId, Interpolator fallback) {
108 return mInterpolators[animId] == null ? fallback : mInterpolators[animId];
109 }
110
111 /**
112 * Sets an interpolator for a given animation type
113 */
114 public void setInterpolator(@AnimType int animId, Interpolator interpolator) {
115 mInterpolators[animId] = interpolator;
116 }
117
118 /**
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700119 * Returns true if the config and any of the provided component flags
120 */
121 public boolean hasAnimationFlag(@AnimationFlags int a) {
122 return (animFlags & a) != 0;
123 }
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700124}