Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
- package com.example.uz_system_1.lockscreen;
- import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
- import android.support.v4.hardware.fingerprint.FingerprintManagerCompat.AuthenticationCallback;
- import android.support.v4.hardware.fingerprint.FingerprintManagerCompat.AuthenticationResult;
- import android.support.v4.hardware.fingerprint.FingerprintManagerCompat.CryptoObject;
- import android.support.v4.os.CancellationSignal;
- import android.util.Log;
- import com.google.common.annotations.VisibleForTesting;
- import javax.inject.Inject;
- /**
- * Small helper class to manage text/icon around fingerprint authentication UI.
- */
- public class FingerprintUiHelper extends AuthenticationCallback {
- @VisibleForTesting
- static final long ERROR_TIMEOUT_MILLIS = 1600;
- @VisibleForTesting
- static final long SUCCESS_DELAY_MILLIS = 1300;
- private final FingerprintManagerCompat mFingerprintManager;
- private final Callback mCallback;
- private CancellationSignal mCancellationSignal;
- @VisibleForTesting
- boolean mSelfCancelled;
- /**
- * Builder class for {@link FingerprintUiHelper} in which injected fields from Dagger
- * holds its fields and takes other arguments in the {@link #build} method.
- */
- public static class FingerprintUiHelperBuilder {
- private final FingerprintManagerCompat mFingerPrintManager;
- @Inject
- public FingerprintUiHelperBuilder(FingerprintManagerCompat fingerprintManager) {
- mFingerPrintManager = fingerprintManager;
- }
- public FingerprintUiHelper build(Callback callback) {
- return new FingerprintUiHelper(mFingerPrintManager,
- callback);
- }
- }
- /**
- * Constructor for {@link FingerprintUiHelper}. This method is expected to be called from
- * only the {@link FingerprintUiHelperBuilder} class.
- */
- private FingerprintUiHelper(FingerprintManagerCompat fingerprintManager,
- Callback callback) {
- mFingerprintManager = fingerprintManager;
- mCallback = callback;
- }
- public boolean isFingerprintAuthAvailable() {
- return mFingerprintManager.isHardwareDetected()
- && mFingerprintManager.hasEnrolledFingerprints();
- }
- public void startListening(CryptoObject cryptoObject) {
- if (!isFingerprintAuthAvailable()) {
- return;
- }
- mCancellationSignal = new CancellationSignal();
- mSelfCancelled = false;
- mFingerprintManager
- .authenticate(cryptoObject, 0 /* flags */, mCancellationSignal, this, null);
- }
- public void stopListening() {
- if (mCancellationSignal != null) {
- mSelfCancelled = true;
- mCancellationSignal.cancel();
- mCancellationSignal = null;
- }
- }
- @Override
- public void onAuthenticationError(int errMsgId, CharSequence errString) {
- if (!mSelfCancelled) {
- showError(errString);
- mCallback.onError();
- }
- }
- @Override
- public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
- showError(helpString);
- }
- @Override
- public void onAuthenticationFailed() {
- Log.i("adsa","dsa");
- }
- @Override
- public void onAuthenticationSucceeded(AuthenticationResult result) {
- mCallback.onAuthenticated();
- }
- private void showError(CharSequence error) {
- }
- public interface Callback {
- void onAuthenticated();
- void onError();
- }
- }
Add Comment
Please, Sign In to add comment