Skip to content

Commit

Permalink
Untangle profile creation and initialisation, and add functionality (#36
Browse files Browse the repository at this point in the history
)

* feat: add option to initialize method to skip profile creation

* chore: upgrade dependencies

* refactor: update generated classes

* feat: expand capabilities of Example application

* feat: add Android Code to handle GetProfilesList and GetActiveProfile

* feat: GetProfiles and ActiveProfiles functions are now available

* refactor: restrcuture package so that we control what we export

* chore: update README

* fix: remove profileName form constrcutor

* fix: use older UUID version

* refactor: make comman in ActionResult String again

* feat: add convenience function for logging

* fix: wrong comparison

* fix: adnroid native code issues

* refactor: remove unused method getPlatformVersion

* chore: update CHANGELOG and pubspec for prerelease

* Fix usage of correct result.

---------

Co-authored-by: Tobias Ottenweller <tobias@circuskitchens.com>
  • Loading branch information
felixwoestmann and t-unit committed Oct 20, 2023
1 parent 89fa385 commit fd9209a
Show file tree
Hide file tree
Showing 34 changed files with 827 additions and 578 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.0.0-dev.1

* Added functions `requestProfiles` and `requestActiveProfile` to query the available profiles and the active profile
* Creating a default profile will not be automatically done when calling initialize anymore. Instead the user has to call `createDefaultProfile` manually.

# 2.1.0

