-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
474 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
|
||
android { | ||
compileSdkVersion parent.ext.compileSdkVersion | ||
buildToolsVersion parent.ext.buildToolsVersion | ||
|
||
|
||
defaultConfig { | ||
applicationId "com.jesusm.kfingerprintmanager.javasample" | ||
minSdkVersion parent.ext.minSdkVersion | ||
targetSdkVersion parent.ext.targetSdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile project(':kfingerprintmanager') | ||
|
||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/jesus/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.jesusm.fingerprintmanager.javasample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="com.jesusm.fingerprintmanager.javasample.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
201 changes: 201 additions & 0 deletions
201
javasample/src/main/java/com/jesusm/fingerprintmanager/javasample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
package com.jesusm.fingerprintmanager.javasample; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import com.jesusm.kfingerprintmanager.KFingerprintManager; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String KEY = "KEY"; | ||
private int dialogTheme; | ||
private TextView messageText; | ||
private EditText encryptionMessageEditText; | ||
private Button encryptButton; | ||
private Button decryptButton; | ||
private String messageToDecrypt; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
selectView(findViewById(R.id.buttonDialogThemeLight)); | ||
messageText = (TextView) findViewById(R.id.message); | ||
encryptionMessageEditText = (EditText) findViewById(R.id.editText); | ||
encryptButton = (Button) findViewById(R.id.buttonEncrypt); | ||
decryptButton = (Button) findViewById(R.id.buttonDecrypt); | ||
|
||
initClickListeners(); | ||
} | ||
|
||
private void initClickListeners() { | ||
findViewById(R.id.buttonDialogThemeLight).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
selectView(v); | ||
|
||
deselectView(findViewById(R.id.buttonDialogThemeDark)); | ||
|
||
dialogTheme = R.style.DialogThemeLight; | ||
} | ||
}); | ||
|
||
findViewById(R.id.buttonDialogThemeDark).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
selectView(v); | ||
|
||
deselectView(findViewById(R.id.buttonDialogThemeLight)); | ||
|
||
dialogTheme = R.style.DialogThemeDark; | ||
} | ||
}); | ||
|
||
findViewById(R.id.buttonAuthenticate).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
createFingerprintManagerInstance().authenticate(new KFingerprintManager.AuthenticationCallback() { | ||
@Override | ||
public void onAuthenticationSuccess() { | ||
messageText.setText("Successfully authenticated"); | ||
} | ||
|
||
@Override | ||
public void onSuccessWithManualPassword(@NotNull String password) { | ||
messageText.setText("Manual password: " + password); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotRecognized() { | ||
messageText.setText("Fingerprint not recognized"); | ||
} | ||
|
||
@Override | ||
public void onAuthenticationFailedWithHelp(@Nullable String help) { | ||
messageText.setText(help); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotAvailable() { | ||
messageText.setText("Fingerprint not available"); | ||
} | ||
|
||
@Override | ||
public void onCancelled() { | ||
messageText.setText("Operation cancelled by user"); | ||
} | ||
}, getSupportFragmentManager()); | ||
} | ||
}); | ||
|
||
encryptButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
messageToDecrypt = encryptionMessageEditText.getText().toString(); | ||
createFingerprintManagerInstance().encrypt(messageToDecrypt, new KFingerprintManager.EncryptionCallback() { | ||
@Override | ||
public void onEncryptionSuccess(@NotNull String messageEncrypted) { | ||
String message = getString(R.string.encrypt_message_success, messageEncrypted); | ||
messageText.setText(message); | ||
encryptionMessageEditText.setText(messageEncrypted); | ||
encryptButton.setVisibility(View.GONE); | ||
decryptButton.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void onEncryptionFailed() { | ||
messageText.setText("Encryption failed"); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotRecognized() { | ||
messageText.setText("Fingerprint not recognized"); | ||
} | ||
|
||
@Override | ||
public void onAuthenticationFailedWithHelp(@Nullable String help) { | ||
messageText.setText(help); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotAvailable() { | ||
messageText.setText("Fingerprint not available"); | ||
} | ||
|
||
@Override | ||
public void onCancelled() { | ||
messageText.setText("Operation cancelled by user"); | ||
} | ||
}, getSupportFragmentManager()); | ||
} | ||
}); | ||
|
||
decryptButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
messageToDecrypt = encryptionMessageEditText.getText().toString(); | ||
createFingerprintManagerInstance().decrypt(messageToDecrypt, new KFingerprintManager.DecryptionCallback() { | ||
@Override | ||
public void onDecryptionSuccess(@NotNull String messageDecrypted) { | ||
String message = getString(R.string.decrypt_message_success, messageDecrypted); | ||
messageText.setText(message); | ||
encryptionMessageEditText.setText(""); | ||
decryptButton.setVisibility(View.GONE); | ||
encryptButton.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void onDecryptionFailed() { | ||
messageText.setText("Encryption failed"); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotRecognized() { | ||
messageText.setText("Fingerprint not recognized"); | ||
} | ||
|
||
@Override | ||
public void onAuthenticationFailedWithHelp(@Nullable String help) { | ||
messageText.setText(help); | ||
} | ||
|
||
@Override | ||
public void onFingerprintNotAvailable() { | ||
messageText.setText("Fingerprint not available"); | ||
} | ||
|
||
@Override | ||
public void onCancelled() { | ||
messageText.setText("Operation cancelled by user"); | ||
} | ||
}, getSupportFragmentManager()); | ||
} | ||
}); | ||
} | ||
|
||
private KFingerprintManager createFingerprintManagerInstance() { | ||
KFingerprintManager fingerprintManager = new KFingerprintManager(this, KEY); | ||
fingerprintManager.setAuthenticationDialogStyle(dialogTheme); | ||
return fingerprintManager; | ||
} | ||
|
||
private void selectView(View view) { | ||
view.setSelected(true); | ||
view.setElevation(32f); | ||
} | ||
|
||
private void deselectView(View view) { | ||
view.setSelected(true); | ||
view.setElevation(0f); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
javasample/src/main/res/drawable/dialog_dark_theme_button_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<selector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:enterFadeDuration="@android:integer/config_shortAnimTime" | ||
android:exitFadeDuration="@android:integer/config_shortAnimTime"> | ||
|
||
<item android:drawable="@color/dialog_dark_theme_background_selected" android:state_selected="true"/> | ||
<item android:drawable="@color/dialog_dark_theme_background"/> | ||
|
||
</selector> |
10 changes: 10 additions & 0 deletions
10
javasample/src/main/res/drawable/dialog_light_theme_button_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<selector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:enterFadeDuration="@android:integer/config_shortAnimTime" | ||
android:exitFadeDuration="@android:integer/config_shortAnimTime"> | ||
|
||
<item android:drawable="@color/dialog_light_theme_background_selected" android:state_selected="true"/> | ||
<item android:drawable="@color/dialog_light_theme_background"/> | ||
|
||
</selector> |
Oops, something went wrong.