Home | History | Annotate | Download | only in animations
      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 
     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             long delay = Math.max(mDelay * i, 0);
     51             view.setTranslationX(-mTranslationX);
     52             view.animate()
     53                     .alpha(isPipShown ? mDimAlpha : 1.0f)
     54                     .translationX(0)
     55                     .setDuration(mDuration)
     56                     .setStartDelay(delay)
     57                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
     58         }
     59     }
     60 
     61     public void startExitAnimation(DismissRecentsToHomeAnimationStarted dismissEvent) {
     62         for(int i = mGridView.getChildCount() - 1; i >= 0; i--) {
     63             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
     64             long delay = Math.max(mDelay * (mGridView.getChildCount() - 1 - i), 0);
     65             view.animate()
     66                     .alpha(0.0f)
     67                     .translationXBy(-mTranslationX)
     68                     .setDuration(mDuration)
     69                     .setStartDelay(delay)
     70                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
     71             if(i == 0) {
     72                 view.animate().setListener(dismissEvent.getAnimationTrigger()
     73                         .decrementOnAnimationEnd());
     74                 dismissEvent.getAnimationTrigger().increment();
     75             }
     76         }
     77     }
     78 
     79     /**
     80      * Sets the initial values Recents enter animation
     81      * when Recents is started from the Launcher.
     82      */
     83     public void setEnterFromHomeStartingAnimationValues(boolean isPipShown) {
     84         for(int i = 0; i < mGridView.getChildCount(); i++) {
     85             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
     86             view.setTranslationX(0);
     87             view.setAlpha(0.0f);
     88             view.getInfoFieldView().setAlpha(isPipShown ? 0 : 1f);
     89             if (isPipShown && view.hasFocus()) {
     90                 view.getViewFocusAnimator().changeSize(false);
     91             }
     92         }
     93     }
     94 
     95     /**
     96      * Sets the initial values Recents enter animation
     97      * when Recents is started from an app.
     98      */
     99     public void setEnterFromAppStartingAnimationValues(boolean isPipShown) {
    100         for(int i = 0; i < mGridView.getChildCount(); i++) {
    101             TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
    102             view.setTranslationX(0);
    103             view.setAlpha(isPipShown ? mDimAlpha : 1f);
    104             view.getInfoFieldView().setAlpha(isPipShown ? 0 : 1f);
    105             if (isPipShown && view.hasFocus()) {
    106                 view.getViewFocusAnimator().changeSize(false);
    107             }
    108         }
    109     }
    110 }
    111