import { Component , ChangeDetectorRef } from '@angular/core' ; import { BarcodeProvider } from '../providers/barcode/barcode' ; import { Events } from '../services/events' ; import { AlertController } from '@ionic/angular' ; import { Platform } from '@ionic/angular' ; import { Device } from '@ionic-native/device/ngx' ; import { ToastController } from '@ionic/angular' ; @ Component ( { selector : 'app-home' , templateUrl : 'home.page.html' , styleUrls : [ 'home.page.scss' ] , providers : [ BarcodeProvider , Device ] , } ) export class HomePage { private scans = [ ] ; private scanners = [ { "SCANNER_NAME" : "Please Wait..." , "SCANNER_INDEX" : 0 , "SCANNER_CONNECTION_STATE" : true } ] ; private selectedScanner = "Please Select..." ; private selectedScannerId = - 1 ; private ean8Decoder = true ; private ean13Decoder = true ; private code39Decoder = true ; private code128Decoder = true ; private dataWedgeVersion = "Pre 6.3. Please create & configure profile manually.  See the ReadMe for more details." ; private availableScannersText = "Requires Datawedge 6.3+" ; private activeProfileText = "Requires Datawedge 6.3+" ; private commandResultText = "Messages from DataWedge will go here" ; private uiHideDecoders = true ; private uiDatawedgeVersionAttention = true ; private uiHideSelectScanner = true ; private uiHideShowAvailableScanners = false ; private uiHideCommandMessages = true ; private uiHideFloatingActionButton = true ; public constructor ( private barcodeProvider , public events , private changeDetectorRef , private device , private alertController , private platform , private toastController ) { this . platform . ready ( ) . then ( ( readySource ) => { console . log ( "Device manufacturer is: " + this . device . manufacturer ) ; if ( ! ( this . device . manufacturer . toLowerCase ( ) . includes ( "zebra" ) || this . device . manufacturer . toLowerCase ( ) . includes ( "motorola solutions" ) ) ) { this . presentAlert ( ) ; } this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.GET_VERSION_INFO" , "" ) ; events . subscribe ( 'status:dw63ApisAvailable' , ( isAvailable ) => { console . log ( "DataWedge 6.3 APIs are available" ) ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.CREATE_PROFILE" , "ZebraIonicDemo" ) ; this . dataWedgeVersion = "6.3.  Please configure profile manually.  See the ReadMe for more details." ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.GET_ACTIVE_PROFILE" , "" ) ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.ENUMERATE_SCANNERS" , "" ) ; this . uiHideFloatingActionButton = false ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'status:dw64ApisAvailable' , ( isAvailable ) => { console . log ( "DataWedge 6.4 APIs are available" ) ; this . dataWedgeVersion = "6.4" ; this . uiDatawedgeVersionAttention = false ; this . uiHideDecoders = ! isAvailable ; let profileConfig = { "PROFILE_NAME" : "ZebraIonicDemo" , "PROFILE_ENABLED" : "true" , "CONFIG_MODE" : "UPDATE" , "PLUGIN_CONFIG" : { "PLUGIN_NAME" : "BARCODE" , "RESET_CONFIG" : "true" , "PARAM_LIST" : { } } , "APP_LIST" : [ { "PACKAGE_NAME" : "com.zebra.zebraionicdemo" , "ACTIVITY_LIST" : [ "*" ] } ] } ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SET_CONFIG" , profileConfig ) ; let profileConfig2 = { "PROFILE_NAME" : "ZebraIonicDemo" , "PROFILE_ENABLED" : "true" , "CONFIG_MODE" : "UPDATE" , "PLUGIN_CONFIG" : { "PLUGIN_NAME" : "INTENT" , "RESET_CONFIG" : "true" , "PARAM_LIST" : { "intent_output_enabled" : "true" , "intent_action" : "com.zebra.ionicdemo.ACTION" , "intent_delivery" : "2" } } } ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SET_CONFIG" , profileConfig2 ) ; setTimeout ( function ( ) { barcodeProvider . sendCommand ( "com.symbol.datawedge.api.GET_ACTIVE_PROFILE" , "" ) ; } , 1000 ) ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'status:dw65ApisAvailable' , ( isAvailable ) => { console . log ( "DataWedge 6.5 APIs are available" ) ; this . uiHideSelectScanner = false ; this . uiHideShowAvailableScanners = true ; this . uiHideCommandMessages = false ; this . barcodeProvider . requestResult ( true ) ; this . dataWedgeVersion = "6.5 or higher" ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'data:activeProfile' , ( activeProfile ) => { console . log ( "Active profile: " + activeProfile ) ; this . activeProfileText = activeProfile ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'data:commandResult' , ( commandResult ) => { this . commandResultText = commandResult ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'data:enumeratedScanners' , ( enumeratedScanners ) => { this . scanners = enumeratedScanners ; let humanReadableScannerList = "" ; enumeratedScanners . forEach ( ( scanner , index ) => { console . log ( "Scanner found: name= " + scanner . SCANNER_NAME + ", id=" + scanner . SCANNER_INDEX + ", connected=" + scanner . SCANNER_CONNECTION_STATE ) ; humanReadableScannerList += scanner . SCANNER_NAME ; if ( index < enumeratedScanners . length - 1 ) humanReadableScannerList += ", " ; } ) ; this . availableScannersText = humanReadableScannerList ; this . scanners . unshift ( { "SCANNER_NAME" : "Please Select..." , "SCANNER_INDEX" : - 1 , "SCANNER_CONNECTION_STATE" : false } ) ; this . changeDetectorRef . detectChanges ( ) ; } ) ; events . subscribe ( 'data:scan' , ( data ) => { let scannedData = data . scanData . extras [ "com.symbol.datawedge.data_string" ] ; let scannedType = data . scanData . extras [ "com.symbol.datawedge.label_type" ] ; this . scans . unshift ( { "data" : scannedData , "type" : scannedType , "timeAtDecode" : data . time } ) ; this . uiDatawedgeVersionAttention = false ; this . changeDetectorRef . detectChanges ( ) ; } ) ; } ) ; } public setDecoders ( ) { var paramList = { "scanner_selection" : "auto" , "decoder_ean8" : "" + this . ean8Decoder , "decoder_ean13" : "" + this . ean13Decoder , "decoder_code128" : "" + this . code128Decoder , "decoder_code39" : "" + this . code39Decoder } ; if ( this . selectedScannerId > - 1 ) { paramList [ "current-device-id" ] = "" + this . selectedScannerId ; delete paramList [ "scanner_selection" ] ; } let profileConfig = { "PROFILE_NAME" : "ZebraIonicDemo" , "PROFILE_ENABLED" : "true" , "CONFIG_MODE" : "UPDATE" , "PLUGIN_CONFIG" : { "PLUGIN_NAME" : "BARCODE" , "PARAM_LIST" : paramList } } ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SET_CONFIG" , profileConfig ) ; } private async presentAlert ( ) { let alert = await this . alertController . create ( { subHeader : 'Requires Zebra device' , message : 'This application requires a Zebra mobile device in order to run' , cssClass : 'nonZebraAlert' , buttons : [ { text : 'Close app' , handler : data => { console . log ( 'Closing application since we are not running on a Zebra device' ) ; navigator [ 'app' ] . exitApp ( ) ; } } ] } ) ; await alert . present ( ) ; } public async scannerSelected ( ) { console . log ( "Requested scanner is: " + this . selectedScanner ) ; let localScannerIndex = 0 ; let localScannerName = "" ; for ( let scanner of this . scanners ) { if ( scanner . SCANNER_NAME == this . selectedScanner ) { localScannerIndex = scanner . SCANNER_INDEX ; localScannerName = scanner . SCANNER_NAME ; } } if ( this . selectedScannerId == localScannerIndex || localScannerIndex < 0 ) { console . log ( "Not switching scanner, new scanner ID == old scanner ID" ) ; let toast = await this . toastController . create ( { message : 'Invalid scanner selection' , position : 'bottom' , duration : 3000 } ) ; await toast . present ( ) ; return ; } this . selectedScanner = localScannerName ; this . selectedScannerId = localScannerIndex ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SWITCH_SCANNER" , localScannerIndex + "" ) ; this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.ENUMERATE_SCANNERS" , "" ) ; } public fabDown ( ) { this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER" , "START_SCANNING" ) ; } public fabUp ( ) { this . barcodeProvider . sendCommand ( "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER" , "STOP_SCANNING" ) ; } }