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.quickstep.util; 17 18 import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET; 19 20 import android.animation.Animator; 21 import android.animation.ObjectAnimator; 22 import android.content.Context; 23 24 import androidx.dynamicanimation.animation.DynamicAnimation; 25 26 import com.android.launcher3.anim.SpringAnimationBuilder; 27 import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory; 28 import com.android.quickstep.views.RecentsView; 29 import com.android.quickstep.views.RecentsViewContainer; 30 31 public class RecentsAtomicAnimationFactory<CONTAINER extends Context & RecentsViewContainer, 32 STATE_TYPE> extends AtomicAnimationFactory<STATE_TYPE> { 33 34 public static final int INDEX_RECENTS_FADE_ANIM = AtomicAnimationFactory.NEXT_INDEX + 0; 35 public static final int INDEX_RECENTS_TRANSLATE_X_ANIM = AtomicAnimationFactory.NEXT_INDEX + 1; 36 37 private static final int MY_ANIM_COUNT = 2; 38 39 protected final CONTAINER mContainer; 40 RecentsAtomicAnimationFactory(CONTAINER container)41 public RecentsAtomicAnimationFactory(CONTAINER container) { 42 super(MY_ANIM_COUNT); 43 mContainer = container; 44 } 45 46 @Override createStateElementAnimation(int index, float... values)47 public Animator createStateElementAnimation(int index, float... values) { 48 switch (index) { 49 case INDEX_RECENTS_FADE_ANIM: 50 ObjectAnimator alpha = ObjectAnimator.ofFloat(mContainer.getOverviewPanel(), 51 RecentsView.CONTENT_ALPHA, values); 52 return alpha; 53 case INDEX_RECENTS_TRANSLATE_X_ANIM: { 54 RecentsView rv = mContainer.getOverviewPanel(); 55 return new SpringAnimationBuilder(mContainer) 56 .setMinimumVisibleChange(DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE) 57 .setDampingRatio(0.8f) 58 .setStiffness(250) 59 .setValues(values) 60 .build(rv, ADJACENT_PAGE_HORIZONTAL_OFFSET); 61 } 62 default: 63 return super.createStateElementAnimation(index, values); 64 } 65 } 66 } 67