• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.keyguard;
18 
19 import android.animation.Animator;
20 import android.animation.AnimatorListenerAdapter;
21 import android.content.Context;
22 import android.util.AttributeSet;
23 import android.view.MotionEvent;
24 import android.widget.LinearLayout;
25 
26 import androidx.annotation.Nullable;
27 
28 import com.android.internal.jank.InteractionJankMonitor;
29 
30 /**
31  * A Base class for all Keyguard password/pattern/pin related inputs.
32  */
33 public abstract class KeyguardInputView extends LinearLayout {
34     private Runnable mOnFinishImeAnimationRunnable;
35 
KeyguardInputView(Context context)36     public KeyguardInputView(Context context) {
37         super(context);
38     }
39 
KeyguardInputView(Context context, @Nullable AttributeSet attrs)40     public KeyguardInputView(Context context,
41             @Nullable AttributeSet attrs) {
42         super(context, attrs);
43     }
44 
KeyguardInputView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)45     public KeyguardInputView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46         super(context, attrs, defStyleAttr);
47     }
48 
getTitle()49     abstract CharSequence getTitle();
50 
disallowInterceptTouch(MotionEvent event)51     boolean disallowInterceptTouch(MotionEvent event) {
52         return false;
53     }
54 
startAppearAnimation()55     void startAppearAnimation() {}
56 
startDisappearAnimation(Runnable finishRunnable)57     boolean startDisappearAnimation(Runnable finishRunnable) {
58         return false;
59     }
60 
getAnimationListener(int cuj)61     protected AnimatorListenerAdapter getAnimationListener(int cuj) {
62         return new AnimatorListenerAdapter() {
63             private boolean mIsCancel;
64 
65             @Override
66             public void onAnimationCancel(Animator animation) {
67                 mIsCancel = true;
68             }
69 
70             @Override
71             public void onAnimationEnd(Animator animation) {
72                 if (mIsCancel) {
73                     InteractionJankMonitor.getInstance().cancel(cuj);
74                 } else {
75                     InteractionJankMonitor.getInstance().end(cuj);
76                 }
77             }
78 
79             @Override
80             public void onAnimationStart(Animator animation) {
81                 InteractionJankMonitor.getInstance().begin(KeyguardInputView.this, cuj);
82             }
83         };
84     }
85 
setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable)86     public void setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable) {
87         mOnFinishImeAnimationRunnable = onFinishImeAnimationRunnable;
88     }
89 
runOnFinishImeAnimationRunnable()90     public void runOnFinishImeAnimationRunnable() {
91         if (mOnFinishImeAnimationRunnable != null) {
92             mOnFinishImeAnimationRunnable.run();
93             mOnFinishImeAnimationRunnable = null;
94         }
95     }
96 }
97