From 7c70dd8ae1f0a6d26083995f557ea4457d1f9a76 Mon Sep 17 00:00:00 2001 From: Mateusz Maziec Date: Fri, 9 Feb 2024 18:52:26 +0100 Subject: [PATCH] create a update profile method to full support the "Set Config" values from the official data wedge api --- .../FlutterDatawedgePlugin.kt | 60 +++++++++++++++++++ .../flutter_datawedge/consts/MyMethods.kt | 1 + example/lib/button_tab_view.dart | 28 +++++++++ example/lib/log_tab_view.dart | 2 + lib/src/consts/datawedge_api_targets.dart | 1 + lib/src/consts/method_channel_methods.dart | 1 + lib/src/flutter_datawedge.dart | 22 +++++++ 7 files changed, 115 insertions(+) diff --git a/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/FlutterDatawedgePlugin.kt b/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/FlutterDatawedgePlugin.kt index da06c5a..98ad613 100644 --- a/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/FlutterDatawedgePlugin.kt +++ b/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/FlutterDatawedgePlugin.kt @@ -77,6 +77,29 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler { result.success(null) // DataWedge does not return responses } + MyMethods.updateDataWedgeProfile -> { + val arguments = JSONObject(call.arguments.toString()) + val profileName: String = arguments.get("profileName") as String + val pluginName: String = arguments.get("pluginName") as String + val commandIdentifier: String = arguments.get("commandIdentifier") as String + + val configJson: JSONObject = arguments.getJSONObject("config") + val config = mutableMapOf() + + for (key in configJson.keys()) { + config[key] = configJson.get(key) + } + + updateProfilePluginConfig( + profileName, + pluginName, + config.toMap(), + commandIdentifier + ) + + result.success(null) // DataWedge does not return responses + } + MyMethods.listenScannerStatus -> { val arguments = JSONObject(call.arguments.toString()) val commandIdentifier: String = arguments.get("commandIdentifier") as String @@ -164,6 +187,43 @@ class FlutterDatawedgePlugin : FlutterPlugin, MethodCallHandler, StreamHandler { } + private fun updateProfilePluginConfig( + profileName: String, + pluginName: String, + config: Map, + commandIdentifier: String, + ) { + val profileConfig = Bundle() + profileConfig.putString(DWInterface.EXTRA_KEY_VALUE_NOTIFICATION_PROFILE_NAME, profileName) + profileConfig.putString("CONFIG_MODE", "UPDATE") + + val pluginConfig = Bundle() + pluginConfig.putString("PLUGIN_NAME", pluginName.uppercase()) + pluginConfig.putString("RESET_CONFIG", "false") + + val paramBundle = Bundle() + + for ((key, value) in config) { + when (value) { + is String -> paramBundle.putString(key, value) + //bool value is always passed as string + is Boolean -> paramBundle.putString(key, value.toString()) + is Double -> paramBundle.putDouble(key, value) + is Int -> paramBundle.putInt(key, value) + } + } + + pluginConfig.putBundle("PARAM_LIST", paramBundle) + profileConfig.putBundle("PLUGIN_CONFIG", pluginConfig) + + dwInterface.sendCommandBundle( + context, + DWInterface.ACTION_SET_CONFIG, + profileConfig, + "profileConfigUpdate_$commandIdentifier" + ) + } + private fun listenScannerStatus(commandIdentifier: String) { //https://techdocs.zebra.com/datawedge/latest/guide/api/registerfornotification diff --git a/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/consts/MyMethods.kt b/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/consts/MyMethods.kt index 6442fa9..7383caa 100644 --- a/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/consts/MyMethods.kt +++ b/android/src/main/kotlin/com/circuskitchens/flutter_datawedge/consts/MyMethods.kt @@ -4,6 +4,7 @@ class MyMethods { companion object { const val sendDataWedgeCommandStringParameter = "sendDataWedgeCommandStringParameter" const val createDataWedgeProfile = "createDataWedgeProfile" + const val updateDataWedgeProfile = "updateDataWedgeProfile" const val listenScannerStatus = "listenScannerStatus" } } diff --git a/example/lib/button_tab_view.dart b/example/lib/button_tab_view.dart index 2df1387..942a2de 100644 --- a/example/lib/button_tab_view.dart +++ b/example/lib/button_tab_view.dart @@ -78,6 +78,34 @@ class ButtonTabView extends StatelessWidget { ), ], ), + Row( + children: [ + Expanded( + child: ElevatedButton( + onPressed: () => fdw.updateProfile( + profileName: 'Example app profile', + pluginName: 'KEYSTROKE', + config: { + 'keystroke_output_enabled': true, + }, + ), + child: Text('Enable KeyStroke Events'), + ), + ), + Expanded( + child: ElevatedButton( + onPressed: () => fdw.updateProfile( + profileName: 'Example app profile', + pluginName: 'KEYSTROKE', + config: { + 'keystroke_output_enabled': false, + }, + ), + child: Text('Disable KeyStroke Events'), + ), + ), + ], + ), ], ), ); diff --git a/example/lib/log_tab_view.dart b/example/lib/log_tab_view.dart index f4ec630..2a20701 100644 --- a/example/lib/log_tab_view.dart +++ b/example/lib/log_tab_view.dart @@ -120,6 +120,8 @@ extension ActionResultLog on ActionResult { result == "SUCCESS" ? '$result' : '${resultInfo!['RESULT_CODE']}', DatawedgeApiTargets.getProfiles => '${resultInfo!['profiles']}', DatawedgeApiTargets.getActiveProfile => '${resultInfo!['activeProfile']}', + DatawedgeApiTargets.setConfig => + result == "SUCCESS" ? '$result' : '${resultInfo!['RESULT_CODE']}', }; } } diff --git a/lib/src/consts/datawedge_api_targets.dart b/lib/src/consts/datawedge_api_targets.dart index b5ed76b..ddab6ff 100644 --- a/lib/src/consts/datawedge_api_targets.dart +++ b/lib/src/consts/datawedge_api_targets.dart @@ -6,6 +6,7 @@ enum DatawedgeApiTargets with ValueEnum { softScanTrigger('com.symbol.datawedge.api.SOFT_SCAN_TRIGGER'), scannerPlugin('com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN'), getProfiles('com.symbol.datawedge.api.GET_PROFILES_LIST'), + setConfig('com.symbol.datawedge.api.SET_CONFIG'), getActiveProfile('com.symbol.datawedge.api.GET_ACTIVE_PROFILE'); final String value; diff --git a/lib/src/consts/method_channel_methods.dart b/lib/src/consts/method_channel_methods.dart index 973474f..ead086d 100644 --- a/lib/src/consts/method_channel_methods.dart +++ b/lib/src/consts/method_channel_methods.dart @@ -1,5 +1,6 @@ enum MethodChannelMethods { createDataWedgeProfile("createDataWedgeProfile"), + updateDataWedgeProfile("updateDataWedgeProfile"), listenScannerStatus("listenScannerStatus"), sendDataWedgeCommandStringParameter("sendDataWedgeCommandStringParameter"); diff --git a/lib/src/flutter_datawedge.dart b/lib/src/flutter_datawedge.dart index 111f672..42002e1 100644 --- a/lib/src/flutter_datawedge.dart +++ b/lib/src/flutter_datawedge.dart @@ -160,6 +160,28 @@ class FlutterDataWedge { ); } + /// update existing Datawedge profile and the specified plugin config + /// Returns when the Command is executed NOT when DataWedge is ready to be operated again + /// For that use [onScannerEvent] to listen for the Result of the Command + /// Check out the official documentation https://techdocs.zebra.com/datawedge/13-0/guide/api/setconfig/ + /// to know which config attributes are supported + Future updateProfile( + {required String profileName, + required String pluginName, + Map config = const {}, + String? commandIdentifier}) async { + final identifier = commandIdentifier ?? Uuid().v4(); + _methodChannel.invokeMethod( + MethodChannelMethods.updateDataWedgeProfile.value, + jsonEncode({ + "profileName": profileName, + "pluginName": pluginName, + "commandIdentifier": identifier, + "config": config, + }), + ); + } + Future _enableListeningScannerStatus(String commandIdentifier) { return _methodChannel.invokeMethod( MethodChannelMethods.listenScannerStatus.value,