Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "com.example.android.barcode_scanner"
minSdkVersion 21
targetSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -22,6 +22,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.google.android.gms:play-services:7.8+'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"/>
<uses-feature android:name="android.hardware.camera.autofocus"
android:required="true" />

<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode"/>

Expand All @@ -12,7 +14,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.android.barcode_scanner;

import android.Manifest;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.SparseArray;
import android.view.SurfaceHolder;
Expand All @@ -17,11 +22,23 @@

public class MainActivity extends Activity {

private static final int CAMERA_PERMISSION_CAMERA = 0x000000;

@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo
.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Check for Camera Permission
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CAMERA);
}

final SurfaceView cameraView = (SurfaceView) findViewById(R.id.camera_view);
final TextView barcodeInfo = (TextView) findViewById(R.id.code_info);
BarcodeDetector barcodeDetector =
Expand All @@ -33,10 +50,16 @@ protected void onCreate(Bundle savedInstanceState) {
.Builder(this, barcodeDetector)
.setRequestedPreviewSize(640, 480)
.build();

cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
return;
}
cameraSource.start(cameraView.getHolder());

} catch (IOException ie) {
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_color">

<SurfaceView
android:layout_width="640px"
android:layout_height="480px"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:id="@+id/camera_view"
/>
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/code_info"
android:layout_toRightOf="@+id/camera_view"
android:textSize="20sp"
android:text="@string/text"
android:layout_below="@id/camera_view"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:text="Nothing to read."
android:layout_alignParentTop="true"
/>
android:layout_marginRight="16dp"
android:layout_marginBottom="10dp"/>

</RelativeLayout>



</RelativeLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorPrimary">#8e8d8d</color>
<color name="colorPrimaryDark">#434242</color>
<color name="colorAccent">#FF4081</color>
<color name="bg_color">#d7d6d6</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Barcode_Scanner</string>
<string name="text">Nothing to read.</string>
</resources>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:3.0.0-beta7'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 21 00:53:27 IST 2016
#Wed Oct 18 13:36:45 WAT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip