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