From aa0cd81931a3de595549afc5b9340eeb46734ee8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Sep 2017 20:40:40 +0200 Subject: [PATCH] add a helper function for checking if fingerprint sensor is available --- commons/src/main/AndroidManifest.xml | 7 ++++++- .../commons/extensions/Context-storage.kt | 6 ------ .../commons/extensions/Context.kt | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/commons/src/main/AndroidManifest.xml b/commons/src/main/AndroidManifest.xml index e47b33e90..807eece84 100644 --- a/commons/src/main/AndroidManifest.xml +++ b/commons/src/main/AndroidManifest.xml @@ -1,2 +1,7 @@ - + + + + diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt index e7b90389c..30d399ed0 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt @@ -97,12 +97,6 @@ fun Context.getInternalStoragePath() = Environment.getExternalStorageDirectory() @SuppressLint("NewApi") fun Context.isPathOnSD(path: String) = sdCardPath.isNotEmpty() && path.startsWith(sdCardPath) -fun Context.isKitkatPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT - -fun Context.isLollipopPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP - -fun Context.isNougatPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N - @SuppressLint("NewApi") fun Context.needsStupidWritePermissions(path: String) = isPathOnSD(path) && isLollipopPlus() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index 713bacc05..37a57803d 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -1,9 +1,12 @@ package com.simplemobiletools.commons.extensions import android.Manifest +import android.annotation.SuppressLint import android.content.Context import android.content.pm.PackageManager import android.graphics.drawable.ColorDrawable +import android.hardware.fingerprint.FingerprintManager +import android.os.Build import android.os.Looper import android.support.v4.content.ContextCompat import android.support.v7.app.AlertDialog @@ -19,6 +22,7 @@ import com.simplemobiletools.commons.helpers.PREFS_KEY import com.simplemobiletools.commons.views.* import kotlinx.android.synthetic.main.dialog_title.view.* + fun Context.isOnMainThread() = Looper.myLooper() == Looper.getMainLooper() fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE) @@ -27,6 +31,14 @@ fun Context.hasWriteStoragePermission() = ContextCompat.checkSelfPermission(this fun Context.hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED fun Context.hasRecordAudioPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED +fun Context.isKitkatPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT + +fun Context.isLollipopPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + +fun Context.isMarshmallowPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + +fun Context.isNougatPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N + fun Context.updateTextColors(viewGroup: ViewGroup, tmpTextColor: Int = 0, tmpAccentColor: Int = 0) { val textColor = if (tmpTextColor == 0) baseConfig.textColor else tmpTextColor val accentColor = if (tmpAccentColor == 0) baseConfig.primaryColor else tmpAccentColor @@ -113,3 +125,6 @@ fun Context.isThankYouInstalled(): Boolean { false } } + +@SuppressLint("InlinedApi", "NewApi") +fun Context.isFingerPrintSensorAvailable() = isMarshmallowPlus() && (getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager).isHardwareDetected