Add fingerprint on SecurityScene
This commit is contained in:
8 files changed
+163
-4
No files matched your search
Regular → Executable
+88
@@ -19,11 +19,15 @@ package com.hippo.ehviewer.ui.scene;
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -42,15 +46,21 @@ public class SecurityScene extends SolidScene implements
|
||||
LockPatternView.OnPatternListener, ShakeDetector.OnShakeListener {
|
||||
|
||||
private static final int MAX_RETRY_TIMES = 5;
|
||||
private static final long ERROR_TIMEOUT_MILLIS = 1200;
|
||||
private static final long SUCCESS_DELAY_MILLIS = 100;
|
||||
|
||||
private static final String KEY_RETRY_TIMES = "retry_times";
|
||||
|
||||
@Nullable
|
||||
private LockPatternView mPatternView;
|
||||
private ImageView mFingerprintIcon;
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private ShakeDetector mShakeDetector;
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
private CancellationSignal mFingerprintCancellationSignal;
|
||||
|
||||
private int mRetryTimes;
|
||||
|
||||
@@ -73,6 +83,9 @@ public class SecurityScene extends SolidScene implements
|
||||
mShakeDetector.setOnShakeListener(this);
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mFingerprintManager = context.getSystemService(FingerprintManager.class);
|
||||
}
|
||||
|
||||
if (null == savedInstanceState) {
|
||||
mRetryTimes = MAX_RETRY_TIMES;
|
||||
@@ -97,6 +110,38 @@ public class SecurityScene extends SolidScene implements
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
|
||||
}
|
||||
|
||||
if (isFingerprintAuthAvailable()) {
|
||||
mFingerprintCancellationSignal = new CancellationSignal();
|
||||
// The line below prevents the false positive inspection from Android Studio
|
||||
// noinspection ResourceType
|
||||
mFingerprintManager.authenticate(null, mFingerprintCancellationSignal, 0,
|
||||
new FingerprintManager.AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
||||
fingerprintError(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
fingerprintError(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(
|
||||
FingerprintManager.AuthenticationResult result) {
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fingerprint_success);
|
||||
mFingerprintIcon.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startSceneForCheckStep(CHECK_STEP_SECURITY, getArguments());
|
||||
finish();
|
||||
}
|
||||
}, SUCCESS_DELAY_MILLIS);
|
||||
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,6 +151,10 @@ public class SecurityScene extends SolidScene implements
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.unregisterListener(mShakeDetector);
|
||||
}
|
||||
if (isFingerprintAuthAvailable() && mFingerprintCancellationSignal != null) {
|
||||
mFingerprintCancellationSignal.cancel();
|
||||
mFingerprintCancellationSignal = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,6 +172,11 @@ public class SecurityScene extends SolidScene implements
|
||||
mPatternView = (LockPatternView) ViewUtils.$$(view, R.id.pattern_view);
|
||||
mPatternView.setOnPatternListener(this);
|
||||
|
||||
mFingerprintIcon = (ImageView) ViewUtils.$$(view, R.id.fingerprint_icon);
|
||||
if (Settings.getEnableFingerprint() && isFingerprintAuthAvailable()) {
|
||||
mFingerprintIcon.setVisibility(View.VISIBLE);
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fp_40px);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -176,4 +230,38 @@ public class SecurityScene extends SolidScene implements
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFingerprintAuthAvailable() {
|
||||
// The line below prevents the false positive inspection from Android Studio
|
||||
// noinspection ResourceType
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Settings.getEnableFingerprint()
|
||||
&& mFingerprintManager != null
|
||||
&& mFingerprintManager.isHardwareDetected()
|
||||
&& mFingerprintManager.hasEnrolledFingerprints();
|
||||
}
|
||||
|
||||
private Runnable mResetFingerprintRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mFingerprintIcon != null)
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fp_40px);
|
||||
}
|
||||
};
|
||||
|
||||
private void fingerprintError(boolean unrecoverable) {
|
||||
// Do not decrease mRetryTimes here since Android system will handle it :)
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fingerprint_error);
|
||||
mFingerprintIcon.removeCallbacks(mResetFingerprintRunnable);
|
||||
if (unrecoverable) {
|
||||
mFingerprintIcon.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mFingerprintIcon.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}, ERROR_TIMEOUT_MILLIS);
|
||||
} else {
|
||||
mFingerprintIcon.postDelayed(mResetFingerprintRunnable, ERROR_TIMEOUT_MILLIS);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
+28
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="40.0dp"
|
||||
android:height="40.0dp"
|
||||
android:viewportWidth="40.0"
|
||||
android:viewportHeight="40.0">
|
||||
<path
|
||||
android:pathData="M20.0,0.0C8.96,0.0 0.0,8.95 0.0,20.0s8.96,20.0 20.0,20.0c11.04,0.0 20.0,-8.95 20.0,-20.0S31.04,0.0 20.0,0.0z"
|
||||
android:fillColor="#F4511E"/>
|
||||
<path
|
||||
android:pathData="M21.33,29.33l-2.67,0.0l0.0,-2.67l2.67,0.0L21.33,29.33zM21.33,22.67l-2.67,0.0l0.0,-12.0l2.67,0.0L21.33,22.67z"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="40.0dp"
|
||||
android:height="40.0dp"
|
||||
android:viewportWidth="40.0"
|
||||
android:viewportHeight="40.0">
|
||||
<path
|
||||
android:pathData="M20.0,20.0m-20.0,0.0a20.0,20.0 0.0,1.0 1.0,40.0 0.0a20.0,20.0 0.0,1.0 1.0,-40.0 0.0"
|
||||
android:fillColor="#009688"/>
|
||||
<path
|
||||
android:pathData="M11.2,21.41l1.63,-1.619999 4.17,4.169998 10.59,-10.589999 1.619999,1.63 -12.209999,12.209999z"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
</vector>
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Regular → Executable
+19
-4
@@ -27,12 +27,27 @@
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="32dp"
|
||||
app:maxWidth="320dp"
|
||||
app:maxHeight="320dp">
|
||||
app:maxHeight="360dp">
|
||||
|
||||
<com.hippo.widget.lockpattern.LockPatternView
|
||||
android:id="@+id/pattern_view"
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.hippo.widget.lockpattern.LockPatternView
|
||||
android:id="@+id/pattern_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fingerprint_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_fp_40px"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.hippo.widget.MaxSizeContainer>
|
||||
</FrameLayout>
|
||||
Reference in new issue
Block a user