ECopyOptionContext.java 4.5 KB

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