Skip to content

Commit f435a4b

Browse files
author
ci-bot
committed
Updated projects
1 parent a18f076 commit f435a4b

35 files changed

Lines changed: 351 additions & 112 deletions

File tree

BasicSample/app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ plugins {
44
}
55

66
android {
7-
compileSdk 35
7+
compileSdk 36
88

99
defaultConfig {
1010
applicationId "com.regula.facesamplekotlin"
1111
minSdk 21
12-
targetSdk 35
12+
targetSdk 36
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -29,7 +29,6 @@ android {
2929
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
3030
}
3131
}
32-
3332
buildFeatures {
3433
viewBinding true
3534
}
@@ -48,9 +47,9 @@ dependencies {
4847
implementation "androidx.core:core-ktx:1.7.0"
4948
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5049

51-
implementation ('com.regula.face:api:7.1.+@aar'){
50+
implementation ('com.regula.face:api:7.2.+@aar'){
5251
transitive = true
5352
}
5453

55-
implementation ('com.regula.face.core:basic:7.1.+@aar')
54+
implementation ('com.regula.face.core:basic:7.2.+@aar')
5655
}

BasicSample/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<activity
2020
android:name=".MatchFacesActivity"
2121
android:exported="false"
22-
android:screenOrientation="portrait" />
22+
android:screenOrientation="portrait"
23+
android:configChanges="orientation|screenSize|screenLayout" />
2324
<activity
2425
android:name=".MainActivity"
2526
android:exported="true">
@@ -31,10 +32,12 @@
3132
</activity>
3233
<activity
3334
android:name=".DetectFacesActivity"
34-
android:screenOrientation="portrait" />
35+
android:screenOrientation="portrait"
36+
android:configChanges="orientation|screenSize|screenLayout" />
3537
<activity
3638
android:name=".FaceImageQualityActivity"
37-
android:screenOrientation="portrait" />
39+
android:screenOrientation="portrait"
40+
android:configChanges="orientation|screenSize|screenLayout" />
3841

3942
<provider
4043
android:name="androidx.core.content.FileProvider"

BasicSample/app/src/main/java/com/regula/facesamplekotlin/DetectFacesActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import androidx.appcompat.app.AppCompatActivity
2424
import androidx.core.content.ContentProviderCompat.requireContext
2525
import androidx.core.content.ContextCompat
2626
import androidx.core.content.FileProvider
27+
import androidx.core.view.ViewCompat
28+
import androidx.core.view.WindowInsetsCompat
2729
import androidx.fragment.app.DialogFragment
2830
import com.regula.facesamplekotlin.databinding.ActivityDetectFacesBinding
2931
import com.regula.facesamplekotlin.util.RandomColors
@@ -127,7 +129,7 @@ class DetectFacesActivity : AppCompatActivity() {
127129
val option = BitmapFactory.Options()
128130
option.inScaled = false
129131
val bitmap = BitmapFactory.decodeResource(resources, res, option)
130-
bitmapToDetect = bitmap;
132+
bitmapToDetect = bitmap
131133
binding.imageViewMain.setImageBitmap(bitmapToDetect);
132134
}
133135

BasicSample/app/src/main/java/com/regula/facesamplekotlin/FaceImageQualityActivity.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.regula.facesamplekotlin
22

33
import android.os.Bundle
4+
import android.view.View
45
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.view.ViewCompat
7+
import androidx.core.view.WindowInsetsCompat
58
import com.regula.facesamplekotlin.detection.fragment.FaceImageQualityFragment
69
import com.regula.facesdk.detection.response.DetectFacesResponse
710

@@ -18,4 +21,29 @@ class FaceImageQualityActivity : AppCompatActivity() {
1821
.commitNow()
1922
}
2023
}
24+
25+
override fun setContentView(layoutResID: Int) {
26+
super.setContentView(layoutResID)
27+
28+
applyEdgeToEdgeInsets()
29+
}
30+
31+
private fun applyEdgeToEdgeInsets() {
32+
val rootView = window.decorView.findViewWithTag<View>("content")
33+
if (rootView != null) {
34+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
35+
val systemBars = insets.getInsets(
36+
WindowInsetsCompat.Type.systemBars()
37+
or WindowInsetsCompat.Type.displayCutout()
38+
)
39+
view.setPadding(
40+
systemBars.left,
41+
systemBars.top,
42+
systemBars.right,
43+
systemBars.bottom
44+
)
45+
insets
46+
}
47+
}
48+
}
2149
}

