Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

changed title, statusbar color, actionbar color of activity on Android #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
64 changes: 35 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Barcode Scanner

A flutter plugin for scanning 2D barcodes and QR codes.
A flutter plugin for scanning 2D barcodes and QR codes.

This provides a simple wrapper for two commonly used iOS and Android libraries:

Expand All @@ -14,6 +14,7 @@ iOS: https://github.com/mikebuss/MTBBarcodeScanner
Android: https://github.com/dm77/barcodescanner

### Features

- [x] Scan 2D barcodes
- [x] Scan QR codes
- [x] Control the flash while scanning
Expand All @@ -22,15 +23,17 @@ Android: https://github.com/dm77/barcodescanner
## Getting Started

### Android

For Android, you must do the following before you can use the plugin:

* Add the camera permission to your AndroidManifest.xml
`<uses-permission android:name="android.permission.CAMERA" />`
- Add the camera permission to your AndroidManifest.xml

`<uses-permission android:name="android.permission.CAMERA" />`

* This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See [installing the Kotlin plugin](https://kotlinlang.org/docs/tutorials/kotlin-android.html#installing-the-kotlin-plugin).
- This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See [installing the Kotlin plugin](https://kotlinlang.org/docs/tutorials/kotlin-android.html#installing-the-kotlin-plugin).

Edit your project-level build.gradle file to look like this:

```groovy
buildscript {
ext.kotlin_version = '1.3.61'
Expand Down Expand Up @@ -58,12 +61,14 @@ Now you can depend on the barcode_scan plugin in your pubspec.yaml file:

```yaml
dependencies:
# ...
barcode_scan: any
# ...
barcode_scan: any
```

Click "Packages get" in Android Studio or run `flutter packages get` in your project folder.

### iOS

To use on iOS, you must add the the camera usage description to your Info.plist

```xml
Expand All @@ -75,7 +80,6 @@ To use on iOS, you must add the the camera usage description to your Info.plist
</dict>
```


## Usage

```dart
Expand All @@ -84,57 +88,62 @@ import 'package:barcode_scan/barcode_scan.dart';

void main() async {
var result = await BarcodeScanner.scan();

print(result.type); // The result type (barcode, cancelled, failed)
print(result.rawContent); // The barcode content
print(result.format); // The barcode format (as enum)
print(result.formatNote); // If a unknown format was scanned this field contains a note
}
```


## Advanced usage

You can pass options to the scan method:

```dart

import 'package:barcode_scan/barcode_scan.dart';

void main() async {

var options = ScanOptions(
// set the options
);

var result = await BarcodeScanner.scan(options: options);

// ...
}
```

### Supported options
| Option | Type | Description | Supported by |
|----------------------------|-------------------|-------------------------------------------------------------------------------------------|---------------|
| `strings.cancel` | `String` | The cancel button text on iOS | iOS only |
| `strings.flash_on` | `String` | The flash on button text | iOS + Android |
| `strings.flash_off` | `String` | The flash off button text | iOS + Android |
| `restrictFormat` | `BarcodeFormat[]` | Restrict the formats which are recognized | iOS + Android |
| `useCamera` | `int` | The index of the camera which is used for scanning (See `BarcodeScanner.numberOfCameras`) | iOS + Android |
| `autoEnableFlash` | `bool` | Enable the flash when start scanning | iOS + Android |
| `android.aspectTolerance` | `double` | Enable auto focus on Android | Android only |
| `android.useAutoFocus` | `bool` | Set aspect ratio tolerance level used in calculating the optimal Camera preview size | Android only |

| Option | Type | Description | Supported by |
| ------------------------- | ----------------- | ----------------------------------------------------------------------------------------- | ------------- |
| `strings.cancel` | `String` | The cancel button text on iOS | iOS only |
| `strings.flash_on` | `String` | The flash on button text | iOS + Android |
| `strings.flash_off` | `String` | The flash off button text | iOS + Android |
| `restrictFormat` | `BarcodeFormat[]` | Restrict the formats which are recognized | iOS + Android |
| `useCamera` | `int` | The index of the camera which is used for scanning (See `BarcodeScanner.numberOfCameras`) | iOS + Android |
| `autoEnableFlash` | `bool` | Enable the flash when start scanning | iOS + Android |
| `android.aspectTolerance` | `double` | Enable auto focus on Android | Android only |
| `android.useAutoFocus` | `bool` | Set aspect ratio tolerance level used in calculating the optimal Camera preview size | Android only |
| `android.title` | `String` | Set title of activity | Android only |
| `android.statusbarColor` | `String` | Set statusbar color | Android only |
| `android.actionBarColor` | `String` | Set actionbar/toolbar color | Android only |

## Development setup

### Setup protobuf
### Setup protobuf

Mac:

```bash
$ brew install protobuf
$ brew install swift-protobuf
```
Windows / Linux: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation

Windows / Linux: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation

Activate the protobuf dart plugin:
`$ pub global activate protoc_plugin`
Expand All @@ -143,12 +152,9 @@ Install the`Protobuf Support` plugin for IDEA / Android Studio or `vscode-proto3

If you changed the protos.proto you've to execute the ./generate_proto.sh to update the dart / swift sources






## Common problems

### Android "Could not find org.jetbrains.kotlin:kotlin-stdlib-jre..."

Change `org.jetbrains.kotlin:kotlin-stdlib-jre` to `org.jetbrains.kotlin:kotlin-stdlib-jdk`
([StackOverflow](https://stackoverflow.com/a/53358817))
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package de.mintware.barcode_scan

import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import com.google.zxing.BarcodeFormat
import com.google.zxing.Result
import me.dm7.barcodescanner.zxing.ZXingScannerView
Expand Down Expand Up @@ -46,6 +50,34 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
super.onCreate(savedInstanceState)

config = Protos.Configuration.parseFrom(intent.extras!!.getByteArray(EXTRA_CONFIG))
title = config.android.title ?: ""

val statusBarColor = try {
Color.parseColor(config.android.statusbarColor)
} catch (e: IllegalArgumentException) {
Int.MAX_VALUE
} catch (e: StringIndexOutOfBoundsException) {
Int.MAX_VALUE
}
val actionBarColor = try {
Color.parseColor(config.android.actionBarColor)
} catch (e: IllegalArgumentException) {
Int.MIN_VALUE
} catch (e: StringIndexOutOfBoundsException) {
Int.MIN_VALUE
}

if (statusBarColor != Int.MAX_VALUE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
it.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
it.statusBarColor = statusBarColor
}
}
if (actionBarColor != Int.MIN_VALUE) {
actionBar?.setBackgroundDrawable(ColorDrawable(actionBarColor))
}

}

private fun setupScannerView() {
Expand Down
8 changes: 5 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ class _MyAppState extends State<_MyApp> {
useCamera: _selectedCamera,
autoEnableFlash: _autoEnableFlash,
android: AndroidOptions(
aspectTolerance: _aspectTolerance,
useAutoFocus: _useAutoFocus,
),
aspectTolerance: _aspectTolerance,
useAutoFocus: _useAutoFocus,
title: "Flutter Barcode Reader",
statusbarColor: "#e67e22",
actionBarColor: "#f1c40f"),
);

var result = await BarcodeScanner.scan(options: options);
Expand Down
Loading