Skip to content

Instantly share code, notes, and snippets.

View Jaosrikate's full-sized avatar

Srikate Jaosrikate

View GitHub Profile
@Jaosrikate
Jaosrikate / ApiHelper.kt
Created October 1, 2019 05:52
Retrofit2/OkHttp3 CookieJar Interceptor [kotlin]
// Retrofit2/OkHttp3 CookieJar Interceptor kotlin
// JaoSrikate
import android.util.Log
import android.webkit.CookieManager
import io.reactivex.Observable
import okhttp3.*
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Call
import retrofit2.Response
@Jaosrikate
Jaosrikate / MainActivity.java
Last active October 16, 2019 05:57
MPAndroidChart Pie chart highlighter
package com.example.myapplication;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
@Jaosrikate
Jaosrikate / GradientConstant.kt
Last active May 17, 2022 13:52
Android create gradient drawable programmatically (allow to use more than 3 colors) example
import android.content.Context
import android.graphics.drawable.GradientDrawable
import androidx.core.content.ContextCompat
class GradientConstant {
companion object {
fun goldGradient(activity: Context): GradientDrawable {
val colors: IntArray = intArrayOf(
@Jaosrikate
Jaosrikate / build.gradle
Last active January 25, 2022 15:47
Import Library for Biometric Prompt
def biometric_version = '1.1.0'
//Biometric
implementation "androidx.biometric:biometric:$biometric_version"
private fun buildBiometricPrompt(): BiometricPrompt.PromptInfo {
return BiometricPrompt.PromptInfo.Builder()
.setTitle(getString(R.string.bio_authen_title))
.setDescription(getString(R.string.bio_authen_description))
.setNegativeButtonText(getString(R.string.bio_authen_negative_button))
.setConfirmationRequired(false) //Allows user to authenticate without performing an action, such as pressing a button, after their biometric credential is accepted.
.setAllowedAuthenticators(BIOMETRIC_STRONG)
.build()
}
val biometricManager = BiometricManager.from(this)
when (biometricManager.canAuthenticate(BIOMETRIC_STRONG)) {
BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED,
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE,
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE,
BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED,
-> showErrorNoHardwareBio()
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED,
BiometricManager.BIOMETRIC_STATUS_UNKNOWN,
val cipher = CryptographyManager().getCipherForEncryption(BIO_KEY_NAME)
biometricPrompt.authenticate(
buildBiometricPrompt(),
BiometricPrompt.CryptoObject(cipher)
)
@Jaosrikate
Jaosrikate / LoginActivity.kt
Last active January 25, 2022 17:12
Biometric prompt Login Activity
class LoginActivity : AppCompatActivity() {
private lateinit var biometricPrompt: BiometricPrompt
private lateinit var promptInfo: BiometricPrompt.PromptInfo
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
biometricPrompt = createBiometricPrompt()
private fun getOrCreateSecretKey(keyName: String): SecretKey {
// If Secretkey was previously created for that keyName, then grab and return it.
try {
val keyStore = KeyStore.getInstance(ANDROID_KEYSTORE)
try {
keyStore.load(null) // Keystore must be loaded before it can be accessed
keyStore.getKey(keyName, null)?.let {
return it as SecretKey
}
} catch (ex: Exception) {
override fun getCipherForEncryption(keyName: String): Cipher {
val cipher = getCipher()
val secretKey = getOrCreateSecretKey(keyName)
cipher.init(Cipher.ENCRYPT_MODE, secretKey)
return cipher
}