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.view.View; 25 import android.widget.LinearLayout; 26 27 import androidx.annotation.CallSuper; 28 import androidx.annotation.Nullable; 29 30 import com.android.internal.jank.InteractionJankMonitor; 31 import com.android.systemui.R; 32 33 /** 34 * A Base class for all Keyguard password/pattern/pin related inputs. 35 */ 36 public abstract class KeyguardInputView extends LinearLayout { 37 private Runnable mOnFinishImeAnimationRunnable; 38 39 @Nullable 40 private View mBouncerMessageView; 41 KeyguardInputView(Context context)42 public KeyguardInputView(Context context) { 43 super(context); 44 } 45 KeyguardInputView(Context context, @Nullable AttributeSet attrs)46 public KeyguardInputView(Context context, 47 @Nullable AttributeSet attrs) { 48 super(context, attrs); 49 } 50 KeyguardInputView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)51 public KeyguardInputView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 52 super(context, attrs, defStyleAttr); 53 } 54 getTitle()55 abstract CharSequence getTitle(); 56 disallowInterceptTouch(MotionEvent event)57 boolean disallowInterceptTouch(MotionEvent event) { 58 return false; 59 } 60 startAppearAnimation()61 void startAppearAnimation() {} 62 startDisappearAnimation(Runnable finishRunnable)63 boolean startDisappearAnimation(Runnable finishRunnable) { 64 return false; 65 } 66 getAnimationListener(int cuj)67 protected AnimatorListenerAdapter getAnimationListener(int cuj) { 68 return new AnimatorListenerAdapter() { 69 private boolean mIsCancel; 70 71 @Override 72 public void onAnimationCancel(Animator animation) { 73 mIsCancel = true; 74 } 75 76 @Override 77 public void onAnimationEnd(Animator animation) { 78 if (mIsCancel) { 79 InteractionJankMonitor.getInstance().cancel(cuj); 80 } else { 81 InteractionJankMonitor.getInstance().end(cuj); 82 } 83 } 84 85 @Override 86 public void onAnimationStart(Animator animation) { 87 InteractionJankMonitor.getInstance().begin(KeyguardInputView.this, cuj); 88 } 89 }; 90 } 91 setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable)92 public void setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable) { 93 mOnFinishImeAnimationRunnable = onFinishImeAnimationRunnable; 94 } 95 96 @Override 97 @CallSuper onFinishInflate()98 protected void onFinishInflate() { 99 super.onFinishInflate(); 100 mBouncerMessageView = findViewById(R.id.bouncer_message_view); 101 } 102 103 @Nullable getBouncerMessageView()104 public final View getBouncerMessageView() { 105 return mBouncerMessageView; 106 } 107 runOnFinishImeAnimationRunnable()108 public void runOnFinishImeAnimationRunnable() { 109 if (mOnFinishImeAnimationRunnable != null) { 110 mOnFinishImeAnimationRunnable.run(); 111 mOnFinishImeAnimationRunnable = null; 112 } 113 } 114 } 115