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 */ 16package com.android.systemui.recents.tv.animations; 17 18import android.animation.Animator; 19import android.animation.AnimatorSet; 20import android.animation.ObjectAnimator; 21import android.content.res.Resources; 22import android.view.View; 23 24import com.android.systemui.Interpolators; 25import com.android.systemui.R; 26import com.android.systemui.recents.tv.views.TaskCardView; 27 28/** 29 * Recents row's focus animation with PIP controls. 30 */ 31public class RecentsRowFocusAnimationHolder { 32 private final View mView; 33 private final View mTitleView; 34 35 private AnimatorSet mFocusGainAnimatorSet; 36 private AnimatorSet mFocusLossAnimatorSet; 37 38 public RecentsRowFocusAnimationHolder(View view, View titleView) { 39 mView = view; 40 mTitleView = titleView; 41 42 Resources res = view.getResources(); 43 int duration = res.getInteger(R.integer.recents_tv_pip_focus_anim_duration); 44 float dimAlpha = res.getFloat(R.dimen.recents_recents_row_dim_alpha); 45 46 mFocusGainAnimatorSet = new AnimatorSet(); 47 mFocusGainAnimatorSet.playTogether( 48 ObjectAnimator.ofFloat(mView, "alpha", 1f), 49 ObjectAnimator.ofFloat(mTitleView, "alpha", 1f)); 50 mFocusGainAnimatorSet.setDuration(duration); 51 mFocusGainAnimatorSet.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); 52 53 mFocusLossAnimatorSet = new AnimatorSet(); 54 mFocusLossAnimatorSet.playTogether( 55 // Animation doesn't start from the current value (1f) sometimes, 56 // so specify the desired initial value here. 57 ObjectAnimator.ofFloat(mView, "alpha", 1f, dimAlpha), 58 ObjectAnimator.ofFloat(mTitleView, "alpha", 0f)); 59 mFocusLossAnimatorSet.setDuration(duration); 60 mFocusLossAnimatorSet.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); 61 } 62 63 /** 64 * Starts the Recents row's focus gain animation. 65 */ 66 public void startFocusGainAnimation() { 67 cancelAnimator(mFocusLossAnimatorSet); 68 mFocusGainAnimatorSet.start(); 69 } 70 71 /** 72 * Starts the Recents row's focus loss animation. 73 */ 74 public void startFocusLossAnimation() { 75 cancelAnimator(mFocusGainAnimatorSet); 76 mFocusLossAnimatorSet.start(); 77 } 78 79 /** 80 * Resets the views immediately and ends the animations. 81 */ 82 public void reset() { 83 cancelAnimator(mFocusLossAnimatorSet); 84 cancelAnimator(mFocusGainAnimatorSet); 85 mView.setAlpha(1f); 86 mTitleView.setAlpha(1f); 87 } 88 89 private static void cancelAnimator(Animator animator) { 90 if (animator.isStarted()) { 91 animator.cancel(); 92 } 93 } 94} 95