1010import android .view .View ;
1111import android .view .inputmethod .InputConnection ;
1212
13- import com .csl .cs710library4a . CsLibrary4A ;
13+ import com .csl .cslibrary4a . RfidReaderChipData ;
1414
1515import java .util .ArrayList ;
1616
@@ -46,70 +46,94 @@ public void onDestroy() {
4646
4747 ArrayList <String > epcArrayList = new ArrayList <String >();
4848 InventoryRfidTask inventoryRfidTask ;
49+ InventoryBarcodeTask inventoryBarcodeTask ;
4950 boolean inventoring = false ;
5051 private Runnable serviceRunnable = new Runnable () {
5152 @ Override
5253 public void run () {
5354 String strCurrentIME = Settings .Secure .getString (getContentResolver (), Settings .Secure .DEFAULT_INPUT_METHOD );
5455 String strCompare = getPackageName ();
5556 appendToLog ("CustomIME Debug 0 with strCurrentIME = " + strCurrentIME + ", strCompare = " + strCompare );
56- if (strCurrentIME .contains (strCompare ) == false ) return ;
57-
58- mHandler .postDelayed (serviceRunnable , 1000 );
59- if (MainActivity .sharedObjects == null ) return ;
60- if (MainActivity .csLibrary4A == null ) return ;
61-
62- if (inventoring == false ) { MainActivity .sharedObjects .serviceArrayList .clear (); epcArrayList .clear (); }
63- if (MainActivity .mContext == null ) return ;
64- appendToLog ("CustomIME Debug 1 with activityActive = " + MainActivity .activityActive + ", wedged = " + MainActivity .wedged + ", isBleConnected = " + MainActivity .csLibrary4A .isBleConnected ());
65- if (MainActivity .activityActive == false /*&& MainActivity.wedged*/ && MainActivity .csLibrary4A .isBleConnected ()) {
66- if (MainActivity .csLibrary4A .getTriggerButtonStatus () == false ) {
67- appendToLog ("CustomIME Debug 2" );
68- startStopHandler ();
69- inventoring = false ;
70- } else if (inventoring == false ) {
71- appendToLog ("CustomIME Debug 3" );
72- if (MainActivity .sharedObjects .runningInventoryRfidTask == false && MainActivity .sharedObjects .runningInventoryBarcodeTask == false && MainActivity .csLibrary4A .mrfidToWriteSize () == 0 ) {
57+ if (strCurrentIME .contains (strCompare ) == false ) { }
58+ else if (MainActivity .sharedObjects == null || MainActivity .csLibrary4A == null ) { }
59+ else if (MainActivity .mContext == null ) return ;
60+ else {
61+ if (inventoring == false ) {
62+ MainActivity .sharedObjects .serviceArrayList .clear ();
63+ epcArrayList .clear ();
64+ }
65+ appendToLog ("CustomIME Debug 1 with activityActive = " + MainActivity .activityActive + ", wedged = " + MainActivity .wedged + ", isBleConnected = " + MainActivity .csLibrary4A .isBleConnected ());
66+ if (MainActivity .activityActive == false /*&& MainActivity.wedged*/ && MainActivity .csLibrary4A .isBleConnected ()) {
67+ if (MainActivity .csLibrary4A .getTriggerButtonStatus () == false ) {
68+ appendToLog ("CustomIME Debug 2 with runningInventoryRfidTask = " + MainActivity .sharedObjects .runningInventoryRfidTask );
69+ appendToLog ("CustomIME Debug 2 with runningInventoryBarcodeTask = " + MainActivity .sharedObjects .runningInventoryBarcodeTask );
7370 startStopHandler ();
74- inventoring = true ;
75- }
76- } else {
77- appendToLog ("CustomIME Debug 4" );
78- while (MainActivity .sharedObjects .serviceArrayList .size () != 0 ) {
79- String strEpc = MainActivity .sharedObjects .serviceArrayList .get (0 ); MainActivity .sharedObjects .serviceArrayList .remove (0 );
80- boolean matched = false ;
81- for (int i = 0 ; i < epcArrayList .size (); i ++) {
82- if (epcArrayList .get (i ).matches (strEpc )) {
83- matched = true ;
84- break ;
85- }
71+ inventoring = false ;
72+ } else if (inventoring == false ) {
73+ appendToLog ("CustomIME Debug 3 with runningInventoryRfidTask = " + MainActivity .sharedObjects .runningInventoryRfidTask + ", and mrfidToWriteSize = " + MainActivity .csLibrary4A .mrfidToWriteSize ());
74+ appendToLog ("CustomIME Debug 3 with runningInventoryBarcodeTask = " + MainActivity .sharedObjects .runningInventoryBarcodeTask );
75+ if (MainActivity .sharedObjects .runningInventoryRfidTask == false && MainActivity .sharedObjects .runningInventoryBarcodeTask == false && MainActivity .csLibrary4A .mrfidToWriteSize () == 0 ) {
76+ startStopHandler ();
77+ inventoring = true ;
8678 }
87- if (matched == false && strEpc != null ) {
88- epcArrayList .add (strEpc );
89- InputConnection ic = getCurrentInputConnection ();
90- if (MainActivity .wedgePrefix != null ) strEpc = MainActivity .wedgePrefix + strEpc ;
91- if (MainActivity .wedgeSuffix != null ) strEpc += MainActivity .wedgeSuffix ;
92- switch (MainActivity .wedgeDelimiter ) {
93- default :
94- strEpc += "\n " ;
95- break ;
96- case 0x09 :
97- strEpc += "\t " ;
98- break ;
99- case 0x2C :
100- strEpc += "," ;
101- break ;
102- case 0x20 :
103- strEpc += " " ;
104- break ;
105- case -1 :
106- break ;
79+ } else {
80+ appendToLog ("CustomIME Debug 4" );
81+ while (MainActivity .sharedObjects .serviceArrayList .size () != 0 ) {
82+ String strEpc = MainActivity .sharedObjects .serviceArrayList .get (0 );
83+ MainActivity .sharedObjects .serviceArrayList .remove (0 );
84+ appendToLog ("CustomIME Debug 4A with strEpc = " + strEpc );
85+ String strSgtin = null ;
86+ if (MainActivity .wedgeOutput == 1 ) {
87+ strSgtin = MainActivity .csLibrary4A .getUpcSerial (strEpc );
88+ MainActivity .csLibrary4A .appendToLog ("strSgtin = " + (strSgtin == null ? "null" : strSgtin ));
89+ if (strSgtin == null ) strEpc = null ;
90+ }
91+ boolean matched = false ;
92+ if (epcArrayList != null && strEpc != null ) {
93+ for (int i = 0 ; i < epcArrayList .size (); i ++) {
94+ if (epcArrayList .get (i ).matches (strEpc )) {
95+ matched = true ;
96+ break ;
97+ }
98+ }
99+ }
100+ if (matched == false && strEpc != null ) {
101+ epcArrayList .add (strEpc );
102+ InputConnection ic = getCurrentInputConnection ();
103+ String strValue = strEpc ;
104+ if (strSgtin != null ) strValue = strSgtin ;
105+ if (MainActivity .wedgePrefix != null )
106+ strValue = MainActivity .wedgePrefix + strValue ;
107+ if (MainActivity .wedgeSuffix != null )
108+ strValue += MainActivity .wedgeSuffix ;
109+ MainActivity .csLibrary4A .appendToLog ("CustomIME, serviceRunnable: wedgeDelimiter = " + MainActivity .wedgeDelimiter );
110+ switch (MainActivity .wedgeDelimiter ) {
111+ default :
112+ strValue += "\n " ;
113+ break ;
114+ case 0x09 :
115+ strValue += "\t " ;
116+ break ;
117+ case 0x2C :
118+ strValue += "," ;
119+ break ;
120+ case 0x20 :
121+ strValue += " " ;
122+ break ;
123+ case -1 :
124+ break ;
125+ }
126+ MainActivity .csLibrary4A .appendToLog ("CustomIME BtData to Keyboard: " + strValue );
127+ ic .commitText (strValue , 1 );
107128 }
108- ic .commitText (strEpc , 1 );
109129 }
110130 }
111131 }
112132 }
133+ int iDelayms = 500 ;
134+ if (inventoring ) iDelayms = 100 ;
135+ MainActivity .csLibrary4A .appendToLog ("CustomIME BtData set next time as " + iDelayms );
136+ mHandler .postDelayed (serviceRunnable , iDelayms );
113137 }
114138 };
115139
@@ -121,17 +145,26 @@ void startStopHandler() {
121145 if (inventoryRfidTask != null ) {
122146 if (inventoryRfidTask .getStatus () == AsyncTask .Status .RUNNING ) started = true ;
123147 }
148+ if (inventoryBarcodeTask != null ) {
149+ if (inventoryBarcodeTask .getStatus () == AsyncTask .Status .RUNNING ) started = true ;
150+ }
124151 appendToLog ("CustomIME Debug 10" );
125152 if ((started && MainActivity .csLibrary4A .getTriggerButtonStatus ()) || (started == false && MainActivity .csLibrary4A .getTriggerButtonStatus () == false )) return ;
126153 if (started == false ) {
154+ appendToLog ("CustomIME Debug 11 with BtData wedgeOutput = " + MainActivity .wedgeOutput );
155+ if (MainActivity .wedgeOutput == 2 ) {
156+ inventoryBarcodeTask = new InventoryBarcodeTask ();
157+ inventoryBarcodeTask .execute ();
158+ } else {
159+ MainActivity .csLibrary4A .setPowerLevel (MainActivity .wedgePower );
160+ MainActivity .csLibrary4A .startOperation (RfidReaderChipData .OperationTypes .TAG_INVENTORY_COMPACT );
161+ inventoryRfidTask = new InventoryRfidTask ();
162+ inventoryRfidTask .execute ();
163+ }
164+ } else {
127165 appendToLog ("CustomIME Debug 11" );
128- MainActivity .csLibrary4A .startOperation (CsLibrary4A .OperationTypes .TAG_INVENTORY );
129- inventoryRfidTask = new InventoryRfidTask ();
130- inventoryRfidTask .execute ();
131- }
132- else {
133- appendToLog ("CustomIME Debug 11" );
134- inventoryRfidTask .taskCancelReason = InventoryRfidTask .TaskCancelRReason .BUTTON_RELEASE ;
166+ if (inventoryRfidTask != null ) inventoryRfidTask .taskCancelReason = InventoryRfidTask .TaskCancelRReason .BUTTON_RELEASE ;
167+ if (inventoryBarcodeTask != null ) inventoryBarcodeTask .taskCancelReason = InventoryBarcodeTask .TaskCancelRReason .BUTTON_RELEASE ;
135168 }
136169 }
137170}
0 commit comments