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_OFFSET; 19 20 import android.animation.Animator; 21 import android.animation.ObjectAnimator; 22 23 import com.android.launcher3.anim.SpringAnimationBuilder; 24 import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory; 25 import com.android.launcher3.statemanager.StatefulActivity; 26 import com.android.quickstep.views.RecentsView; 27 28 public class RecentsAtomicAnimationFactory<ACTIVITY_TYPE extends StatefulActivity, STATE_TYPE> 29 extends AtomicAnimationFactory<STATE_TYPE> { 30 31 public static final int INDEX_RECENTS_FADE_ANIM = AtomicAnimationFactory.NEXT_INDEX + 0; 32 public static final int INDEX_RECENTS_TRANSLATE_X_ANIM = AtomicAnimationFactory.NEXT_INDEX + 1; 33 34 private static final int MY_ANIM_COUNT = 2; 35 protected static final int NEXT_INDEX = AtomicAnimationFactory.NEXT_INDEX + MY_ANIM_COUNT; 36 37 protected final ACTIVITY_TYPE mActivity; 38 39 /** 40 * @param extraAnims number of animations supported by the subclass. This should not include 41 * the 2 animations supported by this class. 42 */ RecentsAtomicAnimationFactory(ACTIVITY_TYPE activity, int extraAnims)43 public RecentsAtomicAnimationFactory(ACTIVITY_TYPE activity, int extraAnims) { 44 super(MY_ANIM_COUNT + extraAnims); 45 mActivity = activity; 46 } 47 48 @Override createStateElementAnimation(int index, float... values)49 public Animator createStateElementAnimation(int index, float... values) { 50 switch (index) { 51 case INDEX_RECENTS_FADE_ANIM: 52 return ObjectAnimator.ofFloat(mActivity.getOverviewPanel(), 53 RecentsView.CONTENT_ALPHA, values); 54 case INDEX_RECENTS_TRANSLATE_X_ANIM: { 55 RecentsView rv = mActivity.getOverviewPanel(); 56 return new SpringAnimationBuilder(mActivity) 57 .setMinimumVisibleChange(1f / rv.getPageOffsetScale()) 58 .setDampingRatio(0.8f) 59 .setStiffness(250) 60 .setValues(values) 61 .build(rv, ADJACENT_PAGE_OFFSET); 62 } 63 default: 64 return super.createStateElementAnimation(index, values); 65 } 66 } 67 } 68