1 /* 2 * Copyright (C) 2021 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.statusbar.phone; 18 19 import android.animation.Animator; 20 import android.animation.AnimatorListenerAdapter; 21 import android.animation.AnimatorSet; 22 import android.animation.ObjectAnimator; 23 import android.annotation.ColorInt; 24 import android.content.Context; 25 import android.util.AttributeSet; 26 import android.view.View; 27 import android.widget.TextView; 28 29 import androidx.annotation.NonNull; 30 import androidx.annotation.Nullable; 31 32 import com.android.settingslib.Utils; 33 import com.android.systemui.res.R; 34 import com.android.wm.shell.animation.Interpolators; 35 36 /** 37 * View to show a toast-like popup on the notification shade and quick settings. 38 */ 39 public class TapAgainView extends TextView { 40 private TextView mTextView; 41 TapAgainView( @onNull Context context, @Nullable AttributeSet attrs)42 public TapAgainView( 43 @NonNull Context context, @Nullable AttributeSet attrs) { 44 super(context, attrs); 45 } 46 47 @Override onFinishInflate()48 protected void onFinishInflate() { 49 super.onFinishInflate(); 50 updateColor(); 51 } 52 updateColor()53 void updateColor() { 54 final @ColorInt int onSurface = Utils.getColorAttrDefaultColor(mContext, 55 com.android.internal.R.attr.materialColorOnSurface); 56 setTextColor(onSurface); 57 setBackground(getResources().getDrawable(R.drawable.rounded_bg_full, mContext.getTheme())); 58 } 59 60 /** Make the view visible. */ animateIn()61 public void animateIn() { 62 int yTranslation = mContext.getResources().getDimensionPixelSize( 63 R.dimen.keyguard_indication_y_translation); 64 65 AnimatorSet animatorSet = new AnimatorSet(); 66 ObjectAnimator fadeIn = ObjectAnimator.ofFloat(this, View.ALPHA, 1f); 67 fadeIn.setStartDelay(150); // From KeyguardIndicationTextView#getFadeInDelay 68 fadeIn.setDuration(317); // From KeyguardIndicationTextView#getFadeInDuration 69 fadeIn.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); 70 71 Animator yTranslate = 72 ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, yTranslation, 0); 73 yTranslate.setDuration(600); // From KeyguardIndicationTextView#getYInDuration 74 yTranslate.addListener(new AnimatorListenerAdapter() { 75 @Override 76 public void onAnimationCancel(Animator animation) { 77 setTranslationY(0); 78 } 79 }); 80 animatorSet.playTogether(yTranslate, fadeIn); 81 animatorSet.start(); 82 setVisibility(View.VISIBLE); 83 } 84 85 /** Make the view gone. */ animateOut()86 public void animateOut() { 87 long fadeOutDuration = 167L; // From KeyguardIndicationTextView#getFadeOutDuration 88 int yTranslation = mContext.getResources().getDimensionPixelSize( 89 com.android.systemui.res.R.dimen.keyguard_indication_y_translation); 90 91 AnimatorSet animatorSet = new AnimatorSet(); 92 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(this, View.ALPHA, 0f); 93 fadeOut.setDuration(fadeOutDuration); 94 fadeOut.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); 95 96 Animator yTranslate = 97 ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0, -yTranslation); 98 yTranslate.setDuration(fadeOutDuration); 99 animatorSet.addListener(new AnimatorListenerAdapter() { 100 @Override 101 public void onAnimationEnd(Animator animation) { 102 setVisibility(GONE); 103 } 104 105 @Override 106 public void onAnimationCancel(Animator animation) { 107 setVisibility(GONE); 108 } 109 }); 110 animatorSet.playTogether(yTranslate, fadeOut); 111 animatorSet.start(); 112 } 113 } 114