Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 2c16dbf

Browse files
author
Mateusz Maziec
committed
Merge branch 'release/1.0.20'
2 parents dfe28de + cc99982 commit 2c16dbf

File tree

10 files changed

+65
-28
lines changed

10 files changed

+65
-28
lines changed

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
66

77
android {
8-
compileSdkVersion 27
8+
compileSdkVersion 28
99
defaultConfig {
1010
applicationId "com.bobekos.bobek.simplebarcodescanner"
1111
minSdkVersion 15
12-
targetSdkVersion 27
12+
targetSdkVersion 28
1313
versionCode 1
1414
versionName "1.0"
15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
}
1717
buildTypes {
1818
release {
@@ -25,7 +25,7 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28-
implementation 'com.android.support:appcompat-v7:27.1.1'
28+
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
2929

3030
testImplementation 'junit:junit:4.12'
3131

app/src/main/java/com/bobekos/bobek/simplebarcodescanner/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bobekos.bobek.simplebarcodescanner
22

33
import android.os.Bundle
4-
import android.support.v7.app.AppCompatActivity
4+
import androidx.appcompat.app.AppCompatActivity
55
import android.widget.Toast
66
import com.google.android.gms.vision.CameraSource
77
import io.reactivex.android.schedulers.AndroidSchedulers

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.2.51'
4+
ext.kotlin_version = '1.3.10'
55
repositories {
66
google()
77
jcenter()
88
mavenCentral()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.3.0-alpha03'
11+
classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1414

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
77
# Specifies the JVM arguments used for the daemon process.
88
# The setting is particularly useful for tweaking memory settings.
9+
android.enableJetifier=true
10+
android.useAndroidX=true
911
org.gradle.jvmargs=-Xmx1536m
1012
# When configured, Gradle will run in incubating parallel mode.
1113
# This option should only be used with decoupled projects. More details, visit
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Aug 01 21:01:12 CEST 2018
1+
#Sat Oct 27 00:18:43 CEST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-rc-1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

scanner/build.gradle

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ apply plugin: 'com.github.dcendents.android-maven'
44
group = 'com.github.bobekos'
55

66
android {
7-
compileSdkVersion 27
7+
compileSdkVersion 28
88

99
defaultConfig {
1010
minSdkVersion 15
11-
targetSdkVersion 27
12-
versionCode 18
13-
versionName "1.0.18"
11+
targetSdkVersion 28
12+
versionCode 20
13+
versionName "1.0.20"
1414

15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616

1717
}
1818

@@ -28,18 +28,18 @@ android {
2828
dependencies {
2929
implementation fileTree(dir: 'libs', include: ['*.jar'])
3030

31-
implementation 'com.android.support:appcompat-v7:27.1.1'
32-
implementation 'com.android.support:support-media-compat:27.1.1'
33-
implementation 'com.android.support:support-v4:27.1.1'
31+
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
32+
implementation 'androidx.media:media:1.1.0-alpha01'
33+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
3434

3535
testImplementation 'junit:junit:4.12'
3636
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3737

38-
api 'com.google.android.gms:play-services-gcm:15.0.1'
39-
api 'com.google.android.gms:play-services-vision:15.0.2'
38+
api 'com.google.android.gms:play-services-gcm:16.0.0'
39+
api 'com.google.android.gms:play-services-vision:17.0.2'
4040

41-
api "io.reactivex.rxjava2:rxandroid:2.0.2"
42-
api "io.reactivex.rxjava2:rxjava:2.1.15"
41+
api "io.reactivex.rxjava2:rxandroid:2.1.0"
42+
api "io.reactivex.rxjava2:rxjava:2.2.3"
4343
}
4444
repositories {
4545
mavenCentral()

scanner/src/main/java/com/bobekos/bobek/scanner/BarcodeView.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import android.content.pm.PackageManager
66
import android.content.res.Configuration
77
import android.graphics.Color
88
import android.graphics.Rect
9-
import android.support.v4.app.ActivityCompat
109
import android.util.AttributeSet
1110
import android.util.DisplayMetrics
12-
import android.view.*
11+
import android.view.SurfaceHolder
12+
import android.view.SurfaceView
13+
import android.view.View
14+
import android.view.WindowManager
1315
import android.widget.FrameLayout
16+
import androidx.core.app.ActivityCompat
1417
import com.bobekos.bobek.scanner.overlay.BarcodeOverlay
1518
import com.bobekos.bobek.scanner.overlay.BarcodeRectOverlay
1619
import com.bobekos.bobek.scanner.overlay.Optional
@@ -23,7 +26,6 @@ import io.reactivex.Observable
2326
import io.reactivex.ObservableEmitter
2427
import io.reactivex.android.schedulers.AndroidSchedulers
2528
import io.reactivex.disposables.Disposable
26-
import io.reactivex.schedulers.Schedulers
2729
import io.reactivex.subjects.PublishSubject
2830

2931

@@ -63,15 +65,15 @@ class BarcodeView : FrameLayout {
6365
BarcodeScanner(context, cameraView.holder, config)
6466
}
6567

66-
constructor(context: Context?) : super(context) {
68+
constructor(context: Context) : super(context) {
6769
init(null)
6870
}
6971

70-
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
72+
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
7173
init(attrs)
7274
}
7375

74-
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
76+
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
7577
init(attrs)
7678
}
7779

@@ -165,6 +167,17 @@ class BarcodeView : FrameLayout {
165167
fun setVibration(duration: Long = 500) = apply {
166168
config.vibrateDuration = duration
167169
}
170+
171+
/**
172+
* If this function is set, the DetectorNotReadyException will
173+
* be thrown in onError if isOperational function of the detector return false.
174+
* By default the subscription is resubscribed every 3 seconds until the detector is ready.
175+
* Use only if you want to handle this exception by yourself.
176+
* @see <a href="https://developers.google.com/android/reference/com/google/android/gms/vision/barcode/BarcodeDetector.html#isOperational()">BarcodeDetector.isOperational()</a>
177+
*/
178+
fun setManualIsOperationalCheck() = apply {
179+
config.isManualOperationalCheck = true
180+
}
168181
//endregion
169182

170183
//region private

scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.reactivex.ObservableEmitter
1515
import io.reactivex.disposables.Disposable
1616
import io.reactivex.schedulers.Schedulers
1717
import io.reactivex.subjects.PublishSubject
18+
import java.util.concurrent.TimeUnit
1819

1920

2021
internal class BarcodeScanner(
@@ -46,6 +47,8 @@ internal class BarcodeScanner(
4647
} else {
4748
if (context == null && !emitter.isDisposed) {
4849
emitter.onError(NullPointerException("Context is null"))
50+
} else if (!barcodeDetector.isOperational) {
51+
emitter.onError(DetectorNotReadyException())
4952
} else {
5053
camera.init(barcodeDetector).getCameraSource()?.start(holder)
5154
camera.setParametersFromConfig()
@@ -70,6 +73,15 @@ internal class BarcodeScanner(
7073
if (config.vibrateDuration > 0) {
7174
DetectionHelper.vibrate(context, config.vibrateDuration)
7275
}
76+
}.retryWhen { exc ->
77+
exc.flatMap {
78+
if (it is DetectorNotReadyException && !config.isManualOperationalCheck) {
79+
Observable.timer(3, TimeUnit.SECONDS)
80+
} else {
81+
Observable.error(it)
82+
}
83+
}
84+
7385
}.subscribeOn(Schedulers.io())
7486
}
7587

scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScannerConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ internal data class BarcodeScannerConfig(
1212
var previewSize: Size,
1313
var barcodeFormat: Int = Barcode.ALL_FORMATS,
1414
var playBeep: Boolean = false,
15-
var vibrateDuration: Long = 0
15+
var vibrateDuration: Long = 0,
16+
var isManualOperationalCheck: Boolean = false
1617
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.bobekos.bobek.scanner.scanner
2+
3+
/**
4+
* When an app is first installed, it may be necessary to download required files.
5+
* If this is throw, those files are not yet available.
6+
* Usually this download is taken care of at application install time, but this is not guaranteed.
7+
* In some cases the download may have been delayed.
8+
*/
9+
class DetectorNotReadyException : Exception()

0 commit comments

Comments
 (0)