BasicSample/app/src/main/java/com/regula/facesamplekotlin/MainActivity.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package com.regula.facesamplekotlin
22

33
import android.os.Bundle
44
import android.util.Log
5+
import android.view.View
56
import android.widget.Toast
67
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.core.view.ViewCompat
9+
import androidx.core.view.WindowInsetsCompat
710
import androidx.recyclerview.widget.LinearLayoutManager
811
import com.regula.facesamplekotlin.CategoryDataProvider.Companion.getCategoryData
912
import com.regula.facesamplekotlin.databinding.ActivityMainBinding
@@ -36,4 +39,29 @@ class MainActivity : AppCompatActivity() {
3639
Log.d("MainActivity", "FaceSDK init completed successfully")
3740
}
3841
}
42+
43+
override fun setContentView(view: View?) {
44+
super.setContentView(view)
45+
46+
applyEdgeToEdgeInsets()
47+
}
48+
49+
private fun applyEdgeToEdgeInsets() {
50+
val rootView = window.decorView.findViewWithTag<View>("content")
51+
if (rootView != null) {
52+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
53+
val systemBars = insets.getInsets(
54+
WindowInsetsCompat.Type.systemBars()
55+
or WindowInsetsCompat.Type.displayCutout()
56+
)
57+
view.setPadding(
58+
systemBars.left,
59+
systemBars.top,
60+
systemBars.right,
61+
systemBars.bottom
62+
)
63+
insets
64+
}
65+
}
66+
}
3967
}

BasicSample/app/src/main/java/com/regula/facesamplekotlin/MatchFacesActivity.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import androidx.activity.result.contract.ActivityResultContracts.RequestPermissi
2828
import androidx.appcompat.app.AppCompatActivity
2929
import androidx.appcompat.widget.SwitchCompat
3030
import androidx.core.content.ContextCompat
31+
import androidx.core.view.ViewCompat
32+
import androidx.core.view.WindowInsetsCompat
3133
import androidx.fragment.app.DialogFragment
3234
import com.regula.facesamplekotlin.util.ResizeTransformation
3335
import com.regula.facesdk.FaceSDK
@@ -283,11 +285,7 @@ class MatchFacesActivity : AppCompatActivity() {
283285
}
284286

285287
imageUri?.let {
286-
val bitmap = contentResolver?.openInputStream(it).use { data ->
287-
BitmapFactory.decodeStream(data)
288-
}
289-
val resizedBitmap = ResizeTransformation(1080).transform(bitmap)
290-
imageView?.setImageBitmap(resizedBitmap)
288+
imageView?.setImageBitmap(photoHelper.getBitmapImageByUri(it))
291289
}
292290

293291
spinner?.setSelection(0)
@@ -401,4 +399,29 @@ class MatchFacesActivity : AppCompatActivity() {
401399
}
402400
}
403401
}
402+
403+
override fun setContentView(layoutResId: Int) {
404+
super.setContentView(layoutResId)
405+
406+
applyEdgeToEdgeInsets()
407+
}
408+
409+
private fun applyEdgeToEdgeInsets() {
410+
val rootView = window.decorView.findViewWithTag<View>("content")
411+
if (rootView != null) {
412+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
413+
val systemBars = insets.getInsets(
414+
WindowInsetsCompat.Type.systemBars()
415+
or WindowInsetsCompat.Type.displayCutout()
416+
)
417+
view.setPadding(
418+
systemBars.left,
419+
systemBars.top,
420+
systemBars.right,
421+
systemBars.bottom
422+
)
423+
insets
424+
}
425+
}
426+
}
404427
}

