@@ -36,11 +36,35 @@ public enum TaskCancelRReason {
3636 boolean done = false ;
3737 boolean ending = false ;
3838 private String endingMessaage ;
39- int qValue ;
40- boolean repeat , nextNew ;
39+
40+ int qValue =0 ;
41+ boolean repeat =false , nextNew =false ;
42+ boolean bEnableErrorPopWindow =true ;
43+
4144 boolean gotInventory ;
4245 int batteryCountInventory_old ;
4346
47+ public AccessTask (Button button , boolean invalidRequest ,
48+ String selectMask , int selectBank , int selectOffset ,
49+ String strPassword , int powerLevel , Cs108Connector .HostCommands hostCommand , boolean bEnableErrorPopWindow ) {
50+ this .button = button ;
51+ this .registerTagGot = registerTagGot ;
52+ this .registerVoltageLevel = registerVoltageLevel ;
53+
54+ this .invalidRequest = invalidRequest ; MainActivity .mCs108Library4a .appendToLog ("invalidRequest = " + invalidRequest );
55+ this .selectMask = selectMask ;
56+ this .selectBank = selectBank ;
57+ this .selectOffset = selectOffset ;
58+ this .strPassword = strPassword ;
59+ this .powerLevel = powerLevel ;
60+ this .hostCommand = hostCommand ;
61+ this .bEnableErrorPopWindow = bEnableErrorPopWindow ;
62+ if (true ) {
63+ total = 0 ;
64+ tagList .clear ();
65+ }
66+ preExecute ();
67+ }
4468 public AccessTask (Button button , TextView textViewWriteCount , boolean invalidRequest ,
4569 String selectMask , int selectBank , int selectOffset ,
4670 String strPassword , int powerLevel , Cs108Connector .HostCommands hostCommand ,
@@ -69,15 +93,15 @@ public AccessTask(Button button, TextView textViewWriteCount, boolean invalidReq
6993 total = 0 ;
7094 tagList .clear ();
7195 }
96+ preExecute ();
97+ }
7298
99+ void preExecute () {
73100 accessResult = null ;
74101 playerO = MainActivity .sharedObjects .playerO ;
75102 playerN = MainActivity .sharedObjects .playerN ;
76- playerN .start ();
77- }
103+ //playerN.start();
78104
79- @ Override
80- protected void onPreExecute () {
81105 buttonText = button .getText ().toString ().trim ();
82106 String buttonText1 = null ; String strLastChar = buttonText .substring (buttonText .length ()-1 );
83107 if (strLastChar .toUpperCase ().matches ("E" )) {
@@ -158,7 +182,7 @@ else if (rx000pkgData != null) {
158182 } else if (rx000pkgData .responseType == Cs108Connector .HostCmdResponseTypes .TYPE_18K6C_TAG_ACCESS ) {
159183 if (true ) {
160184 if (rx000pkgData .decodedError == null ) {
161- if (done == false ) { accessResult = rx000pkgData .decodedResult ; }
185+ if (done == false ) { accessResult = rx000pkgData .decodedResult ; MainActivity . mCs108Library4a . appendToLog ( "HelloA, accResult=" + accessResult ); }
162186 done = true ;
163187 publishProgress (null , rx000pkgData .decodedResult );
164188 }
@@ -194,18 +218,19 @@ else if (repeat && (nextNew == false || resultError.length() != 0)) {
194218 String tagInventoried = null ;
195219 @ Override
196220 protected void onProgressUpdate (String ... output ) {
197- if (output [0 ] != null ) {
221+ if (true ) progressUpdate (output );
222+ else if (output [0 ] != null ) {
198223 if (output [0 ].length () == 2 ) {
199224 if (output [0 ].contains ("TT" )) {
200225 gotInventory = true ;
201- if (registerTagGot != null ) registerTagGot .setText (output [1 ]);
202226 boolean matched = false ;
203227 for (int i = 0 ; i < tagList .size (); i ++) {
204228 if (output [1 ].matches (tagList .get (i ))) {
205229 matched = true ;
206230 break ;
207231 }
208232 }
233+ if (registerTagGot != null ) registerTagGot .setText (output [1 ]);
209234 if (matched == false ) tagInventoried = output [1 ];
210235 } else if (output [0 ].contains ("WW" )) {
211236 long timePeriod = (System .currentTimeMillis () - startTimeMillis ) / 1000 ;
@@ -249,6 +274,45 @@ protected void onPostExecute(String result) {
249274 DeviceConnectTask4RegisterEnding ();
250275 }
251276
277+ protected void progressUpdate (String ... output ) {
278+ if (output [0 ] != null ) {
279+ if (output [0 ].length () == 2 ) {
280+ if (output [0 ].contains ("TT" )) {
281+ gotInventory = true ;
282+ boolean matched = false ;
283+ for (int i = 0 ; i < tagList .size (); i ++) {
284+ if (output [1 ].matches (tagList .get (i ))) {
285+ matched = true ;
286+ break ;
287+ }
288+ }
289+ if (registerTagGot != null ) registerTagGot .setText (output [1 ]);
290+ if (matched == false ) tagInventoried = output [1 ];
291+ } else if (output [0 ].contains ("WW" )) {
292+ long timePeriod = (System .currentTimeMillis () - startTimeMillis ) / 1000 ;
293+ if (timePeriod > 0 ) {
294+ if (registerRunTime != null ) registerRunTime .setText (String .format ("Run time: %d sec" , timePeriod ));
295+ }
296+ } else if (taskCancelReason == TaskCancelRReason .NULL ) {
297+ if (registerVoltageLevel != null ) registerVoltageLevel .setText (MainActivity .mCs108Library4a .getBatteryDisplay (true ));
298+ }
299+ } else {
300+ resultError += output [0 ];
301+ if (true )
302+ MainActivity .mCs108Library4a .appendToLog ("output[0]: " + output [0 ] + ", resultError = " + resultError );
303+ }
304+ } else {
305+ if (registerYield != null ) {
306+ if (tagInventoried != null ) {
307+ tagList .add (tagInventoried );
308+ tagInventoried = null ;
309+ }
310+ registerYield .setText ("Unique:" + Integer .toString (tagList .size ()));
311+ }
312+ if (registerTotal != null ) registerTotal .setText ("Total:" + Integer .toString (++total ));
313+ }
314+ }
315+
252316 void DeviceConnectTask4RegisterEnding () {
253317 String strErrorMessage = "" ;
254318 if (false ) {
@@ -267,7 +331,7 @@ void DeviceConnectTask4RegisterEnding() {
267331 switch (taskCancelReason ) {
268332 case NULL :
269333 if (accessResult == null || (resultError != null && resultError .length () != 0 ) || (endingMessaage != null && endingMessaage .length () != 0 )) strErrorMessage += ("Finish as COMMAND END is received " + (gotInventory ? "WITH" : "WITHOUT" ) + " tag response" );
270- else Toast .makeText (MainActivity .mContext , R .string .toast_abort_by_SUCCESS , Toast .LENGTH_SHORT ).show ();
334+ // else Toast.makeText(MainActivity.mContext, R.string.toast_abort_by_SUCCESS, Toast.LENGTH_SHORT).show();
271335 break ;
272336 case STOP :
273337 strErrorMessage += "Finish as STOP is pressed. " ;
@@ -290,9 +354,12 @@ void DeviceConnectTask4RegisterEnding() {
290354 if (strErrorMessage .length () != 0 ) endingMessaage = strErrorMessage ;
291355 button .setText (buttonText );
292356 if (endingMessaage != null ) {
293- if (endingMessaage .length () != 0 ) {
294- CustomPopupWindow customPopupWindow = new CustomPopupWindow (MainActivity .mContext );
295- customPopupWindow .popupStart (endingMessaage , false );
357+ if (endingMessaage .length () != 0 || true ) {
358+ MainActivity .mCs108Library4a .appendToLog ("endingMessage=" + endingMessaage );
359+ if (bEnableErrorPopWindow ) {
360+ CustomPopupWindow customPopupWindow = new CustomPopupWindow (MainActivity .mContext );
361+ customPopupWindow .popupStart (endingMessaage , false );
362+ }
296363 }
297364 }
298365 }
0 commit comments