HomeRecentsEnterExitAnimationHolder.java revision 419c89533a148d0037e98b801068bb81f8a2cd2a
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
17package com.android.systemui.recents.tv.animations;
18
19import android.content.Context;
20import com.android.systemui.Interpolators;
21import com.android.systemui.R;
22import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
23import com.android.systemui.recents.tv.views.TaskCardView;
24import com.android.systemui.recents.tv.views.TaskStackHorizontalGridView;
25
26
27public 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
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
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
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    public void setEnterFromHomeStartingAnimationValues() {
78        for(int i = 0; i < mGridView.getChildCount(); i++) {
79            TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
80            view.setTranslationX(0);
81            view.setAlpha(0.0f);
82        }
83    }
84
85    public void setEnterFromAppStartingAnimationValues() {
86        for(int i = 0; i < mGridView.getChildCount(); i++) {
87            TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
88            view.setTranslationX(0);
89            view.setAlpha(1.0f);
90        }
91    }
92}
93