FindPrinterTask.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.epson.mobilephone.common.wifidirect;
  2. import android.os.AsyncTask;
  3. import android.os.Handler;
  4. class FindPrinterTask extends AsyncTask<Void, Void, Boolean> {
  5. private static final String TAG = "FindPrinterTask";
  6. boolean canceled = false;
  7. Handler handler = null;
  8. int idFound;
  9. int idNotFound;
  10. escprLib mEscprLib = new escprLib();
  11. int timeout;
  12. FindPrinterTask(Handler handler2, int i, int i2, int i3) {
  13. handler = handler2;
  14. timeout = i;
  15. idFound = i2;
  16. idNotFound = i3;
  17. }
  18. protected void onPreExecute() {
  19. super.onPreExecute();
  20. mEscprLib.setHanlder(handler, idFound);
  21. mEscprLib.setSearchStt(true);
  22. }
  23. protected Boolean doInBackground(Void... voidArr) {
  24. int epsWrapperInitDriver = mEscprLib.epsWrapperInitDriver(192);
  25. boolean z = true;
  26. if (epsWrapperInitDriver != -1050 && epsWrapperInitDriver != 0) {
  27. return true;
  28. }
  29. EPLog.d(TAG, "epsWrapperFindPrinter start");
  30. int epsWrapperFindPrinter = mEscprLib.epsWrapperFindPrinter(192, timeout);
  31. if (epsWrapperFindPrinter == 0 || epsWrapperFindPrinter == 42) {
  32. z = false;
  33. }
  34. mEscprLib.epsWrapperReleaseDriver();
  35. return Boolean.valueOf(z);
  36. }
  37. protected void onPostExecute(Boolean bool) {
  38. if (bool.booleanValue() || !this.canceled) {
  39. EPLog.d(TAG, "epsWrapperFindPrinter = EPS_ERR_PRINTER_NOT_FOUND");
  40. handler.sendEmptyMessage(idNotFound);
  41. }
  42. }
  43. public void cancel() {
  44. mEscprLib.setSearchStt(false);
  45. mEscprLib.epsWrapperCancelFindPrinter();
  46. canceled = true;
  47. }
  48. }