1 /*
2  * Copyright (C) 2016 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 
17 package com.android.systemui.recents.tv.animations;
18 
19 import android.content.Context;
20 import com.android.systemui.Interpolators;
21 import com.android.systemui.R;
22 import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
23 import com.android.systemui.recents.tv.views.TaskCardView;
24 import com.android.systemui.recents.tv.views.TaskStackHorizontalGridView;
25 
26 
27 public class HomeRecentsEnterExitAnimationHolder {
28 
29     private Context mContext;
30     private TaskStackHorizontalGridView mGridView;
31     private float mDimAlpha;
32     private long mDelay;
33     private int mDuration;
34     private int mTranslationX;
35 
HomeRecentsEnterExitAnimationHolder(Context context, TaskStackHorizontalGridView gridView)36     public HomeRecentsEnterExitAnimationHolder(Context context,
37             TaskStackHorizontalGridView gridView) {
38         mContext = context;
39         mGridView = gridView;
40         mDimAlpha = mContext.getResources().getFloat(R.dimen.recents_recents_row_dim_alpha);
41         mTranslationX = mContext.getResources()
42                 .getDimensionPixelSize(R.dimen.recents_tv_home_recents_shift);
43         mDelay = mContext.getResources().getInteger(R.integer.recents_home_delay);
44         mDuration =  mContext.getResources().getInteger(R.integer.recents_home_duration);
45     }
46 
startEnterAnimation(boolean isPipShown)47     public void startEnterAnimation(boolean isPipShown) {
48         for(int i = 0; i < mGridView.getChildCount(); i++) {
49             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
50             view.setTranslationX(-mTranslationX);
51             view.animate()
52                     .alpha(isPipShown ? mDimAlpha : 1.0f)
53                     .translationX(0)
54                     .setDuration(mDuration)
55                     .setStartDelay(mDelay * i)
56                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
57         }
58     }
59 
startExitAnimation(DismissRecentsToHomeAnimationStarted dismissEvent)60     public void startExitAnimation(DismissRecentsToHomeAnimationStarted dismissEvent) {
61         for(int i = mGridView.getChildCount() - 1; i >= 0; i--) {
62             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
63             view.animate()
64                     .alpha(0.0f)
65                     .translationXBy(-mTranslationX)
66                     .setDuration(mDuration)
67                     .setStartDelay(mDelay * (mGridView.getChildCount() - 1 - i))
68                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
69             if(i == 0) {
70                 view.animate().setListener(dismissEvent.getAnimationTrigger()
71                         .decrementOnAnimationEnd());
72                 dismissEvent.getAnimationTrigger().increment();
73             }
74         }
75     }
76 
77     /**
78      * Sets the initial values Recents enter animation
79      * when Recents is started from the Launcher.
80      */
setEnterFromHomeStartingAnimationValues(boolean isPipShown)81     public void setEnterFromHomeStartingAnimationValues(boolean isPipShown) {
82         for(int i = 0; i < mGridView.getChildCount(); i++) {
83             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
84             view.setTranslationX(0);
85             view.setAlpha(0.0f);
86             view.getInfoFieldView().setAlpha(isPipShown ? 0 : 1f);
87             if (isPipShown && view.hasFocus()) {
88                 view.getViewFocusAnimator().changeSize(false);
89             }
90         }
91     }
92 
93     /**
94      * Sets the initial values Recents enter animation
95      * when Recents is started from an app.
96      */
setEnterFromAppStartingAnimationValues(boolean isPipShown)97     public void setEnterFromAppStartingAnimationValues(boolean isPipShown) {
98         for(int i = 0; i < mGridView.getChildCount(); i++) {
99             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
100             view.setTranslationX(0);
101             view.setAlpha(isPipShown ? mDimAlpha : 1f);
102             view.getInfoFieldView().setAlpha(isPipShown ? 0 : 1f);
103             if (isPipShown && view.hasFocus()) {
104                 view.getViewFocusAnimator().changeSize(false);
105             }
106         }
107     }
108 }
109