-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
17 changed files
with
634 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
app/src/main/java/ani/dantotsu/others/calc/BiometricPromptUtils.kt
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,57 @@ | ||
package ani.dantotsu.others.calc | ||
|
||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.biometric.BiometricPrompt | ||
import androidx.core.content.ContextCompat | ||
import ani.dantotsu.R | ||
import ani.dantotsu.util.Logger | ||
|
||
object BiometricPromptUtils { | ||
private const val TAG = "BiometricPromptUtils" | ||
|
||
/** | ||
* Create a BiometricPrompt instance | ||
* @param activity: AppCompatActivity | ||
* @param processSuccess: success callback | ||
*/ | ||
fun createBiometricPrompt( | ||
activity: AppCompatActivity, | ||
processSuccess: (BiometricPrompt.AuthenticationResult) -> Unit | ||
): BiometricPrompt { | ||
val executor = ContextCompat.getMainExecutor(activity) | ||
|
||
val callback = object : BiometricPrompt.AuthenticationCallback() { | ||
|
||
override fun onAuthenticationError(errCode: Int, errString: CharSequence) { | ||
super.onAuthenticationError(errCode, errString) | ||
Logger.log("$TAG errCode is $errCode and errString is: $errString") | ||
} | ||
|
||
override fun onAuthenticationFailed() { | ||
super.onAuthenticationFailed() | ||
Logger.log("$TAG User biometric rejected.") | ||
} | ||
|
||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { | ||
super.onAuthenticationSucceeded(result) | ||
Log.d(TAG, "Authentication was successful") | ||
processSuccess(result) | ||
} | ||
} | ||
return BiometricPrompt(activity, executor, callback) | ||
} | ||
|
||
/** | ||
* Create a BiometricPrompt.PromptInfo instance | ||
* @param activity: AppCompatActivity | ||
* @return BiometricPrompt.PromptInfo: instance | ||
*/ | ||
fun createPromptInfo(activity: AppCompatActivity): BiometricPrompt.PromptInfo = | ||
BiometricPrompt.PromptInfo.Builder().apply { | ||
setTitle(activity.getString(R.string.bio_prompt_info_title)) | ||
setDescription(activity.getString(R.string.bio_prompt_info_desc)) | ||
setConfirmationRequired(false) | ||
setNegativeButtonText(activity.getString(R.string.cancel)) | ||
}.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
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
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
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
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
Oops, something went wrong.