Skip to content

Commit

Permalink
adapter: Flutter 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
liupandeng committed Jun 4, 2022
1 parent 0f302f0 commit 9468b58
Show file tree
Hide file tree
Showing 27 changed files with 373 additions and 310 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
## [3.2.0]

* Flutter 3.0.1
* Dart 2.17.1
* fix something
* improve something

## [3.1.0]

* Flutter 3.0.1
Expand Down
17 changes: 12 additions & 5 deletions android/build.gradle
Expand Up @@ -6,7 +6,7 @@ buildscript {
ext.android_gradle_version = '7.2.0'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
Expand All @@ -18,8 +18,7 @@ buildscript {
rootProject.allprojects {
repositories {
google()
// mavenCentral()
jcenter()
mavenCentral()
}
}

Expand All @@ -30,6 +29,9 @@ android {
compileSdkVersion 31

compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand All @@ -43,11 +45,16 @@ android {
}

defaultConfig {
minSdkVersion 16
multiDexEnabled true
minSdkVersion 19
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'me.dm7.barcodescanner:zxing:1.9.13'

implementation 'com.journeyapps:zxing-android-embedded:4.3.0'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.multidex:multidex:2.0.1"
}
21 changes: 14 additions & 7 deletions android/src/main/kotlin/com/air/ai_barcode/AndroidCreatorView.kt
Expand Up @@ -17,7 +17,7 @@ import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.platform.PlatformView
import me.dm7.barcodescanner.zxing.ZXingScannerView

import java.util.*


Expand All @@ -29,7 +29,12 @@ import java.util.*
* Create QRCode view
* </p>
*/
class AndroidCreatorView(binaryMessenger: BinaryMessenger, context: Context?, viewid: Int, args: Any?) : PlatformView, MethodChannel.MethodCallHandler, EventChannel.StreamHandler {
class AndroidCreatorView(
binaryMessenger: BinaryMessenger,
context: Context?,
viewid: Int,
args: Any?
) : PlatformView, MethodChannel.MethodCallHandler, EventChannel.StreamHandler {
/**
* 用于向Flutter发送数据
*/
Expand Down Expand Up @@ -74,12 +79,14 @@ class AndroidCreatorView(binaryMessenger: BinaryMessenger, context: Context?, vi
/*
MethodChannel
*/
var methodChannel: MethodChannel = MethodChannel(binaryMessenger, "view_type_id_creator_view_method_channel");
var methodChannel: MethodChannel =
MethodChannel(binaryMessenger, "view_type_id_creator_view_method_channel");
methodChannel.setMethodCallHandler(this);
/*
EventChannel
*/
var eventChannel: EventChannel = EventChannel(binaryMessenger, "view_type_id_creator_view_event_channel");
var eventChannel: EventChannel =
EventChannel(binaryMessenger, "view_type_id_creator_view_event_channel");
eventChannel.setStreamHandler(this);
}

Expand Down Expand Up @@ -113,7 +120,7 @@ class AndroidCreatorView(binaryMessenger: BinaryMessenger, context: Context?, vi


private fun createQRImage(
content: String?, widthPix: Int, heightPix: Int
content: String?, widthPix: Int, heightPix: Int
): Bitmap? {
try {
val hints = HashMap<EncodeHintType, Any>()
Expand All @@ -123,8 +130,8 @@ class AndroidCreatorView(binaryMessenger: BinaryMessenger, context: Context?, vi
var bitMatrix: BitMatrix? = null
try {
bitMatrix = QRCodeWriter().encode(
content, BarcodeFormat.QR_CODE, widthPix,
heightPix, hints
content, BarcodeFormat.QR_CODE, widthPix,
heightPix, hints
)
} catch (e: WriterException) {

Expand Down
93 changes: 67 additions & 26 deletions android/src/main/kotlin/com/air/ai_barcode/AndroidScannerView.kt
Expand Up @@ -4,20 +4,28 @@ import android.content.Context
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.google.zxing.Result
import com.google.zxing.BarcodeFormat
import com.google.zxing.ResultPoint
import com.journeyapps.barcodescanner.*
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.platform.PlatformView
import me.dm7.barcodescanner.zxing.ZXingScannerView


/**
* <p>
* Created by air on 2019-12-02.
* </p>
*/
class AndroidScannerView(binaryMessenger: BinaryMessenger, context: Context?, viewid: Int, args: Any?) : PlatformView, MethodChannel.MethodCallHandler, EventChannel.StreamHandler, ZXingScannerView.ResultHandler {
class AndroidScannerView(
binaryMessenger: BinaryMessenger,
context: Context?,
viewid: Int,
args: Any?
) : PlatformView, MethodChannel.MethodCallHandler, EventChannel.StreamHandler, BarcodeCallback {

/**
* 用于向Flutter发送数据
*/
Expand All @@ -29,13 +37,24 @@ class AndroidScannerView(binaryMessenger: BinaryMessenger, context: Context?, vi
override fun onCancel(arguments: Any?) {
}

/**
* 识别二维码结果
*/
override fun handleResult(rawResult: Result?) {

this.channelResult.success("${rawResult?.toString()}");
// this.eventChannelSink?.success("${rawResult?.toString()}")
override fun barcodeResult(result: BarcodeResult?) {

if (result == null) {
return;
}
if (result.text == null || result.text == mLastText) {
// Prevent duplicate scans
return
}

mLastText = result.text

this.channelResult.success(result.text.toString());
}

override fun possibleResultPoints(resultPoints: MutableList<ResultPoint>?) {
super.possibleResultPoints(resultPoints)
}

/**
Expand All @@ -59,34 +78,56 @@ class AndroidScannerView(binaryMessenger: BinaryMessenger, context: Context?, vi
/**
* 二维码扫描组件
*/
var zxing: ZXingScannerView = ZXingScannerView(context);
var linear: LinearLayout = LinearLayout(context);
var textView: TextView = TextView(context);
var mContext: Context? = context;
var mZXingBarcode: DecoratedBarcodeView = DecoratedBarcodeView(context);


var mTextView: TextView = TextView(context);
var mLastText: String = "";


lateinit var channelResult: MethodChannel.Result;
var eventChannelSink: EventChannel.EventSink? = null;

init {
textView.setText("Scanner view");
mTextView.text = "Scanner view";
/*
MethodChannel
*/
var methodChannel: MethodChannel = MethodChannel(binaryMessenger, "view_type_id_scanner_view_method_channel");
val methodChannel: MethodChannel =
MethodChannel(binaryMessenger, "view_type_id_scanner_view_method_channel");
methodChannel.setMethodCallHandler(this);
/*
EventChannel
*/
var eventChannel: EventChannel = EventChannel(binaryMessenger, "view_type_id_scanner_view_event_channel");
val eventChannel: EventChannel =
EventChannel(binaryMessenger, "view_type_id_scanner_view_event_channel");
eventChannel.setStreamHandler(this);
}

override fun getView(): View {


zxing.setAutoFocus(true);
zxing.setAspectTolerance(0.5f);
return zxing;
val formats: Collection<BarcodeFormat> =
listOf(
BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E,
BarcodeFormat.EAN_8,
BarcodeFormat.EAN_13,
BarcodeFormat.RSS_14,
BarcodeFormat.CODE_39,
BarcodeFormat.CODE_93,
BarcodeFormat.CODE_128,
BarcodeFormat.ITF,
BarcodeFormat.RSS_EXPANDED,
BarcodeFormat.QR_CODE,
BarcodeFormat.CODABAR,
)
mZXingBarcode.barcodeView.decoderFactory = DefaultDecoderFactory(formats)
mZXingBarcode.setStatusText("")
mZXingBarcode.decodeContinuous(this)


return mZXingBarcode;
}

override fun dispose() {
Expand All @@ -99,30 +140,30 @@ class AndroidScannerView(binaryMessenger: BinaryMessenger, context: Context?, vi
}

private fun startCamera() {
zxing.startCamera();
mZXingBarcode.pauseAndWait();
}

private fun stopCamera() {
zxing.stopCamera();
mZXingBarcode.pause();
}

private fun resumeCameraPreview() {
zxing.resumeCameraPreview(this);
mZXingBarcode.resume()
}

private fun stopCameraPreview() {
zxing.stopCameraPreview();
mZXingBarcode.pauseAndWait();
}

private fun openFlash() {
zxing.flash = true;
// zxing.flash = true;
}

private fun closeFlash() {
zxing.flash = false;
// zxing.flash = false;
}

private fun toggleFlash() {
zxing.toggleFlash();
// zxing.toggleFlash();
}
}
41 changes: 38 additions & 3 deletions example/.metadata
@@ -1,10 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: c06bf6503a8b6690b2740a7101852fcc8f133057
channel: master
revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: android
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: ios
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: linux
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: macos
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: web
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: windows
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
6 changes: 6 additions & 0 deletions example/android/.gitignore
Expand Up @@ -5,3 +5,9 @@ gradle-wrapper.jar
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
28 changes: 16 additions & 12 deletions example/android/app/build.gradle
Expand Up @@ -26,24 +26,31 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 31
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

lintOptions {
disable 'InvalidPackage'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.air.ai_barcode_example"
minSdkVersion 16
targetSdkVersion 28
applicationId "com.air.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -61,7 +68,4 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

0 comments on commit 9468b58

Please sign in to comment.