Add fingerprint dialog and update icons

This commit is contained in:
J-Jamet committed 2017-12-06 22:28:25 +01:00
1 parent 8536586c13
commit 05a5da4c8d
19 files changed
+705 -59

No files matched your search

@@ -44,11 +44,10 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.R;
import com.keepassdroid.app.App;
import com.keepassdroid.compat.BackupManagerCompat;
import com.keepassdroid.compat.ClipDataCompat;
@@ -58,6 +57,7 @@ import com.keepassdroid.database.edit.LoadDB;
import com.keepassdroid.database.edit.OnFinish;
import com.keepassdroid.dialog.PasswordEncodingDialogHelper;
import com.keepassdroid.fileselect.BrowserDialog;
import com.keepassdroid.fingerprint.FingerPrintAnimatedVector;
import com.keepassdroid.fingerprint.FingerPrintHelper;
import com.keepassdroid.intents.Intents;
import com.keepassdroid.utils.EmptyUtils;
@@ -65,6 +65,9 @@ import com.keepassdroid.utils.Interaction;
import com.keepassdroid.utils.MenuUtil;
import com.keepassdroid.utils.UriUtil;
import com.keepassdroid.utils.Util;
import com.keepassdroid.view.FingerPrintDialog;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.R;
import java.io.File;
import java.io.FileNotFoundException;
@@ -96,8 +99,10 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
private int mode;
private static final String PREF_KEY_VALUE_PREFIX = "valueFor_"; // key is a combination of db file name and this prefix
private static final String PREF_KEY_IV_PREFIX = "ivFor_"; // key is a combination of db file name and this prefix
private View fingerprintView;
private TextView confirmationView;
private View fingerprintContainerView;
private View fingerprintImageView;
private FingerPrintAnimatedVector fingerPrintAnimatedVector;
private TextView fingerprintTextView;
private EditText passwordView;
private Button confirmButton;
@@ -205,10 +210,16 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
getSupportActionBar().setDisplayShowHomeEnabled(true);
confirmButton = (Button) findViewById(R.id.pass_ok);
fingerprintView = findViewById(R.id.fingerprint);
confirmationView = (TextView) findViewById(R.id.fingerprint_label);
fingerprintContainerView = findViewById(R.id.fingerprint_container);
fingerprintImageView = findViewById(R.id.fingerprint_image);
fingerprintTextView = (TextView) findViewById(R.id.fingerprint_label);
passwordView = (EditText) findViewById(R.id.password);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
fingerPrintAnimatedVector = new FingerPrintAnimatedVector(this,
(ImageView) fingerprintImageView);
}
new InitTask().execute(i);
}
@@ -216,6 +227,11 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
protected void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& fingerPrintAnimatedVector != null) {
fingerPrintAnimatedVector.startScan();
}
// If the application was shutdown make sure to clear the password field, if it
// was saved in the instance state
if (App.isShutdown()) {
@@ -287,7 +303,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
if ( !fingerprintMustBeConfigured ) {
final boolean validInput = s.length() > 0;
// encrypt or decrypt mode based on how much input or not
confirmationView.setText(validInput ? R.string.store_with_fingerprint : R.string.scanning_fingerprint);
fingerprintTextView.setText(validInput ? R.string.store_with_fingerprint : R.string.scanning_fingerprint);
mode = validInput ? toggleMode(Cipher.ENCRYPT_MODE) : toggleMode(Cipher.DECRYPT_MODE);
}
}
@@ -304,7 +320,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
// errorCode = 5
// errString = "Fingerprint operation canceled."
//onFingerprintException();
//confirmationView.setText(errString);
//fingerprintTextView.setText(errString);
// true false fingerprint readings are handled otherwise with the toast messages, see below in code
}
@@ -314,7 +330,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
final CharSequence helpString) {
onFingerprintException(new Exception("onAuthenticationHelp"));
confirmationView.setText(helpString);
fingerprintTextView.setText(helpString);
}
@Override
@@ -370,6 +386,12 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
@Override
protected void onPause() {
super.onPause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& fingerPrintAnimatedVector != null) {
fingerPrintAnimatedVector.stopScan();
}
// stop listening when we go in background
if (fingerPrintHelper != null) {
fingerPrintHelper.stopListening();
@@ -377,42 +399,48 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
}
private void setFingerPrintVisibility(int vis) {
fingerprintView.setVisibility(vis);
confirmationView.setVisibility(vis);
fingerprintContainerView.setVisibility(vis);
}
@RequiresApi(api = Build.VERSION_CODES.M)
private void checkAvailability() {
// fingerprint not supported (by API level or hardware) so keep option hidden
if (!fingerPrintHelper.isFingerprintSupported(FingerprintManagerCompat.from(this))) {
setFingerPrintVisibility(View.GONE);
}
// fingerprint is available but not configured show icon but in disabled state with some information
else if (!fingerPrintHelper.hasEnrolledFingerprints()) {
setFingerPrintVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
fingerprintView.setAlpha(0.3f);
}
// This happens when no fingerprints are registered. Listening won't start
confirmationView.setText(R.string.configure_fingerprint);
}
// finally fingerprint available and configured so we can use it
else {
fingerprintMustBeConfigured = false;
// show explanations
fingerprintContainerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FingerPrintDialog fingerPrintDialog = new FingerPrintDialog();
fingerPrintDialog.show(getSupportFragmentManager(), "fingerprintDialog");
}
});
setFingerPrintVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
fingerprintView.setAlpha(1f);
if (!fingerPrintHelper.hasEnrolledFingerprints()) {
fingerprintImageView.setAlpha(0.3f);
// This happens when no fingerprints are registered. Listening won't start
fingerprintTextView.setText(R.string.configure_fingerprint);
}
// fingerprint available but no stored password found yet for this DB so show info don't listen
if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) {
confirmationView.setText(R.string.no_password_stored);
}
// all is set here so we can confirm to user and start listening for fingerprints
// finally fingerprint available and configured so we can use it
else {
confirmationView.setText(R.string.scanning_fingerprint);
// listen for decryption by default
toggleMode(Cipher.DECRYPT_MODE);
fingerprintMustBeConfigured = false;
fingerprintImageView.setAlpha(1f);
// fingerprint available but no stored password found yet for this DB so show info don't listen
if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) {
fingerprintTextView.setText(R.string.no_password_stored);
}
// all is set here so we can confirm to user and start listening for fingerprints
else {
fingerprintTextView.setText(R.string.scanning_fingerprint);
// listen for decryption by default
toggleMode(Cipher.DECRYPT_MODE);
}
}
}
}
@@ -428,7 +456,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
.apply();
// and remove visual input to reset UI
confirmButton.performClick();
confirmationView.setText(R.string.encrypted_value_stored);
fingerprintTextView.setText(R.string.encrypted_value_stored);
}
@Override
@@ -0,0 +1,54 @@
/*
* Copyright 2017 Brian Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.fingerprint;
import android.content.Context;
import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.widget.ImageView;
import com.kunzisoft.keepass.R;
@RequiresApi(api = Build.VERSION_CODES.M)
public class FingerPrintAnimatedVector {
private AnimatedVectorDrawable scanFingerprint;
public FingerPrintAnimatedVector(Context context, ImageView imageView) {
scanFingerprint = (AnimatedVectorDrawable) context.getDrawable(R.drawable.scan_fingerprint);
imageView.setImageDrawable(scanFingerprint);
}
public void startScan() {
scanFingerprint.registerAnimationCallback(new Animatable2.AnimationCallback() {
public void onAnimationEnd(Drawable drawable) {
scanFingerprint.start();
}
});
scanFingerprint.start();
}
public void stopScan() {
scanFingerprint.stop();
}
}
@@ -0,0 +1,84 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.view;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.keepassdroid.fingerprint.FingerPrintAnimatedVector;
import com.kunzisoft.keepass.R;
@RequiresApi(api = Build.VERSION_CODES.M)
public class FingerPrintDialog extends DialogFragment {
private FingerPrintAnimatedVector fingerPrintAnimatedVector;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View rootView = inflater.inflate(R.layout.fingerprint_dialog, null);
View fingerprintSettingWayTextView = rootView.findViewById(R.id.fingerprint_setting_way_text);
fingerprintSettingWayTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
}
});
fingerPrintAnimatedVector =
new FingerPrintAnimatedVector(getContext(),
(ImageView) rootView.findViewById(R.id.fingerprint_image));
builder.setView(rootView)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
@Override
public void onResume() {
super.onResume();
fingerPrintAnimatedVector.startScan();
}
@Override
public void onPause() {
super.onPause();
fingerPrintAnimatedVector.stopScan();
}
}