* Update to Gradle 8
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![pub package](https://img.shields.io/pub/v/flutter_datawedge.svg)](https://pub.dev/packages/flutter_datawedge)

A Flutter package communicate with Zebra DataWedge scanners.
A Flutter package to communicate with Zebra DataWedge scanners.

## Getting Started (under development)

Expand All @@ -12,8 +12,9 @@ Initialize the FlutterDataWedge Object and attach a listener to the onScanResult

``` dart
FlutterDataWedge dw = FlutterDataWedge(profileName: "Example Profile");
FlutterDataWedge dw = FlutterDataWedge();
await dw.initialize();
await createDefaultProfile(profileName: "Example Profile");
StreamSubscription onScanSubscription = dw.onScanResult.listen((ScanResult result) {
print(result.data);
});
Expand All @@ -29,6 +30,12 @@ Initialize the FlutterDataWedge Object and attach a listener to the onScanResult

*Also checkout the example application.*

### Profiles
Unlike previous versions, this version of the package won't create a profile and configure it while calling `initialize`.
Instead a profile can be created using the `createDefaultProfile` method.
To query all available profiles use `requestProfiles`, to query the active profile use `requestActiveProfile`.
The functions `waitForProfiles` and `waitForActiveProfile` can be used to wait results after the requesting function has been called.

#### async/await

Event though the public methods enableScanner(), activateScanner() and scannerControl() are
Expand All @@ -39,7 +46,7 @@ Those can be used to determine the outcome of a command and properly wait for it
Here is a short example:

``` dart
FlutterDataWedge dw = FlutterDataWedge(profileName: "Example Profile");
FlutterDataWedge dw = FlutterDataWedge();
await dw.initialize();
// This would be a properly awaited version of enableScanner
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 19
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ import android.content.Intent
import android.os.Bundle
import android.util.Log

class DWInterface() {
class DWInterface {
companion object {

// DataWedge Extras
const val EXTRA_GET_VERSION_INFO = "com.symbol.datawedge.api.GET_VERSION_INFO"
const val EXTRA_CREATE_PROFILE = "com.symbol.datawedge.api.CREATE_PROFILE"
const val EXTRA_GET_PROFILES = "com.symbol.datawedge.api.GET_PROFILES_LIST"
const val EXTRA_ACTIVE_PROFILE = "com.symbol.datawedge.api.GET_ACTIVE_PROFILE"
const val EXTRA_KEY_APPLICATION_NAME = "com.symbol.datawedge.api.APPLICATION_NAME"
const val EXTRA_KEY_NOTIFICATION_TYPE = "com.symbol.datawedge.api.NOTIFICATION_TYPE"
const val EXTRA_SOFT_SCAN_TRIGGER = "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER"
const val EXTRA_RESULT_NOTIFICATION = "com.symbol.datawedge.api.NOTIFICATION"
const val EXTRA_REGISTER_NOTIFICATION = "com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION"
const val EXTRA_UNREGISTER_NOTIFICATION =
"com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION"

const val EXTRA_RESULT_NOTIFICATION_TYPE = "NOTIFICATION_TYPE"
const val EXTRA_KEY_VALUE_SCANNER_STATUS = "SCANNER_STATUS"
const val EXTRA_KEY_VALUE_PROFILE_SWITCH = "PROFILE_SWITCH"
const val EXTRA_KEY_VALUE_PROFILE_ENABLED = "PROFILE_ENABLED"
const val EXTRA_KEY_VALUE_CONFIGURATION_UPDATE = "CONFIGURATION_UPDATE"
const val EXTRA_KEY_VALUE_NOTIFICATION_STATUS = "STATUS"
const val EXTRA_KEY_VALUE_NOTIFICATION_PROFILE_NAME = "PROFILE_NAME"
const val EXTRA_SEND_RESULT = "SEND_RESULT"

const val EXTRA_EMPTY = ""

const val EXTRA_RESULT_GET_VERSION_INFO = "com.symbol.datawedge.api.RESULT_GET_VERSION_INFO"
const val EXTRA_RESULT = "RESULT"
const val EXTRA_RESULT_GET_ACTIVE_PROFILE =
"com.symbol.datawedge.api.RESULT_GET_ACTIVE_PROFILE"
const val EXTRA_RESULT_GET_PROFILES_LIST =
"com.symbol.datawedge.api.RESULT_GET_PROFILES_LIST"
const val EXTRA_RESULT_INFO = "RESULT_INFO"
const val EXTRA_COMMAND = "COMMAND"
const val EXTRA_COMMAND_IDENTIFIER = "COMMAND_IDENTIFIER"
Expand All @@ -40,7 +38,6 @@ class DWInterface() {
const val ACTION_RESULT_NOTIFICATION = "com.symbol.datawedge.api.NOTIFICATION_ACTION"
const val ACTION_RESULT = "com.symbol.datawedge.api.RESULT_ACTION"

const val ACTION_GET_SCANNER_STATUS = "com.symbol.datawedge.api.GET_SCANNER_STATUS"
const val ACTION_SET_CONFIG = "com.symbol.datawedge.api.SET_CONFIG"

const val DATAWEDGE_SCAN_EXTRA_SOURCE = "com.symbol.datawedge.source"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.circuskitchens.flutter_datawedge

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.util.Log
import androidx.annotation.NonNull
import com.circuskitchens.flutter_datawedge.consts.MyChannels
import com.circuskitchens.flutter_datawedge.consts.MyIntents
import com.circuskitchens.flutter_datawedge.consts.MyMethods
import src.main.kotlin.com.circuskitchens.flutter_datawedge.consts.MyMethods
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.EventChannel.EventSink
import io.flutter.plugin.common.EventChannel.StreamHandler
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import org.json.JSONObject

class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
Expand All @@ -38,7 +36,7 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {

private lateinit var intentFilter: IntentFilter

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {

context = flutterPluginBinding.applicationContext

Expand All @@ -59,39 +57,40 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {

}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {

when (call.method) {
MyMethods.getPlatformVersion -> {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
}
MyMethods.sendDataWedgeCommandStringParameter -> {
val arguments = JSONObject(call.arguments.toString())
val command: String = arguments.get("command") as String
val parameter: String = arguments.get("parameter") as String
val commandIdentifier: String = arguments.get("commandIdentifier") as String
dwInterface.sendCommandString(context, command, parameter, commandIdentifier)
result.success(null); // DataWedge does not return responses
result.success(null) // DataWedge does not return responses
}

MyMethods.createDataWedgeProfile -> {
val arguments = JSONObject(call.arguments.toString())
val name: String = arguments.get("name") as String
val commandIdentifier: String = arguments.get("commandIdentifier") as String
createDataWedgeProfile(name, commandIdentifier)
result.success(null); // DataWedge does not return responses
result.success(null) // DataWedge does not return responses
}

MyMethods.listenScannerStatus -> {
val arguments = JSONObject(call.arguments.toString())
val commandIdentifier: String = arguments.get("commandIdentifier") as String
listenScannerStatus(commandIdentifier)
result.success(null); // DataWedge does not return responses
result.success(null) // DataWedge does not return responses
}

else -> {
result.notImplemented()
}
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
override fun onListen(arguments: Any?, events: EventSink?) {
val receiver = SinkBroadcastReceiver(events)
registeredReceivers.add(receiver)
Expand Down Expand Up @@ -149,8 +148,7 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
val intentProps = Bundle()
intentProps.putString("intent_output_enabled", "true")
intentProps.putString(
"intent_action",
context.packageName + MyIntents.SCAN_EVENT_INTENT_ACTION
"intent_action", context.packageName + MyIntents.SCAN_EVENT_INTENT_ACTION
)
intentProps.putString("intent_delivery", profileIntentBroadcast) // "2"
intentConfig.putBundle("PARAM_LIST", intentProps)
Expand All @@ -172,8 +170,7 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
val b = Bundle()
b.putString(DWInterface.EXTRA_KEY_APPLICATION_NAME, context.packageName)
b.putString(
DWInterface.EXTRA_KEY_NOTIFICATION_TYPE,
DWInterface.EXTRA_KEY_VALUE_SCANNER_STATUS
DWInterface.EXTRA_KEY_NOTIFICATION_TYPE, DWInterface.EXTRA_KEY_VALUE_SCANNER_STATUS
)

//https://techdocs.zebra.com/datawedge/latest/guide/api/setconfig/
Expand All @@ -185,7 +182,7 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
)
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
for (receiver in registeredReceivers) {
context.unregisterReceiver(receiver)
}
Expand Down

This file was deleted.

Loading

0 comments on commit fd9209a

Please sign in to comment.