-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
3,534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "uz.theairsoft.barcodescanner" | ||
minSdkVersion 18 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support:design:28.0.0' | ||
implementation 'com.google.android.gms:play-services-vision:17.0.2' | ||
implementation 'org.greenrobot:eventbus:3.0.0' | ||
implementation 'junit:junit:4.13-beta-1' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/uz/theairsoft/barcodescanner/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uz.theairsoft.barcodescanner; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("uz.theairsoft.barcodescanner", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="uz.theairsoft.barcodescanner"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<uses-feature android:name="android.hardware.camera" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<meta-data | ||
android:name="com.google.android.gms.version" | ||
android:value="@integer/google_play_services_version" /> | ||
<meta-data | ||
android:name="com.google.android.gms.vision.DEPENDENCIES" | ||
android:value="barcode" /> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/uz/theairsoft/barcodescanner/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package uz.theairsoft.barcodescanner; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
|
||
import com.google.android.gms.vision.barcode.Barcode; | ||
|
||
import uz.theairsoft.barcodescanner.materialbarcodescanner.MaterialBarcodeScanner; | ||
import uz.theairsoft.barcodescanner.materialbarcodescanner.MaterialBarcodeScannerBuilder; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
} | ||
private void startScan() { | ||
/** | ||
* Build a new MaterialBarcodeScanner | ||
*/ | ||
final MaterialBarcodeScanner materialBarcodeScanner = new MaterialBarcodeScannerBuilder() | ||
.withActivity(MainActivity.this) | ||
.withEnableAutoFocus(true) | ||
.withBleepEnabled(true) | ||
.withBackfacingCamera() | ||
.withCenterTracker() | ||
.withText("Scanning...") | ||
.withResultListener(new MaterialBarcodeScanner.OnResultListener() { | ||
@Override | ||
public void onResult(Barcode barcode) { | ||
|
||
} | ||
}) | ||
.build(); | ||
materialBarcodeScanner.setActivityCompat(this); | ||
materialBarcodeScanner.setContainerId(R.id.content); | ||
materialBarcodeScanner.startScan(); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
app/src/main/java/uz/theairsoft/barcodescanner/materialbarcodescanner/BarcodeGraphic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (C) The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package uz.theairsoft.barcodescanner.materialbarcodescanner; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
|
||
import com.google.android.gms.vision.barcode.Barcode; | ||
|
||
/** | ||
* Graphic instance for rendering barcode position, size, and ID within an associated graphic | ||
* overlay view. | ||
*/ | ||
public class BarcodeGraphic extends GraphicOverlay.Graphic { | ||
|
||
private int mId; | ||
|
||
private static int mCurrentColorIndex = 0; | ||
|
||
private Paint mRectPaint; | ||
private Paint mTextPaint; | ||
private volatile Barcode mBarcode; | ||
|
||
private int mStrokeWidth = 24; | ||
private int mCornerWidth = 64; | ||
private int mCorderPadding = mStrokeWidth / 2; | ||
|
||
public BarcodeGraphic(GraphicOverlay overlay, final int trackerColor) { | ||
super(overlay); | ||
|
||
mRectPaint = new Paint(); | ||
mRectPaint.setColor(trackerColor); | ||
mRectPaint.setStyle(Paint.Style.STROKE); | ||
mRectPaint.setStrokeWidth(mStrokeWidth); | ||
//mRectPaint.setAlpha(100); | ||
|
||
mTextPaint = new Paint(); | ||
mTextPaint.setColor(trackerColor); | ||
mTextPaint.setFakeBoldText(true); | ||
mTextPaint.setTextSize(46.0f); | ||
} | ||
|
||
public int getId() { | ||
return mId; | ||
} | ||
|
||
public void setId(int id) { | ||
this.mId = id; | ||
} | ||
|
||
public Barcode getBarcode() { | ||
return mBarcode; | ||
} | ||
|
||
/** | ||
* Updates the barcode instance from the detection of the most recent frame. Invalidates the | ||
* relevant portions of the overlay to trigger a redraw. | ||
*/ | ||
void updateItem(Barcode barcode) { | ||
mBarcode = barcode; | ||
postInvalidate(); | ||
} | ||
|
||
/** | ||
* Draws the barcode annotations for position, size, and raw value on the supplied canvas. | ||
*/ | ||
@Override | ||
public void draw(Canvas canvas) { | ||
Barcode barcode = mBarcode; | ||
if (barcode == null) { | ||
return; | ||
} | ||
|
||
// Draws the bounding box around the barcode. | ||
RectF rect = new RectF(barcode.getBoundingBox()); | ||
rect.left = translateX(rect.left); | ||
rect.top = translateY(rect.top); | ||
rect.right = translateX(rect.right); | ||
rect.bottom = translateY(rect.bottom); | ||
|
||
//canvas.drawRect(rect, mRectPaint); | ||
|
||
/** | ||
* Draw the top left corner | ||
*/ | ||
canvas.drawLine(rect.left - mCorderPadding, rect.top, rect.left + mCornerWidth, rect.top, mRectPaint); | ||
canvas.drawLine(rect.left, rect.top, rect.left, rect.top + mCornerWidth, mRectPaint); | ||
|
||
/** | ||
* Draw the bottom left corner | ||
*/ | ||
canvas.drawLine(rect.left, rect.bottom, rect.left, rect.bottom - mCornerWidth, mRectPaint); | ||
canvas.drawLine(rect.left - mCorderPadding, rect.bottom, rect.left + mCornerWidth, rect.bottom, mRectPaint); | ||
|
||
/** | ||
* Draw the top right corner | ||
*/ | ||
canvas.drawLine(rect.right + mCorderPadding, rect.top, rect.right - mCornerWidth, rect.top, mRectPaint); | ||
canvas.drawLine(rect.right, rect.top, rect.right, rect.top + mCornerWidth, mRectPaint); | ||
|
||
/** | ||
* Draw the bottom right corner | ||
*/ | ||
canvas.drawLine(rect.right + mCorderPadding, rect.bottom, rect.right - mCornerWidth, rect.bottom, mRectPaint); | ||
canvas.drawLine(rect.right, rect.bottom, rect.right, rect.bottom - mCornerWidth, mRectPaint); | ||
|
||
// Draws a label at the bottom of the barcode indicate the barcode value that was detected. | ||
canvas.drawText(barcode.displayValue, rect.left, rect.bottom + 100, mTextPaint); | ||
} | ||
} |
Oops, something went wrong.