Skip to content

Commit dbc285f

Browse files
committed
Update Android build
1 parent a8c381f commit dbc285f

6 files changed

Lines changed: 44 additions & 53 deletions

File tree

app/build.gradle

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
plugins {
22
id 'com.android.application'
3-
id 'org.jetbrains.kotlin.android'
43
}
54

65
android {
7-
namespace 'com.aspose.barcode.cloud.demo_app'
8-
compileSdk 35
6+
namespace = 'com.aspose.barcode.cloud.demo_app'
7+
compileSdk = 36
98

109
defaultConfig {
11-
applicationId "com.aspose.barcode.cloud.demo_app"
12-
minSdk 23
13-
targetSdk 35
14-
versionCode 1
15-
versionName "1.0"
10+
applicationId = "com.aspose.barcode.cloud.demo_app"
11+
minSdk = 23
12+
targetSdk = 36
13+
versionCode = 1
14+
versionName = "1.0"
1615

17-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1817
}
1918

2019
buildTypes {
2120
release {
22-
minifyEnabled false
21+
minifyEnabled = false
2322
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2423
}
2524
}
2625

2726
compileOptions {
28-
sourceCompatibility JavaVersion.VERSION_1_8
29-
targetCompatibility JavaVersion.VERSION_1_8
30-
}
31-
32-
kotlinOptions {
33-
jvmTarget = '1.8'
27+
sourceCompatibility = JavaVersion.VERSION_17
28+
targetCompatibility = JavaVersion.VERSION_17
3429
}
3530

3631
buildFeatures {
37-
buildConfig true
38-
viewBinding true
32+
buildConfig = true
33+
viewBinding = true
3934
}
4035
}
4136

4237
dependencies {
43-
implementation fileTree(dir: "libs", include: ["*.jar"])
44-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
45-
implementation 'androidx.core:core-ktx:1.9.0'
46-
implementation 'androidx.appcompat:appcompat:1.6.0'
47-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
48-
implementation 'com.aspose:aspose-barcode-cloud:26.3.0'
49-
implementation 'com.google.android.material:material:1.8.0'
38+
implementation 'androidx.core:core-ktx:1.18.0'
39+
implementation 'androidx.appcompat:appcompat:1.7.1'
40+
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
41+
implementation 'com.aspose:aspose-barcode-cloud:26.3.2'
42+
implementation 'com.google.android.material:material:1.13.0'
5043
testImplementation 'junit:junit:4.13.2'
51-
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
52-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
44+
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
45+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
5346
}

app/src/main/java/com/aspose/barcode/cloud/demo_app/MainActivity.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import android.widget.Spinner
4444
import androidx.activity.result.PickVisualMediaRequest
4545
import androidx.activity.result.contract.ActivityResultContracts
4646
import androidx.appcompat.app.AppCompatActivity
47+
import androidx.core.os.BundleCompat
4748
import androidx.core.view.ViewCompat
4849
import androidx.core.view.WindowCompat
4950
import androidx.core.view.WindowInsetsCompat
@@ -59,11 +60,10 @@ import com.google.android.material.snackbar.Snackbar
5960
import java.io.File
6061
import java.io.FileOutputStream
6162
import kotlin.math.floor
63+
import androidx.core.graphics.scale
6264

6365
class MainActivity : AppCompatActivity() {
6466
companion object {
65-
const val ACTION_IMAGE_CAPTURE_CALLBACK_CODE = 3
66-
6767
private fun imageSize(width: Int, height: Int, maxSize: Int = 384): Size {
6868
val ratio = width.toFloat() / height
6969
if (ratio > 1) {
@@ -84,7 +84,7 @@ class MainActivity : AppCompatActivity() {
8484

8585
private fun reduceBitmapSize(image: Bitmap): Bitmap {
8686
val newSize = imageSize(image.width, image.height)
87-
return Bitmap.createScaledBitmap(image, newSize.width, newSize.height, true)
87+
return image.scale(newSize.width, newSize.height)
8888
}
8989
}
9090

@@ -94,7 +94,21 @@ class MainActivity : AppCompatActivity() {
9494

9595
private lateinit var scanApi: ScanApi
9696
private lateinit var generateApi: GenerateApi
97-
private val encodeTypes = EncodeBarcodeType.values().map { it.toString() }.sorted()
97+
private val encodeTypes = EncodeBarcodeType.entries.map { it.toString() }.sorted()
98+
99+
private val cameraLauncher =
100+
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
101+
if (result.resultCode == Activity.RESULT_OK) {
102+
val bmpImage = result.data?.extras?.let {
103+
BundleCompat.getParcelable(it, "data", Bitmap::class.java)
104+
}
105+
if (bmpImage == null) {
106+
showErrorMessage("No photo captured")
107+
return@registerForActivityResult
108+
}
109+
recognizeBarcode(bmpImage)
110+
}
111+
}
98112

99113
private val photoPickerLauncher =
100114
registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
@@ -150,19 +164,6 @@ class MainActivity : AppCompatActivity() {
150164
barcodeTypeSpinner.setSelection(encodeTypes.indexOf("QR"))
151165
}
152166

153-
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
154-
super.onActivityResult(requestCode, resultCode, data)
155-
156-
if (requestCode == ACTION_IMAGE_CAPTURE_CALLBACK_CODE && resultCode == Activity.RESULT_OK) {
157-
val bmpImage = data?.extras?.get("data") as? Bitmap
158-
if (bmpImage == null) {
159-
showErrorMessage("No photo captured")
160-
return
161-
}
162-
recognizeBarcode(bmpImage)
163-
}
164-
}
165-
166167
private fun recognizeSelectedImage(uri: Uri) {
167168
try {
168169
val bytes = contentResolver.openInputStream(uri)?.use { it.readBytes() }
@@ -178,7 +179,7 @@ class MainActivity : AppCompatActivity() {
178179
}
179180

180181
recognizeBarcode(bmpImage)
181-
} catch (e: Exception) {
182+
} catch (_: Exception) {
182183
showErrorMessage("Unable to read selected image")
183184
}
184185
}
@@ -280,7 +281,7 @@ class MainActivity : AppCompatActivity() {
280281
fun onBtnTakePhotoClick(@Suppress("UNUSED_PARAMETER") view: View) {
281282
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
282283
if (takePictureIntent.resolveActivity(packageManager) != null) {
283-
startActivityForResult(takePictureIntent, ACTION_IMAGE_CAPTURE_CALLBACK_CODE)
284+
cameraLauncher.launch(takePictureIntent)
284285
}
285286
}
286287

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '8.7.3' apply false
4-
id 'com.android.library' version '8.7.3' apply false
5-
id 'org.jetbrains.kotlin.android' version '2.1.0' apply false
3+
id 'com.android.application' version '9.1.0' apply false
4+
id 'com.android.library' version '9.1.0' apply false
65
}
7-
ext.kotlin_version = '2.1.0'

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ kotlin.code.style=official
2121
# resources declared in the library itself and none from the library's dependencies,
2222
# thereby reducing the size of the R class for that library
2323
android.nonTransitiveRClass=true
24-
android.nonFinalResIds=false
2524
org.gradle.configuration-cache=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Fri Jan 27 19:13:42 YEKT 2023
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencyResolutionManagement {
1010
repositories {
1111
google()
1212
mavenCentral()
13-
maven { url 'https://releases.aspose.cloud/java/repo/' }
13+
maven { url = 'https://releases.aspose.cloud/java/repo/' }
1414

1515
}
1616
}

0 commit comments

Comments
 (0)