Skip to content

Commit a7e29c7

Browse files
committed
Release version 1.0.0
1 parent 3043157 commit a7e29c7

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

README.md

+99-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,109 @@
1+
[![](https://jitpack.io/v/javaherisaber/MLBarcodeScanner.svg)](https://jitpack.io/#javaherisaber/MLBarcodeScanner)
12
# MLBarcodeScanner
2-
A demo project to show how to implement barcode scanner using Google ML-Kit Vision api
3+
Android barcode scanner using Google ML-Kit Vision
34

4-
<img src="Screenshot.png" width="256" height="455">
5+
<img src="Screenshot.jpg" width="256" height="455">
6+
7+
# Usage
8+
## Dependency
9+
Top level build.gradle
10+
```groovy
11+
allprojects {
12+
repositories {
13+
maven { url 'https://jitpack.io' }
14+
// other repositories
15+
}
16+
}
17+
```
18+
19+
Module level build.gradle
20+
```groovy
21+
dependencies {
22+
implementation "com.github.javaherisaber:MLBarcodeScanner:1.0.0"
23+
}
24+
```
25+
26+
Create your layout
27+
```xml
28+
<androidx.constraintlayout.widget.ConstraintLayout android:layout_height="match_parent"
29+
android:layout_width="match_parent"
30+
xmlns:android="http://schemas.android.com/apk/res/android"
31+
xmlns:app="http://schemas.android.com/apk/res-auto"
32+
xmlns:tools="http://schemas.android.com/tools">
33+
34+
<androidx.camera.view.PreviewView
35+
android:id="@+id/previewView_cameraScanning"
36+
android:layout_height="0dp"
37+
android:layout_width="match_parent"
38+
app:layout_constraintTop_toTopOf="parent"
39+
app:layout_constraintBottom_toBottomOf="parent" />
40+
41+
<com.buildtoapp.mlbarcodescanner.GraphicOverlay
42+
android:id="@+id/graphic_overlay"
43+
android:layout_height="0dp"
44+
android:layout_width="0dp"
45+
app:layout_constraintBottom_toBottomOf="@id/previewView_cameraScanning"
46+
app:layout_constraintLeft_toLeftOf="@id/previewView_cameraScanning"
47+
app:layout_constraintRight_toRightOf="@id/previewView_cameraScanning"
48+
app:layout_constraintTop_toTopOf="@id/previewView_cameraScanning" />
49+
50+
<ImageView
51+
android:layout_height="264dp"
52+
android:layout_width="264dp"
53+
android:src="@drawable/ic_scan_area"
54+
app:layout_constraintBottom_toBottomOf="parent"
55+
app:layout_constraintEnd_toEndOf="parent"
56+
app:layout_constraintStart_toStartOf="parent"
57+
app:layout_constraintTop_toTopOf="parent"
58+
tools:ignore="ContentDescription" />
59+
60+
</androidx.constraintlayout.widget.ConstraintLayout>
61+
62+
```
63+
64+
Make sure to grant `android.permission.CAMERA` and then use the library
65+
```kotlin
66+
class MainActivity : AppCompatActivity() {
67+
private lateinit var binding: ActivityMainBinding
68+
private lateinit var barcodeScanner: MLBarcodeScanner
69+
70+
override fun onCreate(savedInstanceState: Bundle?) {
71+
super.onCreate(savedInstanceState)
72+
binding = ActivityMainBinding.inflate(layoutInflater)
73+
setContentView(binding.root)
74+
75+
if (!PermissionUtils.allRuntimePermissionsGranted(this, REQUIRED_RUNTIME_PERMISSIONS)) {
76+
PermissionUtils.getRuntimePermissions(this, REQUIRED_RUNTIME_PERMISSIONS)
77+
}
78+
initBarcodeScanner()
79+
}
80+
81+
private fun initBarcodeScanner() {
82+
barcodeScanner = MLBarcodeScanner(
83+
callback = { displayValue, rawValue ->
84+
// you can process your barcode here
85+
},
86+
focusBoxSize = MetricUtils.dpToPx(264),
87+
graphicOverlay = binding.graphicOverlay,
88+
previewView = binding.previewViewCameraScanning,
89+
lifecycleOwner = this,
90+
context = this,
91+
drawOverlay = true, // show rectangle around detected barcode
92+
drawBanner = true // show detected barcode value on top of it
93+
)
94+
}
95+
96+
companion object {
97+
private val REQUIRED_RUNTIME_PERMISSIONS = arrayOf(Manifest.permission.CAMERA)
98+
}
99+
}
100+
```
5101

6102
# Supported barcode types
7103
- **2D formats**: QR Code, Aztec, Data Matrix, PDF417
8104
- **Linear formats**: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, EAN-128, ITF, UPC-A, UPC-E
9105

10-
# Usage
106+
# Model types
11107
There are two types of dependency for barcode scanning using ML-Kit vision
12108

13109
## Bundled model

Screenshot.jpg

919 KB
Loading

Screenshot.png

-467 KB
Binary file not shown.

lib/build.gradle

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
plugins {
22
id 'com.android.library'
33
id 'org.jetbrains.kotlin.android'
4+
id 'maven-publish'
45
}
56

67
android {
78
namespace 'com.buildtoapp.mlbarcodescanner'
89
compileSdk 32
9-
1010
defaultConfig {
1111
minSdk 21
1212
targetSdk 32
13-
1413
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1514
consumerProguardFiles "consumer-rules.pro"
1615
}
@@ -43,4 +42,17 @@ dependencies {
4342
testImplementation 'junit:junit:4.13.2'
4443
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4544
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45+
}
46+
47+
afterEvaluate {
48+
publishing {
49+
publications {
50+
release(MavenPublication) {
51+
from components.release
52+
groupId = 'com.github.javaherisaber'
53+
artifactId = 'MLBarcodeScanner'
54+
version = '1.0.0'
55+
}
56+
}
57+
}
4658
}

0 commit comments

Comments
 (0)