ECopyOptionContext.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package epson.print.rpcopy.Component.ecopycomponent;
  2. import android.os.Parcel;
  3. import android.os.Parcelable;
  4. import org.json.JSONException;
  5. import org.json.JSONObject;
  6. import java.util.ArrayList;
  7. import java.util.Iterator;
  8. import epson.print.rpcopy.Component.eremoteoperation.ERemoteCopy;
  9. import epson.print.rpcopy.Component.eremoteoperation.ERemoteOperation;
  10. public class ECopyOptionContext implements Parcelable {
  11. public static final Parcelable.Creator<ECopyOptionContext> CREATOR = new Parcelable.Creator<ECopyOptionContext>() {
  12. public ECopyOptionContext createFromParcel(Parcel parcel) {
  13. return new ECopyOptionContext(parcel);
  14. }
  15. public ECopyOptionContext[] newArray(int i) {
  16. return new ECopyOptionContext[i];
  17. }
  18. };
  19. ERemoteCopy.ERemoteCopyOptionsResult copyOptionsResult;
  20. ECopyComponent.ECopyType copyType;
  21. ArrayList<ECopyOptionItem> optionItems;
  22. public int describeContents() {
  23. return 0;
  24. }
  25. public void writeToParcel(Parcel parcel, int i) {
  26. parcel.writeString(copyType.name());
  27. parcel.writeInt(optionItems.size());
  28. Iterator<ECopyOptionItem> it = optionItems.iterator();
  29. while (it.hasNext()) {
  30. parcel.writeParcelable(it.next(), 0);
  31. }
  32. parcel.writeString(copyOptionsResult.toString());
  33. }
  34. ECopyOptionContext(Parcel parcel) {
  35. optionItems = new ArrayList<>();
  36. copyType = ECopyComponent.ECopyType.valueOf(parcel.readString());
  37. int readInt = parcel.readInt();
  38. for (int i = 0; i < readInt; i++) {
  39. optionItems.add((ECopyOptionItem) parcel.readParcelable(ECopyOptionItem.class.getClassLoader()));
  40. }
  41. try {
  42. JSONObject jSONObject = new JSONObject(parcel.readString());
  43. ERemoteCopy eRemoteCopy = new ERemoteCopy();
  44. eRemoteCopy.getClass();
  45. copyOptionsResult = new ERemoteCopy.ERemoteCopyOptionsResult(jSONObject);
  46. } catch (JSONException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. private boolean isNull() {
  51. return copyType == null;
  52. }
  53. ECopyOptionContext() {
  54. optionItems = new ArrayList<>();
  55. copyType = null;
  56. }
  57. ECopyOptionContext(ECopyComponent.ECopyType eCopyType) {
  58. optionItems = new ArrayList<>();
  59. copyType = eCopyType;
  60. }
  61. ECopyOptionContext(ECopyOptionContext eCopyOptionContext) {
  62. optionItems = new ArrayList<>();
  63. copyType = null;
  64. if (eCopyOptionContext != null) {
  65. copyType = eCopyOptionContext.copyType;
  66. Iterator<ECopyOptionItem> it = eCopyOptionContext.optionItems.iterator();
  67. while (it.hasNext()) {
  68. optionItems.add(new ECopyOptionItem(it.next()));
  69. }
  70. copyOptionsResult = eCopyOptionContext.copyOptionsResult;
  71. }
  72. }
  73. private ECopyComponent.ECopyType getCopyType() {
  74. return copyType;
  75. }
  76. private ArrayList<ECopyOptionItem> getCopyOptionItems() {
  77. return optionItems;
  78. }
  79. private ECopyOptionItem getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey eCopyOptionItemKey) {
  80. Iterator<ECopyOptionItem> it = optionItems.iterator();
  81. while (it.hasNext()) {
  82. ECopyOptionItem next = it.next();
  83. if (next.key == eCopyOptionItemKey) {
  84. return next;
  85. }
  86. }
  87. return null;
  88. }
  89. private void add(ECopyOptionItem eCopyOptionItem) {
  90. optionItems.add(eCopyOptionItem);
  91. }
  92. public ECopyOptionItem replace(ECopyOptionItem eCopyOptionItem) {
  93. Iterator<ECopyOptionItem> it = optionItems.iterator();
  94. int i = 0;
  95. while (it.hasNext()) {
  96. if (it.next().key == eCopyOptionItem.key) {
  97. return optionItems.set(i, eCopyOptionItem);
  98. }
  99. i++;
  100. }
  101. return null;
  102. }
  103. public boolean hasCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey eCopyOptionItemKey) {
  104. ECopyOptionItem copyOptionItemOf = getCopyOptionItemOf(eCopyOptionItemKey);
  105. if (copyOptionItemOf == null) {
  106. return false;
  107. }
  108. ERemoteOperation.ERemoteParam eRemoteParam = copyOptionItemOf.getSelectedChoice().param;
  109. if (!ERemoteOperation.ERemoteParam.x_null.equals(eRemoteParam) && !ERemoteOperation.ERemoteParam.dash.equals(eRemoteParam)) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. private boolean isChanged(ECopyOptionItem eCopyOptionItem) {
  115. Iterator<ECopyOptionItem> it = optionItems.iterator();
  116. while (true) {
  117. if (!it.hasNext()) {
  118. break;
  119. }
  120. ECopyOptionItem next = it.next();
  121. if (next.key == eCopyOptionItem.key) {
  122. if (!next.equals(eCopyOptionItem)) {
  123. return true;
  124. }
  125. }
  126. }
  127. return false;
  128. }
  129. private void setCopyOptionsResult(ERemoteCopy.ERemoteCopyOptionsResult eRemoteCopyOptionsResult) {
  130. copyOptionsResult = eRemoteCopyOptionsResult;
  131. }
  132. private ERemoteCopy.ERemoteCopyOptionsResult getCopyOptionsResult() {
  133. return copyOptionsResult;
  134. }
  135. }