EscprLibPrinter.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.epson.memcardacc;
  2. import android.content.Context;
  3. import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
  4. import epson.print.MyPrinter;
  5. public class EscprLibPrinter {
  6. public static final int ERROR_PRINTER_CONNECTION = 2;
  7. public static final int ERROR_PRINTER_LOCATION = 1;
  8. public static final int NO_ERROR = 0;
  9. public static final int STATUS_BUSY = 2;
  10. public static final int STATUS_CANCELLING = 3;
  11. public static final int STATUS_ERROR = 4;
  12. public static final int STATUS_IDEL = 0;
  13. public static final int STATUS_PRINTING = 1;
  14. MaintainPrinter2 mMaintainPrinter;
  15. public int init(Context context, int i, boolean z) {
  16. EPLog.i();
  17. MyPrinter currentPrinter = getCurrentPrinter(context);
  18. String printerId = currentPrinter.getPrinterId();
  19. String ip = currentPrinter.getIp();
  20. int location = currentPrinter.getLocation();
  21. if (location != 1 && location != 3) {
  22. return 1;
  23. }
  24. mMaintainPrinter = getMaintainPrinter();
  25. mMaintainPrinter.doInitDriver(context, 2);
  26. if (mMaintainPrinter.doProbePrinter(i, printerId, ip, location) != 0) {
  27. mMaintainPrinter = null;
  28. return 2;
  29. } else if (mMaintainPrinter.doSetPrinter() != 0) {
  30. mMaintainPrinter = null;
  31. return 2;
  32. } else if (location == 1) {
  33. String doGetIp = mMaintainPrinter.doGetIp();
  34. if (ip.equals(doGetIp) || !z) {
  35. return 0;
  36. }
  37. currentPrinter.setIp(doGetIp);
  38. currentPrinter.setCurPrinter(context);
  39. return 0;
  40. } else if (location != 3 || printerId.equals(mMaintainPrinter.doGetId())) {
  41. return 0;
  42. } else {
  43. mMaintainPrinter = null;
  44. return 2;
  45. }
  46. }
  47. public int getStatus() {
  48. if (mMaintainPrinter.doGetStatus() != 0) {
  49. return 4;
  50. }
  51. switch (mMaintainPrinter.getMPrinterInfor().getMStatus()[0]) {
  52. case 0:
  53. return 0;
  54. case 1:
  55. return 1;
  56. case 2:
  57. return 2;
  58. case 3:
  59. return 3;
  60. default:
  61. return 4;
  62. }
  63. }
  64. public void release() {
  65. if (mMaintainPrinter != null) {
  66. mMaintainPrinter = null;
  67. }
  68. }
  69. public static int checkIdleOrError(Context context, int i) {
  70. EscprLibPrinter escprLibPrinter = new EscprLibPrinter();
  71. if (escprLibPrinter.init(context, i, false) != 0) {
  72. return 1;
  73. }
  74. int status = escprLibPrinter.getStatus();
  75. escprLibPrinter.release();
  76. if (status == 0 || status == 4) {
  77. return 0;
  78. }
  79. return 2;
  80. }
  81. private MyPrinter getCurrentPrinter(Context context) {
  82. return MyPrinter.getCurPrinter(context);
  83. }
  84. private MaintainPrinter2 getMaintainPrinter() {
  85. return MaintainPrinter2.getInstance();
  86. }
  87. }