Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Roux committed Nov 19, 2019
0 parents commit c7b82e5
Show file tree
Hide file tree
Showing 90 changed files with 13,299 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Built application files
*.apk
*.ap_

# Files for the dex VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Android Studio
*.iml
.idea
.gradle
build/
.navigation
captures/
output.json

# NDK
obj/
.externalNativeBuild

# Keys
keystore.properties
keys/


# Android QiSDK project config
robotsdk.xml
6 changes: 6 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Pepper Code Scanner Authors

The Pepper Code Scanner library was written by the Developer Experience team at Softbank Robotics, Paris, November 2019.

* **Alexandre Roux** (aroux@softbankrobotics.com)
* **Émile Kroeger** (ekroeger@softbankrobotics.com)
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2011-2019, SoftBank Robotics Europe
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the SoftBank Robotics Europe nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SoftBank Robotics Europe BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Pepper Code Scanner Library

This Android Library will help you to scan barcodes and QR codes using the Google Vision library.

## Getting Started


### Prerequisites

A robotified project for Pepper with QiSDK. Read the [documentation](https://developer.softbankrobotics.com/pepper-qisdk) if needed.

Barcodes and QR codes.

### Running the Sample Application

The project comes complete with two sample projects. You can clone the repository, open it in Android Studio, and run this directly onto a Robot.

The two samples demonstrate two ways of using the library:

* By requesting an intent, that will launch a dedicated activity for scanning: **app-sample-with-intent**
* By integrating a scanning fragment in your activity: **app-sample-with-fragment**

Full implementation details are available to see in those projects.

### Installing

[**Download the latest compiled .aar**](pepper-code-scanner-root/pepper-code-scanner/compiled/pepper-code-scanner-1.0.0.aar)

In order to implement the library into your own project, you must build and install the .aar library, please follow this steps:

1. Build the `pepper-code-scanner` project either with Android Studio, or by running `./gradlew build` The output AAR file is located in **pepper-code-scanner > build > outputs > aar**.

2. In your robotified project, add the compiled AAR file:
* Click File > New > New Module.
* Click Import .JAR/.AAR Package then click Next.
* Enter the location of the compiled AAR or JAR file then click Finish.

3. Make sure the library is listed at the top of your `settings.gradle` file:
```
include ':app', ':pepper-code-scanner-1.0.0'
```

4. Open the app module's `build.gradle` file and add a new line to the `dependencies` block as shown in the following snippet:
```
dependencies {
implementation project(":pepper-code-scanner-1.0.0")
}
```

5. Click **Sync Project with Gradle Files**.


## Usage

*This README assumes some standard setup can be done by the user, such as initialising variables or implementing code in the correct functions. Refer to the Sample Project for full usage code.*

Initialise the QiSDK in the onCreate. If you are unsure how to do this, refer to the QiSDK tutorials [here](https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch1_gettingstarted/starting_project.html)
```
QiSDK.register(this, this)
```
You can launch the barcode scanner as an Activity with the following code:
```
val launchIntent = Intent(this, BarcodeReaderActivity::class.java)
startActivityForResult(launchIntent, BARCODE_READER_ACTIVITY_REQUEST)
```
The Activity will close once a code has been read. You will be able to get the result by overriding the onActivityResult function:
```
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode != Activity.RESULT_OK) {
Log.e(TAG, "Scan error")
return
}
if (requestCode == BARCODE_READER_ACTIVITY_REQUEST && data != null) {
val barcode: Barcode? = data.getParcelableExtra(BarcodeReaderActivity.KEY_CAPTURED_BARCODE)
result.text = barcode?.rawValue ?: ""
}
}
```
Here we display the result in a TextView.

You can also launch the barcode scanner in a Fragment. You'll first have to make your Activity implements BarcodeReaderFragment.BarcodeReaderListener, and then use the following code to add the Fragment:
```
val readerFragment = BarcodeReaderFragment()
readerFragment.setListener(this)
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fm_container, readerFragment)
fragmentTransaction.commitAllowingStateLoss()
```
The result of the scan will be given in the onScanned callback. You'll have to override it:
```
override fun onScanned(barcode: Barcode?) {
result.text = barcode?.rawValue ?: ""
// Remove Fragment
val fragmentTransaction = supportFragmentManager.beginTransaction()
val fragmentId = supportFragmentManager.findFragmentById(R.id.fm_container)
if (fragmentId != null) {
fragmentTransaction.remove(fragmentId)
}
fragmentTransaction.commitAllowingStateLoss()
}
```
Here we display the result in a TextView and we remove the Fragment as we don't need it anymore.

By default, a scanner overlay is displayed for UX purposes. If you launch the barcode scanner as an Activity, you can disable the scanner overlay in the Intent used to launch the Activity:
```
val launchIntent = Intent(this, BarcodeReaderActivity::class.java)
launchIntent.putExtra(KEY_SCAN_OVERLAY_VISIBILITY, false)
startActivityForResult(launchIntent, BARCODE_READER_ACTIVITY_REQUEST)
```
With KEY_SCAN_OVERLAY_VISIBILITY = "key_scan_overlay_visibility"

If you launch the barcode scanner in a Fragment, you can remove the scanner overlay this way:
```
val readerFragment = BarcodeReaderFragment(false)
readerFragment.setListener(this)
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fm_container, readerFragment)
fragmentTransaction.commitAllowingStateLoss()
```


## Known limitations

Because of the resolution and depth of field of the camera, it may be difficult to read small barcodes.


## License

This project is licensed under the BSD 3-Clause "New" or "Revised" License- see the [LICENSE](LICENSE.md) file for details.
14 changes: 14 additions & 0 deletions pepper-code-scanner-root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.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
.cxx
28 changes: 28 additions & 0 deletions pepper-code-scanner-root/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
21 changes: 21 additions & 0 deletions pepper-code-scanner-root/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit c7b82e5

Please sign in to comment.