Skip to content

Commit b41ccd2

Browse files
committed
Init project
0 parents  commit b41ccd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1820
-0
lines changed

Diff for: .gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

Diff for: app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Diff for: app/build.gradle

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'nl.storegear.android.mlbarcodescanner'
8+
compileSdk 32
9+
10+
defaultConfig {
11+
applicationId "nl.storegear.android.mlbarcodescanner"
12+
minSdk 21
13+
targetSdk 32
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
buildFeatures {
20+
viewBinding true
21+
}
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
32+
kotlinOptions {
33+
jvmTarget = '1.8'
34+
}
35+
}
36+
37+
dependencies {
38+
implementation 'androidx.core:core-ktx:1.7.0'
39+
implementation 'androidx.appcompat:appcompat:1.5.1'
40+
implementation 'com.google.android.material:material:1.6.1'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
42+
testImplementation 'junit:junit:4.13.2'
43+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45+
}

Diff for: app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package nl.storegear.android.mlbarcodescanner
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("nl.storegear.android.mlbarcodescanner", appContext.packageName)
23+
}
24+
}

Diff for: app/src/main/AndroidManifest.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.MLBarcodeScanner"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
24+
<meta-data
25+
android:name="android.app.lib_name"
26+
android:value="" />
27+
</activity>
28+
</application>
29+
30+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package nl.storegear.android.mlbarcodescanner
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
6+
class MainActivity : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_main)
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package nl.storegear.android.mlbarcodescanner.mlkit
2+
3+
import android.graphics.Rect
4+
import com.google.android.gms.tasks.Task
5+
import com.google.mlkit.vision.barcode.BarcodeScanner
6+
import com.google.mlkit.vision.barcode.BarcodeScanning
7+
import com.google.mlkit.vision.barcode.common.Barcode
8+
import com.google.mlkit.vision.common.InputImage
9+
import nl.storegear.android.mlbarcodescanner.util.BarcodeGraphic
10+
import nl.storegear.android.mlbarcodescanner.util.MetricUtils.dpToPx
11+
12+
/** Barcode Detector Demo. */
13+
class BarcodeScannerProcessor(private val callback: CameraXBarcodeCallback, private val offset: Int) : VisionProcessorBase<List<Barcode>>() {
14+
15+
// Note that if you know which format of barcode your app is dealing with, detection will be
16+
// faster to specify the supported barcode formats one by one, e.g.
17+
// BarcodeScannerOptions.Builder()
18+
// .setBarcodeFormats(Barcode.FORMAT_QR_CODE)
19+
// .build();
20+
private val barcodeScanner: BarcodeScanner = BarcodeScanning.getClient()
21+
22+
override fun stop() {
23+
super.stop()
24+
barcodeScanner.close()
25+
}
26+
27+
override fun detectInImage(image: InputImage): Task<List<Barcode>> {
28+
return barcodeScanner.process(image)
29+
}
30+
31+
override fun onSuccess(results: List<Barcode>, graphicOverlay: GraphicOverlay) {
32+
for (barcode in results) {
33+
val height = graphicOverlay.measuredHeight
34+
val width = graphicOverlay.measuredWidth
35+
val area = dpToPx(264)
36+
val left = (width / 2) - (area / 2)
37+
val right = (width / 2) + (area / 2)
38+
val top = (height / 2) - (area / 2)
39+
val bottom = (height / 2) + (area / 2)
40+
val focusArea = Rect(left, top, right, bottom)
41+
val box = barcode.boundingBox ?: return
42+
val barcodeRect = Rect(dpToPx(box.left), dpToPx(box.top), dpToPx(box.right), dpToPx(box.bottom))
43+
val displayValue = barcode.displayValue
44+
val rawValue = barcode.rawValue
45+
if (barcodeIsInFocusArea(focusArea, barcodeRect) && displayValue != null && rawValue != null) {
46+
callback.onNewBarcodeScanned(displayValue, rawValue)
47+
}
48+
49+
// todo: if you don't want to draw the banner remove this line and [BarcodeGraphic] class
50+
graphicOverlay.add(BarcodeGraphic(graphicOverlay, barcode))
51+
}
52+
}
53+
54+
private fun barcodeIsInFocusArea(focus: Rect, target: Rect): Boolean {
55+
return (focus.left < target.left - target.width() + offset) && (target.right < focus.right + offset)
56+
&& (focus.top < target.top + offset) && (focus.bottom > target.bottom + target.height() - offset)
57+
}
58+
59+
override fun onFailure(e: Exception) {
60+
// do nothing
61+
}
62+
}
63+
64+
fun interface CameraXBarcodeCallback {
65+
fun onNewBarcodeScanned(displayValue: String, rawValue: String)
66+
}

0 commit comments

Comments
 (0)