Skip to content

Commit

Permalink
6.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Nov 16, 2022
1 parent dc7a708 commit 9563045
Show file tree
Hide file tree
Showing 24 changed files with 906 additions and 1,649 deletions.
2 changes: 1 addition & 1 deletion RNDocumentReaderApi.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Pod::Spec.new do |s|
s.source = { :http => 'file:' + __dir__ }
s.ios.deployment_target = '11.0'
s.source_files = "ios/*.{h,m}"
s.dependency 'DocumentReader', '6.5.2633'
s.dependency 'DocumentReader', '6.6.2753'
s.dependency 'React'
end
33 changes: 4 additions & 29 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,55 +1,30 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
mavenCentral()
}

rootProject.allprojects {
repositories {
maven {
url "https://maven.regulaforensics.com/RegulaDocumentReader"
}
maven {
url "https://maven.regulaforensics.com/RegulaDocumentReader/Beta"
}
}
}

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
//noinspection GradleDependency
implementation('com.regula.documentreader:api:6.5.7488') {
implementation('com.regula.documentreader:api:6.6.8072') {
transitive = true
}
}
Expand Down
6 changes: 5 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.regula.documentreader">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
</manifest>


108 changes: 108 additions & 0 deletions android/src/main/java/com/regula/documentreader/BluetoothUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.regula.documentreader

import android.Manifest.permission.*
import android.annotation.SuppressLint
import android.app.Activity
import android.bluetooth.BluetoothAdapter
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.os.Build
import android.os.IBinder
import android.provider.Settings
import androidx.annotation.RequiresPermission
import androidx.core.app.ActivityCompat.requestPermissions
import androidx.core.content.ContextCompat.checkSelfPermission
import com.regula.documentreader.api.ble.BLEWrapper
import com.regula.documentreader.api.ble.BleWrapperCallback
import com.regula.documentreader.api.ble.RegulaBleService
import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelper.BLE_ACCESS_PERMISSION
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled

class BluetoothUtil {
companion object {
private const val REQUEST_ENABLE_LOCATION = 196
private const val REQUEST_ENABLE_BT = 197

@SuppressLint("StaticFieldLeak")
var bleManager: BLEWrapper? = null

@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
private fun requestEnableBle(activity: Activity) {
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
}

private fun requestEnableLocationService(activity: Activity) {
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
}

// requestEnableBle() is called after a check for permission
@SuppressLint("MissingPermission")
fun isBlePermissionsGranted(activity: Activity): Boolean {
if (!isLocationServiceEnabled(activity)) {
requestEnableLocationService(activity)
return false
}
deniedBluetoothPermissions(activity)?.let {
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
return false
}
if (!isBluetoothEnabled(activity)) {
requestEnableBle(activity)
return false
}
return true
}

private fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
val result = mutableListOf<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
} else
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
return result.let { if (it.size > 0) it.toTypedArray() else null }
}

private fun deniedBluetoothPermission(
activity: Activity,
permission: String
): Array<String> {
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
return arrayOf(permission)
return arrayOf()
}

fun startBluetoothService(
activity: Activity,
onConnected: (Boolean) -> Unit,
onDisconnected: () -> Unit,
onReady: () -> Unit,
) {
val bleIntent = Intent(activity, RegulaBleService::class.java)
activity.startService(bleIntent)

activity.bindService(bleIntent, object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
val isBleManagerConnected = bleManager?.isConnected == true
onConnected(isBleManagerConnected)
if (!isBleManagerConnected) {
bleManager?.addCallback(object : BleWrapperCallback() {
override fun onDeviceReady() {
bleManager!!.removeCallback(this)
onReady()
}
})
}
}

override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
}, 0)
}
}
}
9 changes: 4 additions & 5 deletions android/src/main/java/com/regula/documentreader/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ static Bitmap bitmapFromBase64(String base64) {
return result;
}

static BitmapDrawable drawableFromBase64(String base64, Context context)
{
static BitmapDrawable drawableFromBase64(String base64, Context context) {
byte[] decodedByte = Base64.decode(base64, 0);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
float density = context.getResources().getDisplayMetrics().density;
int width = (int)(bitmap.getWidth()*density);
int height = (int)(bitmap.getHeight()*density);
int width = (int) (bitmap.getWidth() * density);
int height = (int) (bitmap.getHeight() * density);
return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, width, height, false));
}

Expand Down
Loading

0 comments on commit 9563045

Please sign in to comment.