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 animateForIme(float interpolatedFraction, boolean appearingAnim)51 void animateForIme(float interpolatedFraction, boolean appearingAnim) { 52 return; 53 } 54 disallowInterceptTouch(MotionEvent event)55 boolean disallowInterceptTouch(MotionEvent event) { 56 return false; 57 } 58 startAppearAnimation()59 void startAppearAnimation() {} 60 startDisappearAnimation(Runnable finishRunnable)61 boolean startDisappearAnimation(Runnable finishRunnable) { 62 return false; 63 } 64 getAnimationListener(int cuj)65 protected AnimatorListenerAdapter getAnimationListener(int cuj) { 66 return new AnimatorListenerAdapter() { 67 private boolean mIsCancel; 68 69 @Override 70 public void onAnimationCancel(Animator animation) { 71 mIsCancel = true; 72 } 73 74 @Override 75 public void onAnimationEnd(Animator animation) { 76 if (mIsCancel) { 77 InteractionJankMonitor.getInstance().cancel(cuj); 78 } else { 79 InteractionJankMonitor.getInstance().end(cuj); 80 } 81 } 82 83 @Override 84 public void onAnimationStart(Animator animation) { 85 InteractionJankMonitor.getInstance().begin(KeyguardInputView.this, cuj); 86 } 87 }; 88 } 89 setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable)90 public void setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable) { 91 mOnFinishImeAnimationRunnable = onFinishImeAnimationRunnable; 92 } 93 runOnFinishImeAnimationRunnable()94 public void runOnFinishImeAnimationRunnable() { 95 if (mOnFinishImeAnimationRunnable != null) { 96 mOnFinishImeAnimationRunnable.run(); 97 mOnFinishImeAnimationRunnable = null; 98 } 99 } 100 } 101