ActivityBase.java 21 KB

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