mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-04 15:52:34 -08:00
feat: Fingerprint button as real button
This commit is contained in:
1 parent
244174e494
commit
8fa8043ff4
42 files changed
+65
-437
No files matched your search
@@ -221,8 +221,6 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
allowOpenBiometricPrompt = true
|
||||
if (PreferencesUtil.isBiometricUnlockEnable(context)) {
|
||||
mAdvancedUnlockInfoView?.setIconResource(R.drawable.fingerprint)
|
||||
|
||||
// biometric not supported (by API level or hardware) so keep option hidden
|
||||
// or manually disable
|
||||
val biometricCanAuthenticate = AdvancedUnlockManager.canAuthenticate(context)
|
||||
@@ -241,7 +239,6 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
}
|
||||
}
|
||||
} else if (PreferencesUtil.isDeviceCredentialUnlockEnable(context)) {
|
||||
mAdvancedUnlockInfoView?.setIconResource(R.drawable.bolt)
|
||||
if (AdvancedUnlockManager.isDeviceSecure(context)) {
|
||||
selectMode()
|
||||
} else {
|
||||
@@ -297,12 +294,12 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
private fun initNotAvailable() {
|
||||
showViews(false)
|
||||
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener(false, null)
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener(null)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun openBiometricSetting() {
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener(false) {
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener {
|
||||
try {
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
@@ -351,11 +348,11 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun initWaitData() {
|
||||
showViews(true)
|
||||
setAdvancedUnlockedTitleView(R.string.no_credentials_stored)
|
||||
setAdvancedUnlockedTitleView(R.string.unavailable)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
context?.let { context ->
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener(false) {
|
||||
mAdvancedUnlockInfoView?.setIconViewClickListener {
|
||||
onAuthenticationError(BiometricPrompt.ERROR_UNABLE_TO_PROCESS,
|
||||
context.getString(R.string.credential_before_click_advanced_unlock_button))
|
||||
}
|
||||
@@ -382,7 +379,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun initEncryptData() {
|
||||
showViews(true)
|
||||
setAdvancedUnlockedTitleView(R.string.open_advanced_unlock_prompt_store_credential)
|
||||
setAdvancedUnlockedTitleView(R.string.link_biometric_and_unlock)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
advancedUnlockManager?.initEncryptData { cryptoPrompt ->
|
||||
@@ -396,7 +393,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun initDecryptData() {
|
||||
showViews(true)
|
||||
setAdvancedUnlockedTitleView(R.string.open_advanced_unlock_prompt_unlock_database)
|
||||
setAdvancedUnlockedTitleView(R.string.unlock)
|
||||
setAdvancedUnlockedMessageView("")
|
||||
|
||||
advancedUnlockManager?.let { unlockHelper ->
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
* KeePassDX 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePassDX 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 KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.biometric
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import android.widget.ImageView
|
||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
class FingerPrintAnimatedVector(context: Context, imageView: ImageView) {
|
||||
|
||||
private val scanFingerprint: AnimatedVectorDrawableCompat? =
|
||||
AnimatedVectorDrawableCompat.create(context, R.drawable.scan_fingerprint)
|
||||
|
||||
init {
|
||||
imageView.setImageDrawable(scanFingerprint)
|
||||
}
|
||||
|
||||
private var animationCallback = object : Animatable2Compat.AnimationCallback() {
|
||||
override fun onAnimationEnd(drawable: Drawable) {
|
||||
imageView.post {
|
||||
scanFingerprint?.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun startScan() {
|
||||
scanFingerprint?.registerAnimationCallback(animationCallback)
|
||||
|
||||
if (scanFingerprint?.isRunning != true)
|
||||
scanFingerprint?.start()
|
||||
}
|
||||
|
||||
fun stopScan() {
|
||||
scanFingerprint?.unregisterAnimationCallback(animationCallback)
|
||||
|
||||
if (scanFingerprint?.isRunning == true)
|
||||
scanFingerprint.stop()
|
||||
}
|
||||
}
|
||||
@@ -23,15 +23,12 @@ import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.biometric.FingerPrintAnimatedVector
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
class AdvancedUnlockInfoView @JvmOverloads constructor(context: Context,
|
||||
@@ -39,60 +36,26 @@ class AdvancedUnlockInfoView @JvmOverloads constructor(context: Context,
|
||||
defStyle: Int = 0)
|
||||
: LinearLayout(context, attrs, defStyle) {
|
||||
|
||||
private val unlockContainerView: View
|
||||
private var unlockAnimatedVector: FingerPrintAnimatedVector? = null
|
||||
private var unlockTitleTextView: TextView? = null
|
||||
private var unlockIconImageView: ImageView? = null
|
||||
private var biometricButtonView: TextView? = null
|
||||
|
||||
init {
|
||||
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
|
||||
inflater?.inflate(R.layout.view_advanced_unlock, this)
|
||||
|
||||
unlockContainerView = findViewById(R.id.fingerprint_container)
|
||||
unlockTitleTextView = findViewById(R.id.biometric_title)
|
||||
unlockIconImageView = findViewById(R.id.biometric_image)
|
||||
biometricButtonView = findViewById(R.id.biometric_button)
|
||||
}
|
||||
|
||||
private fun startIconViewAnimation() {
|
||||
unlockAnimatedVector?.startScan()
|
||||
}
|
||||
|
||||
private fun stopIconViewAnimation() {
|
||||
unlockAnimatedVector?.stopScan()
|
||||
}
|
||||
|
||||
fun setIconResource(iconId: Int) {
|
||||
unlockIconImageView?.setImageResource(iconId)
|
||||
// Init the fingerprint animation
|
||||
unlockAnimatedVector = when (iconId) {
|
||||
R.drawable.fingerprint -> FingerPrintAnimatedVector(context, unlockIconImageView!!)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun setIconViewClickListener(animation: Boolean = true,
|
||||
listener: ((view: View)->Unit)?) {
|
||||
var animateButton = animation
|
||||
if (listener == null)
|
||||
animateButton = false
|
||||
if (animateButton) {
|
||||
startIconViewAnimation()
|
||||
unlockContainerView.alpha = 1f
|
||||
} else {
|
||||
stopIconViewAnimation()
|
||||
unlockContainerView.alpha = 0.8f
|
||||
}
|
||||
unlockIconImageView?.setOnClickListener(listener)
|
||||
unlockTitleTextView?.setOnClickListener(listener)
|
||||
fun setIconViewClickListener(listener: OnClickListener?) {
|
||||
biometricButtonView?.setOnClickListener(listener)
|
||||
}
|
||||
|
||||
var title: CharSequence
|
||||
get() {
|
||||
return unlockTitleTextView?.text?.toString() ?: ""
|
||||
return biometricButtonView?.text?.toString() ?: ""
|
||||
}
|
||||
set(value) {
|
||||
unlockTitleTextView?.text = value
|
||||
biometricButtonView?.text = value
|
||||
}
|
||||
|
||||
fun setTitle(@StringRes textId: Int) {
|
||||
|
||||
Reference in new issue
Block a user