1 /* 2 * Copyright (C) 2015 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.settings; 18 19 import android.annotation.Nullable; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.view.View; 23 import android.widget.Button; 24 import android.widget.ImageView; 25 import android.widget.TextView; 26 27 import com.android.settings.fingerprint.FingerprintUiHelper; 28 29 /** 30 * Base fragment to be shared for PIN/Pattern/Password confirmation fragments. 31 */ 32 public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFragment 33 implements FingerprintUiHelper.Callback { 34 35 public static final String PACKAGE = "com.android.settings"; 36 public static final String TITLE_TEXT = PACKAGE + ".ConfirmCredentials.title"; 37 public static final String HEADER_TEXT = PACKAGE + ".ConfirmCredentials.header"; 38 public static final String DETAILS_TEXT = PACKAGE + ".ConfirmCredentials.details"; 39 public static final String ALLOW_FP_AUTHENTICATION = 40 PACKAGE + ".ConfirmCredentials.allowFpAuthentication"; 41 public static final String DARK_THEME = PACKAGE + ".ConfirmCredentials.darkTheme"; 42 public static final String SHOW_CANCEL_BUTTON = 43 PACKAGE + ".ConfirmCredentials.showCancelButton"; 44 public static final String SHOW_WHEN_LOCKED = 45 PACKAGE + ".ConfirmCredentials.showWhenLocked"; 46 47 private FingerprintUiHelper mFingerprintHelper; 48 private boolean mAllowFpAuthentication; 49 protected Button mCancelButton; 50 protected ImageView mFingerprintIcon; 51 52 @Override onCreate(@ullable Bundle savedInstanceState)53 public void onCreate(@Nullable Bundle savedInstanceState) { 54 super.onCreate(savedInstanceState); 55 mAllowFpAuthentication = getActivity().getIntent().getBooleanExtra( 56 ALLOW_FP_AUTHENTICATION, false); 57 } 58 59 @Override onViewCreated(View view, @Nullable Bundle savedInstanceState)60 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 61 super.onViewCreated(view, savedInstanceState); 62 mCancelButton = (Button) view.findViewById(R.id.cancelButton); 63 mFingerprintIcon = (ImageView) view.findViewById(R.id.fingerprintIcon); 64 mFingerprintHelper = new FingerprintUiHelper( 65 mFingerprintIcon, 66 (TextView) view.findViewById(R.id.errorText), this); 67 boolean showCancelButton = getActivity().getIntent().getBooleanExtra( 68 SHOW_CANCEL_BUTTON, false); 69 mCancelButton.setVisibility(showCancelButton ? View.VISIBLE : View.GONE); 70 mCancelButton.setOnClickListener(new View.OnClickListener() { 71 @Override 72 public void onClick(View v) { 73 getActivity().finish(); 74 } 75 }); 76 } 77 78 @Override onResume()79 public void onResume() { 80 super.onResume(); 81 if (mAllowFpAuthentication) { 82 mFingerprintHelper.startListening(); 83 } 84 } 85 setAccessibilityTitle(CharSequence suplementalText)86 protected void setAccessibilityTitle(CharSequence suplementalText) { 87 Intent intent = getActivity().getIntent(); 88 if (intent != null) { 89 CharSequence titleText = intent.getCharSequenceExtra( 90 ConfirmDeviceCredentialBaseFragment.TITLE_TEXT); 91 if (titleText == null || suplementalText == null) { 92 return; 93 } 94 String accessibilityTitle = 95 new StringBuilder(titleText).append(",").append(suplementalText).toString(); 96 getActivity().setTitle(Utils.createAccessibleSequence(titleText, accessibilityTitle)); 97 } 98 } 99 100 @Override onPause()101 public void onPause() { 102 super.onPause(); 103 if (mAllowFpAuthentication) { 104 mFingerprintHelper.stopListening(); 105 } 106 } 107 108 @Override onAuthenticated()109 public void onAuthenticated() { 110 // Check whether we are still active. 111 if (getActivity() != null && getActivity().isResumed()) { 112 authenticationSucceeded(); 113 } 114 } 115 authenticationSucceeded()116 protected abstract void authenticationSucceeded(); 117 118 @Override onFingerprintIconVisibilityChanged(boolean visible)119 public void onFingerprintIconVisibilityChanged(boolean visible) { 120 } 121 prepareEnterAnimation()122 public void prepareEnterAnimation() { 123 } 124 startEnterAnimation()125 public void startEnterAnimation() { 126 } 127 } 128