ActivityBase.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. package epson.print.rpcopy;
  2. import android.annotation.SuppressLint;
  3. import android.app.AlertDialog;
  4. import android.app.Dialog;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.SharedPreferences;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import epson.common.Constants;
  17. import epson.print.ActivityIACommon;
  18. import epson.print.CommonDefine;
  19. import epson.print.R;
  20. import epson.print.Util.EPLog;
  21. import epson.print.copy.DisplayUtil;
  22. import epson.print.rpcopy.Component.ecopycomponent.ECopyComponent;
  23. import epson.print.rpcopy.Component.ecopycomponent.ECopyOptionContext;
  24. import epson.print.rpcopy.Component.ecopycomponent.ECopyOptionItem;
  25. import epson.print.rpcopy.Component.eremoteoperation.ERemoteOperation;
  26. import epson.print.screen.WorkingDialog;
  27. import epson.print.widgets.CustomTitleAlertDialogBuilder;
  28. @SuppressLint({"Registered"})
  29. class ActivityBase extends ActivityIACommon {
  30. static final String Title = "Title";
  31. private static final HashMap<String, String> mParamStringToDisplayStringHash = new HashMap<>();
  32. static String printerId;
  33. static String printerIp;
  34. private String TAG = "ActivityBase";
  35. ECopyComponent copyComponent = ECopyComponent.sharedComponent();
  36. ECopyComponent.ECopyType copyType = ECopyComponent.ECopyType.Standard;
  37. boolean isKeepSimpleAPConnection = false;
  38. boolean isTryConnectSimpleAp = false;
  39. WorkingDialog loading;
  40. ECopyOptionContext mECopyOptionContext;
  41. HashMap<ECopyOptionItem.ECopyOptionItemKey, OptionValue> optionValueMap = new HashMap<>();
  42. public interface CancelRequestCallback {
  43. void onCancelRequest();
  44. }
  45. enum ClickButton {
  46. Ok,
  47. Cancel,
  48. ClearError
  49. }
  50. enum DialogButtons {
  51. Ok,
  52. Cancel,
  53. ClearErrorCancel
  54. }
  55. interface IClose {
  56. void onClose(ClickButton clickButton);
  57. }
  58. interface INextPageClose {
  59. void onClose(ECopyComponent.ICopyResumeRequest.ResumeState resumeState);
  60. }
  61. interface OptionItemChangedListener {
  62. void onOptionItemChanged(ECopyOptionItem eCopyOptionItem);
  63. }
  64. private void buildCopyOptions(ArrayList<ECopyOptionItem> arrayList) {
  65. }
  66. ActivityBase() {
  67. }
  68. class WheelDialog extends Dialog {
  69. Button cancelButton;
  70. CancelRequestCallback cancelCallback;
  71. Dialog cancelDialog;
  72. TextView messageText = ((TextView) findViewById(R.id.messageText));
  73. private Dialog createCancelDialog() {
  74. AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
  75. builder.setMessage(getString(R.string.str_msg_scan_cancel));
  76. builder.setCancelable(false);
  77. builder.setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
  78. public void onClick(DialogInterface dialogInterface, int i) {
  79. WheelDialog.this.cancelButton.setEnabled(false);
  80. WheelDialog.this.cancelCallback.onCancelRequest();
  81. dialogInterface.cancel();
  82. }
  83. });
  84. builder.setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
  85. public void onClick(DialogInterface dialogInterface, int i) {
  86. WheelDialog.this.cancelButton.setEnabled(true);
  87. dialogInterface.cancel();
  88. }
  89. });
  90. return builder.create();
  91. }
  92. public WheelDialog(Context context) {
  93. super(context, R.style.AppTheme_Translucent_Gray);
  94. setContentView(R.layout.wheel_dialog);
  95. setCancelable(false);
  96. }
  97. private void show(String str, CancelRequestCallback cancelRequestCallback) {
  98. cancelCallback = cancelRequestCallback;
  99. messageText.setText(str);
  100. messageText.setVisibility(0);
  101. cancelButton = (Button) findViewById(R.id.cancelButton);
  102. cancelButton.setOnClickListener(new View.OnClickListener() {
  103. public void onClick(View view) {
  104. WheelDialog wheelDialog = WheelDialog.this;
  105. wheelDialog.cancelDialog = wheelDialog.createCancelDialog();
  106. WheelDialog.this.cancelDialog.show();
  107. }
  108. });
  109. cancelButton.setVisibility(0);
  110. show();
  111. }
  112. private void setText(String str) {
  113. messageText.setText(str);
  114. }
  115. private void hideCancelButton() {
  116. cancelButton.setVisibility(4);
  117. }
  118. private void dissmiss() {
  119. super.dismiss();
  120. Dialog dialog = cancelDialog;
  121. if (dialog != null) {
  122. dialog.dismiss();
  123. }
  124. }
  125. }
  126. public void onCreate(Bundle bundle) {
  127. super.onCreate(bundle);
  128. loading = new WorkingDialog(this);
  129. DisplayUtil.setMap(this, mParamStringToDisplayStringHash);
  130. }
  131. public class errorDialog {
  132. public static final int MESSAGE = 1;
  133. public static final int TITLE = 0;
  134. Context context;
  135. Dialog dialog;
  136. public errorDialog(Context context2) {
  137. context = context2;
  138. }
  139. private void showErrorDialog(String str, String str2) {
  140. showErrorDialog(str, str2, DialogButtons.Ok, (IClose) null);
  141. }
  142. private void showErrorDialog(int i) {
  143. showErrorDialog((String) null, getString(i));
  144. }
  145. private void showErrorDialog(String str, String str2, final DialogButtons dialogButtons, final IClose iClose) {
  146. String str3;
  147. CustomTitleAlertDialogBuilder customTitleAlertDialogBuilder = new CustomTitleAlertDialogBuilder(context);
  148. String str4 = null;
  149. switch (dialogButtons) {
  150. case Ok:
  151. str4 = getString(R.string.str_ok);
  152. str3 = null;
  153. break;
  154. case Cancel:
  155. str3 = getString(R.string.str_cancel);
  156. break;
  157. case ClearErrorCancel:
  158. str4 = getString(R.string.str_continue);
  159. str3 = getString(R.string.str_cancel);
  160. break;
  161. default:
  162. str3 = null;
  163. break;
  164. }
  165. if (str != null) {
  166. customTitleAlertDialogBuilder.setTitle(str);
  167. }
  168. customTitleAlertDialogBuilder.setMessage(str2);
  169. customTitleAlertDialogBuilder.setCancelable(false);
  170. if (str4 != null) {
  171. customTitleAlertDialogBuilder.setPositiveButton(str4, new DialogInterface.OnClickListener() {
  172. public void onClick(DialogInterface dialogInterface, int i) {
  173. dialogInterface.cancel();
  174. IClose iClose = iClose;
  175. if (iClose != null) {
  176. iClose.onClose(dialogButtons == DialogButtons.Ok ? ClickButton.Ok : ClickButton.ClearError);
  177. }
  178. }
  179. });
  180. }
  181. if (str3 != null) {
  182. customTitleAlertDialogBuilder.setNegativeButton(str3, new DialogInterface.OnClickListener() {
  183. public void onClick(DialogInterface dialogInterface, int i) {
  184. dialogInterface.cancel();
  185. IClose iClose = iClose;
  186. if (iClose != null) {
  187. iClose.onClose(ClickButton.Cancel);
  188. }
  189. }
  190. });
  191. }
  192. dialog = customTitleAlertDialogBuilder.create();
  193. dialog.show();
  194. }
  195. private void Cancel() {
  196. Dialog dialog2 = dialog;
  197. if (dialog2 != null) {
  198. dialog2.cancel();
  199. }
  200. }
  201. public String[] getReasonText(ECopyComponent.ICopyStatusListener.CopyTaskResult copyTaskResult) {
  202. String[] strArr = new String[2];
  203. switch (copyTaskResult) {
  204. case ErrorCommunication:
  205. strArr[0] = getString(R.string.EPS_PRNERR_COMM_TITLE);
  206. strArr[1] = getString(R.string.CopyCommErrorText);
  207. break;
  208. case Busy:
  209. strArr[0] = getString(R.string.EPS_PRNST_BUSY_TITLE);
  210. strArr[1] = getString(R.string.EPS_PRNST_BUSY_MSG);
  211. break;
  212. case RemoveAdfPaper:
  213. strArr[0] = getString(R.string.CopyTaskResultRemoveAdfPaperTitle);
  214. strArr[1] = getString(R.string.CopyTaskResultRemoveAdfPaper);
  215. break;
  216. case ErrorOther:
  217. strArr[0] = getString(R.string.EPS_PRNERR_GENERAL_ERR);
  218. strArr[1] = getString(R.string.CopyTaskResultErrorOtherText);
  219. break;
  220. }
  221. return strArr;
  222. }
  223. public String[] getReasonText(ECopyComponent.ICopyOptionContextListener.ContextCreationError contextCreationError) {
  224. String[] strArr = new String[2];
  225. switch (contextCreationError) {
  226. case ErrorCommunication:
  227. strArr[0] = getString(R.string.EPS_PRNERR_COMM_TITLE);
  228. strArr[1] = getString(R.string.EPS_PRNERR_COMM5);
  229. break;
  230. case ErrorNotCopySupported:
  231. case Error:
  232. strArr[0] = getString(R.string.EPS_PRNERR_GENERAL_ERR);
  233. strArr[1] = getString(R.string.CopyTaskResultErrorOtherText);
  234. break;
  235. }
  236. return strArr;
  237. }
  238. public String[] getReasonText(ECopyComponent.ICopyOptionListener.CopyOptionChangedError copyOptionChangedError) {
  239. String[] strArr = new String[2];
  240. switch (copyOptionChangedError) {
  241. case ErrorCommunication:
  242. strArr[0] = getString(R.string.EPS_PRNERR_COMM_TITLE);
  243. strArr[1] = getString(R.string.EPS_PRNERR_COMM5);
  244. break;
  245. case ErrorInvalidOption:
  246. case Error:
  247. strArr[0] = getString(R.string.EPS_PRNERR_GENERAL_ERR);
  248. strArr[1] = getString(R.string.CopyTaskResultErrorOtherText);
  249. break;
  250. }
  251. return strArr;
  252. }
  253. public String[] getReasonText(ECopyComponent.ICopyResumeRequest.StopReason stopReason) {
  254. String[] strArr = new String[2];
  255. switch (stopReason) {
  256. case PrinterMarkerSupplyEmptyError:
  257. strArr[0] = getString(R.string.EPS_PRNERR_INKOUT_TITLE);
  258. strArr[1] = getString(R.string.EPS_PRNERR_INKOUT_MSG);
  259. break;
  260. case PrinterMarkerWasteFullError:
  261. strArr[0] = getString(R.string.EPS_PRNERR_WEB_REMOTE_MAINTENANCE_BOX_TITLE);
  262. strArr[1] = getString(R.string.EPS_PRNERR_WEB_REMOTE_MAINTENANCE_BOX_MSG);
  263. break;
  264. case PrinterMediaJamError:
  265. strArr[0] = getString(R.string.EPS_PRNERR_PAPERJAM_TITLE);
  266. strArr[1] = getString(R.string.CopyPaperJamErrorText);
  267. break;
  268. case PrinterMediaEmptyError:
  269. strArr[0] = getString(R.string.EPS_PRNERR_PAPEROUT_TITLE);
  270. strArr[1] = getString(R.string.EPS_PRNERR_PAPEROUT_MSG);
  271. break;
  272. case ManualfeedGuide:
  273. strArr[0] = getString(R.string.EPS_PRNERR_MANUALFEED_SET_PAPER_TITLE);
  274. strArr[1] = getString(R.string.EPS_PRNERR_MANUALFEED_SET_PAPER_MSG);
  275. break;
  276. case PrinterCoverOpenError:
  277. strArr[0] = getString(R.string.EPS_PRNERR_COVEROPEN_TITLE);
  278. strArr[1] = getString(R.string.EPS_PRNERR_COVEROPEN_MSG);
  279. break;
  280. case PrinterOutputAreaFullError:
  281. strArr[0] = getString(R.string.EPS_PRNERR_CDRGUIDEOPEN_TITLE);
  282. strArr[1] = getString(R.string.CopyCDdiscErrorText);
  283. break;
  284. case PrinterOtherError:
  285. strArr[0] = getString(R.string.EPS_PRNERR_GENERAL_ERR);
  286. strArr[1] = getString(R.string.CopyTaskResultErrorOtherText);
  287. break;
  288. case ScannerOtherError:
  289. strArr[0] = getString(R.string.str_err_msg_scan_generic_internal_title);
  290. strArr[1] = getString(R.string.str_err_msg_scan_generic_internal);
  291. break;
  292. }
  293. return strArr;
  294. }
  295. }
  296. private void showNextPageDialog(final INextPageClose iNextPageClose) {
  297. C22541 r0 = new DialogInterface.OnClickListener() {
  298. public void onClick(DialogInterface dialogInterface, int i) {
  299. ECopyComponent.ICopyResumeRequest.ResumeState resumeState;
  300. dialogInterface.cancel();
  301. if (i == -1) {
  302. resumeState = ECopyComponent.ICopyResumeRequest.ResumeState.NextPageReady;
  303. } else if (i == -3) {
  304. resumeState = ECopyComponent.ICopyResumeRequest.ResumeState.NextPageNotExist;
  305. } else {
  306. resumeState = ECopyComponent.ICopyResumeRequest.ResumeState.Cancel;
  307. }
  308. iNextPageClose.onClose(resumeState);
  309. }
  310. };
  311. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  312. builder.setMessage(R.string.waiting_2nd_page);
  313. builder.setCancelable(true);
  314. builder.setPositiveButton(getString(R.string.next_page_ready), r0);
  315. builder.setNeutralButton(R.string.next_page_not_exist, r0);
  316. builder.setNegativeButton(getString(R.string.str_cancel), r0);
  317. builder.create().show();
  318. }
  319. abstract class OptionValue {
  320. OptionItemChangedListener changedListener;
  321. ECopyOptionItem optionItem;
  322. OptionValue() {
  323. }
  324. private void setOptionValueChangedListener(OptionItemChangedListener optionItemChangedListener) {
  325. changedListener = optionItemChangedListener;
  326. }
  327. }
  328. class ListOptionValue extends OptionValue {
  329. List<ECopyOptionItem.ECopyOptionItemChoice> choices;
  330. ECopyOptionItem.ECopyOptionItemChoice selected;
  331. ListOptionValue() {
  332. super();
  333. }
  334. private void bindOption(ECopyOptionItem eCopyOptionItem) {
  335. if (ECopyOptionItem.ECopyOptionItemKey.XCutLineStyle.equals(eCopyOptionItem.getKey()) || ECopyOptionItem.ECopyOptionItemKey.XCutLineWeight.equals(eCopyOptionItem.getKey())) {
  336. eCopyOptionItem.updateChoicesXCutLine();
  337. }
  338. optionItem = eCopyOptionItem;
  339. choices = eCopyOptionItem.getSelectableChoices();
  340. selected = eCopyOptionItem.getSelectedChoice();
  341. }
  342. private String[] getKeyArray() {
  343. String[] strArr = new String[this.choices.size()];
  344. for (int i = 0; i < choices.size(); i++) {
  345. strArr[i] = getDisplayString(choices.get(i).name());
  346. }
  347. return strArr;
  348. }
  349. }
  350. class NumberOptionValue extends OptionValue {
  351. Button countDown;
  352. Button countUp;
  353. TextView editText;
  354. int value;
  355. NumberOptionValue() {
  356. super();
  357. }
  358. private void updateWithAddition(int i) {
  359. try {
  360. value = Integer.valueOf(editText.getText().toString()).intValue();
  361. value = Math.min(Math.max(optionItem.getMinimumValue(), value + i), optionItem.getMaximumValue());
  362. optionItem.selectValue(value);
  363. if (changedListener != null) {
  364. changedListener.onOptionItemChanged(optionItem);
  365. }
  366. } catch (NumberFormatException unused) {
  367. }
  368. }
  369. class Counter implements View.OnClickListener {
  370. int amount;
  371. public Counter(int i) {
  372. amount = i;
  373. }
  374. public void onClick(View view) {
  375. NumberOptionValue.this.updateWithAddition(amount);
  376. }
  377. }
  378. private void bindOption(ECopyOptionItem eCopyOptionItem) {
  379. optionItem = eCopyOptionItem;
  380. value = eCopyOptionItem.getSelectedValue();
  381. }
  382. private void bindOption(int i, ECopyOptionItem eCopyOptionItem) {
  383. optionItem = eCopyOptionItem;
  384. editText = (TextView) findViewById(i);
  385. value = eCopyOptionItem.getSelectedValue();
  386. editText.setText(String.valueOf(value));
  387. editText.setEnabled(eCopyOptionItem.isEnabled());
  388. }
  389. private void bindCountUp(int i) {
  390. countUp = (Button) findViewById(i);
  391. countUp.setOnClickListener(new Counter(1));
  392. if (value == optionItem.getMaximumValue()) {
  393. countUp.setEnabled(false);
  394. } else {
  395. countUp.setEnabled(true);
  396. }
  397. }
  398. private void bindCountDown(int i) {
  399. countDown = (Button) findViewById(i);
  400. countDown.setOnClickListener(new Counter(-1));
  401. if (value == optionItem.getMinimumValue()) {
  402. countDown.setEnabled(false);
  403. } else {
  404. countDown.setEnabled(true);
  405. }
  406. }
  407. }
  408. class CopyMagnificationValue extends NumberOptionValue {
  409. public CopyMagnificationValue(ECopyOptionItem eCopyOptionItem) {
  410. super();
  411. bindOption(eCopyOptionItem);
  412. }
  413. }
  414. private String getDisplayString(String str) {
  415. return (String) (mParamStringToDisplayStringHash.containsKey(str) ? mParamStringToDisplayStringHash.get(str) : mParamStringToDisplayStringHash.get("Unknown"));
  416. }
  417. class settingPreference {
  418. private SharedPreferences.Editor editer;
  419. private SharedPreferences presettings;
  420. settingPreference() {
  421. }
  422. private SharedPreferences getPreferences() {
  423. return getSharedPreferences(CommonDefine.PREFS_INFO_REPEAT_COPY, 0);
  424. }
  425. private String loadPrePrinter() {
  426. presettings = getPreferences();
  427. return presettings.getString(Constants.PRINTER_ID, (String) null);
  428. }
  429. private void savePrePrinter() {
  430. presettings = getPreferences();
  431. editer = presettings.edit();
  432. editer.putString(Constants.PRINTER_ID, ActivityBase.printerId);
  433. editer.commit();
  434. }
  435. private void setCopyOptions(ArrayList<ECopyOptionItem> arrayList) {
  436. ECopyOptionContext bindedCopyOptionContext = copyComponent.getBindedCopyOptionContext();
  437. Iterator<ECopyOptionItem> it = arrayList.iterator();
  438. while (it.hasNext()) {
  439. ECopyOptionItem next = it.next();
  440. ECopyOptionItem.ECopyOptionItemKey key = next.getKey();
  441. if (!key.equals(ECopyOptionItem.ECopyOptionItemKey.Copies)) {
  442. setOption(key, next);
  443. bindedCopyOptionContext.replace(next);
  444. }
  445. }
  446. Iterator<ECopyOptionItem> it2 = arrayList.iterator();
  447. while (it2.hasNext()) {
  448. copyComponent.setCopyOptionItem(it2.next());
  449. }
  450. }
  451. private void setOption(ECopyOptionItem.ECopyOptionItemKey eCopyOptionItemKey, ECopyOptionItem eCopyOptionItem) {
  452. presettings = getPreferences();
  453. if (eCopyOptionItem.getChoiceType() != ECopyOptionItem.ECopyOptionItemChoiceType.ChoiceArray) {
  454. eCopyOptionItem.selectValue(presettings.getInt(eCopyOptionItemKey.name(), eCopyOptionItem.getDefaultValue()));
  455. } else if (eCopyOptionItem.getDefaultChoice() == null || eCopyOptionItem.getDefaultChoice().getParam() == null) {
  456. throw new RuntimeException("key: <" + eCopyOptionItem.getKey() + "> error");
  457. } else {
  458. eCopyOptionItem.selectChoice(ECopyOptionItem.ECopyOptionItemChoice.valueOf(eCopyOptionItemKey, ERemoteOperation.ERemoteParam.stringOf(presettings.getString(eCopyOptionItemKey.name(), eCopyOptionItem.getDefaultChoice().getParam().toString()))));
  459. }
  460. }
  461. private void saveCopyOptions(ArrayList<ECopyOptionItem> arrayList) {
  462. savePrePrinter();
  463. Iterator<ECopyOptionItem> it = arrayList.iterator();
  464. while (it.hasNext()) {
  465. ECopyOptionItem next = it.next();
  466. ECopyOptionItem.ECopyOptionItemKey key = next.getKey();
  467. if (!key.equals(ECopyOptionItem.ECopyOptionItemKey.Copies)) {
  468. saveOption(key, next);
  469. }
  470. }
  471. }
  472. private void saveOption(ECopyOptionItem.ECopyOptionItemKey eCopyOptionItemKey, ECopyOptionItem eCopyOptionItem) {
  473. presettings = getPreferences();
  474. if (eCopyOptionItem.getChoiceType() == ECopyOptionItem.ECopyOptionItemChoiceType.ChoiceArray) {
  475. String access$000 = TAG;
  476. EPLog.i(access$000, "cursetting:" + eCopyOptionItem.getSelectedChoice().name());
  477. editer = presettings.edit();
  478. editer.putString(eCopyOptionItemKey.name(), eCopyOptionItem.getSelectedChoice().getParam().toString());
  479. editer.commit();
  480. return;
  481. }
  482. String access$0002 = TAG;
  483. EPLog.i(access$0002, "cursetting:" + String.valueOf(eCopyOptionItem.getSelectedValue()));
  484. editer = presettings.edit();
  485. editer.putInt(eCopyOptionItemKey.name(), eCopyOptionItem.getSelectedValue());
  486. editer.commit();
  487. }
  488. }
  489. }