ECopyOptionContext.java 4.7 KB

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