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 package com.android.systemui.recents.tv.animations; 17 18 import android.animation.Animator.AnimatorListener; 19 import android.content.res.Resources; 20 import android.graphics.drawable.TransitionDrawable; 21 import android.view.View; 22 import android.widget.ImageView; 23 import android.widget.LinearLayout; 24 import android.widget.TextView; 25 import com.android.systemui.Interpolators; 26 import com.android.systemui.recents.tv.views.TaskCardView; 27 28 import com.android.systemui.R; 29 30 public class DismissAnimationsHolder { 31 private LinearLayout mInfoField; 32 private View mThumbnailView; 33 34 private int mDismissEnterYDelta; 35 private int mDismissStartYDelta; 36 37 private ImageView mCardDismissIcon; 38 private TransitionDrawable mDismissDrawable; 39 private TextView mDismissText; 40 41 private float mDismissIconNotInDismissStateAlpha; 42 private long mShortDuration; 43 private long mLongDuration; 44 45 public DismissAnimationsHolder(TaskCardView taskCardView) { 46 47 mInfoField = (LinearLayout) taskCardView.findViewById(R.id.card_info_field); 48 mThumbnailView = taskCardView.findViewById(R.id.card_view_thumbnail); 49 mCardDismissIcon = (ImageView) taskCardView.findViewById(R.id.dismiss_icon); 50 mDismissDrawable = (TransitionDrawable) mCardDismissIcon.getDrawable(); 51 mDismissDrawable.setCrossFadeEnabled(true); 52 mDismissText = (TextView) taskCardView.findViewById(R.id.card_dismiss_text); 53 54 Resources res = taskCardView.getResources(); 55 mDismissEnterYDelta = res.getDimensionPixelOffset(R.dimen.recents_tv_dismiss_shift_down); 56 mDismissStartYDelta = mDismissEnterYDelta * 2; 57 mShortDuration = res.getInteger(R.integer.dismiss_short_duration); 58 mLongDuration = res.getInteger(R.integer.dismiss_long_duration); 59 mDismissIconNotInDismissStateAlpha = res.getFloat(R.integer.dismiss_unselected_alpha); 60 } 61 62 public void startEnterAnimation() { 63 mCardDismissIcon.animate() 64 .setDuration(mShortDuration) 65 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 66 .alpha(1.0f) 67 .withStartAction(new Runnable() { 68 @Override 69 public void run() { 70 mDismissDrawable.startTransition(0); 71 } 72 }); 73 74 mDismissText.animate() 75 .setDuration(mShortDuration) 76 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 77 .alpha(1.0f); 78 79 mInfoField.animate() 80 .setDuration(mShortDuration) 81 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 82 .translationY(mDismissEnterYDelta) 83 .alpha(0.5f); 84 85 mThumbnailView.animate() 86 .setDuration(mShortDuration) 87 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 88 .translationY(mDismissEnterYDelta) 89 .alpha(0.5f); 90 } 91 92 public void startExitAnimation() { 93 mCardDismissIcon.animate() 94 .setDuration(mShortDuration) 95 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 96 .alpha(mDismissIconNotInDismissStateAlpha) 97 .withEndAction(new Runnable() { 98 @Override 99 public void run() { 100 mDismissDrawable.reverseTransition(0); 101 } 102 }); 103 104 mDismissText.animate() 105 .setDuration(mShortDuration) 106 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 107 .alpha(0.0f); 108 109 mInfoField.animate() 110 .setDuration(mShortDuration) 111 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 112 .translationY(0) 113 .alpha(1.0f); 114 115 mThumbnailView.animate() 116 .setDuration(mShortDuration) 117 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 118 .translationY(0) 119 .alpha(1.0f); 120 } 121 122 public void startDismissAnimation(AnimatorListener listener) { 123 mCardDismissIcon.animate() 124 .setDuration(mShortDuration) 125 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 126 .alpha(0.0f) 127 .withEndAction(new Runnable() { 128 @Override 129 public void run() { 130 mDismissDrawable.reverseTransition(0); 131 } 132 }); 133 134 mDismissText.animate() 135 .setDuration(mShortDuration) 136 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 137 .alpha(0.0f); 138 139 mInfoField.animate() 140 .setDuration(mLongDuration) 141 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 142 .translationY(mDismissStartYDelta) 143 .alpha(0.0f) 144 .setListener(listener); 145 146 mThumbnailView.animate() 147 .setDuration(mLongDuration) 148 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) 149 .translationY(mDismissStartYDelta) 150 .alpha(0.0f); 151 } 152 153 public void reset() { 154 mInfoField.setAlpha(1.0f); 155 mInfoField.setTranslationY(0); 156 mInfoField.animate().setListener(null); 157 mThumbnailView.setAlpha(1.0f); 158 mThumbnailView.setTranslationY(0); 159 mCardDismissIcon.setAlpha(0.0f); 160 mDismissText.setAlpha(0.0f); 161 } 162 } 163