Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 756c19c

Browse files
committed
Updated README with Fingerprint Authentication Feature
1 parent e1c098b commit 756c19c

25 files changed

+598
-104
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android:
88
- extra-google-google_play_services
99
- extra-android-m2repository
1010
- extra-google-m2repository
11-
- build-tools-26.0.2
12-
- android-26
11+
- build-tools-28.0.3
12+
- android-28
1313
- android-22
1414
- sys-img-armeabi-v7a-android-22
1515

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mobile-passcode
2-
Library for passcode implementation along with an optional additional feature to ask for passcode when your app resumes from background. (Works with minSDK >= 15)
2+
Library for Passcode and Fingerprint Authentication implementation along with an optional additional
3+
feature to ask for passcode when your app resumes from background. (Works with minSDK >= 15)
34

45
Usage
56
-----
@@ -60,10 +61,35 @@ public class PassCodeActivity extends MifosPassCodeActivity {
6061
return EncryptionUtil.DEFAULT;
6162
}
6263

64+
@Override
65+
public String getFpDialogTitle() {
66+
//Title to be shown for Fingerprint Dialog
67+
return getString(R.string.fingerprint_dialog_title);
68+
}
6369
}
6470

6571
```
6672

73+
## Fingerprint Authentication
74+
75+
- Mention the title of Fingerprint Dialog by overriding **getFpDialogTitle()** method.
76+
77+
- If the device supports Fingerprint Authentication, then a dialog will be shown to the user to enable Fingerprint
78+
Authentication at first time. If the user chooses "No", then he/she will be prompted to the Passcode Screen.
79+
80+
- If the user opts for Fingerprint Authentication, then a dialog will appear asking user to "Touch the Sensor" in
81+
order to access the app.
82+
83+
- On **successful** authentication, **startNextActivity()** method will be executed.
84+
85+
- In case the Authentication **fails**, then after a 1 second delay, the dialog will again ask for Authentication.
86+
87+
- There is also an option to **cancel** Fingerprint Authentication, if chosen results in the execution of
88+
**StartLoginActivity()** method.
89+
90+
- This feature won't work if the Device doesn't have a fingerprint scanner or if the Android Version is below
91+
**Android Marshmallow (Android 6)**. In this case, the user will be directly prompted to the Passcode Screen.
92+
6793
There are 4 different types of encryption methods available with respect to our Android Projects:
6894
- DEFAULT
6995
- MOBILE_BANKING

app/build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android-extensions'
3+
apply plugin: 'kotlin-android'
24

35
android {
6+
compileOptions {
7+
sourceCompatibility JavaVersion.VERSION_1_8
8+
targetCompatibility JavaVersion.VERSION_1_8
9+
}
410
signingConfigs {
511
release {
612
storeFile file("../default_key_store.jks")
@@ -33,6 +39,11 @@ dependencies {
3339
testImplementation 'junit:junit:4.12'
3440
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
3541
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
36-
//implementation project(':mifos-passcode')
37-
implementation 'com.mifos.mobile:mifos-passcode:1.0.0'
42+
implementation project(':mifos-passcode')
43+
//implementation 'com.mifos.mobile:mifos-passcode:1.0.0'
44+
implementation "androidx.core:core-ktx:+"
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46+
}
47+
repositories {
48+
mavenCentral()
3849
}

app/src/main/java/com/mifos/passcode/PassCodeActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public int getEncryptionType() {
3939
return EncryptionUtil.DEFAULT;
4040
}
4141

42+
@Override
43+
public String getFpDialogTitle() {
44+
//Title to be shown for Fingerprint Dialog
45+
return getString(R.string.fingerprint_dialog_title);
46+
}
4247
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">mobile_passcode</string>
3+
<string name="fingerprint_dialog_title">Login</string>
34
</resources>

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
4+
ext.kotlin_version = '1.3.41'
5+
56
repositories {
67
google()
78
jcenter()
@@ -11,6 +12,7 @@ buildscript {
1112
classpath 'com.android.tools.build:gradle:3.3.2'
1213
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
1314
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1416
// NOTE: Do not place your application dependencies here; they belong
1517
// in the individual module build.gradle files
1618
}

mifos-passcode/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android-extensions'
3+
apply plugin: 'kotlin-android'
24

35
ext {
46
bintrayRepo = 'maven'
@@ -54,9 +56,12 @@ dependencies {
5456
testImplementation 'junit:junit:4.12'
5557
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
5658
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
59+
implementation "androidx.core:core-ktx:+"
60+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5761
}
5862

5963
tasks.withType(Javadoc) {
64+
excludes = ['**/*.kt']
6065
options.addStringOption('Xdoclint:none', '-quiet')
6166
options.addStringOption('encoding', 'UTF-8')
6267
options.addStringOption('charSet', 'UTF-8')
@@ -67,6 +72,9 @@ if (project.rootProject.file('local.properties').exists()) {
6772
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
6873
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
6974
}
75+
repositories {
76+
mavenCentral()
77+
}
7078
// Used this article to release the library
7179
// https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
7280

mifos-passcode/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.mifos.mobile.passcode">
44
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
56

67
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.mifos.mobile.passcode
2+
3+
interface FpAuthCallback {
4+
fun onFpAuthSuccess()
5+
fun onCancel()
6+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.mifos.mobile.passcode
2+
3+
import android.app.AlertDialog
4+
import android.content.Context
5+
import android.util.Log
6+
import android.view.LayoutInflater
7+
import android.widget.TextView
8+
import android.widget.Toast
9+
import androidx.appcompat.widget.AppCompatButton
10+
11+
class FpAuthDialog(private val context: Context) {
12+
private var dialogTitle = context.getString(R.string.fp_dialog_title)
13+
private var dialogMessage = context.getString(R.string.fp_dialog_message)
14+
private var dialogCancelText = context.getString(R.string.fp_dialog_cancel)
15+
16+
private var layoutInflater = LayoutInflater.from(context)
17+
private var dialogView = layoutInflater.inflate(R.layout.dialog_fingerprint_auth, null)
18+
private var tvDialogTitle = dialogView.findViewById<TextView>(R.id.fingerprint_dialog_title)
19+
private var tvDialogMessage = dialogView.findViewById<TextView>(R.id.fingerprint_dialog_message)
20+
private var tvDialogStatus = dialogView.findViewById<TextView>(R.id.fingerprint_dialog_status)
21+
private var btnCancel = dialogView.findViewById<AppCompatButton>(R.id.fingerprint_dialog_cancel)
22+
23+
private var dialogBuilder = AlertDialog.Builder(context)
24+
private var dialog: AlertDialog? = null
25+
26+
private var fpAuthCallback: FpAuthCallback = object : FpAuthCallback {
27+
override fun onFpAuthSuccess() {
28+
Toast.makeText(context, context.getString(R.string.authentication_successful), Toast.LENGTH_SHORT).show()
29+
}
30+
31+
override fun onCancel() {
32+
Toast.makeText(context, context.getString(R.string.authentication_cancelled), Toast.LENGTH_SHORT).show()
33+
}
34+
35+
}
36+
private var fpAuthHelper = FpAuthHelper(context, fpAuthCallback, this)
37+
38+
fun setTitle(title: String): FpAuthDialog {
39+
dialogTitle = title
40+
return this
41+
}
42+
43+
fun setTitle(resTitle: Int): FpAuthDialog {
44+
dialogTitle = context.resources.getString(resTitle)
45+
return this
46+
}
47+
48+
fun setMessage(message: String): FpAuthDialog {
49+
dialogMessage = message
50+
return this
51+
}
52+
53+
fun setMessage(resMessage: Int): FpAuthDialog {
54+
dialogMessage = context.resources.getString(resMessage)
55+
return this
56+
}
57+
58+
fun setCancelText(cancelText: String): FpAuthDialog {
59+
dialogCancelText = cancelText
60+
return this
61+
}
62+
63+
fun setCancelText(resCancelText: Int): FpAuthDialog {
64+
dialogCancelText = context.resources.getString(resCancelText)
65+
return this
66+
}
67+
68+
fun setCallback(fpAuthCallback: FpAuthCallback): FpAuthDialog {
69+
this.fpAuthCallback = fpAuthCallback
70+
fpAuthHelper = FpAuthHelper(context, fpAuthCallback, this)
71+
return this
72+
}
73+
74+
internal fun setStatusText(statusText: String) {
75+
tvDialogStatus.text = statusText
76+
}
77+
78+
internal fun setStatusIcon(resIcon: Int) {
79+
tvDialogStatus.setCompoundDrawablesWithIntrinsicBounds(resIcon, 0, 0, 0)
80+
}
81+
82+
fun dismiss() {
83+
fpAuthHelper.stopFpAuth()
84+
dialog!!.dismiss()
85+
}
86+
87+
fun show() {
88+
if (!FpAuthSupport.checkAvailabiltyAndIfFingerprintRegistered(context)) {
89+
Log.e("FingerprintAuth", "Device not Suitable for Fingerprint Authentication")
90+
return
91+
}
92+
tvDialogTitle.text = dialogTitle
93+
tvDialogMessage.text = dialogMessage
94+
btnCancel.text = dialogCancelText
95+
96+
dialog = dialogBuilder.setView(dialogView).create()
97+
dialog!!.setCancelable(false)
98+
dialog!!.show()
99+
100+
fpAuthHelper.startFpAuth()
101+
102+
btnCancel.setOnClickListener {
103+
fpAuthHelper.stopFpAuth()
104+
dialog!!.dismiss()
105+
fpAuthCallback.onCancel()
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)