ScanSearchActivity.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. package epson.scan.activity;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.os.AsyncTask;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.os.Message;
  11. import android.view.ContextMenu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.AdapterView;
  16. import android.widget.Button;
  17. import android.widget.ListView;
  18. import android.widget.ProgressBar;
  19. import android.widget.RadioButton;
  20. import android.widget.TextView;
  21. import androidx.annotation.NonNull;
  22. import com.epson.mobilephone.common.wifidirect.ActivityWiFiDirectStart;
  23. import com.epson.mobilephone.common.wifidirect.ActivityiPrintConnect;
  24. import com.epson.mobilephone.common.wifidirect.MacAddrUtils;
  25. import com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask;
  26. import com.epson.mobilephone.common.wifidirect.WiFiControl;
  27. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  28. import com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils;
  29. import com.epson.mobilephone.common.wifidirect.escprLib;
  30. import java.util.Locale;
  31. import java.util.concurrent.Semaphore;
  32. import epson.common.Constants;
  33. import epson.common.Utils;
  34. import epson.maintain.activity.PrinterNotFoundDialogCreator;
  35. import epson.print.ActivityIACommon;
  36. import epson.print.CommonDefine;
  37. import epson.print.CustomLayoutDialogFragment;
  38. import epson.print.CustomTitleDialogFragment;
  39. import epson.print.MyPrinter;
  40. import epson.print.R;
  41. import epson.print.Util.EPLog;
  42. import epson.print.screen.WorkingDialog;
  43. import epson.print.widgets.ListControlHelper;
  44. import epson.print.widgets.PrinterInfoBuilder;
  45. import epson.scan.lib.CancelableFind;
  46. import epson.scan.lib.CancelablePropertyTaker;
  47. import epson.scan.lib.EscanLibException;
  48. import epson.scan.lib.escanLib;
  49. public class ScanSearchActivity extends ActivityIACommon implements CustomTitleDialogFragment.Callback {
  50. private static final int DIALOG_ID_PRINTER_NOT_FOUND_WITH_WEB_GUIDANCE = 1;
  51. private static final String DIALOG_TAG_PRINTER_NOT_FOUND = "printer_not_found_dialog";
  52. private static final int Menu_Delete = 1;
  53. private static final int Menu_Edit = 2;
  54. private static final String PARAM_KEY_SCANNER_ID = "scanner-id";
  55. private static final String PARAM_KEY_SCANNER_LOCATION = "scanner-location";
  56. private static final String PARAM_KEY_SCANNER_SSID = "scanner-ssid";
  57. private static final String TAG = "ScanSearch";
  58. private static final Semaphore sEscanLibSemaphore = new Semaphore(1);
  59. private final int ADD_SCANER = 8;
  60. private final String COMMONDEVICENAME = "commonDeviceName";
  61. private final int CONNECT_SIMPLEAP = 7;
  62. private final int DELAY = 100;
  63. private final int DELETE_PRINTER = 9;
  64. private final int EDIT_IPPRINTER = 10;
  65. private final int FINISH_FIND_SCANER = 5;
  66. private final int FOUND_SIMPLEAP = 6;
  67. private final String PRINTER_ID = "id";
  68. private final String PRINTER_IP = escprLib.PRINTER_IP;
  69. private final String PRINTER_NAME = "name";
  70. private final int PROBE_SCANNER = 11;
  71. private final String SCANER_ID = "id";
  72. private final String SCANER_INDEX = "index";
  73. private final String SCANER_IP = escprLib.PRINTER_IP;
  74. private final String SCANER_LOCATION = "location";
  75. private final String SCANER_NAME = "name";
  76. private final int SEARCH_PRINTER_P2P = 12;
  77. private final int SEARCH_SCANER = 1;
  78. private final int SELECT_SCANER = 4;
  79. private boolean bCheckWiFiStatus = false;
  80. private String connectionInfo = null;
  81. private AlertDialog errorDialog;
  82. ListControlHelper helper = null;
  83. private volatile boolean isFinishSearchScanner = true;
  84. private Boolean isFocused = true;
  85. private boolean isJapaneseLocale = false;
  86. private volatile boolean isSearchSimpleAp = false;
  87. private boolean isSelected = false;
  88. private AdapterView.AdapterContextMenuInfo listItemIndex;
  89. private volatile boolean mActivityBackRequested;
  90. private boolean mActivityForegroundLifetime;
  91. Button mAddButton;
  92. ScannerListAdapter mBuilder;
  93. private Context mContext = null;
  94. int mDeletePos;
  95. private escanLib mEscanLib;
  96. private FindScannerTask mFindScannerTask;
  97. private GetScannerCapabilityAndFinishTask mGetScannerCapabilityAndFinishTask;
  98. private Handler mHandler = new Handler(new Handler.Callback() {
  99. public boolean handleMessage(android.os.Message r7) {
  100. throw new UnsupportedOperationException("Method not decompiled: epson.scan.activity.ScanSearchActivity.C242011.handleMessage(android.os.Message):boolean");
  101. }
  102. });
  103. RadioButton mIpButton;
  104. ViewGroup mLayout;
  105. private TextView mListEmptyMessageTextView;
  106. private ListView mListView;
  107. RadioButton mLocalButton;
  108. private String mMyPrinterForSimpleApDisconnect;
  109. private volatile boolean mProgress;
  110. ProgressBar mProgressBar;
  111. WorkingDialog mProgressDialog;
  112. private volatile boolean mScannerFindCancelRequested;
  113. Button mSearchButton;
  114. private String mSimpleApSsid;
  115. TextView mTextDetail;
  116. View mWiFiSettingButton;
  117. private String scannerId;
  118. private String scannerKey;
  119. private int scanner_location;
  120. private SearchWiFiDirectPrinterTask searchWiFiDirectPrinter = null;
  121. private TextView tvResult;
  122. WiFiDirectPrinterListUtils wiFiDirectPrinterListUtils = null;
  123. public void onLocalNegativeCallback(int i) {
  124. }
  125. protected void onCreate(Bundle bundle) {
  126. super.onCreate(bundle);
  127. if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
  128. isJapaneseLocale = true;
  129. } else {
  130. isJapaneseLocale = false;
  131. }
  132. mLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.search_printer_layout, (ViewGroup) null);
  133. addWiFiSetupButton();
  134. mEscanLib = new escanLib();
  135. mEscanLib.escanWrapperInitDriver(this);
  136. Bundle extras = getIntent().getExtras();
  137. scanner_location = extras.getInt(PARAM_KEY_SCANNER_LOCATION);
  138. if (scanner_location == 0) {
  139. scanner_location = 1;
  140. }
  141. if (scanner_location != 3) {
  142. scannerId = extras.getString(PARAM_KEY_SCANNER_ID);
  143. connectionInfo = extras.getString(PARAM_KEY_SCANNER_SSID);
  144. } else {
  145. scannerKey = extras.getString(PARAM_KEY_SCANNER_ID);
  146. }
  147. setContentView((View) mLayout);
  148. tvResult = (TextView) mLayout.findViewById(R.id.empty);
  149. tvResult.setText(getString(R.string.lbl_scanner_search_processing));
  150. mListEmptyMessageTextView = (TextView) mLayout.findViewById(R.id.list_empty_message);
  151. mListView = (ListView) mLayout.findViewById(16908298);
  152. EPLog.i("epson.scan.activity.ScanSearchActivity", "builElements");
  153. buildElements();
  154. setNotFoundPrinterButton();
  155. setActionBar(R.string.title_addprint, true);
  156. mContext = this;
  157. }
  158. private void setNotFoundPrinterButton() {
  159. mLayout.findViewById(R.id.not_found_printer_epsonsn).setOnClickListener(new View.OnClickListener() {
  160. public void onClick(View view) {
  161. ScanSearchActivity scanSearchActivity = ScanSearchActivity.this;
  162. scanSearchActivity.startActivity(PrinterNotFoundDialogCreator.getStartIntent(scanSearchActivity.getApplicationContext()));
  163. }
  164. });
  165. }
  166. private void addWiFiSetupButton() {
  167. mWiFiSettingButton = mLayout.findViewById(R.id.rlWifiSettings);
  168. if (isJapaneseLocale) {
  169. ((TextView) mWiFiSettingButton).setText(R.string.str_goto_wifidirect_settings);
  170. } else {
  171. ((TextView) mWiFiSettingButton).setText(R.string.str_wifidirect_settings);
  172. }
  173. mWiFiSettingButton.setOnClickListener(new View.OnClickListener() {
  174. public void onClick(View view) {
  175. ScanSearchActivity.this.startWifiPrinterSelect();
  176. }
  177. });
  178. }
  179. private void startWifiPrinterSelect() {
  180. startActivityForResult(new Intent(this, ActivityWiFiDirectStart.class), 7);
  181. }
  182. private void buildElements() {
  183. mLocalButton = (RadioButton) mLayout.findViewById(R.id.btn_local);
  184. mIpButton = (RadioButton) mLayout.findViewById(R.id.btn_ip);
  185. mSearchButton = (Button) mLayout.findViewById(R.id.function_button);
  186. mProgressBar = (ProgressBar) mLayout.findViewById(R.id.progress_bar);
  187. mAddButton = (Button) mLayout.findViewById(R.id.edit_button);
  188. mTextDetail = (TextView) mLayout.findViewById(R.id.detail);
  189. mTextDetail.setVisibility(View.VISIBLE);
  190. findViewById(R.id.btn_remote).setVisibility(View.GONE);
  191. mIpButton.setBackground(getResources().getDrawable(R.drawable.printer_selector_background_remote));
  192. mLayout.findViewById(R.id.ble_wifi_setting).setVisibility(View.GONE);
  193. Utils.setDrawble2TextView(this, mLocalButton, R.drawable.printer_selector_icon_local);
  194. Utils.setDrawble2TextView(this, mIpButton, R.drawable.printer_selector_icon_ip);
  195. TextView textView = null;
  196. if (scanner_location != 3) {
  197. mListView.setEmptyView((View) null);
  198. mListEmptyMessageTextView.setText((CharSequence) null);
  199. mListEmptyMessageTextView.setVisibility(View.GONE);
  200. mAddButton.setVisibility(View.GONE);
  201. mSearchButton.setVisibility(View.VISIBLE);
  202. searchButtonSetEnabled(false);
  203. mProgressBar.setVisibility(View.VISIBLE);
  204. tvResult.setVisibility(View.VISIBLE);
  205. mWiFiSettingButton.setVisibility(View.VISIBLE);
  206. mBuilder = new ScannerListAdapter(this, mLayout, 2);
  207. mBuilder.setResource(WiFiDirectPrinterListUtils.getCurPrinterString(this, scannerId, connectionInfo));
  208. helper = new ListControlHelper((PrinterInfoBuilder) mBuilder.getBuilder());
  209. wiFiDirectPrinterListUtils = new WiFiDirectPrinterListUtils(this, mBuilder.getData(), helper, connectionInfo);
  210. mLocalButton.setChecked(true);
  211. mTextDetail.setText(R.string.str_detailtext_local_scan);
  212. mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(View.VISIBLE);
  213. } else {
  214. mListEmptyMessageTextView.setText(R.string.printer_list_empty_message);
  215. textView = mListEmptyMessageTextView;
  216. mAddButton.setVisibility(View.VISIBLE);
  217. mSearchButton.setVisibility(View.GONE);
  218. mProgressBar.setVisibility(View.GONE);
  219. tvResult.setVisibility(View.GONE);
  220. mWiFiSettingButton.setVisibility(View.GONE);
  221. mBuilder = new ScannerListAdapter(this, mLayout, 1);
  222. mBuilder.setResource(scannerKey);
  223. mIpButton.setChecked(true);
  224. mTextDetail.setText(R.string.str_detailtext_ip_scan);
  225. mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(View.GONE);
  226. }
  227. mBuilder.build();
  228. mBuilder.refresh();
  229. mListView.setEmptyView(textView);
  230. mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  231. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  232. if (!isSelected && ScanSearchActivity.this.isFocused.booleanValue()) {
  233. Boolean unused = ScanSearchActivity.this.isFocused = false;
  234. boolean unused2 = ScanSearchActivity.this.isSelected = true;
  235. MyPrinter myPrinter = (MyPrinter) ScanSearchActivity.mBuilder.getData().elementAt(i);
  236. String ip = myPrinter.getIp();
  237. if (!WiFiControl.ConnectType.NONE.equals(WiFiDirectManager.getConnectType(ScanSearchActivity.this, ip))) {
  238. ScanSearchActivity.this.interruptSearch();
  239. WiFiDirectManager.connect(ScanSearchActivity.this, ip, 7);
  240. return;
  241. }
  242. myPrinter.setLocation (scanner_location);
  243. ScanSearchActivity scanSearchActivity = ScanSearchActivity.this;
  244. String unused3 = scanSearchActivity.mSimpleApSsid = scanSearchActivity.getSimpleApSsid(myPrinter);
  245. ScanSearchActivity.this.startGetCapabilityAndFinishTask(myPrinter);
  246. }
  247. }
  248. });
  249. mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  250. public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
  251. if (scanner_location == 1) {
  252. return true;
  253. }
  254. ScanSearchActivity scanSearchActivity = ScanSearchActivity.this;
  255. scanSearchActivity.mDeletePos = i;
  256. scanSearchActivity.registerForContextMenu(scanSearchActivity.mListView);
  257. return false;
  258. }
  259. });
  260. mAddButton.setOnClickListener(new View.OnClickListener() {
  261. public void onClick(View view) {
  262. if (scanner_location == 3) {
  263. if (ScanSearchActivity.mBuilder.getData().size() >= 32) {
  264. new AlertDialog.Builder (getString(R.string.str_yes), new DialogInterface.OnClickListener() {
  265. public void onClick(DialogInterface dialogInterface, int i) {
  266. }
  267. }).show();
  268. return;
  269. }
  270. Message message = new Message();
  271. message.what = 10;
  272. message.obj = null;
  273. ScanSearchActivity.mHandler.sendMessage(message);
  274. }
  275. }
  276. });
  277. mSearchButton.setOnClickListener(new View.OnClickListener() {
  278. public void onClick(View view) {
  279. ScanSearchActivity.mHandler.sendEmptyMessageDelayed(1, 100);
  280. }
  281. });
  282. mLocalButton.setOnClickListener(new View.OnClickListener() {
  283. public void onClick(View view) {
  284. if (scanner_location != 1) {
  285. int unused = ScanSearchActivity.this.scanner_location = 1;
  286. ScanSearchActivity.this.buildElements();
  287. ScanSearchActivity.mHandler.sendEmptyMessageDelayed(1, 100);
  288. }
  289. }
  290. });
  291. mIpButton.setOnClickListener(new View.OnClickListener() {
  292. public void onClick(View view) {
  293. if (scanner_location != 3) {
  294. ScanSearchActivity.this.interruptSearch();
  295. int unused = ScanSearchActivity.this.scanner_location = 3;
  296. ScanSearchActivity.this.buildElements();
  297. }
  298. }
  299. });
  300. }
  301. public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
  302. super.onCreateContextMenu(contextMenu, view, contextMenuInfo);
  303. contextMenu.setHeaderTitle(R.string.str_edit_bookmark);
  304. contextMenu.add(0, 1, 0, R.string.str_delete);
  305. contextMenu.add(0, 2, 0, R.string.str_edit_bookmark);
  306. }
  307. public boolean onContextItemSelected(MenuItem menuItem) {
  308. listItemIndex = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
  309. if (listItemIndex == null) {
  310. return true;
  311. }
  312. switch (menuItem.getItemId()) {
  313. case 1:
  314. new AlertDialog.Builder(mContext).setCancelable(false).setTitle(getString(R.string.delete_file)).setIcon(getResources().getDrawable(R.drawable.delete_file)).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  315. public void onClick(DialogInterface dialogInterface, int i) {
  316. Message obtainMessage = ScanSearchActivity.mHandler.obtainMessage();
  317. obtainMessage.what = 9;
  318. ScanSearchActivity.mHandler.sendMessageDelayed(obtainMessage, 100);
  319. }
  320. }).setPositiveButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
  321. public void onClick(DialogInterface dialogInterface, int i) {
  322. }
  323. }).show();
  324. break;
  325. case 2:
  326. Message message = new Message();
  327. if (scanner_location == 3) {
  328. message.what = 10;
  329. }
  330. message.obj = mBuilder.getData().elementAt(mDeletePos);
  331. mHandler.sendMessage(message);
  332. break;
  333. }
  334. return true;
  335. }
  336. protected void onDestroy() {
  337. EPLog.i("epson.scan.activity.ScanSearchActivity", "Destroy search screen");
  338. interruptSearch();
  339. mBuilder.destructor();
  340. super.onDestroy();
  341. }
  342. public void onBackPressed() {
  343. if (!mProgress) {
  344. mActivityBackRequested = true;
  345. if (sEscanLibSemaphore.availablePermits() <= 0) {
  346. interruptSearch();
  347. new CancelWaitTask().execute(new Void[0]);
  348. return;
  349. }
  350. releaseAndFinish();
  351. }
  352. }
  353. private void releaseAndFinish() {
  354. mEscanLib.escanWrapperReleaseDriver();
  355. setResult(0);
  356. finish();
  357. }
  358. protected void onActivityResult(int i, int i2, Intent intent) {
  359. super.onActivityResult(i, i2, intent);
  360. if (i != 7) {
  361. if (i == 10 && i2 == -1) {
  362. mBuilder.refresh();
  363. MyPrinter myPrinter = new MyPrinter(intent.getStringExtra(Constants.PRINTER_NAME), intent.getStringExtra(Constants.PRINTER_IP), intent.getStringExtra(Constants.SCAN_REFS_SCANNER_ID), (String) null);
  364. myPrinter.setLocation(3);
  365. startGetCapabilityAndFinishTask(myPrinter);
  366. }
  367. } else if (i2 == -1) {
  368. isSelected = true;
  369. intent.getBooleanExtra(ActivityiPrintConnect.FINISH_EAYSETUP, false);
  370. MyPrinter myPrinter2 = new MyPrinter(intent.getStringExtra("name"), intent.getStringExtra(escprLib.PRINTER_IP), intent.getStringExtra("id"), (String) null);
  371. myPrinter2.setLocation(scanner_location);
  372. mSimpleApSsid = getSimpleApSsid(myPrinter2);
  373. startGetCapabilityAndFinishTask(myPrinter2);
  374. } else {
  375. forceSetPrinterSearchEnd();
  376. }
  377. }
  378. /* access modifiers changed from: private */
  379. @UiThread
  380. public void search() {
  381. interruptSearch();
  382. mScannerFindCancelRequested = false;
  383. mEscanLib.resetEscanLib();
  384. mBuilder.refresh();
  385. mBuilder.destructor();
  386. wiFiDirectPrinterListUtils.clearPrinterInfoList();
  387. if (WiFiDirectManager.getCurSSID(this) != null) {
  388. mHandler.sendEmptyMessageDelayed(12, 5000);
  389. isSearchSimpleAp = true;
  390. } else if (WiFiDirectManager.isWifiEnabled(this)) {
  391. mHandler.sendEmptyMessage(12);
  392. isSearchSimpleAp = true;
  393. } else {
  394. boolean z = bCheckWiFiStatus;
  395. if (!z && !z) {
  396. bCheckWiFiStatus = true;
  397. WiFiDirectManager.enableWiFi(this, -1);
  398. return;
  399. }
  400. }
  401. WiFiDirectManager.setPriorityToSimpleAP(this, true);
  402. searchButtonSetEnabled(false);
  403. mProgressBar.setVisibility(View.VISIBLE);
  404. tvResult.setText(getString(R.string.lbl_scanner_search_processing));
  405. isFinishSearchScanner = false;
  406. mEscanLib.setScanHandler(mHandler);
  407. mFindScannerTask = new FindScannerTask(mEscanLib);
  408. mFindScannerTask.execute(new Void[0]);
  409. }
  410. /* access modifiers changed from: private */
  411. @UiThread
  412. public void interruptSearch() {
  413. mScannerFindCancelRequested = true;
  414. mHandler.removeMessages(1);
  415. mHandler.removeMessages(12);
  416. EPLog.i("epson.scan.activity.ScanSettingsActivity", "Cancel search scanner");
  417. mHandler.removeMessages(8);
  418. mHandler.removeMessages(6);
  419. SearchWiFiDirectPrinterTask searchWiFiDirectPrinterTask = searchWiFiDirectPrinter;
  420. if (searchWiFiDirectPrinterTask != null) {
  421. searchWiFiDirectPrinterTask.interrupt();
  422. searchWiFiDirectPrinter = null;
  423. }
  424. isSearchSimpleAp = false;
  425. FindScannerTask findScannerTask = mFindScannerTask;
  426. if (findScannerTask != null) {
  427. findScannerTask.cancelFind();
  428. }
  429. }
  430. private void updateFindScannerResult() {
  431. if (!isFinishing()) {
  432. mProgressBar.setVisibility(View.GONE);
  433. searchButtonSetEnabled(true);
  434. int size = mBuilder.getData().size();
  435. if (size <= 0) {
  436. tvResult.setText(R.string.lbl_scanner_search_result_none);
  437. if (mActivityForegroundLifetime) {
  438. showPrinterNotFoundDialog(getPrinterNotFoundDialog(isSearchSimpleAp));
  439. }
  440. } else if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
  441. tvResult.setText(getString(R.string.lbl_scanner_search_result));
  442. } else {
  443. tvResult.setText(String.format(getString(R.string.lbl_scanner_search_result), new Object[]{Integer.valueOf(size)}));
  444. }
  445. }
  446. }
  447. private DialogFragment getPrinterNotFoundDialog(boolean z) {
  448. String str;
  449. String str2;
  450. if (z) {
  451. str = getString(R.string.EPS_PRNERR_COMM1_NOWIFI);
  452. str2 = getString(R.string.str_err_msg_scan_not_found_title);
  453. } else {
  454. str2 = getString(R.string.str_err_msg_scan_not_found_title);
  455. if (Utils.getPrefBoolean(getApplicationContext(), Constants.SCAN_REFS_USED_SCANNER_PATH, CommonDefine.RE_SEARCH)) {
  456. str = getString(R.string.str_err_msg_scan_not_found_research);
  457. String ssid = Utils.getSSID(this);
  458. if (!Utils.isConnectedWifi(this) || ssid == null) {
  459. return CustomLayoutDialogFragment.newInstance(1, str, str2, 0, R.string.str_btn_close);
  460. }
  461. str2 = str2 + "\nSSID: " + ssid;
  462. } else {
  463. str = getString(R.string.str_err_msg_scan_not_found);
  464. }
  465. }
  466. return CustomLayoutDialogFragment.newInstance(1, str + "\n\n" + getString(R.string.confirm_browse_wlan_setup_info), str2, R.string.browse_site, R.string.str_btn_close);
  467. }
  468. private void showPrinterNotFoundDialog(DialogFragment dialogFragment) {
  469. if (!isFinishing()) {
  470. dialogFragment.show(getSupportFragmentManager(), DIALOG_TAG_PRINTER_NOT_FOUND);
  471. }
  472. }
  473. protected Dialog onCreateDialog(int i) {
  474. Dialog onCreateDialog = super.onCreateDialog(i);
  475. if (i == R.string.EPS_PRNERR_COMM1_NOWIFI) {
  476. return Utils.makeMessageBox(this, getString(R.string.str_err_msg_scan_not_found_title), getString(R.string.EPS_PRNERR_COMM1_NOWIFI), getString(R.string.str_ok));
  477. }
  478. switch (i) {
  479. case R.string.str_err_msg_scan_not_found /*2131625133*/:
  480. case R.string.str_err_msg_scan_not_found_research /*2131625134*/:
  481. String str = "";
  482. String ssid = Utils.getSSID(this);
  483. if (Utils.isConnectedWifi(this) && ssid != null) {
  484. str = "\nSSID: " + ssid;
  485. }
  486. return Utils.makeMessageBox(this, getString(R.string.str_err_msg_scan_not_found_title) + str, getString(i), getString(R.string.str_ok));
  487. default:
  488. return onCreateDialog;
  489. }
  490. }
  491. /* access modifiers changed from: package-private */
  492. /* JADX WARNING: Failed to process nested try/catch */
  493. /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0012 */
  494. /* Code decompiled incorrectly, please refer to instructions dump. */
  495. public void removeAllDialog() {
  496. /*
  497. r1 = this;
  498. r0 = 2131625133(0x7f0e04ad, float:1.8877465E38)
  499. r1.removeDialog(r0) // Catch:{ IllegalArgumentException -> 0x0006 }
  500. L_0x0006:
  501. r0 = 2131625134(0x7f0e04ae, float:1.8877467E38)
  502. r1.removeDialog(r0) // Catch:{ IllegalArgumentException -> 0x000c }
  503. L_0x000c:
  504. r0 = 2131624361(0x7f0e01a9, float:1.88759E38)
  505. r1.removeDialog(r0) // Catch:{ IllegalArgumentException -> 0x0012 }
  506. L_0x0012:
  507. r1.dismissPrinterNotFoundDialog() // Catch:{ Exception -> 0x0015 }
  508. L_0x0015:
  509. return
  510. */
  511. throw new UnsupportedOperationException("Method not decompiled: epson.scan.activity.ScanSearchActivity.removeAllDialog():void");
  512. }
  513. private void dismissPrinterNotFoundDialog() {
  514. DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(DIALOG_TAG_PRINTER_NOT_FOUND);
  515. if (dialogFragment != null) {
  516. dialogFragment.dismiss();
  517. }
  518. }
  519. public void searchButtonSetEnabled(boolean z) {
  520. mSearchButton.setVisibility(View.VISIBLE);
  521. if (z) {
  522. mSearchButton.setEnabled(true);
  523. } else {
  524. mSearchButton.setEnabled(false);
  525. }
  526. }
  527. protected void onResume() {
  528. super.onResume();
  529. EPLog.e("Epson", "ScanSearchActivity.java call onResume()");
  530. mActivityForegroundLifetime = true;
  531. dismissPrinterNotFoundDialog();
  532. if (scanner_location != 3) {
  533. if (!isSelected) {
  534. mHandler.removeMessages(1);
  535. mHandler.sendEmptyMessageDelayed(1, 100);
  536. }
  537. EPLog.d("ScanSearchActivity", "Send CHECK_PRINTER Message.");
  538. }
  539. }
  540. protected void onPause() {
  541. EPLog.d("SearchPrinterScr", "onPause");
  542. super.onPause();
  543. mActivityForegroundLifetime = false;
  544. interruptSearch();
  545. if (!isSelected) {
  546. removeAllDialog();
  547. }
  548. GetScannerCapabilityAndFinishTask getScannerCapabilityAndFinishTask = mGetScannerCapabilityAndFinishTask;
  549. if (getScannerCapabilityAndFinishTask != null) {
  550. getScannerCapabilityAndFinishTask.cancelTask();
  551. }
  552. }
  553. /* access modifiers changed from: package-private */
  554. @UiThread
  555. public void showErrorDialog(EscanLibException escanLibException) {
  556. int[] iArr;
  557. if (!isFinishing()) {
  558. if (escanLibException.getEscIVersion() == 1) {
  559. iArr = getEscanI1ErrorTitleAndMessageId(escanLibException.getEscanLibErrorCode());
  560. } else {
  561. iArr = getEscanI2ErrorTitleAndMessageId(escanLibException.getEscanLibErrorCode());
  562. }
  563. errorDialog = Utils.makeMessageBox(this, getString(iArr[0]), getString(iArr[1]), getString(R.string.str_ok));
  564. errorDialog.show();
  565. }
  566. }
  567. @NonNull
  568. private static int[] getEscanI1ErrorTitleAndMessageId(int i) {
  569. if (i == -500001) {
  570. return new int[]{R.string.EPS_PRNERR_COMM_TITLE2, R.string.str_ipprinter_comerror};
  571. }
  572. if (i != -1501) {
  573. if (i == -1300) {
  574. return new int[]{R.string.str_err_msg_scan_not_found_title, R.string.str_err_msg_scan_not_found_research};
  575. }
  576. if (i != -1100) {
  577. switch (i) {
  578. case 5:
  579. break;
  580. case 6:
  581. break;
  582. default:
  583. return new int[]{R.string.str_err_msg_scan_generic_internal_title, R.string.str_err_msg_scan_generic_internal};
  584. }
  585. }
  586. return new int[]{R.string.str_err_msg_scan_comm_title, R.string.str_err_msg_scan_comm};
  587. }
  588. return new int[]{R.string.str_err_msg_scan_busy_title, R.string.str_err_msg_scan_busy};
  589. }
  590. @NonNull
  591. private static int[] getEscanI2ErrorTitleAndMessageId(int i) {
  592. int[] iArr = new int[2];
  593. switch (i) {
  594. case Constants.ESCAN_ERR_SCANNER_OCCUPIED:
  595. case -213:
  596. iArr[0] = R.string.str_err_msg_scan_busy_title;
  597. iArr[1] = R.string.str_err_msg_scan_busy;
  598. break;
  599. case -1300:
  600. iArr[0] = R.string.str_err_msg_scan_not_found_title;
  601. iArr[1] = R.string.str_err_msg_scan_not_found_research;
  602. break;
  603. case -1114:
  604. case -1100:
  605. case -214:
  606. iArr[0] = R.string.str_err_msg_scan_comm_title;
  607. iArr[1] = R.string.str_err_msg_scan_comm;
  608. break;
  609. case -202:
  610. case -201:
  611. case -102:
  612. case -101:
  613. iArr[0] = R.string.str_blank;
  614. iArr[1] = R.string.str_err_msg_out_of_memory_title;
  615. break;
  616. default:
  617. iArr[0] = R.string.str_err_msg_scan_generic_internal_title;
  618. iArr[1] = R.string.str_err_msg_scan_generic_internal;
  619. break;
  620. }
  621. return iArr;
  622. }
  623. private void forceSetPrinterSearchEnd() {
  624. isFocused = true;
  625. isSelected = false;
  626. }
  627. private void localFinish(ScannerPropertyWrapper scannerPropertyWrapper) {
  628. scannerPropertyWrapper.setSimpleApSsid(mSimpleApSsid);
  629. setResult(-1, SettingActivityParams.getScanSearchReturnIntent(scannerPropertyWrapper));
  630. finish();
  631. }
  632. private String getSimpleApSsid(MyPrinter myPrinter) {
  633. String macAddressFromScannerId = MacAddrUtils.getMacAddressFromScannerId(myPrinter.getScannerId());
  634. if (macAddressFromScannerId == null) {
  635. macAddressFromScannerId = MacAddrUtils.getMacAddressFromPrinterId(myPrinter.getPrinterId());
  636. }
  637. String curConnectInfo = WiFiDirectManager.getCurConnectInfo(this, macAddressFromScannerId);
  638. return curConnectInfo != null ? curConnectInfo : "";
  639. }
  640. public void onLocalPositiveCallback(int i) {
  641. if (i == 1) {
  642. startActivity(PrinterNotFoundDialogCreator.getStartIntent(this));
  643. }
  644. }
  645. private void showProgress() {
  646. mProgress = true;
  647. mProgressDialog = new WorkingDialog(this);
  648. mProgressDialog.show();
  649. }
  650. private void dismissProgress() {
  651. if (mProgressBar != null && mProgressDialog.isShowing()) {
  652. mProgressDialog.dismiss();
  653. }
  654. mProgress = false;
  655. }
  656. private void startGetCapabilityAndFinishTask(MyPrinter myPrinter) {
  657. mMyPrinterForSimpleApDisconnect = myPrinter.getIp();
  658. interruptSearch();
  659. mGetScannerCapabilityAndFinishTask = new GetScannerCapabilityAndFinishTask(mEscanLib, myPrinter);
  660. mGetScannerCapabilityAndFinishTask.execute(new Void[0]);
  661. }
  662. private void disconnectSimpleAp() {
  663. WiFiDirectManager.disconnect(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_SCANNER, mMyPrinterForSimpleApDisconnect);
  664. WiFiDirectManager.disconnectSimpleAP(getApplicationContext(), WiFiDirectManager.getCurSSID(this), mMyPrinterForSimpleApDisconnect);
  665. }
  666. public static Intent getStartIntent(Context context, String str, int i, String str2) {
  667. Intent intent = new Intent(context, ScanSearchActivity.class);
  668. intent.putExtra(PARAM_KEY_SCANNER_LOCATION, i);
  669. intent.putExtra(PARAM_KEY_SCANNER_ID, str);
  670. intent.putExtra(PARAM_KEY_SCANNER_SSID, str2);
  671. return intent;
  672. }
  673. private class FindScannerTask extends AsyncTask<Void, Void, Boolean> {
  674. private CancelableFind mCancelableFind = new CancelableFind();
  675. protected void onCancelled(Boolean bool) {
  676. }
  677. FindScannerTask(escanLib escanlib) {
  678. mCancelableFind.setEscanLib(escanlib);
  679. }
  680. protected Boolean doInBackground(Void... voidArr) {
  681. if (ScanSearchActivity.mScannerFindCancelRequested) {
  682. return true;
  683. }
  684. try {
  685. ScanSearchActivity.sEscanLibSemaphore.acquire();
  686. mCancelableFind.setEscanLib(ScanSearchActivity.mEscanLib);
  687. mCancelableFind.findScanner (getApplicationContext(), ScanSearchActivity.mHandler);
  688. } catch (InterruptedException unused) {
  689. } catch (Throwable th) {
  690. ScanSearchActivity.sEscanLibSemaphore.release();
  691. throw th;
  692. }
  693. ScanSearchActivity.sEscanLibSemaphore.release();
  694. return true;
  695. }
  696. protected void onPostExecute(Boolean bool) {
  697. boolean unused = ScanSearchActivity.this.isFinishSearchScanner = true;
  698. if (!mCancelableFind.isCanceled() && !ScanSearchActivity.this.isSearchSimpleAp) {
  699. ScanSearchActivity.this.updateFindScannerResult();
  700. }
  701. }
  702. public void cancelFind() {
  703. mCancelableFind.cancel();
  704. }
  705. }
  706. private class GetScannerCapabilityAndFinishTask extends AsyncTask<Void, Void, Boolean> {
  707. private boolean mCancelRequested;
  708. private CancelablePropertyTaker mCancelablePropertyTaker;
  709. private EscanLibException mEscanErrorCode = null;
  710. private escanLib mEscanLib;
  711. private MyPrinter mMyPrinter;
  712. private ScannerPropertyWrapper mScannerPropertyWrapper;
  713. public GetScannerCapabilityAndFinishTask(escanLib escanlib, MyPrinter myPrinter) {
  714. mEscanLib = escanlib;
  715. mMyPrinter = myPrinter;
  716. }
  717. protected Boolean doInBackground(Void... voidArr) {
  718. if (ScanSearchActivity.mActivityBackRequested) {
  719. return false;
  720. }
  721. try {
  722. ScanSearchActivity.sEscanLibSemaphore.acquire();
  723. if (!ScanSearchActivity.mActivityBackRequested) {
  724. if (!mCancelRequested) {
  725. synchronized (this) {
  726. mCancelablePropertyTaker = new CancelablePropertyTaker(mEscanLib);
  727. }
  728. mScannerPropertyWrapper = mCancelablePropertyTaker.getScannerProperty(mMyPrinter);
  729. if (!ScanSearchActivity.mActivityBackRequested) {
  730. if (!mCancelRequested) {
  731. if (mScannerPropertyWrapper == null) {
  732. mEscanErrorCode = new EscanLibException(1, -1300);
  733. ScanSearchActivity.this.disconnectSimpleAp();
  734. ScanSearchActivity.sEscanLibSemaphore.release();
  735. return false;
  736. }
  737. mEscanLib.escanWrapperReleaseDriver();
  738. ScanSearchActivity.this.disconnectSimpleAp();
  739. ScanSearchActivity.sEscanLibSemaphore.release();
  740. return true;
  741. }
  742. }
  743. ScanSearchActivity.this.disconnectSimpleAp();
  744. ScanSearchActivity.sEscanLibSemaphore.release();
  745. return false;
  746. }
  747. }
  748. ScanSearchActivity.this.disconnectSimpleAp();
  749. ScanSearchActivity.sEscanLibSemaphore.release();
  750. return false;
  751. } catch (EscanLibException e) {
  752. try {
  753. mEscanErrorCode = e;
  754. return false;
  755. } finally {
  756. ScanSearchActivity.this.disconnectSimpleAp();
  757. ScanSearchActivity.sEscanLibSemaphore.release();
  758. }
  759. } catch (InterruptedException unused) {
  760. }
  761. }
  762. protected void onPostExecute(Boolean bool) {
  763. EscanLibException escanLibException;
  764. if (!isFinishing()) {
  765. ScanSearchActivity.this.dismissProgress();
  766. if (!bool.booleanValue()) {
  767. ScanSearchActivity.this.forceSetPrinterSearchEnd();
  768. if (!mCancelRequested && (escanLibException = mEscanErrorCode) != null) {
  769. ScanSearchActivity.this.showErrorDialog(escanLibException);
  770. return;
  771. }
  772. return;
  773. }
  774. ScanSearchActivity.this.localFinish(mScannerPropertyWrapper);
  775. }
  776. }
  777. protected void onPreExecute() {
  778. ScanSearchActivity.this.showProgress();
  779. }
  780. private void cancelTask() {
  781. mCancelRequested = true;
  782. synchronized (this) {
  783. if (mCancelablePropertyTaker != null) {
  784. mCancelablePropertyTaker.cancel();
  785. }
  786. }
  787. }
  788. }
  789. class CancelWaitTask extends AsyncTask<Void, Void, Void> {
  790. CancelWaitTask() {
  791. }
  792. protected Void doInBackground(Void... voidArr) {
  793. try {
  794. ScanSearchActivity.sEscanLibSemaphore.acquire();
  795. ScanSearchActivity.this.disconnectSimpleAp();
  796. ScanSearchActivity.sEscanLibSemaphore.release();
  797. return null;
  798. } catch (InterruptedException unused) {
  799. return null;
  800. }
  801. }
  802. protected void onPostExecute(Void voidR) {
  803. ScanSearchActivity.this.releaseAndFinish();
  804. }
  805. }
  806. }