123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- package com.epson.mobilephone.common.ble;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Handler;
- import android.os.HandlerThread;
- import com.epson.mobilephone.common.EpLog;
- import com.epson.mobilephone.common.ble.util.BLEUtility;
- import com.epson.mobilephone.common.ble.util.ScannedDevice;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.CancellationException;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.TimeoutException;
- public class BleAsyncTask extends AsyncTask<Void, Void, Boolean> {
- private static AlertDialog dialog = null;
- private static HandlerThread handlerThread = null;
- private static boolean mStop = false;
- private static BleAsyncTask mTask;
- private static Runnable mTimeOutTask;
- private BleScanWork mBleWork = null;
- private BLEUtility.BleWorkCallback mCallBack = null;
- private List<ScannedDevice> mDevicelist = null;
- private Boolean mFind = false;
- private long mTimeOut = -1;
- private long mTimeOutScan = -1;
- private Activity m_Activity;
- public static void setStop(boolean z) {
- EpLog.m69d("mStop " + z);
- mStop = z;
- if (z) {
- EpLog.m69d("★ stopScan");
- BleScanWork.getInstace().stopScan();
- if (mTimeOutTask != null) {
- mTimeOutTask = null;
- BleAsyncTask bleAsyncTask = mTask;
- if (bleAsyncTask != null) {
- bleAsyncTask.cancel(true);
- }
- }
- }
- }
- public BleAsyncTask(Activity activity) {
- mTimeOutTask = new Runnable() {
- public void run() {
- try {
- BleAsyncTask.this.get(BleAsyncTask.mTimeOut, TimeUnit.MILLISECONDS);
- } catch (InterruptedException unused) {
- EpLog.m71e("InterruptedException");
- } catch (ExecutionException unused2) {
- EpLog.m71e("ExecutionException");
- } catch (TimeoutException unused3) {
- EpLog.m77i("Running task has timed out!!");
- if (BleAsyncTask.mBleWork != null) {
- BleAsyncTask.mBleWork.stopScan();
- }
- BleAsyncTask.mTask.cancel(true);
- } catch (CancellationException unused4) {
- EpLog.m71e("CancellationException");
- }
- }
- };
- m_Activity = activity;
- mTimeOut = (long) (BleWork.getScanAdvertisingPacketTimeout() + 2000);
- mTimeOutScan = -1;
- }
- public BleAsyncTask(Activity activity, BLEUtility.BleWorkCallback bleWorkCallback, int i) {
- mTimeOutTask = new Runnable() {
- public void run() {
- try {
- BleAsyncTask.this.get(BleAsyncTask.mTimeOut, TimeUnit.MILLISECONDS);
- } catch (InterruptedException unused) {
- EpLog.m71e("InterruptedException");
- } catch (ExecutionException unused2) {
- EpLog.m71e("ExecutionException");
- } catch (TimeoutException unused3) {
- EpLog.m77i("Running task has timed out!!");
- if (BleAsyncTask.mBleWork != null) {
- BleAsyncTask.mBleWork.stopScan();
- }
- BleAsyncTask.mTask.cancel(true);
- } catch (CancellationException unused4) {
- EpLog.m71e("CancellationException");
- }
- }
- };
- m_Activity = activity;
- mTimeOut = (long) (i + 2000);
- mTimeOutScan = (long) i;
- mCallBack = bleWorkCallback;
- }
- protected void onPreExecute() {
- super.onPreExecute();
- mBleWork = BleScanWork.getInstace();
- }
-
-
-
-
- public java.lang.Boolean doInBackground(java.lang.Void... r5) {
-
- throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.ble.BleAsyncTask.doInBackground(java.lang.Void[]):java.lang.Boolean");
- }
- protected void onPostExecute(Boolean bool) {
- super.onPostExecute(bool);
- EpLog.m69d("" + bool);
- }
- private void showAdvanceToSettingDialog() {
- if (mCallBack != null) {
- mDevicelist = mBleWork.getScannedDeviceList();
- ArrayList arrayList = new ArrayList();
- for (ScannedDevice next : mDevicelist) {
- arrayList.add(new ScannedDevice(next.getDevice(), next.getRssi(), next.getDisplayName(), next.getHardwareType()));
- }
- EpLog.m69d(" ★ mDevicelist " + arrayList.size());
- mCallBack.call(arrayList);
- return;
- }
- dialog = new AlertDialog.Builder(m_Activity).setCancelable(false).setMessage(m_Activity.getString(R.string.BLE_find_unconfigured_printer_title)).setPositiveButton(m_Activity.getString(R.string.BLE_find_unconfigured_printer_setup_button), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- EpLog.m69d("★ stopScan");
- BleAsyncTask.mBleWork.stopScan();
- BleAsyncTask bleAsyncTask = BleAsyncTask.this;
- List unused = bleAsyncTask.mDevicelist = bleAsyncTask.mBleWork.getScannedDeviceList();
- ArrayList arrayList = new ArrayList();
- for (ScannedDevice scannedDevice : BleAsyncTask.mDevicelist) {
- arrayList.add(new ScannedDevice(scannedDevice.getDevice(), scannedDevice.getRssi(), scannedDevice.getDisplayName(), scannedDevice.getHardwareType()));
- }
- Intent intent = new Intent(BleAsyncTask.m_Activity.getApplicationContext(), BleWorkActivity.class);
- intent.putParcelableArrayListExtra(ScannedDevice.TYPE, arrayList);
- BleAsyncTask.m_Activity.startActivity(intent);
- }
- }).setNegativeButton(m_Activity.getString(R.string.BLE_find_unconfigured_printer_not_now_button), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- EpLog.m69d("★ stopScan");
- BleAsyncTask.mBleWork.stopScan();
- BleAsyncTask.setStop(true);
- }
- }).create();
- dialog.show();
- }
- protected void onCancelled(Boolean bool) {
- super.onCancelled(bool);
- EpLog.m69d("死にました。 " + bool);
- }
- protected void onCancelled() {
- super.onCancelled();
- }
- public BleAsyncTask setTimeOut(long j) {
- mTimeOut = j;
- return this;
- }
- public static void blePrinterCheck(Context context) {
- setStop(false);
- EpLog.m76i();
- AlertDialog alertDialog = dialog;
- if (alertDialog == null || !alertDialog.isShowing()) {
- final Activity activity = (Activity) context;
- if (BLEUtility.isThreadAlive("bleCheck")) {
- EpLog.m69d("isAlive bleCheck");
- } else if (handlerThread != null) {
- EpLog.m71e("handlerThread != null ");
- } else {
- EpLog.m77i("★ handlerThread start ");
- handlerThread = new HandlerThread("bleCheck");
- handlerThread.start();
- new Handler(handlerThread.getLooper()).postDelayed(new Runnable() {
- public void run() {
- EpLog.m77i(" 0 handlerThread run !!!!");
- BleAsyncTask.handlerThread.quitSafely();
- new BleAsyncTask(activity).execute(new Void[0]);
- }
- }, 500);
- }
- }
- }
- public static void blePrinterCheck(Context context, final BLEUtility.BleWorkCallback bleWorkCallback) {
- setStop(false);
- EpLog.m76i();
- final Activity activity = (Activity) context;
- if (BLEUtility.isThreadAlive("bleCheck")) {
- EpLog.m69d(" ‼ isAlive bleCheck");
- return;
- }
- EpLog.m77i("handlerThread");
- handlerThread = new HandlerThread("bleCheck");
- handlerThread.start();
- new Handler(handlerThread.getLooper()).postDelayed(new Runnable() {
- public void run() {
- EpLog.m77i(" handlerThread run !!!!");
- BleAsyncTask.handlerThread.quitSafely();
- new BleAsyncTask(activity, bleWorkCallback, BleWork.getScanAdvertisingPacketTimeout()).execute(new Void[0]);
- }
- }, 1000);
- }
- public static void blePrinterCheckStop() {
- EpLog.m76i();
- if (handlerThread != null) {
- setStop(true);
- handlerThread.quitSafely();
- handlerThread = null;
- AlertDialog alertDialog = dialog;
- if (alertDialog != null && alertDialog.isShowing()) {
- dialog.dismiss();
- }
- Thread thread = BLEUtility.getThread("bleCheck");
- if (thread != null && thread.isAlive()) {
- EpLog.m77i("interrupt");
- thread.interrupt();
- try {
- EpLog.m77i("join");
- thread.join(50);
- } catch (InterruptedException e) {
- EpLog.m71e(e.getMessage());
- }
- }
- } else {
- EpLog.m77i("handlerThread NULL return !!");
- }
- }
- }
|