BleWorkActivity.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. package com.epson.mobilephone.common.ble;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.os.Handler;
  8. import android.text.Editable;
  9. import android.text.InputFilter;
  10. import android.text.Spanned;
  11. import android.text.TextWatcher;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.view.inputmethod.InputMethodManager;
  16. import android.widget.AdapterView;
  17. import android.widget.Button;
  18. import android.widget.EditText;
  19. import android.widget.LinearLayout;
  20. import android.widget.ListView;
  21. import android.widget.ProgressBar;
  22. import android.widget.TextView;
  23. import androidx.annotation.NonNull;
  24. import com.epson.iprint.prtlogger.Analytics;
  25. import com.epson.mobilephone.common.ble.util.BLEUtility;
  26. import com.epson.mobilephone.common.ble.util.ScannedDevice;
  27. import epson.epsonconnectregistration.ActivityECConfiguration;
  28. import epson.maintain.activity.PrinterNotFoundDialogCreator;
  29. import epson.print.ActivityIACommon;
  30. import epson.print.CommonDefine;
  31. import epson.print.R;
  32. import epson.print.Util.EPLog;
  33. import java.io.UnsupportedEncodingException;
  34. import java.util.ArrayList;
  35. import java.util.Collections;
  36. import java.util.Comparator;
  37. import java.util.List;
  38. import org.apache.commons.lang.CharEncoding;
  39. import org.apache.commons.lang.StringUtils;
  40. import org.apache.commons.lang.time.DateUtils;
  41. public class BleWorkActivity extends ActivityIACommon {
  42. private static final int CONNECT_TIME_OUT = 60000;
  43. private static final int FIRST_DELAY = 10000;
  44. private static final int FIRST_DELAY_SEC = 10;
  45. private static final int FIRST_PROGRESS_PER = 90;
  46. private static final int FIRST_PROGRESS_SEC = 90;
  47. private static final int REQUEST_CODE_EPSON_CONNECT_REGISTRATION = 212;
  48. private static final int SECOND_DELAY = 200000;
  49. private static final int TOTAL_MARGIN_SEC = 30;
  50. private static final int TOTAL_PROGRESS_SEC = 210;
  51. int count = 0;
  52. private boolean isAlive;
  53. boolean isStopSetUpProgress = false;
  54. AlertDialog mAlertDialog;
  55. private BleWork mBleWork = null;
  56. private CallbackWork mCompletion = null;
  57. private Context mContext;
  58. private DeviceAdapter mDeviceAdapter;
  59. AlertDialog mDialog;
  60. private CallbackWork mNext = null;
  61. TextView mPercentView;
  62. ProbePrinter mProbePrinter;
  63. ProgressBar mProgressPercent;
  64. private BLEUtility.BleWorkCallback mSequenceCallbackFailed = null;
  65. private BLEUtility.BleWorkCallback mSequenceCallbackSuccess = null;
  66. private Handler mTimeoutHandler;
  67. private Handler mWifiSearchHandler;
  68. private Runnable runnableSetUpProgress;
  69. private Runnable runnableWifiSearch;
  70. private Handler setUpProgressHandler;
  71. public interface CallbackWork {
  72. void call(Object obj);
  73. }
  74. protected void onCreate(Bundle bundle) {
  75. EPLog.i();
  76. super.onCreate(bundle);
  77. requestWindowFeature(5);
  78. setContentView(R.layout.activity_scan);
  79. setActionBar(R.string.BLE_select_unconfigured_printer_title, true);
  80. findViewById(R.id.progress_bar).setVisibility(View.GONE);
  81. mContext = this;
  82. callBackFuncs();
  83. getWindow().addFlags(128);
  84. mProbePrinter = ProbePrinter.create().setContext(mContext);
  85. mBleWork = BleWork.getInstace();
  86. mBleWork.resetSequence();
  87. }
  88. protected void onResume() {
  89. ArrayList parcelableArrayListExtra;
  90. super.onResume();
  91. mProbePrinter.bindEpsonService();
  92. EPLog.i("mSequence = " + BleWork.getInstace().mSequence);
  93. if (mDeviceAdapter == null && BleWork.getInstace().mSequence == BleWork.jobSequence.UNINITIALIZED && (parcelableArrayListExtra = getIntent().getParcelableArrayListExtra(ScannedDevice.TYPE)) != null && parcelableArrayListExtra.size() > 0) {
  94. init(parcelableArrayListExtra);
  95. }
  96. }
  97. protected void onPause() {
  98. super.onPause();
  99. EPLog.i();
  100. }
  101. protected void onStart() {
  102. super.onStart();
  103. isAlive = true;
  104. }
  105. protected void onStop() {
  106. super.onStop();
  107. EPLog.i();
  108. isAlive = false;
  109. getWindow().clearFlags(128);
  110. }
  111. protected void onDestroy() {
  112. super.onDestroy();
  113. mProbePrinter.unbindEpsonService();
  114. }
  115. private void callBackFuncs() {
  116. mCompletion = new CallbackWork() {
  117. public void call(Object obj) {
  118. if (!(obj instanceof Boolean)) {
  119. EPLog.e(" type mismatch !");
  120. }
  121. StringBuilder sb = new StringBuilder();
  122. sb.append("result = ");
  123. Boolean bool = (Boolean) obj;
  124. sb.append(bool.booleanValue());
  125. EPLog.i(sb.toString());
  126. if (bool.booleanValue()) {
  127. count = TOTAL_PROGRESS_SEC;
  128. EPLog.i("count = " + count);
  129. }
  130. stopCallbacks();
  131. if (mAlertDialog != null && mAlertDialog.isShowing()) {
  132. runOnUiThread(new Runnable() {
  133. public void run() {
  134. EPLog.i("dismiss ");
  135. mAlertDialog.dismiss();
  136. mAlertDialog = null;
  137. }
  138. });
  139. }
  140. mBleWork.resetSequence();
  141. settingResultDailog(bool.booleanValue());
  142. }
  143. };
  144. mNext = new CallbackWork() {
  145. public void call(Object obj) {
  146. stopWifiSearch();
  147. Handler unused = mWifiSearchHandler = new Handler();
  148. runOnUiThread(new Runnable() {
  149. public void run() {
  150. EPLog.i("setSSID");
  151. mBleWork.setSSID(new BLEUtility.BleWorkCallback() {
  152. public void call(Object obj) {
  153. Runnable unused = runnableWifiSearch = new Runnable() {
  154. int postCount = 0;
  155. public void run() {
  156. int i = postCount;
  157. if (i >= 2) {
  158. EPLog.i("postCount >= 2 ");
  159. mProbePrinter.interruptSearch();
  160. if (mAlertDialog != null) {
  161. mAlertDialog.dismiss();
  162. mAlertDialog = null;
  163. }
  164. if (mCompletion != null) {
  165. mCompletion.call(false);
  166. return;
  167. }
  168. return;
  169. }
  170. if (i == 1) {
  171. mProbePrinter.setMacAddress(mBleWork.getDeviceMacAddress());
  172. mProbePrinter.setBleCallback(mCompletion);
  173. try {
  174. mProbePrinter.search();
  175. } catch (IllegalStateException e) {
  176. EPLog.e(e.getMessage());
  177. mProbePrinter.interruptSearch();
  178. if (mAlertDialog != null) {
  179. mAlertDialog.dismiss();
  180. mAlertDialog = null;
  181. }
  182. if (mCompletion != null) {
  183. mCompletion.call(false);
  184. }
  185. }
  186. }
  187. postCount++;
  188. if (mCompletion != null) {
  189. StringBuilder sb = new StringBuilder();
  190. sb.append("postDelayed postCount = ");
  191. sb.append(postCount);
  192. sb.append(" delay ");
  193. sb.append(postCount == 1 ? 10000 : SECOND_DELAY);
  194. EPLog.i(sb.toString());
  195. mWifiSearchHandler.postDelayed(this, postCount == 1 ? 10000 : 200000);
  196. }
  197. }
  198. };
  199. mWifiSearchHandler.post(runnableWifiSearch);
  200. }
  201. }, new BLEUtility.BleWorkCallback() {
  202. public void call(Object obj) {
  203. EPLog.e("BleWorkCallback");
  204. if (mCompletion != null) {
  205. mCompletion.call(false);
  206. }
  207. }
  208. });
  209. }
  210. });
  211. }
  212. };
  213. mSequenceCallbackSuccess = new BLEUtility.BleWorkCallback() {
  214. public void call(Object obj) {
  215. BleWork.jobSequence jobsequence = (BleWork.jobSequence) obj;
  216. EPLog.i("mSequenceCallbackSuccess " + jobsequence);
  217. if (jobsequence == BleWork.jobSequence.UNINITIALIZED || jobsequence == BleWork.jobSequence.BEFORE_CHECK_SSID || jobsequence == BleWork.jobSequence.MIB_GET_MACADDRESS || jobsequence == BleWork.jobSequence.AFTER_SETTING_PASSWORD) {
  218. stopConnectTimeOut();
  219. }
  220. if (!(jobsequence == BleWork.jobSequence.UNINITIALIZED || jobsequence == BleWork.jobSequence.BEFORE_CHECK_SSID || !mBleWork.getSSIDPassword().isEmpty() || mAlertDialog == null || ((jobsequence == BleWork.jobSequence.CHECK_SSID && mBleWork.getSecurityType() == 1) || mBleWork.getSecurityType() == 255))) {
  221. mAlertDialog.dismiss();
  222. mAlertDialog = null;
  223. EPLog.i("mAlertDialog dismiss " + jobsequence);
  224. }
  225. if (jobsequence == BleWork.jobSequence.CHECK_SSID) {
  226. setSSIDPassword();
  227. } else if (jobsequence == BleWork.jobSequence.MIB_GET_SSID_LIST) {
  228. showSSIDList();
  229. }
  230. }
  231. };
  232. mSequenceCallbackFailed = new BLEUtility.BleWorkCallback() {
  233. public void call(Object obj) {
  234. failedDialog((BleWork.jobSequence) obj);
  235. }
  236. };
  237. }
  238. private void stopCallbacks() {
  239. stopConnectTimeOut();
  240. stopWifiSearch();
  241. isStopSetUpProgress = true;
  242. stopSetUpProgress();
  243. }
  244. private void stopSetUpProgress() {
  245. Handler handler = setUpProgressHandler;
  246. if (handler != null) {
  247. handler.removeCallbacks(runnableSetUpProgress);
  248. setUpProgressHandler = null;
  249. runnableSetUpProgress = null;
  250. }
  251. }
  252. private void stopWifiSearch() {
  253. Handler handler = mWifiSearchHandler;
  254. if (handler != null) {
  255. handler.removeCallbacks(runnableWifiSearch);
  256. mWifiSearchHandler = null;
  257. runnableWifiSearch = null;
  258. }
  259. }
  260. private void settingResultDailog(final boolean z) {
  261. runOnUiThread(new Runnable() {
  262. public void run() {
  263. AlertDialog.Builder cancelable = new AlertDialog.Builder(mContext).setCancelable(false);
  264. if (z) {
  265. cancelable.setTitle(getString(R.string.BLE_success_setup_printer_title));
  266. cancelable.setMessage(getString(R.string.BLE_success_setup_printer_msg));
  267. cancelable.setPositiveButton(getString(R.string.ok_button), new DialogInterface.OnClickListener() {
  268. public void onClick(DialogInterface dialogInterface, int i) {
  269. Analytics.SetUpPath setUpPath;
  270. if (getCallingActivity() != null) {
  271. setResult(-1);
  272. setUpPath = Analytics.SetUpPath.Button;
  273. } else {
  274. setUpPath = Analytics.SetUpPath.Home;
  275. }
  276. Analytics.sendSetup(mBleWork.getDeviceName(), setUpPath, Analytics.SetUpResult.Success);
  277. Intent intent = new Intent(this, ActivityECConfiguration.class);
  278. intent.putExtra(ActivityECConfiguration.INTENT_EC_BLE_CONTENT, true);
  279. startActivityForResult(intent, REQUEST_CODE_EPSON_CONNECT_REGISTRATION);
  280. }
  281. });
  282. } else {
  283. cancelable.setTitle(getString(R.string.BLE_fail_setup_printer_title));
  284. cancelable.setMessage(getString(R.string.BLE_fail_setup_printer_msg));
  285. cancelable.setPositiveButton(getString(R.string.BLE_fail_setup_printer_other_method_button), new DialogInterface.OnClickListener() {
  286. public void onClick(DialogInterface dialogInterface, int i) {
  287. startActivity(PrinterNotFoundDialogCreator.getStartIntent(getApplicationContext()));
  288. Analytics.sendSetup(mBleWork.getDeviceName(), getCallingActivity() != null ? Analytics.SetUpPath.Button : Analytics.SetUpPath.Home, Analytics.SetUpResult.Fail);
  289. finish();
  290. }
  291. }).setNeutralButton(getString(R.string.str_btn_close), new DialogInterface.OnClickListener() {
  292. public void onClick(DialogInterface dialogInterface, int i) {
  293. Analytics.sendSetup(mBleWork.getDeviceName(), getCallingActivity() != null ? Analytics.SetUpPath.Button : Analytics.SetUpPath.Home, Analytics.SetUpResult.Fail);
  294. finish();
  295. }
  296. });
  297. }
  298. mAlertDialog = cancelable.create();
  299. mAlertDialog.show();
  300. }
  301. });
  302. }
  303. protected void onActivityResult(int i, int i2, Intent intent) {
  304. if (i == REQUEST_CODE_EPSON_CONNECT_REGISTRATION) {
  305. finish();
  306. }
  307. }
  308. private void waitingCommunicationDaialog() {
  309. if (mAlertDialog != null) {
  310. EPLog.i("dismiss ");
  311. mAlertDialog.dismiss();
  312. mAlertDialog = null;
  313. }
  314. isStopSetUpProgress = false;
  315. mAlertDialog = new AlertDialog.Builder(mContext).setCancelable(false).create();
  316. View inflate = LayoutInflater.from(mContext).inflate(R.layout.ble_progress_layout, (ViewGroup) null);
  317. mAlertDialog.setView(inflate);
  318. mProgressPercent = (ProgressBar) inflate.findViewById(R.id.progress_percent);
  319. mProgressPercent.setVisibility(View.VISIBLE);
  320. mPercentView = (TextView) inflate.findViewById(R.id.percent);
  321. mPercentView.setVisibility(View.VISIBLE);
  322. inflate.findViewById(R.id.space_upper).setVisibility(View.VISIBLE);
  323. mProgressPercent.setProgress(0);
  324. mProgressPercent.setMax(100);
  325. mPercentView.setText("0%");
  326. mAlertDialog.setMessage(getResources().getString(R.string.BLE_wait_setup_complete_msg));
  327. mAlertDialog.show();
  328. count = 0;
  329. stopSetUpProgress();
  330. setUpProgressHandler = new Handler();
  331. runnableSetUpProgress = new Runnable() {
  332. public void run() {
  333. int i;
  334. if (isStopSetUpProgress) {
  335. EPLog.i("☆☆runnableSetUpProgress retuen ");
  336. return;
  337. }
  338. EPLog.i("mSequence " + mBleWork.mSequence);
  339. BleWorkActivity bleWorkActivity = this;
  340. count = count + 1;
  341. int i2 = count;
  342. int i3 = TOTAL_PROGRESS_SEC;
  343. if (i2 > TOTAL_PROGRESS_SEC) {
  344. if (mAlertDialog != null) {
  345. mAlertDialog.dismiss();
  346. mAlertDialog = null;
  347. }
  348. EPLog.e("TIME OUT");
  349. mCompletion.call(false);
  350. CallbackWork unused = mCompletion = null;
  351. return;
  352. }
  353. if (count <= 90) {
  354. i = count;
  355. } else {
  356. if (count <= TOTAL_PROGRESS_SEC) {
  357. i3 = count;
  358. }
  359. i = ((((i3 - 90)) / 12.0d) + 90.0d);
  360. }
  361. EPLog.i(count + "::" + i + " %");
  362. updateProgress(i);
  363. if (!isStopSetUpProgress) {
  364. setUpProgressHandler.postDelayed(this, 1000);
  365. }
  366. }
  367. };
  368. setUpProgressHandler.post(runnableSetUpProgress);
  369. }
  370. private void updateProgress(int i) {
  371. mProgressPercent.setProgress(i);
  372. TextView textView = mPercentView;
  373. textView.setText(i + " %");
  374. mProgressPercent.invalidate();
  375. mPercentView.invalidate();
  376. }
  377. private void init(ArrayList<ScannedDevice> arrayList) {
  378. ListView listView = (ListView) findViewById(R.id.list);
  379. Collections.sort(arrayList, new ScannedDeviceComparator());
  380. mDeviceAdapter = new DeviceAdapter(this, R.layout.listitem_device, arrayList != null ? arrayList : new ArrayList<>());
  381. listView.setAdapter(mDeviceAdapter);
  382. if (arrayList.size() == 1) {
  383. selectDevice((ScannedDevice) mDeviceAdapter.getItem(0));
  384. }
  385. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  386. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  387. ScannedDevice scannedDevice = (ScannedDevice) mDeviceAdapter.getItem(i);
  388. if (scannedDevice != null) {
  389. selectDevice(scannedDevice);
  390. }
  391. }
  392. });
  393. }
  394. public class ScannedDeviceComparator implements Comparator<ScannedDevice> {
  395. public ScannedDeviceComparator() {
  396. }
  397. public int compare(ScannedDevice scannedDevice, ScannedDevice scannedDevice2) {
  398. if (scannedDevice.getRssi() == scannedDevice2.getRssi()) {
  399. return 0;
  400. }
  401. return scannedDevice.getRssi() < scannedDevice2.getRssi() ? 1 : -1;
  402. }
  403. }
  404. private void selectDevice(@NonNull ScannedDevice scannedDevice) {
  405. String displayName = scannedDevice.getDisplayName();
  406. BleScanWork.getInstace().stopScan();
  407. mBleWork.resetSequence();
  408. mBleWork.setSequenceCallback(mSequenceCallbackSuccess, mSequenceCallbackFailed);
  409. EPLog.d(" getInfoForConnectDialog");
  410. getInfoForConnectDialog(displayName);
  411. mBleWork.init(this, scannedDevice);
  412. }
  413. private void getInfoForConnectDialog(String str) {
  414. mAlertDialog = new AlertDialog.Builder(this).setCancelable(false).create();
  415. mAlertDialog.setView(LayoutInflater.from(mContext).inflate(R.layout.ble_progress_layout, (ViewGroup) null));
  416. String property = System.getProperty("line.separator");
  417. AlertDialog alertDialog = mAlertDialog;
  418. alertDialog.setMessage(str + property + property + getString(R.string.BLE_inquiry_access_point_information_msg));
  419. if (isAlive && !isFinishing()) {
  420. mAlertDialog.show();
  421. }
  422. setConnectTimeOut();
  423. }
  424. private void setConnectTimeOut() {
  425. mTimeoutHandler = new Handler();
  426. mTimeoutHandler.postDelayed(new Runnable() {
  427. public void run() {
  428. EPLog.e(" timeout ------------" + mBleWork.mSequence);
  429. if (mBleWork.mSequence == BleWork.jobSequence.AFTER_SETTING_PASSWORD || mBleWork.mSequence == BleWork.jobSequence.MIB_GET_MACADDRESS || mBleWork.mSequence == BleWork.jobSequence.BEFORE_CHECK_SSID || mBleWork.mSequence == BleWork.jobSequence.UNINITIALIZED) {
  430. mBleWork.failedProcessing();
  431. }
  432. mBleWork.setRetryFinish();
  433. }
  434. }, DateUtils.MILLIS_PER_MINUTE);
  435. }
  436. private void stopConnectTimeOut() {
  437. Handler handler = mTimeoutHandler;
  438. if (handler != null) {
  439. handler.removeCallbacksAndMessages((Object) null);
  440. mTimeoutHandler = null;
  441. }
  442. }
  443. private void failedDialog(final BleWork.jobSequence jobsequence) {
  444. runOnUiThread(new Runnable() {
  445. public void run() {
  446. stopCallbacks();
  447. BleWork.jobSequence jobsequence = jobsequence;
  448. EPLog.i("sequence = " + jobsequence);
  449. if (mAlertDialog != null) {
  450. mAlertDialog.dismiss();
  451. }
  452. BleWorkActivity bleWorkActivity = this;
  453. mAlertDialog = null;
  454. AlertDialog.Builder cancelable = new AlertDialog.Builder(mContext).setCancelable(false);
  455. cancelable.setMessage(getString(R.string.BLE_setup_general_error_msg));
  456. cancelable.setPositiveButton(getString(R.string.BLE_setup_abort_button), new DialogInterface.OnClickListener() {
  457. public void onClick(DialogInterface dialogInterface, int i) {
  458. Analytics.sendSetup(mBleWork.getDeviceName(), getCallingActivity() != null ? Analytics.SetUpPath.Button : Analytics.SetUpPath.Home, Analytics.SetUpResult.Error);
  459. finish();
  460. }
  461. });
  462. if (isAlive && !isFinishing()) {
  463. mAlertDialog = cancelable.create();
  464. mAlertDialog.show();
  465. }
  466. }
  467. });
  468. }
  469. private void SSIDfailedDialog(BleWork.jobSequence jobsequence) {
  470. runOnUiThread(new Runnable(jobsequence) {
  471. private final /* synthetic */ BleWork.jobSequence f$1;
  472. {
  473. f$1 = r2;
  474. }
  475. public final void run() {
  476. lambda$SSIDfailedDialog$1(this, f$1);
  477. }
  478. });
  479. }
  480. public static /* synthetic */ void lambda$SSIDfailedDialog$1(BleWorkActivity bleWorkActivity, BleWork.jobSequence jobsequence) {
  481. stopCallbacks();
  482. EPLog.i("sequence = " + jobsequence);
  483. AlertDialog alertDialog = mAlertDialog;
  484. if (alertDialog != null) {
  485. alertDialog.dismiss();
  486. }
  487. mAlertDialog = null;
  488. boolean z = !mBleWork.getSsidLis().isEmpty();
  489. AlertDialog.Builder cancelable = new AlertDialog.Builder(mContext).setCancelable(false);
  490. cancelable.setMessage(getString(R.string.BLE_not_support_security_type));
  491. cancelable.setPositiveButton(getString(z ? R.string.str_btn_close : R.string.BLE_setup_abort_button), new DialogInterface.OnClickListener(z) {
  492. private final /* synthetic */ boolean f$1;
  493. {
  494. f$1 = r2;
  495. }
  496. public final void onClick(DialogInterface dialogInterface, int i) {
  497. lambda$null$0(this, f$1, dialogInterface, i);
  498. }
  499. });
  500. if (isAlive && !isFinishing()) {
  501. mAlertDialog = cancelable.create();
  502. mAlertDialog.show();
  503. }
  504. }
  505. public static /* synthetic */ void lambda$null$0(BleWorkActivity bleWorkActivity, boolean z, DialogInterface dialogInterface, int i) {
  506. Analytics.sendSetup(mBleWork.getDeviceName(), getCallingActivity() != null ? Analytics.SetUpPath.Button : Analytics.SetUpPath.Home, z ? Analytics.SetUpResult.Error119 : Analytics.SetUpResult.Error106);
  507. if (z) {
  508. mBleWork.mSequence = BleWork.jobSequence.MIB_GET_SSID_LIST;
  509. mBleWork.setSecurityType(0);
  510. showSSIDList();
  511. return;
  512. }
  513. mBleWork.disconnect();
  514. finish();
  515. }
  516. private void showSSIDList() {
  517. runOnUiThread(new Runnable() {
  518. public void run() {
  519. mBleWork.mSequence = BleWork.jobSequence.MIB_SET_SSID;
  520. mBleWork.disconnect(false);
  521. EPLog.d("sequence = " + mBleWork.mSequence);
  522. List<String> ssidLis = mBleWork.getSsidLis();
  523. ssidLis.remove(getResources().getText(R.string.BLE_select_SSID_manual_button).toString());
  524. sortSSIDlist(ssidLis);
  525. ssidLis.add(getResources().getText(R.string.BLE_select_SSID_manual_button).toString());
  526. final String[] strArr = (String[]) ssidLis.toArray(new String[ssidLis.size()]);
  527. LinearLayout linearLayout = new LinearLayout(this);
  528. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
  529. layoutParams.setMargins(40, 25, 40, 25);
  530. TextView textView = new TextView(this);
  531. textView.setText(getResources().getText(R.string.BLE_select_SSID_screen_msg));
  532. textView.setTextSize(20.0f);
  533. textView.setLayoutParams(layoutParams);
  534. linearLayout.addView(textView);
  535. AlertDialog.Builder cancelable = new AlertDialog.Builder(this).setCancelable(false);
  536. cancelable.setCustomTitle(linearLayout);
  537. cancelable.setItems(strArr, new DialogInterface.OnClickListener() {
  538. public void onClick(DialogInterface dialogInterface, int i) {
  539. String str = strArr[i];
  540. EPLog.d("select = " + str);
  541. if (i == strArr.length - 1) {
  542. setSSID();
  543. return;
  544. }
  545. EPLog.i("☆" + mBleWork.mSequence + "::" + mBleWork.mStatus);
  546. mBleWork.setSSID(str);
  547. if (mBleWork.mSequence == BleWork.jobSequence.DISCONNECTED || mBleWork.mStatus == 0) {
  548. EPLog.i("☆☆ " + mBleWork.mSequence + "::" + mBleWork.mStatus);
  549. mBleWork.mSequence = BleWork.jobSequence.BEFORE_CHECK_SSID;
  550. mBleWork.connect();
  551. EPLog.d(" getInfoForConnectDialog");
  552. getInfoForConnectDialog(mBleWork.getDeviceName());
  553. return;
  554. }
  555. EPLog.i("☆☆☆☆ " + mBleWork.mSequence + "::" + mBleWork.mStatus);
  556. mBleWork.setSSIDType();
  557. }
  558. });
  559. cancelable.setNegativeButton(getString(R.string.BLE_setup_abort_button), new DialogInterface.OnClickListener() {
  560. public void onClick(DialogInterface dialogInterface, int i) {
  561. EPLog.i();
  562. mBleWork.disconnect(true);
  563. }
  564. });
  565. cancelable.show();
  566. }
  567. });
  568. }
  569. private void sortSSIDlist(List<String> list) {
  570. Collections.sort(list);
  571. String replaceAll = BleWork.getSSID(this).toUpperCase().replaceAll(CommonDefine.UNDER_BAR, "-");
  572. int i = 0;
  573. while (true) {
  574. if (i >= list.size()) {
  575. i = -1;
  576. break;
  577. }
  578. String replaceAll2 = list.get(i).toUpperCase().replaceAll(CommonDefine.UNDER_BAR, "-");
  579. if (replaceAll2.replaceAll("-A$", "-G").equals(replaceAll) || replaceAll2.replaceFirst("-A-", "-G-").equals(replaceAll) || replaceAll.replaceAll("-5G$", "").equals(replaceAll2) || replaceAll.replaceAll("-5GHZ$", "").equals(replaceAll2)) {
  580. break;
  581. }
  582. i++;
  583. }
  584. if (i > 0) {
  585. list.add(0, list.get(i));
  586. list.remove(i + 1);
  587. }
  588. }
  589. private void setSSID() {
  590. runOnUiThread(new Runnable() {
  591. public void run() {
  592. EPLog.i("inputs = ");
  593. final EditText editText = new EditText(this);
  594. editText.setInputType(33);
  595. editText.setFilters(getInputFilters(100));
  596. editText.addTextChangedListener(new TextWatcher() {
  597. public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  598. }
  599. public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  600. }
  601. public void afterTextChanged(Editable editable) {
  602. EPLog.i("afterTextChanged " + editable);
  603. validateInputText(100, editable.toString());
  604. }
  605. });
  606. AlertDialog.Builder cancelable = new AlertDialog.Builder(this).setCancelable(false);
  607. cancelable.setTitle(getString(R.string.BLE_input_SSID_by_manual_dialog_title));
  608. cancelable.setMessage(getString(R.string.BLE_input_SSID_by_manual_dialog_msg));
  609. cancelable.setView(editText);
  610. cancelable.setPositiveButton(getString(R.string.ok_button), new DialogInterface.OnClickListener() {
  611. public void onClick(DialogInterface dialogInterface, int i) {
  612. EPLog.i(editText.getText().toString());
  613. mBleWork.setSSID(editText.getText().toString());
  614. mBleWork.setSecurityType(255);
  615. mBleWork.mSequence = BleWork.jobSequence.SET_PASSWORD;
  616. setSSIDPassword();
  617. }
  618. });
  619. cancelable.setNegativeButton(getString(R.string.no_button), new DialogInterface.OnClickListener() {
  620. public void onClick(DialogInterface dialogInterface, int i) {
  621. EPLog.i();
  622. ((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(editText.getWindowToken(), 2);
  623. if (!mBleWork.getSsidLis().isEmpty()) {
  624. mBleWork.mSequence = BleWork.jobSequence.MIB_GET_SSID_LIST;
  625. mBleWork.setSecurityType(0);
  626. showSSIDList();
  627. return;
  628. }
  629. mBleWork.disconnect();
  630. }
  631. });
  632. if (!isFinishing()) {
  633. mDialog = cancelable.create();
  634. mDialog.show();
  635. mDialog.getButton(-1).setEnabled(false);
  636. }
  637. }
  638. });
  639. }
  640. private void setSSIDPassword() {
  641. EPLog.i();
  642. if (!mBleWork.getSSIDPassword().isEmpty() || mBleWork.getSecurityType() == 1 || (mBleWork.getSecurityType() == 255 && mBleWork.mSequence != BleWork.jobSequence.SET_PASSWORD)) {
  643. runOnUiThread(new Runnable() {
  644. public void run() {
  645. EPLog.i("password mNext");
  646. mNext.call("");
  647. if (setUpProgressHandler == null && runnableSetUpProgress == null) {
  648. if (mAlertDialog != null) {
  649. mAlertDialog.dismiss();
  650. mAlertDialog = null;
  651. }
  652. EPLog.d("waitingCommunicationDaialog");
  653. waitingCommunicationDaialog();
  654. }
  655. }
  656. });
  657. } else {
  658. runOnUiThread(new Runnable() {
  659. public void run() {
  660. EPLog.i("inputs = ");
  661. final short securityType = mBleWork.getSecurityType();
  662. if (securityType == 7 || securityType == 10) {
  663. BleWorkActivity bleWorkActivity = this;
  664. SSIDfailedDialog(mBleWork.mSequence);
  665. return;
  666. }
  667. final EditText editText = new EditText(this);
  668. editText.setInputType(33);
  669. editText.setFilters(getInputFilters(securityType));
  670. editText.addTextChangedListener(new TextWatcher() {
  671. public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  672. }
  673. public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  674. }
  675. public void afterTextChanged(Editable editable) {
  676. EPLog.i("afterTextChanged " + editable);
  677. validateInputText(securityType, editable.toString());
  678. }
  679. });
  680. AlertDialog.Builder cancelable = new AlertDialog.Builder(this).setCancelable(false);
  681. cancelable.setTitle(getString(R.string.BLE_input_password_of_SSID_dialog_title));
  682. BleWorkActivity bleWorkActivity2 = this;
  683. boolean z = true;
  684. cancelable.setMessage(bleWorkActivity2.getString(R.string.BLE_input_password_of_SSID_dialog_msg, new Object[]{bleWorkActivity2.mBleWork.getSSID()}));
  685. cancelable.setView(editText);
  686. cancelable.setPositiveButton(getString(R.string.ok_button), new DialogInterface.OnClickListener() {
  687. public void onClick(DialogInterface dialogInterface, int i) {
  688. EPLog.i(editText.getText().toString());
  689. mBleWork.setSSIDPassword(editText.getText().toString());
  690. mBleWork.mSequence = BleWork.jobSequence.MIB_GET_MACADDRESS;
  691. mBleWork.connect();
  692. setConnectTimeOut();
  693. EPLog.d("waitingCommunicationDaialog");
  694. waitingCommunicationDaialog();
  695. ((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(editText.getWindowToken(), 2);
  696. }
  697. });
  698. cancelable.setNegativeButton(getString(R.string.no_button), new DialogInterface.OnClickListener() {
  699. public void onClick(DialogInterface dialogInterface, int i) {
  700. EPLog.i();
  701. ((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(editText.getWindowToken(), 2);
  702. if (!mBleWork.getSsidLis().isEmpty()) {
  703. mBleWork.mSequence = BleWork.jobSequence.MIB_GET_SSID_LIST;
  704. mBleWork.setSecurityType(0);
  705. showSSIDList();
  706. return;
  707. }
  708. mBleWork.disconnect();
  709. }
  710. });
  711. if (!isFinishing()) {
  712. mDialog = cancelable.create();
  713. mDialog.show();
  714. Button button = mDialog.getButton(-1);
  715. if (securityType != 255) {
  716. z = false;
  717. }
  718. button.setEnabled(z);
  719. }
  720. EPLog.d("sequence = " + mBleWork.mSequence);
  721. mBleWork.mSequence = BleWork.jobSequence.AFTER_SETTING_PASSWORD;
  722. mBleWork.disconnect(false);
  723. EPLog.d("sequence = " + mBleWork.mSequence);
  724. }
  725. });
  726. }
  727. }
  728. /* access modifiers changed from: private */
  729. @NonNull
  730. public InputFilter[] getInputFilters(int i) {
  731. int i2 = 26;
  732. if (i != 7) {
  733. if (i != 100) {
  734. switch (i) {
  735. case 2:
  736. case 4:
  737. break;
  738. case 3:
  739. i2 = 10;
  740. break;
  741. case 5:
  742. break;
  743. default:
  744. switch (i) {
  745. case 9:
  746. case 10:
  747. case 11:
  748. break;
  749. default:
  750. i2 = 63;
  751. break;
  752. }
  753. }
  754. } else {
  755. i2 = 32;
  756. }
  757. return new InputFilter[]{new InputFilter.LengthFilter(i2), new PasswordFilter(i)};
  758. }
  759. i2 = 63;
  760. return new InputFilter[]{new InputFilter.LengthFilter(i2), new PasswordFilter(i)};
  761. }
  762. class PasswordFilter implements InputFilter {
  763. int filterType;
  764. PasswordFilter(int i) {
  765. filterType = i;
  766. }
  767. public CharSequence filter(CharSequence charSequence, int i, int i2, Spanned spanned, int i3, int i4) {
  768. String charSequence2 = charSequence.toString();
  769. if (charSequence2.contains(" ")) {
  770. return StringUtils.deleteWhitespace(charSequence2);
  771. }
  772. try {
  773. charSequence = charSequence2.replace(new String(new byte[]{-62, -91}, CharEncoding.UTF_8), new String("\\".getBytes(), CharEncoding.UTF_8));
  774. } catch (UnsupportedEncodingException e) {
  775. EPLog.e(e.getMessage());
  776. }
  777. if (charSequence.toString().matches("^[a-zA-Z0-9!-/:-@\\[-\\`\\{-\\~]+$")) {
  778. return charSequence;
  779. }
  780. EPLog.i("in NG");
  781. return "";
  782. }
  783. }
  784. public void validateInputText(int r10, java.lang.String r11) {
  785. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.ble.validateInputText(int, java.lang.String):void");
  786. }
  787. }