PrinterFinder.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. package epson.print.screen;
  2. import android.app.Dialog;
  3. import android.content.ComponentName;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.content.ServiceConnection;
  8. import android.net.Uri;
  9. import android.os.AsyncTask;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.os.IBinder;
  13. import android.os.Message;
  14. import android.os.RemoteException;
  15. import android.view.View;
  16. import android.view.ViewGroup;
  17. import android.widget.AdapterView;
  18. import android.widget.Button;
  19. import android.widget.ListView;
  20. import android.widget.ProgressBar;
  21. import android.widget.TextView;
  22. import com.epson.iprint.prtlogger.Analytics;
  23. import com.epson.mobilephone.common.escpr.MediaInfo;
  24. import com.epson.mobilephone.common.wifidirect.escprLib;
  25. import epson.common.Constants;
  26. import epson.common.IPAddressUtils;
  27. import epson.common.Utils;
  28. import epson.common.httpclient.IAHttpClient;
  29. import epson.print.ActivityIACommon;
  30. import epson.print.R;
  31. import epson.print.CommonDefine;
  32. import epson.print.MyPrinter;
  33. import epson.print.Util.EPLog;
  34. import epson.print.service.EpsonService;
  35. import epson.print.service.IEpsonService;
  36. import epson.print.service.IEpsonServiceCallback;
  37. import epson.print.widgets.AbstractListBuilder;
  38. import epson.print.widgets.CustomTitleAlertDialogBuilder;
  39. import epson.print.widgets.PrinterInfoBuilder;
  40. import java.io.IOException;
  41. import java.util.ArrayList;
  42. import java.util.Locale;
  43. public class PrinterFinder extends ActivityIACommon {
  44. private static final int DELAY = 100;
  45. private static final int DIALOG_INFORM = 0;
  46. /* access modifiers changed from: private */
  47. public static boolean foundPrinter = false;
  48. /* access modifiers changed from: private */
  49. public static final Object mLock = new Object();
  50. private final int CANCEL_FIND_PRINTER = 2;
  51. private final int DISPLAY_FIND_RESULT = 6;
  52. private final int INFORM_DIALOG = 5;
  53. private final String PRINTER_COMMON_DEVICENAME = "common_devicename";
  54. private final String PRINTER_ID = "id";
  55. private final String PRINTER_INDEX = "index";
  56. private final String PRINTER_IP = escprLib.PRINTER_IP;
  57. private final String PRINTER_NAME = "name";
  58. private final int SEARCH_PRINTER = 1;
  59. private final int SELECT_PRINTER = 4;
  60. private final int UPDATE_PRINTER = 3;
  61. int curError;
  62. /* access modifiers changed from: private */
  63. public boolean isDialogOpen = false;
  64. /* access modifiers changed from: private */
  65. public boolean isFinishSearchPrinter = false;
  66. /* access modifiers changed from: private */
  67. public Boolean isFocused = true;
  68. AbstractListBuilder mBuilder;
  69. /* access modifiers changed from: private */
  70. public IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
  71. public void onGetInkState() throws RemoteException {
  72. }
  73. public void onGetStatusState() throws RemoteException {
  74. }
  75. public void onNotifyContinueable(int i) throws RemoteException {
  76. }
  77. public void onNotifyEndJob(int i) throws RemoteException {
  78. }
  79. public void onNotifyProgress(int i, int i2) throws RemoteException {
  80. }
  81. public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
  82. Message obtain = Message.obtain();
  83. obtain.what = 3;
  84. Bundle bundle = new Bundle();
  85. bundle.putString("name", str);
  86. bundle.putString(escprLib.PRINTER_IP, str2);
  87. bundle.putString("id", str3);
  88. bundle.putString("common_devicename", str5);
  89. obtain.setData(bundle);
  90. PrinterFinder.this.mHandler.sendMessage(obtain);
  91. }
  92. public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
  93. synchronized (PrinterFinder.mLock) {
  94. boolean unused = PrinterFinder.foundPrinter = Utils.getPrefBoolean(PrinterFinder.this.getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH);
  95. if ((i2 == -1300 || i2 == -1351) && !PrinterFinder.foundPrinter) {
  96. i2 = -1100;
  97. } else if ((i2 == -1300 || i2 == -1351 || i2 == -1100) && PrinterFinder.foundPrinter) {
  98. i2 = -11001;
  99. }
  100. }
  101. PrinterFinder printerFinder = PrinterFinder.this;
  102. printerFinder.curError = i2;
  103. printerFinder.mHandler.sendEmptyMessage(5);
  104. }
  105. };
  106. Context mContext;
  107. private ServiceConnection mEpsonConnection = new ServiceConnection() {
  108. public void onServiceDisconnected(ComponentName componentName) {
  109. try {
  110. PrinterFinder.this.mEpsonService.unregisterCallback(PrinterFinder.this.mCallback);
  111. } catch (RemoteException e) {
  112. e.printStackTrace();
  113. }
  114. IEpsonService unused = PrinterFinder.this.mEpsonService = null;
  115. }
  116. public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  117. IEpsonService unused = PrinterFinder.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
  118. if (PrinterFinder.this.mEpsonService != null) {
  119. try {
  120. PrinterFinder.this.mEpsonService.registerCallback(PrinterFinder.this.mCallback);
  121. } catch (RemoteException e) {
  122. e.printStackTrace();
  123. }
  124. }
  125. }
  126. };
  127. /* access modifiers changed from: private */
  128. public IEpsonService mEpsonService = null;
  129. Handler mHandler = new Handler(new Handler.Callback() {
  130. public boolean handleMessage(Message message) {
  131. switch (message.what) {
  132. case 1:
  133. if (PrinterFinder.this.mEpsonService == null) {
  134. PrinterFinder.this.mHandler.sendEmptyMessageDelayed(1, 100);
  135. break;
  136. } else {
  137. try {
  138. boolean unused = PrinterFinder.this.isFinishSearchPrinter = false;
  139. PrinterFinder.this.searchButtonSetEnabled(false);
  140. PrinterFinder.this.mProgressBar.setVisibility(0);
  141. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.searching_text));
  142. PrinterFinder.this.mEpsonService.searchPrinters((String) null, (String) null, 1);
  143. break;
  144. } catch (RemoteException e) {
  145. e.printStackTrace();
  146. break;
  147. }
  148. }
  149. case 2:
  150. if (PrinterFinder.this.mEpsonService != null) {
  151. try {
  152. PrinterFinder.this.mEpsonService.cancelSearchPrinter();
  153. break;
  154. } catch (RemoteException e2) {
  155. e2.printStackTrace();
  156. break;
  157. }
  158. }
  159. break;
  160. case 3:
  161. final Bundle data = message.getData();
  162. String string = data.getString("name");
  163. if (string == null || string.contentEquals("FINISH")) {
  164. if (!PrinterFinder.this.mIsClickSelect) {
  165. if (PrinterFinder.this.mBuilder.getData().size() <= 0) {
  166. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.EPS_PRNERR_COMM_TITLE1));
  167. } else if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
  168. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable));
  169. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable));
  170. } else {
  171. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(String.format(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable), new Object[]{Integer.valueOf(PrinterFinder.this.mBuilder.getData().size())}));
  172. }
  173. PrinterFinder.this.mBuilder.getAdapter().notifyDataSetChanged();
  174. PrinterFinder.this.mProgressBar.setVisibility(8);
  175. PrinterFinder.this.searchButtonSetEnabled(true);
  176. boolean unused2 = PrinterFinder.this.isFinishSearchPrinter = true;
  177. break;
  178. }
  179. } else {
  180. synchronized (PrinterFinder.mLock) {
  181. if (!PrinterFinder.this.printerList.contains(data.getString("id"))) {
  182. new AsyncTask<Void, Void, MyPrinter[]>() {
  183. /* access modifiers changed from: protected */
  184. public MyPrinter[] doInBackground(Void... voidArr) {
  185. IAHttpClient.HttpResponse httpResponse;
  186. String buildURL = IPAddressUtils.buildURL(Analytics.EXTENSION_STRING_WEB, data.getString(escprLib.PRINTER_IP), "/PRESENTATION/EPSONCONNECT");
  187. IAHttpClient.HttpGet httpGet = new IAHttpClient.HttpGet(buildURL);
  188. IAHttpClient iAHttpClient = new IAHttpClient();
  189. iAHttpClient.setFollowRedirects(false);
  190. try {
  191. httpResponse = iAHttpClient.execute(httpGet);
  192. } catch (IOException unused) {
  193. EPLog.m305d("httpResponse", "IOException");
  194. httpResponse = null;
  195. }
  196. if (httpResponse != null) {
  197. int responseCode = httpResponse.getResponseCode();
  198. EPLog.m305d("Response", "res : " + responseCode);
  199. if (200 == responseCode || (300 <= responseCode && responseCode < 400)) {
  200. MyPrinter myPrinter = new MyPrinter(data.getString("name"), data.getString(escprLib.PRINTER_IP), data.getString("id"), (String) null);
  201. myPrinter.setCommonDeviceName(data.getString("common_devicename"));
  202. return new MyPrinter[]{myPrinter};
  203. } else if (404 == responseCode) {
  204. EPLog.m305d("Response", "NotFound:" + buildURL);
  205. } else {
  206. EPLog.m305d("Response", "Error:" + buildURL);
  207. }
  208. }
  209. return null;
  210. }
  211. /* access modifiers changed from: protected */
  212. public void onPostExecute(MyPrinter[] myPrinterArr) {
  213. super.onPostExecute(myPrinterArr);
  214. if (myPrinterArr != null) {
  215. ((PrinterInfoBuilder) PrinterFinder.this.mBuilder).addPrinter(myPrinterArr[0]);
  216. PrinterFinder.this.printerList.add(data.getString("id"));
  217. }
  218. }
  219. }.execute(new Void[0]);
  220. boolean unused3 = PrinterFinder.foundPrinter = true;
  221. break;
  222. } else {
  223. break;
  224. }
  225. }
  226. }
  227. break;
  228. case 4:
  229. if (PrinterFinder.this.mEpsonService != null) {
  230. try {
  231. PrinterFinder.this.mEpsonService.setCurPrinter(message.getData().getInt("index"));
  232. } catch (RemoteException e3) {
  233. e3.printStackTrace();
  234. }
  235. }
  236. Intent intent = new Intent();
  237. Bundle bundle = new Bundle();
  238. bundle.putString(Constants.PRINTER_NAME, message.getData().getString("name"));
  239. bundle.putString(Constants.PRINTER_IP, message.getData().getString(escprLib.PRINTER_IP));
  240. bundle.putString(Constants.PRINTER_ID, message.getData().getString("id"));
  241. intent.putExtras(bundle);
  242. PrinterFinder.this.setResult(-1, intent);
  243. PrinterFinder.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(IPAddressUtils.buildURL(Analytics.EXTENSION_STRING_WEB, message.getData().getString(escprLib.PRINTER_IP), "/PRESENTATION/EPSONCONNECT"))));
  244. PrinterFinder.this.finish();
  245. break;
  246. case 5:
  247. if (!PrinterFinder.this.isDialogOpen) {
  248. boolean unused4 = PrinterFinder.this.isDialogOpen = true;
  249. EPLog.m313i("mHandler", "curError = " + PrinterFinder.this.curError);
  250. PrinterFinder.this.showDialog(0);
  251. break;
  252. }
  253. break;
  254. }
  255. return false;
  256. }
  257. });
  258. boolean mIsClickSelect = false;
  259. ViewGroup mLayout;
  260. ProgressBar mProgressBar;
  261. Button mSearchButton;
  262. /* access modifiers changed from: private */
  263. public ArrayList<String> printerList = new ArrayList<>();
  264. /* access modifiers changed from: protected */
  265. public void onCreate(Bundle bundle) {
  266. super.onCreate(bundle);
  267. if (this.mEpsonService == null) {
  268. bindService(new Intent(this, EpsonService.class), this.mEpsonConnection, 1);
  269. }
  270. this.printerList.clear();
  271. this.mLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.search_printer_layout, (ViewGroup) null);
  272. buildElements();
  273. this.mIsClickSelect = false;
  274. setContentView((View) this.mLayout);
  275. this.mContext = this;
  276. setActionBar((int) R.string.remoteprinter_get_emailadress, true);
  277. }
  278. private void buildElements() {
  279. this.mLayout.findViewById(R.id.rl_localremoteselect).setVisibility(8);
  280. this.mSearchButton = (Button) this.mLayout.findViewById(R.id.function_button);
  281. this.mProgressBar = (ProgressBar) this.mLayout.findViewById(R.id.progress_bar);
  282. searchButtonSetEnabled(false);
  283. this.mProgressBar.setVisibility(0);
  284. this.mLayout.findViewById(R.id.ble_wifi_setting).setVisibility(8);
  285. this.mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
  286. this.mBuilder = new PrinterInfoBuilder(getBaseContext(), this.mLayout, 0);
  287. this.mBuilder.setResource(getIntent().getExtras().getString(Constants.PRINTER_NAME));
  288. this.mBuilder.build();
  289. this.mBuilder.refresh();
  290. ((ListView) this.mLayout.findViewById(16908298)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
  291. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  292. if (PrinterFinder.this.isFocused.booleanValue()) {
  293. Boolean unused = PrinterFinder.this.isFocused = false;
  294. PrinterFinder printerFinder = PrinterFinder.this;
  295. printerFinder.mIsClickSelect = true;
  296. Message obtainMessage = printerFinder.mHandler.obtainMessage();
  297. obtainMessage.what = 4;
  298. Bundle bundle = new Bundle();
  299. bundle.putInt("index", i);
  300. bundle.putString("name", ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getName());
  301. bundle.putString("id", ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getPrinterId());
  302. bundle.putString(escprLib.PRINTER_IP, ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getIp());
  303. obtainMessage.setData(bundle);
  304. PrinterFinder.this.mHandler.sendMessageDelayed(obtainMessage, 100);
  305. }
  306. }
  307. });
  308. this.mSearchButton.setOnClickListener(new View.OnClickListener() {
  309. public void onClick(View view) {
  310. synchronized (PrinterFinder.mLock) {
  311. PrinterFinder.this.printerList.clear();
  312. PrinterFinder.this.mBuilder.refresh();
  313. }
  314. boolean unused = PrinterFinder.this.isFinishSearchPrinter = false;
  315. PrinterFinder.this.searchButtonSetEnabled(false);
  316. PrinterFinder.this.mProgressBar.setVisibility(0);
  317. ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.searching_text));
  318. PrinterFinder.this.mHandler.sendEmptyMessageDelayed(1, 100);
  319. }
  320. });
  321. }
  322. /* access modifiers changed from: protected */
  323. public void onDestroy() {
  324. super.onDestroy();
  325. if (this.mEpsonService != null) {
  326. if (!this.isFinishSearchPrinter) {
  327. this.mHandler.sendEmptyMessageDelayed(2, 200);
  328. }
  329. try {
  330. this.mEpsonService.unregisterCallback(this.mCallback);
  331. unbindService(this.mEpsonConnection);
  332. } catch (RemoteException e) {
  333. e.printStackTrace();
  334. }
  335. }
  336. this.mBuilder.destructor();
  337. }
  338. public void onBackPressed() {
  339. super.onBackPressed();
  340. try {
  341. this.mEpsonService.cancelSearchPrinter();
  342. } catch (RemoteException e) {
  343. e.printStackTrace();
  344. }
  345. }
  346. /* access modifiers changed from: protected */
  347. public void onResume() {
  348. super.onResume();
  349. EPLog.m307e("Epson", "PrinterFinder.java call onResume()");
  350. this.mHandler.sendEmptyMessageDelayed(1, 100);
  351. EPLog.m305d("PrinterFinder", "Send CHECK_PRINTER Message.");
  352. }
  353. /* access modifiers changed from: protected */
  354. public void onPause() {
  355. EPLog.m305d("SearchPrinterScr", "onPause");
  356. super.onPause();
  357. }
  358. /* access modifiers changed from: protected */
  359. public Dialog onCreateDialog(int i) {
  360. if (i != 0) {
  361. return null;
  362. }
  363. EPLog.m313i("DIALOG_INFORM", "curError = " + this.curError);
  364. int i2 = this.curError;
  365. if (!(i2 == -1100 && i2 == -11001)) {
  366. if (Utils.getPrefBoolean(getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH)) {
  367. this.curError = -11001;
  368. } else {
  369. this.curError = -1100;
  370. }
  371. }
  372. Integer[] stringId = MediaInfo.ErrorTable.getStringId(this.curError);
  373. if (stringId == null) {
  374. stringId = new Integer[]{Integer.valueOf(R.string.NOT_IMPLEMENT), Integer.valueOf(R.string.NOT_IMPLEMENT_TITLE)};
  375. }
  376. String string = getString(stringId[0].intValue());
  377. String ssid = Utils.getSSID(this);
  378. if (Utils.isConnectedWifi(this) && this.curError == -11001 && ssid != null) {
  379. string = String.format(getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_RESEARCH), new Object[]{ssid});
  380. }
  381. return new CustomTitleAlertDialogBuilder(this).setCancelable(false).setTitle(getString(stringId[1].intValue())).setMessage(string).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  382. public void onClick(DialogInterface dialogInterface, int i) {
  383. PrinterFinder.this.removeDialog(0);
  384. boolean unused = PrinterFinder.this.isDialogOpen = false;
  385. }
  386. }).create();
  387. }
  388. public void searchButtonSetEnabled(boolean z) {
  389. this.mSearchButton.setVisibility(0);
  390. if (z) {
  391. this.mSearchButton.setEnabled(true);
  392. } else {
  393. this.mSearchButton.setEnabled(false);
  394. }
  395. }
  396. }