diff --git a/app/build.gradle b/app/build.gradle index 1af58da..f21d1f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java index 5e71f0d..875f726 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -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); } } diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java index 1515bf2..d24e461 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java @@ -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); + } } diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java index bf42a86..de9b4d9 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java @@ -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); } } diff --git a/app/src/main/res/layout/fragment_fingerprint_scanner.xml b/app/src/main/res/layout/fragment_fingerprint_scanner.xml index c1b7732..567ee10 100644 --- a/app/src/main/res/layout/fragment_fingerprint_scanner.xml +++ b/app/src/main/res/layout/fragment_fingerprint_scanner.xml @@ -1,9 +1,10 @@ @@ -13,7 +14,31 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> - + + + + + + + + +