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 public long duration; 44 public boolean userControlled; 45 public @AnimationFlags int animFlags = 0; 46 47 48 // Various types of animation state transition 49 @IntDef(value = { 50 ANIM_VERTICAL_PROGRESS, 51 ANIM_WORKSPACE_SCALE, 52 ANIM_WORKSPACE_TRANSLATE, 53 ANIM_WORKSPACE_FADE, 54 ANIM_HOTSEAT_SCALE, 55 ANIM_HOTSEAT_TRANSLATE, 56 ANIM_HOTSEAT_FADE, 57 ANIM_OVERVIEW_SCALE, 58 ANIM_OVERVIEW_TRANSLATE_X, 59 ANIM_OVERVIEW_TRANSLATE_Y, 60 ANIM_OVERVIEW_FADE, 61 ANIM_ALL_APPS_FADE, 62 ANIM_SCRIM_FADE, 63 ANIM_OVERVIEW_MODAL, 64 ANIM_DEPTH, 65 ANIM_OVERVIEW_ACTIONS_FADE, 66 ANIM_WORKSPACE_PAGE_TRANSLATE_X, 67 ANIM_OVERVIEW_SPLIT_SELECT_FLOATING_TASK_TRANSLATE_OFFSCREEN, 68 ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE, 69 ANIM_ALL_APPS_BOTTOM_SHEET_FADE, 70 ANIM_ALL_APPS_KEYBOARD_FADE 71 }) 72 @Retention(RetentionPolicy.SOURCE) 73 public @interface AnimType {} 74 public static final int ANIM_VERTICAL_PROGRESS = 0; 75 public static final int ANIM_WORKSPACE_SCALE = 1; 76 public static final int ANIM_WORKSPACE_TRANSLATE = 2; 77 public static final int ANIM_WORKSPACE_FADE = 3; 78 public static final int ANIM_HOTSEAT_SCALE = 4; 79 public static final int ANIM_HOTSEAT_TRANSLATE = 5; 80 public static final int ANIM_HOTSEAT_FADE = 16; 81 public static final int ANIM_OVERVIEW_SCALE = 6; 82 public static final int ANIM_OVERVIEW_TRANSLATE_X = 7; 83 public static final int ANIM_OVERVIEW_TRANSLATE_Y = 8; 84 public static final int ANIM_OVERVIEW_FADE = 9; 85 public static final int ANIM_ALL_APPS_FADE = 10; 86 public static final int ANIM_SCRIM_FADE = 11; 87 public static final int ANIM_OVERVIEW_MODAL = 12; 88 public static final int ANIM_DEPTH = 13; 89 public static final int ANIM_OVERVIEW_ACTIONS_FADE = 14; 90 public static final int ANIM_WORKSPACE_PAGE_TRANSLATE_X = 15; 91 public static final int ANIM_OVERVIEW_SPLIT_SELECT_FLOATING_TASK_TRANSLATE_OFFSCREEN = 17; 92 public static final int ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE = 18; 93 public static final int ANIM_ALL_APPS_BOTTOM_SHEET_FADE = 19; 94 public static final int ANIM_ALL_APPS_KEYBOARD_FADE = 20; 95 96 private static final int ANIM_TYPES_COUNT = 21; 97 98 protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT]; 99 StateAnimationConfig()100 public StateAnimationConfig() { } 101 102 /** 103 * Copies the config to target 104 */ copyTo(StateAnimationConfig target)105 public void copyTo(StateAnimationConfig target) { 106 target.duration = duration; 107 target.animFlags = animFlags; 108 target.userControlled = userControlled; 109 for (int i = 0; i < ANIM_TYPES_COUNT; i++) { 110 target.mInterpolators[i] = mInterpolators[i]; 111 } 112 } 113 114 /** 115 * Returns the interpolator set for animId or fallback if nothing is set 116 * 117 * @see #setInterpolator(int, Interpolator) 118 */ getInterpolator(@nimType int animId, Interpolator fallback)119 public Interpolator getInterpolator(@AnimType int animId, Interpolator fallback) { 120 return mInterpolators[animId] == null ? fallback : mInterpolators[animId]; 121 } 122 123 /** 124 * Sets an interpolator for a given animation type 125 */ setInterpolator(@nimType int animId, Interpolator interpolator)126 public void setInterpolator(@AnimType int animId, Interpolator interpolator) { 127 mInterpolators[animId] = interpolator; 128 } 129 130 /** 131 * Returns true if the config and any of the provided component flags 132 */ hasAnimationFlag(@nimationFlags int a)133 public boolean hasAnimationFlag(@AnimationFlags int a) { 134 return (animFlags & a) != 0; 135 } 136 } 137