Fingerprint lock | Fingerprint dialog

This commit is contained in:
Tanguy Herbron 2018-03-02 00:22:26 +01:00
parent a5dc675627
commit f2be27467d
8 changed files with 131 additions and 23 deletions

View File

@ -1,11 +1,11 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
applicationId "com.nauk.coinfolio"
minSdkVersion 23
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@ -23,15 +23,14 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//implementation 'com.mattprecious.swirl:swirl:1.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.diogobernardino:williamchart:2.5.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:palette-v7:26.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:palette-v7:27.1.0'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.github.armcha:SpaceNavigationView:1.6.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
@ -41,7 +40,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-jackson:2.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
implementation 'org.apache.commons:commons-lang3:3.6'
//implementation 'com.mattprecious.swirl:swirl:1.1.0'
implementation 'com.mattprecious.swirl:swirl:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

View File

@ -3,6 +3,7 @@ package com.nauk.coinfolio.Activities;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
@ -172,8 +173,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
if(preferences.getBoolean("enable_fingerprint", false))
{
DialogFragment newFragment = FingerprintDialogFragment.newInstance(
R.layout.fragment_fingerprint_scanner);
FingerprintDialogFragment newFragment = FingerprintDialogFragment.newInstance();
newFragment.setCancelable(false);
newFragment.show(getFragmentManager(), "dialog");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
@ -212,7 +213,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
{
cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this);
FingerprintHandler helper = new FingerprintHandler(this, newFragment);
helper.startAuth(fingerprintManager, cryptoObject);
}
}

View File

@ -1,13 +1,28 @@
package com.nauk.coinfolio.FingerprintToolkit;
import android.Manifest;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.Button;
import com.mattprecious.swirl.SwirlView;
import com.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.R;
/**
@ -16,11 +31,10 @@ import com.nauk.coinfolio.R;
public class FingerprintDialogFragment extends DialogFragment{
public static FingerprintDialogFragment newInstance(int title)
public static FingerprintDialogFragment newInstance()
{
FingerprintDialogFragment frag = new FingerprintDialogFragment();
Bundle args = new Bundle();
args.putInt("title", title);
frag.setArguments(args);
return frag;
}
@ -30,6 +44,42 @@ public class FingerprintDialogFragment extends DialogFragment{
{
View view = inflater.inflate(R.layout.fragment_fingerprint_scanner, container);
((Button) view.findViewById(R.id.cancelButton)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().finish();
}
});
((SwirlView) view.findViewById(R.id.swirlBackground)).setState(SwirlView.State.ON, false);
return view;
}
public void correctFingerprint()
{
SwirlView swirlView = this.getView().findViewById(R.id.swirl);
swirlView.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_IN);
swirlView.setState(SwirlView.State.ON);
}
public void wrongFingerprint()
{
((SwirlView) this.getView().findViewById(R.id.swirl)).clearColorFilter();
((SwirlView) this.getView().findViewById(R.id.swirlBackground)).clearColorFilter();
((SwirlView) this.getView().findViewById(R.id.swirl)).setState(SwirlView.State.ERROR);
((SwirlView) this.getView().findViewById(R.id.swirlBackground)).setState(SwirlView.State.ERROR);
}
public void resetFingerprint()
{
((SwirlView) this.getView().findViewById(R.id.swirlBackground)).setState(SwirlView.State.ON);
SwirlView swirlView = this.getView().findViewById(R.id.swirl);
swirlView.clearColorFilter();
swirlView.setState(SwirlView.State.OFF);
}
}

View File

@ -5,7 +5,9 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.CancellationSignal;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.app.DialogFragment;
import android.widget.Toast;
/**
@ -16,10 +18,12 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
private CancellationSignal cancellationSignal;
private Context context;
private FingerprintDialogFragment dialogFragment;
public FingerprintHandler(Context context)
public FingerprintHandler(Context context, FingerprintDialogFragment dialogFragment)
{
this.context = context;
this.dialogFragment = dialogFragment;
}
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject)
@ -35,13 +39,27 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationError(int errMsgId, CharSequence errString)
{
Toast.makeText(context, "Authentification error\n" + errString, Toast.LENGTH_LONG).show();
//Toast.makeText(context, "Authentification error\n" + errString, Toast.LENGTH_LONG).show();
dialogFragment.wrongFingerprint();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
dialogFragment.resetFingerprint();
}
}, 500);
}
@Override
public void onAuthenticationFailed()
{
Toast.makeText(context, "Authentification failed", Toast.LENGTH_LONG).show();
//Toast.makeText(context, "Authentification failed", Toast.LENGTH_LONG).show();
dialogFragment.wrongFingerprint();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
dialogFragment.resetFingerprint();
}
}, 500);
}
@Override
@ -53,6 +71,15 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result)
{
Toast.makeText(context, "Success !", Toast.LENGTH_LONG).show();
//Toast.makeText(context, "Success !", Toast.LENGTH_LONG).show();
//dialogFragment.dismiss();
dialogFragment.correctFingerprint();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
dialogFragment.dismiss();
}
}, 250);
}
}

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="250dp"
android:layout_height="125dp"
android:layout_gravity="center"
android:orientation="vertical">
@ -13,7 +14,31 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--<com.mattprecious.swirl.SwirlView
android:layout_width="60dp"
android:layout_height="60dp" />-->
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<com.mattprecious.swirl.SwirlView
android:id="@+id/swirlBackground"
android:layout_width="@dimen/swirl_size"
android:layout_height="@dimen/swirl_size"
tools:swirl_state="on"/>
<com.mattprecious.swirl.SwirlView
android:id="@+id/swirl"
android:layout_width="@dimen/swirl_size"
android:layout_height="@dimen/swirl_size"
tools:swirl_state="on"/>
</FrameLayout>
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fingerprint_dialog_cancel"
style="?android:attr/borderlessButtonStyle"
android:layout_gravity="end"/>
</LinearLayout>

View File

@ -11,4 +11,6 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="swirl_size">60dp</dimen>
</resources>

View File

@ -146,4 +146,6 @@
<string name="currencyPercentagePlaceholder">%1$s%%</string>
<string name="title_activity_main">MainActivity</string>
<string name="fingerprint_dialog_cancel">Cancel</string>
</resources>

View File

@ -6,6 +6,8 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="swirl_ridgeColor">@color/separationLine</item>
<item name="swirl_errorColor">@color/decrease</item>
</style>
<style name="AppTheme.NoActionBar">