ECopyOptionContext.java 5.4 KB

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