BasicSample/app/src/main/java/com/regula/facesamplekotlin/PhotoHelper.kt

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import android.content.Intent
66
import android.graphics.Bitmap
77
import android.graphics.BitmapFactory
88
import android.graphics.Matrix
9+
import android.media.ExifInterface
910
import android.net.Uri
10-
import android.os.Environment
1111
import android.provider.MediaStore
12-
import androidx.activity.result.ActivityResult
1312
import androidx.activity.result.ActivityResultLauncher
14-
import androidx.activity.result.contract.ActivityResultContracts
15-
import androidx.appcompat.app.AppCompatActivity
1613
import androidx.core.content.FileProvider
1714
import java.io.File
15+
import java.io.FileOutputStream
1816
import java.text.SimpleDateFormat
1917
import java.util.Date
2018
import java.util.Locale
@@ -35,24 +33,54 @@ class PhotoHelper (private val context: Context) {
3533
activityResultLauncher.launch(cameraIntent)
3634
}
3735

36+
fun getBitmapImageByUri(uri: Uri): Bitmap{
37+
val file = createImageFile()
38+
39+
val contentResolver = context.contentResolver
40+
val inputStream = contentResolver.openInputStream(uri)
41+
val outputStream = FileOutputStream(file)
42+
43+
inputStream?.use { input ->
44+
outputStream.use { output ->
45+
input.copyTo(output)
46+
}
47+
}
48+
49+
return rotateImageIfRequired(file)
50+
}
51+
3852
private fun createImageFile(): File {
3953
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
4054
val storageDir: File? = this.context.filesDir
4155
return File(storageDir, "temp_photo_${timeStamp}.jpg")
4256
}
4357

4458
fun handleResult(resultCode: Int) : Bitmap? {
45-
if (resultCode == Activity.RESULT_OK) {
46-
val photo = BitmapFactory.decodeFile(photoFile.absolutePath)
47-
val matrix = Matrix().apply {
48-
postRotate(90f)
49-
}
50-
return Bitmap.createBitmap(photo, 0, 0, photo.width, photo.height, matrix, true)
59+
return if (resultCode == Activity.RESULT_OK) {
60+
rotateImageIfRequired(photoFile)
5161
} else {
52-
return null
62+
null
63+
}
64+
}
65+
66+
private fun rotateImageIfRequired(imageFile: File): Bitmap {
67+
val exif = ExifInterface(imageFile.absolutePath)
68+
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
69+
val bitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
70+
return when (orientation) {
71+
ExifInterface.ORIENTATION_ROTATE_90 -> rotateBitmap(bitmap, 90)
72+
ExifInterface.ORIENTATION_ROTATE_180 -> rotateBitmap(bitmap, 180)
73+
ExifInterface.ORIENTATION_ROTATE_270 -> rotateBitmap(bitmap, 270)
74+
else -> bitmap
5375
}
5476
}
5577

78+
private fun rotateBitmap(bitmap: Bitmap, degrees: Int): Bitmap {
79+
val matrix = Matrix()
80+
matrix.postRotate(degrees.toFloat())
81+
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
82+
}
83+
5684
fun deleteImageFile(): Boolean {
5785
return if (photoFile.exists()) {
5886
photoFile.delete()

BasicSample/app/src/main/java/com/regula/facesamplekotlin/detection/fragment/FaceImageQualityFragment.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,7 @@ class FaceImageQualityFragment : Fragment() {
302302
if (result.resultCode == Activity.RESULT_OK) {
303303
val intent = result.data
304304
intent?.data?.let {
305-
val bitmap = context?.contentResolver?.openInputStream(it).use { data ->
306-
BitmapFactory.decodeStream(data)
307-
}
308-
val resizedBitmap = ResizeTransformation(1080).transform(bitmap)
309-
binding.imageViewMain.setImageBitmap(resizedBitmap)
310-
resizedBitmap?.let {
311-
setImage(resizedBitmap)
312-
} ?: binding.imageViewSample1.callOnClick()
305+
setImage(photoHelper.getBitmapImageByUri(it))
313306
}
314307
}
315308
}

BasicSample/app/src/main/res/layout/activity_detect_faces.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="fill_parent"
66
android:layout_height="fill_parent"
7-
android:orientation="vertical">
7+
android:orientation="vertical"
8+
android:tag="content">
89

910
<androidx.fragment.app.FragmentContainerView
1011
android:id="@+id/fragment_container_view"

BasicSample/app/src/main/res/layout/activity_face_quality.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
android:id="@+id/container"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
tools:context=".FaceImageQualityActivity" />
7+
tools:context=".FaceImageQualityActivity"
8+
android:tag="content"/>

0 commit comments

Comments
 (0)