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