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.res.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 67 /** Updates the keyguard view's constraints (single or split constraints). 68 * Split constraints are only used for small landscape screens. 69 * Only called when flag LANDSCAPE_ENABLE_LOCKSCREEN is enabled. */ updateConstraints(boolean useSplitBouncer)70 protected void updateConstraints(boolean useSplitBouncer) { 71 //Unless overridden, never update constrains (keeping default portrait constraints) 72 } 73 getAnimationListener(int cuj)74 protected AnimatorListenerAdapter getAnimationListener(int cuj) { 75 return new AnimatorListenerAdapter() { 76 private boolean mIsCancel; 77 78 @Override 79 public void onAnimationCancel(Animator animation) { 80 mIsCancel = true; 81 } 82 83 @Override 84 public void onAnimationEnd(Animator animation) { 85 if (mIsCancel) { 86 InteractionJankMonitor.getInstance().cancel(cuj); 87 } else { 88 InteractionJankMonitor.getInstance().end(cuj); 89 } 90 } 91 92 @Override 93 public void onAnimationStart(Animator animation) { 94 InteractionJankMonitor.getInstance().begin(KeyguardInputView.this, cuj); 95 } 96 }; 97 } 98 setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable)99 public void setOnFinishImeAnimationRunnable(Runnable onFinishImeAnimationRunnable) { 100 mOnFinishImeAnimationRunnable = onFinishImeAnimationRunnable; 101 } 102 103 @Override 104 @CallSuper onFinishInflate()105 protected void onFinishInflate() { 106 super.onFinishInflate(); 107 mBouncerMessageView = findViewById(R.id.bouncer_message_view); 108 } 109 110 @Nullable getBouncerMessageView()111 public final View getBouncerMessageView() { 112 return mBouncerMessageView; 113 } 114 runOnFinishImeAnimationRunnable()115 public void runOnFinishImeAnimationRunnable() { 116 if (mOnFinishImeAnimationRunnable != null) { 117 mOnFinishImeAnimationRunnable.run(); 118 mOnFinishImeAnimationRunnable = null; 119 } 120 } 121 } 122