package epson.maintain.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.p000v4.app.DialogFragment;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.epson.mobilephone.common.EpLog;
import com.epson.mobilephone.common.ble.BleAsyncTask;
import com.epson.mobilephone.common.ble.BleWork;
import com.epson.mobilephone.common.ble.BleWorkActivity;
import com.epson.mobilephone.common.ble.util.BLEUtility;
import com.epson.mobilephone.common.ble.util.ScannedDevice;
import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
import com.epson.mobilephone.common.wifidirect.ActivityRequestLocationPermission;
import com.epson.mobilephone.common.wifidirect.ActivityWiFiDirectStart;
import com.epson.mobilephone.common.wifidirect.ActivityiPrintConnect;
import com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask;
import com.epson.mobilephone.common.wifidirect.WiFiControl;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils;
import com.epson.mobilephone.common.wifidirect.WiFiNetworkManager;
import com.epson.mobilephone.common.wifidirect.escprLib;
import epson.common.Constants;
import epson.common.ExternalFileUtils;
import epson.common.Utils;
import epson.print.ActivityIACommon;
import epson.print.R;
import epson.print.CustomTitleDialogFragment;
import epson.print.EPPrinterManager;
import epson.print.MyPrinter;
import epson.print.screen.ActivityPrinterSetting;
import epson.print.screen.WorkingDialog;
import epson.print.widgets.AbstractListBuilder;
import epson.print.widgets.ListControlHelper;
import epson.print.widgets.PrinterInfoBuilder;
import epson.print.widgets.PrinterInfoECBuilder;
import epson.print.widgets.PrinterInfoIpBuilder;
import epson.scan.lib.escanLib;
import java.util.ArrayList;
import java.util.Locale;

public class MaintainPrinterSearchActivity extends ActivityIACommon implements CustomTitleDialogFragment.Callback {
    private static final int DELAY = 100;
    private static final int DIALOG_ID_PRINTER_NOT_FOUND_WITH_WEB_GUIDANCE = 1;
    private static final String DIALOG_TAG_PRINTER_NOT_FOUND = "printer_not_found_dialog";
    private static final int EPS_PROTOCOL_ALL = 208;
    private static final int EPS_PROTOCOL_LPR = 64;
    private static final int EPS_PROTOCOL_NET = 192;
    private static final int EPS_PROTOCOL_RAW = 128;
    private static final int EPS_PROTOCOL_USB = 16;
    private static final int Menu_Delete = 1;
    private static final int Menu_Edit = 2;
    private static final String TAG = "MaintainPrinterSearchActivity";
    private static final Object mLock = new Object();
    private static escanLib mScanner = new escanLib();
    private final int BLE_SET_PRINTER = 15;
    private final int CANCEL_FIND_PRINTER = 2;
    private final int CONNECT_SIMPLEAP = 9;
    private final int DELETE_PRINTER = 6;
    private final int EDIT_IPPRINTER = 10;
    private final int EDIT_PRINTER = 7;
    private final int FINISH_FIND_PRINTER = 5;
    private final int FOUND_SIMPLEAP = 8;
    private final String PRINTER_COMMON_DEVICENAME = "common_devicename";
    private final String PRINTER_ID = "id";
    private final String PRINTER_INDEX = "index";
    private final String PRINTER_IP = escprLib.PRINTER_IP;
    private final String PRINTER_NAME = "name";
    private final String PRINTER_SERIAL_NO = escprLib.PRINTER_SERIAL_NO;
    private final int PROBE_PRINTER = 11;
    private final int PROBE_SCANNER = 12;
    private final int REQUEST_CODE_LOCATION_PERMISSION = 14;
    private final int SEARCH_PRINTER = 1;
    private final int SEARCH_PRINTER_P2P = 13;
    private final int SELECT_PRINTER = 4;
    private boolean bCheckWiFiStatus = false;
    private boolean bRejectLocationPermission = false;
    ListControlHelper helper = null;
    private volatile boolean isFinishSearchPrinter = true;
    private Boolean isFocused = true;
    private boolean isJapaneseLocale = false;
    private volatile boolean isSearchSimpleAp = false;
    private AdapterView.AdapterContextMenuInfo listItemIndex;
    View mAboutRemoteButton;
    private boolean mActivityForegroundLifetime;
    Button mAddButton;
    private RelativeLayout mBleButton;
    private BLEUtility.BleWorkCallback mBleFind = null;
    AbstractListBuilder mBuilder;
    private Context mContext = null;
    private int mDeletePos = -1;
    Handler mHandler = new Handler(new Handler.Callback() {
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r8v46, resolved type: java.lang.Object} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v19, resolved type: epson.print.MyPrinter} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r8v55, resolved type: java.lang.Object} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v26, resolved type: epson.print.MyPrinter} */
        /* JADX WARNING: Multi-variable type inference failed */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public boolean handleMessage(android.os.Message r8) {
            /*
                r7 = this;
                int r0 = r8.what
                r1 = 8
                r2 = 0
                r3 = -1
                r4 = 1
                r5 = 0
                switch(r0) {
                    case 0: goto L_0x02c1;
                    case 1: goto L_0x0292;
                    case 2: goto L_0x028b;
                    case 3: goto L_0x000b;
                    case 4: goto L_0x0208;
                    case 5: goto L_0x01fc;
                    case 6: goto L_0x0149;
                    case 7: goto L_0x0104;
                    case 8: goto L_0x00bc;
                    case 9: goto L_0x000b;
                    case 10: goto L_0x0076;
                    case 11: goto L_0x004d;
                    case 12: goto L_0x0029;
                    case 13: goto L_0x000d;
                    default: goto L_0x000b;
                }
            L_0x000b:
                goto L_0x0338
            L_0x000d:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.os.Handler r0 = r8.mHandler
                r2 = 60
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r0 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.searchWiFiDirectPrinter(r8, r0, r1, r2)
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask unused = r8.searchWiFiDirectPrinter = r0
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r8 = r8.searchWiFiDirectPrinter
                if (r8 != 0) goto L_0x0338
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean unused = r8.isSearchSimpleAp = r5
                goto L_0x0338
            L_0x0029:
                java.lang.Object r8 = r8.obj
                epson.print.MyPrinter r8 = (epson.print.MyPrinter) r8
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean r0 = r0.isFinishSearchPrinter
                if (r0 != 0) goto L_0x0041
                java.lang.String r0 = "MaintainPrinterSearchActivity"
                java.lang.String r1 = "cancelSearch for PROBE_SCANNER"
                epson.print.Util.EPLog.m313i(r0, r1)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r0.interruptSearch()
            L_0x0041:
                epson.maintain.activity.MaintainPrinterSearchActivity$14$1 r0 = new epson.maintain.activity.MaintainPrinterSearchActivity$14$1
                r0.<init>(r8)
                java.lang.Void[] r8 = new java.lang.Void[r5]
                r0.execute(r8)
                goto L_0x0338
            L_0x004d:
                java.lang.Object r8 = r8.obj
                epson.print.MyPrinter r8 = (epson.print.MyPrinter) r8
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean r0 = r0.isFinishSearchPrinter
                if (r0 != 0) goto L_0x0065
                java.lang.String r0 = "MaintainPrinterSearchActivity"
                java.lang.String r1 = "cancelSearch for PROBE_PRINTER"
                epson.print.Util.EPLog.m313i(r0, r1)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r0.interruptSearch()
            L_0x0065:
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.maintain.activity.MaintainPrinterSearchActivity$14$2 r1 = new epson.maintain.activity.MaintainPrinterSearchActivity$14$2
                r1.<init>(r8)
                java.lang.Void[] r8 = new java.lang.Void[r5]
                android.os.AsyncTask r8 = r1.execute(r8)
                r0.probePrinterThread = r8
                goto L_0x0338
            L_0x0076:
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r0.interruptSearch()
                java.lang.Object r0 = r8.obj
                if (r0 == 0) goto L_0x0084
                java.lang.Object r8 = r8.obj
                r2 = r8
                epson.print.MyPrinter r2 = (epson.print.MyPrinter) r2
            L_0x0084:
                android.content.Intent r8 = new android.content.Intent
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                java.lang.Class<epson.print.screen.ActivityIpPrinterSetting> r1 = epson.print.screen.ActivityIpPrinterSetting.class
                r8.<init>(r0, r1)
                android.os.Bundle r0 = new android.os.Bundle
                r0.<init>()
                if (r2 == 0) goto L_0x00a4
                java.lang.String r1 = r2.getPrinterId()
                if (r1 == 0) goto L_0x00a4
                java.lang.String r1 = "PRINTER_KEY"
                java.lang.String r2 = r2.getPrinterId()
                r0.putString(r1, r2)
                goto L_0x00ab
            L_0x00a4:
                java.lang.String r1 = "PRINTER_KEY"
                java.lang.String r2 = ""
                r0.putString(r1, r2)
            L_0x00ab:
                epson.maintain.activity.MaintainPrinterSearchActivity r1 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int unused = r1.mDeletePos = r3
                r8.putExtras(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r1 = 10
                r0.startActivityForResult(r8, r1)
                goto L_0x0338
            L_0x00bc:
                android.os.Bundle r8 = r8.getData()
                if (r8 == 0) goto L_0x00ed
                boolean r0 = r8.isEmpty()
                if (r0 != 0) goto L_0x00ed
                java.lang.String r0 = "ssid"
                java.lang.String r0 = r8.getString(r0)
                java.lang.String r1 = "name"
                java.lang.String r1 = r8.getString(r1)
                java.lang.String r2 = "addr_infra"
                java.lang.String r8 = r8.getString(r2)
                if (r1 != 0) goto L_0x00dd
                r1 = r0
            L_0x00dd:
                epson.print.MyPrinter r2 = new epson.print.MyPrinter
                java.lang.String r3 = ""
                r2.<init>(r1, r0, r8, r3)
                epson.maintain.activity.MaintainPrinterSearchActivity r1 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils r1 = r1.wiFiDirectPrinterListUtils
                r1.addPrinter(r2, r5, r0, r8)
                goto L_0x0338
            L_0x00ed:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean unused = r8.isSearchSimpleAp = r5
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean r8 = r8.isFinishSearchPrinter
                if (r8 == 0) goto L_0x0338
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.os.Handler r8 = r8.mHandler
                r0 = 5
                r8.sendEmptyMessage(r0)
                goto L_0x0338
            L_0x0104:
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r0.interruptSearch()
                java.lang.Object r0 = r8.obj
                if (r0 == 0) goto L_0x0112
                java.lang.Object r8 = r8.obj
                r2 = r8
                epson.print.MyPrinter r2 = (epson.print.MyPrinter) r2
            L_0x0112:
                android.content.Intent r8 = new android.content.Intent
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                java.lang.Class<epson.print.screen.ActivityPrinterSetting> r1 = epson.print.screen.ActivityPrinterSetting.class
                r8.<init>(r0, r1)
                android.os.Bundle r0 = new android.os.Bundle
                r0.<init>()
                if (r2 == 0) goto L_0x0132
                java.lang.String r1 = r2.getEmailAddress()
                if (r1 == 0) goto L_0x0132
                java.lang.String r1 = "PRINTER_EMAIL_ADDRESS"
                java.lang.String r2 = r2.getEmailAddress()
                r0.putString(r1, r2)
                goto L_0x0139
            L_0x0132:
                java.lang.String r1 = "PRINTER_EMAIL_ADDRESS"
                java.lang.String r2 = ""
                r0.putString(r1, r2)
            L_0x0139:
                epson.maintain.activity.MaintainPrinterSearchActivity r1 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int unused = r1.mDeletePos = r3
                r8.putExtras(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r1 = 7
                r0.startActivityForResult(r8, r1)
                goto L_0x0338
            L_0x0149:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r8 = r8.mDeletePos
                if (r8 < 0) goto L_0x0338
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r8 = r8.printer_location
                switch(r8) {
                    case 2: goto L_0x019f;
                    case 3: goto L_0x015c;
                    default: goto L_0x015a;
                }
            L_0x015a:
                goto L_0x01e1
            L_0x015c:
                epson.print.EPPrinterManager r8 = new epson.print.EPPrinterManager
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.content.Context r0 = r0.mContext
                r8.<init>(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.maintain.activity.MaintainPrinterSearchActivity r2 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r2 = r2.mDeletePos
                java.lang.Object r0 = r0.elementAt(r2)
                epson.print.MyPrinter r0 = (epson.print.MyPrinter) r0
                java.lang.String r0 = r0.getPrinterId()
                r8.deleteIpPrinterInfo(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r8 = r8.mBuilder
                android.widget.BaseAdapter r8 = r8.getAdapter()
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.maintain.activity.MaintainPrinterSearchActivity r2 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r2 = r2.mDeletePos
                r0.remove(r2)
                r8.notifyDataSetChanged()
                goto L_0x01e1
            L_0x019f:
                epson.print.EPPrinterManager r8 = new epson.print.EPPrinterManager
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.content.Context r0 = r0.mContext
                r8.<init>(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.maintain.activity.MaintainPrinterSearchActivity r2 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r2 = r2.mDeletePos
                java.lang.Object r0 = r0.elementAt(r2)
                epson.print.MyPrinter r0 = (epson.print.MyPrinter) r0
                java.lang.String r0 = r0.getEmailAddress()
                r8.deleteRemotePrinterInfo(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r8 = r8.mBuilder
                android.widget.BaseAdapter r8 = r8.getAdapter()
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.maintain.activity.MaintainPrinterSearchActivity r2 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r2 = r2.mDeletePos
                r0.remove(r2)
                r8.notifyDataSetChanged()
            L_0x01e1:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.displaySearchResult()
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r8 = r8.printer_location
                if (r8 == r4) goto L_0x01f5
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.widget.Button r8 = r8.mSearchButton
                r8.setVisibility(r1)
            L_0x01f5:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int unused = r8.mDeletePos = r3
                goto L_0x0338
            L_0x01fc:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.interruptSearch()
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.displaySearchResult()
                goto L_0x0338
            L_0x0208:
                com.epson.mobilephone.common.ble.BleAsyncTask.blePrinterCheckStop()
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean r0 = r0.isFinishSearchPrinter
                if (r0 == 0) goto L_0x021b
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                boolean r0 = r0.isSearchSimpleAp
                if (r0 == 0) goto L_0x0227
            L_0x021b:
                java.lang.String r0 = "MaintainPrinterSearchActivity"
                java.lang.String r1 = "cancelSearch for SELECT_PRINTER"
                epson.print.Util.EPLog.m313i(r0, r1)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r0.interruptSearch()
            L_0x0227:
                java.lang.Object r8 = r8.obj
                epson.print.MyPrinter r8 = (epson.print.MyPrinter) r8
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.setCurPrinter(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.content.Context r0 = r0.getApplicationContext()
                java.lang.String r1 = "PrintSetting"
                java.lang.String r2 = "RE_SEARCH"
                epson.common.Utils.savePref((android.content.Context) r0, (java.lang.String) r1, (java.lang.String) r2, (boolean) r4)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r0 = r0.printer_location
                if (r0 != r4) goto L_0x0268
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                java.lang.String r1 = r8.getPrinterId()
                java.lang.String r1 = com.epson.mobilephone.common.wifidirect.MacAddrUtils.getMacAddressFromPrinterId(r1)
                java.lang.String r0 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.getCurConnectInfo(r0, r1)
                if (r0 == 0) goto L_0x0261
                epson.maintain.activity.MaintainPrinterSearchActivity r1 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                java.lang.String r2 = "printer"
                java.lang.String r8 = r8.getName()
                com.epson.mobilephone.common.wifidirect.WiFiDirectManager.setConnectInfo(r1, r0, r2, r8)
                goto L_0x0268
            L_0x0261:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                java.lang.String r0 = "printer"
                com.epson.mobilephone.common.wifidirect.WiFiDirectManager.resetConnectInfo(r8, r0)
            L_0x0268:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r8 = r8.printer_location
                r0 = 2
                if (r8 != r0) goto L_0x027a
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                epson.common.ExternalFileUtils r8 = epson.common.ExternalFileUtils.getInstance(r8)
                r8.removeAreaInfo()
            L_0x027a:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.commitEPPrinterInfo()
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.setResult(r4)
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.finish()
                goto L_0x0338
            L_0x028b:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.interruptSearch()
                goto L_0x0338
            L_0x0292:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                int r8 = r8.printer_location
                if (r8 == r4) goto L_0x029c
                goto L_0x0338
            L_0x029c:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.os.AsyncTask<java.lang.Void, java.lang.Void, java.lang.Integer> r8 = r8.probePrinterThread
                if (r8 == 0) goto L_0x02bb
                android.os.AsyncTask$Status r8 = android.os.AsyncTask.Status.RUNNING
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                android.os.AsyncTask<java.lang.Void, java.lang.Void, java.lang.Integer> r0 = r0.probePrinterThread
                android.os.AsyncTask$Status r0 = r0.getStatus()
                boolean r8 = r8.equals(r0)
                if (r8 == 0) goto L_0x02bb
                java.lang.String r8 = "MaintainPrinterSearchActivity"
                java.lang.String r0 = "Cancel serch. probePrinterThread is running."
                epson.print.Util.EPLog.m305d(r8, r0)
                goto L_0x0338
            L_0x02bb:
                epson.maintain.activity.MaintainPrinterSearchActivity r8 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                r8.search()
                goto L_0x0338
            L_0x02c1:
                android.os.Bundle r8 = r8.getData()
                java.lang.String r0 = "name"
                java.lang.String r0 = r8.getString(r0)
                if (r0 == 0) goto L_0x0338
                java.lang.String r0 = "ip"
                java.lang.String r0 = r8.getString(r0)
                if (r0 == 0) goto L_0x0338
                java.lang.String r0 = "id"
                java.lang.String r0 = r8.getString(r0)
                if (r0 == 0) goto L_0x0338
                java.lang.String r0 = "common_devicename"
                java.lang.String r0 = r8.getString(r0)
                java.lang.StringBuilder r1 = new java.lang.StringBuilder
                r1.<init>()
                java.lang.String r2 = "commonDeviceName = "
                r1.append(r2)
                r1.append(r0)
                java.lang.String r1 = r1.toString()
                com.epson.mobilephone.common.EpLog.m69d(r1)
                epson.print.MyPrinter r1 = new epson.print.MyPrinter
                java.lang.String r2 = "name"
                java.lang.String r2 = r8.getString(r2)
                java.lang.String r3 = "ip"
                java.lang.String r3 = r8.getString(r3)
                java.lang.String r4 = "id"
                java.lang.String r4 = r8.getString(r4)
                java.lang.String r6 = "serial_no"
                java.lang.String r6 = r8.getString(r6)
                r1.<init>(r2, r3, r4, r6)
                r1.setCommonDeviceName(r0)
                epson.maintain.activity.MaintainPrinterSearchActivity r0 = epson.maintain.activity.MaintainPrinterSearchActivity.this
                com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils r0 = r0.wiFiDirectPrinterListUtils
                java.lang.String r2 = "index"
                java.lang.String r8 = r8.getString(r2)
                java.lang.Integer r8 = java.lang.Integer.valueOf(r8)
                int r8 = r8.intValue()
                java.lang.String r2 = r1.getIp()
                java.lang.String r3 = r1.getPrinterId()
                java.lang.String r3 = com.epson.mobilephone.common.wifidirect.MacAddrUtils.getMacAddressFromPrinterId(r3)
                r0.addPrinter(r1, r8, r2, r3)
            L_0x0338:
                return r5
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.MaintainPrinterSearchActivity.C203814.handleMessage(android.os.Message):boolean");
        }
    });
    RadioButton mIpButton;
    boolean mIsClickSelect = false;
    ViewGroup mLayout;
    private TextView mListEmptyMessageTextView;
    private ListView mListView;
    RadioButton mLocalButton;
    private MaintainPrinter2 mPrinter = MaintainPrinter2.getInstance();
    ProgressBar mProgressBar;
    RadioButton mRemoteButton;
    Button mSearchButton;
    private Thread mSearchThread;
    TextView mTextDetail;
    View mWiFiSettingButton;
    private String printerEmailAddress = "";
    private String printerId = "";
    private String printerKey = "";
    private volatile int printer_location = 0;
    AsyncTask<Void, Void, Integer> probePrinterThread = null;
    WorkingDialog progress;
    private SearchWiFiDirectPrinterTask searchWiFiDirectPrinter = null;
    WiFiDirectPrinterListUtils wiFiDirectPrinterListUtils = null;

    public void onLocalNegativeCallback(int i) {
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
            isJapaneseLocale = true;
        } else {
            isJapaneseLocale = false;
        }
        mLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.search_printer_layout, (ViewGroup) null);
        addWiFiSetupButton();
        addAboutRemoteButton();
        mListEmptyMessageTextView = (TextView) mLayout.findViewById(R.id.list_empty_message);
        mListView = (ListView) mLayout.findViewById(16908298);
        init();
        setContentView((View) mLayout);
        mContext = this;
        mIsClickSelect = false;
        if (this.printer_location != 1) {
            displaySearchResult();
            mSearchButton.setVisibility(8);
            ((TextView) mLayout.findViewById(R.id.empty)).setVisibility(8);
        }
        setNotFoundPrinterButton();
        setBleWifiSetupButton();
        setActionBar((int) R.string.title_addprint, true);
        requestLocationPermission();
    }

    private void init() {
        MyPrinter curPrinter = MyPrinter.getCurPrinter(this);
        printer_location = curPrinter.getLocation();
        if (this.printer_location == 0) {
            printer_location = 1;
        }
        switch (this.printer_location) {
            case 2:
                printerEmailAddress = curPrinter.getEmailAddress();
                break;
            case 3:
                printerKey = curPrinter.getPrinterId();
                break;
            default:
                printerId = curPrinter.getPrinterId();
                break;
        }
        buildElements();
    }

    private void requestLocationPermission() {
        if (!this.bRejectLocationPermission && !ActivityRequestLocationPermission.canAccessWiFiInfo(this, 20)) {
            if (BleWork.isStartBleProcess(this, false)) {
                ActivityRequestLocationPermission.requestLocationPermission((Activity) this, 14);
            } else if (Build.VERSION.SDK_INT > 28 && !WiFiNetworkManager.getInsetance(this).isWiFiValidated()) {
                ActivityRequestLocationPermission.requestLocationPermissionForce(this, 14);
            }
        }
    }

    private void setBleWifiSetupButton() {
        mBleButton = (RelativeLayout) mLayout.findViewById(R.id.ble_wifi_setting);
        mBleButton.setVisibility(8);
        mBleButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MaintainPrinterSearchActivity.this.interruptSearch();
                BleAsyncTask.blePrinterCheckStop();
                Intent intent = new Intent(MaintainPrinterSearchActivity.this.getApplicationContext(), BleWorkActivity.class);
                intent.putParcelableArrayListExtra(ScannedDevice.TYPE, (ArrayList) MaintainPrinterSearchActivity.mBleButton.getTag());
                MaintainPrinterSearchActivity.this.startActivityForResult(intent, 15);
            }
        });
    }

    private void setNotFoundPrinterButton() {
        mLayout.findViewById(R.id.not_found_printer_epsonsn).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MaintainPrinterSearchActivity maintainPrinterSearchActivity = MaintainPrinterSearchActivity.this;
                maintainPrinterSearchActivity.startActivity(PrinterNotFoundDialogCreator.getStartIntent(maintainPrinterSearchActivity.getApplicationContext()));
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void addWiFiSetupButton() {
        mWiFiSettingButton = mLayout.findViewById(R.id.rlWifiSettings);
        if (this.isJapaneseLocale) {
            ((TextView) mWiFiSettingButton).setText(R.string.str_goto_wifidirect_settings);
        } else {
            ((TextView) mWiFiSettingButton).setText(R.string.str_wifidirect_settings);
        }
        mWiFiSettingButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MaintainPrinterSearchActivity.this.startWifiPrinterSelect();
            }
        });
    }

    private void startWifiPrinterSelect() {
        startActivityForResult(new Intent(this, ActivityWiFiDirectStart.class), 9);
    }

    /* access modifiers changed from: package-private */
    public void addAboutRemoteButton() {
        mAboutRemoteButton = mLayout.findViewById(R.id.AboutRemoteFrame);
        mAboutRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MaintainPrinterSearchActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://www.epsonconnect.com/iguide/")));
            }
        });
    }

    private void buildElements() {
        mSearchButton = (Button) mLayout.findViewById(R.id.function_button);
        mProgressBar = (ProgressBar) mLayout.findViewById(R.id.progress_bar);
        mAddButton = (Button) mLayout.findViewById(R.id.edit_button);
        mTextDetail = (TextView) mLayout.findViewById(R.id.detail);
        searchButtonSetEnabled(false);
        mProgressBar.setVisibility(0);
        mAddButton.setVisibility(8);
        mTextDetail.setVisibility(0);
        mWiFiSettingButton.setVisibility(0);
        mLocalButton = (RadioButton) mLayout.findViewById(R.id.btn_local);
        mIpButton = (RadioButton) mLayout.findViewById(R.id.btn_ip);
        mRemoteButton = (RadioButton) mLayout.findViewById(R.id.btn_remote);
        Utils.setDrawble2TextView(this, mLocalButton, R.C2136drawable.printer_selector_icon_local);
        Utils.setDrawble2TextView(this, mIpButton, R.C2136drawable.printer_selector_icon_ip);
        Utils.setDrawble2TextView(this, mRemoteButton, R.C2136drawable.printer_selector_icon_remote);
        TextView textView = null;
        switch (this.printer_location) {
            case 1:
                mListView.setEmptyView((View) null);
                mListEmptyMessageTextView.setText((CharSequence) null);
                mListEmptyMessageTextView.setVisibility(8);
                mBuilder = new PrinterInfoBuilder(getBaseContext(), mLayout, 0);
                String connectInfo = WiFiDirectManager.getConnectInfo(this, WiFiDirectManager.DEVICE_TYPE_PRINTER);
                mBuilder.setResource(WiFiDirectPrinterListUtils.getCurPrinterString(this, printerId, connectInfo));
                helper = new ListControlHelper((PrinterInfoBuilder) mBuilder);
                wiFiDirectPrinterListUtils = new WiFiDirectPrinterListUtils(this, mBuilder.getData(), helper, connectInfo);
                mLocalButton.setChecked(true);
                mTextDetail.setText(R.string.str_detailtext_local);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(0);
                RelativeLayout relativeLayout = mBleButton;
                if (!(relativeLayout == null || relativeLayout.getTag() == null)) {
                    mBleButton.setVisibility(0);
                    break;
                }
            case 2:
                mAddButton.setVisibility(0);
                mListEmptyMessageTextView.setText(R.string.printer_list_empty_message);
                textView = mListEmptyMessageTextView;
                mBuilder = new PrinterInfoECBuilder(getBaseContext(), mLayout);
                mBuilder.setResource(this.printerEmailAddress);
                mRemoteButton.setChecked(true);
                mTextDetail.setText(R.string.str_detailtext_remote);
                mSearchButton.setVisibility(8);
                mWiFiSettingButton.setVisibility(8);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
                RelativeLayout relativeLayout2 = mBleButton;
                if (relativeLayout2 != null) {
                    relativeLayout2.setVisibility(8);
                    break;
                }
                break;
            case 3:
                mAddButton.setVisibility(0);
                mListEmptyMessageTextView.setText(R.string.printer_list_empty_message);
                textView = mListEmptyMessageTextView;
                mBuilder = new PrinterInfoIpBuilder(getBaseContext(), mLayout, 0);
                mBuilder.setResource(this.printerKey);
                mIpButton.setChecked(true);
                mTextDetail.setText(R.string.str_detailtext_ip);
                mSearchButton.setVisibility(8);
                mWiFiSettingButton.setVisibility(8);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
                RelativeLayout relativeLayout3 = mBleButton;
                if (relativeLayout3 != null) {
                    relativeLayout3.setVisibility(8);
                    break;
                }
                break;
        }
        mBuilder.build();
        mBuilder.refresh();
        mListView.setEmptyView(textView);
        if (this.printer_location == 2) {
            mAboutRemoteButton.setVisibility(0);
        } else {
            mAboutRemoteButton.setVisibility(8);
        }
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (MaintainPrinterSearchActivity.this.isFocused.booleanValue()) {
                    Boolean unused = MaintainPrinterSearchActivity.this.isFocused = false;
                    MaintainPrinterSearchActivity maintainPrinterSearchActivity = MaintainPrinterSearchActivity.this;
                    maintainPrinterSearchActivity.mIsClickSelect = true;
                    Message obtainMessage = maintainPrinterSearchActivity.mHandler.obtainMessage();
                    obtainMessage.obj = MaintainPrinterSearchActivity.mBuilder.getData().elementAt(i);
                    int access$400 = MaintainPrinterSearchActivity.this.printer_location;
                    if (access$400 == 1) {
                        String ip = ((MyPrinter) obtainMessage.obj).getIp();
                        if (!WiFiControl.ConnectType.NONE.equals(WiFiDirectManager.getConnectType(MaintainPrinterSearchActivity.this, ip))) {
                            MaintainPrinterSearchActivity.this.interruptSearch();
                            WiFiDirectManager.connect(MaintainPrinterSearchActivity.this, ip, 9);
                        } else {
                            obtainMessage.what = 11;
                        }
                    } else if (access$400 != 3) {
                        obtainMessage.what = 4;
                    } else {
                        obtainMessage.what = 11;
                    }
                    BleAsyncTask.blePrinterCheckStop();
                    MaintainPrinterSearchActivity.mHandler.sendMessageDelayed(obtainMessage, 100);
                }
            }
        });
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (MaintainPrinterSearchActivity.this.printer_location == 1) {
                    return true;
                }
                int unused = MaintainPrinterSearchActivity.mDeletePos = i;
                MaintainPrinterSearchActivity maintainPrinterSearchActivity = MaintainPrinterSearchActivity.this;
                maintainPrinterSearchActivity.registerForContextMenu(maintainPrinterSearchActivity.mListView);
                return false;
            }
        });
        mAddButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                switch (MaintainPrinterSearchActivity.this.printer_location) {
                    case 2:
                        if (MaintainPrinterSearchActivity.mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(MaintainPrinterSearchActivity.mContext).setCancelable(false).setTitle(MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(MaintainPrinterSearchActivity.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        } else if (MaintainPrinterSearchActivity.this.getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).getBoolean(Constants.ENABLE_SHOW_WARNING, true)) {
                            AlertDialog.Builder cancelable = new AlertDialog.Builder(MaintainPrinterSearchActivity.mContext).setCancelable(false);
                            cancelable.setMessage(MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(MaintainPrinterSearchActivity.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Message message = new Message();
                                    message.what = 7;
                                    message.obj = null;
                                    MaintainPrinterSearchActivity.mHandler.sendMessage(message);
                                }
                            }).setNegativeButton(MaintainPrinterSearchActivity.this.getString(R.string.str_no), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        } else {
                            Message message = new Message();
                            message.what = 7;
                            message.obj = null;
                            MaintainPrinterSearchActivity.mHandler.sendMessage(message);
                            return;
                        }
                    case 3:
                        if (MaintainPrinterSearchActivity.mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(MaintainPrinterSearchActivity.mContext).setCancelable(false).setTitle(MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(MaintainPrinterSearchActivity.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(MaintainPrinterSearchActivity.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        }
                        Message message2 = new Message();
                        message2.what = 10;
                        message2.obj = null;
                        MaintainPrinterSearchActivity.mHandler.sendMessage(message2);
                        return;
                    default:
                        return;
                }
            }
        });
        mSearchButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (MaintainPrinterSearchActivity.this.printer_location == 1) {
                    MaintainPrinterSearchActivity.mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mLocalButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (MaintainPrinterSearchActivity.this.printer_location != 1) {
                    MaintainPrinterSearchActivity.mAddButton.setVisibility(8);
                    ((TextView) MaintainPrinterSearchActivity.mLayout.findViewById(R.id.empty)).setVisibility(0);
                    MaintainPrinterSearchActivity.this.interruptSearch();
                    int unused = MaintainPrinterSearchActivity.this.printer_location = 1;
                    MaintainPrinterSearchActivity.this.buildElements();
                    MaintainPrinterSearchActivity.mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (MaintainPrinterSearchActivity.this.printer_location != 2) {
                    int unused = MaintainPrinterSearchActivity.this.printer_location = 2;
                    MaintainPrinterSearchActivity.this.interruptSearch();
                    ((TextView) MaintainPrinterSearchActivity.mLayout.findViewById(R.id.empty)).setVisibility(8);
                    MaintainPrinterSearchActivity.mBuilder.refresh();
                    MaintainPrinterSearchActivity.this.buildElements();
                    MaintainPrinterSearchActivity.this.displaySearchResult();
                    MaintainPrinterSearchActivity.mSearchButton.setVisibility(8);
                }
            }
        });
        mIpButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (MaintainPrinterSearchActivity.this.printer_location != 3) {
                    int unused = MaintainPrinterSearchActivity.this.printer_location = 3;
                    MaintainPrinterSearchActivity.this.interruptSearch();
                    ((TextView) MaintainPrinterSearchActivity.mLayout.findViewById(R.id.empty)).setVisibility(8);
                    MaintainPrinterSearchActivity.mBuilder.refresh();
                    MaintainPrinterSearchActivity.this.buildElements();
                    MaintainPrinterSearchActivity.this.displaySearchResult();
                    MaintainPrinterSearchActivity.mSearchButton.setVisibility(8);
                }
            }
        });
    }

    public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
        super.onCreateContextMenu(contextMenu, view, contextMenuInfo);
        contextMenu.setHeaderTitle(R.string.str_edit_bookmark);
        contextMenu.add(0, 1, 0, R.string.str_delete);
        contextMenu.add(0, 2, 0, R.string.str_edit_bookmark);
    }

    public boolean onContextItemSelected(MenuItem menuItem) {
        listItemIndex = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
        if (this.listItemIndex == null) {
            return true;
        }
        switch (menuItem.getItemId()) {
            case 1:
                new AlertDialog.Builder(mContext).setCancelable(false).setTitle(getString(R.string.delete_file)).setIcon(getResources().getDrawable(R.C2136drawable.delete_file)).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Message obtainMessage = MaintainPrinterSearchActivity.mHandler.obtainMessage();
                        obtainMessage.what = 6;
                        MaintainPrinterSearchActivity.mHandler.sendMessageDelayed(obtainMessage, 100);
                    }
                }).setPositiveButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }).show();
                break;
            case 2:
                Message message = new Message();
                switch (this.printer_location) {
                    case 2:
                        message.what = 7;
                        break;
                    case 3:
                        message.what = 10;
                        break;
                }
                message.obj = mBuilder.getData().elementAt(mDeletePos);
                mHandler.sendMessage(message);
                break;
        }
        return true;
    }

    protected void onDestroy() {
        mBuilder.destructor();
        super.onDestroy();
    }

    public void onBackPressed() {
        super.onBackPressed();
        EPPrinterManager ePPrinterManager = new EPPrinterManager(mContext);
        ePPrinterManager.rollbackRemotePrinterInfo();
        ePPrinterManager.rollbackIPPrinterInfo();
        finish();
    }

    protected void onResume() {
        mActivityForegroundLifetime = true;
        super.onResume();
        EpLog.m78i(TAG, "onResume()");
        dismissPrinterNotFoundDialog();
        if (this.printer_location == 1) {
            mHandler.sendEmptyMessageDelayed(1, 300);
            EpLog.m70d(TAG, "Send CHECK_PRINTER Message.");
        }
        if (this.printer_location == 1 && mBleButton.getTag() == null && BleWork.isStartBleProcess(this, false)) {
            EpLog.m71e("blePrinterCheck");
            callBackFuncs();
            BleAsyncTask.blePrinterCheck(this, mBleFind);
        }
    }

    protected void onPause() {
        EpLog.m76i();
        super.onPause();
        mActivityForegroundLifetime = false;
        interruptSearch();
        BleAsyncTask.blePrinterCheckStop();
        removeAllDialog();
    }

    protected void onStart() {
        super.onStart();
    }

    protected void onStop() {
        EpLog.m76i();
        super.onStop();
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        interruptSearch();
        switch (i) {
            case 7:
                if (i2 == -1) {
                    ((MyPrinter) intent.getParcelableExtra(ActivityPrinterSetting.KEY_MYPRINTER)).setCurPrinter(this);
                    commitEPPrinterInfo();
                    ExternalFileUtils.getInstance(this).removeAreaInfo();
                    setResult(1);
                    finish();
                    return;
                }
                return;
            case 9:
                if (i2 == -1) {
                    MyPrinter myPrinter = new MyPrinter(intent.getStringExtra("name"), intent.getStringExtra(escprLib.PRINTER_IP), intent.getStringExtra("id"), intent.getStringExtra(escprLib.PRINTER_SERIAL_NO));
                    Message obtainMessage = mHandler.obtainMessage();
                    obtainMessage.what = 11;
                    obtainMessage.obj = myPrinter;
                    mHandler.sendMessage(obtainMessage);
                    intent.getBooleanExtra(ActivityiPrintConnect.FINISH_EAYSETUP, false);
                    return;
                }
                isFocused = true;
                mIsClickSelect = false;
                return;
            case 10:
                if (i2 == -1) {
                    MyPrinter myPrinter2 = new MyPrinter(intent.getStringExtra(Constants.PRINTER_NAME), intent.getStringExtra(Constants.PRINTER_IP), intent.getStringExtra(Constants.PRINTER_ID), intent.getStringExtra(Constants.PRINTER_SERIAL_NO), "", 3);
                    myPrinter2.setScannerId(intent.getStringExtra(Constants.SCAN_REFS_SCANNER_ID));
                    Message obtainMessage2 = mHandler.obtainMessage();
                    obtainMessage2.what = 11;
                    obtainMessage2.obj = myPrinter2;
                    mHandler.sendMessage(obtainMessage2);
                    return;
                }
                return;
            case 14:
                if (i2 != -1) {
                    bRejectLocationPermission = true;
                    return;
                }
                return;
            case 15:
                EpLog.m76i();
                finish();
                return;
            default:
                return;
        }
    }

    private void search() {
        interruptSearch();
        synchronized (mLock) {
            mBuilder.refresh();
            wiFiDirectPrinterListUtils.clearPrinterInfoList();
        }
        mIsClickSelect = false;
        isFinishSearchPrinter = false;
        searchButtonSetEnabled(false);
        mProgressBar.setVisibility(0);
        ((TextView) mLayout.findViewById(R.id.empty)).setText(getString(R.string.searching_text));
        isFocused = true;
        if (WiFiDirectManager.getCurSSID(this) != null) {
            mHandler.sendEmptyMessageDelayed(13, 5000);
            isSearchSimpleAp = true;
        } else if (WiFiDirectManager.isWifiEnabled(this)) {
            mHandler.sendEmptyMessage(13);
            isSearchSimpleAp = true;
        } else {
            boolean z = bCheckWiFiStatus;
            if (!z && !z) {
                bCheckWiFiStatus = true;
                WiFiDirectManager.enableWiFi(this, -1);
                return;
            }
        }
        WiFiDirectManager.setPriorityToSimpleAP(this, true);
        mPrinter.getMEscpLib().setHanlder(mHandler);
        mSearchThread = new Thread() {
            public void run() {
                synchronized (MaintainPrinterSearchActivity.mLock) {
                    boolean unused = MaintainPrinterSearchActivity.this.isFinishSearchPrinter = false;
                }
                MaintainPrinterSearchActivity.mPrinter.doFindPrinter(MaintainPrinterSearchActivity.EPS_PROTOCOL_ALL, 60);
                if (!MaintainPrinterSearchActivity.this.isFinishSearchPrinter) {
                    synchronized (MaintainPrinterSearchActivity.mLock) {
                        boolean unused2 = MaintainPrinterSearchActivity.this.isFinishSearchPrinter = true;
                        if (!MaintainPrinterSearchActivity.this.isSearchSimpleAp) {
                            MaintainPrinterSearchActivity.mHandler.sendEmptyMessage(5);
                        }
                    }
                }
            }
        };
        mSearchThread.start();
    }

    /* access modifiers changed from: private */
    /* JADX WARNING: Code restructure failed: missing block: B:12:0x003b, code lost:
        r6.mPrinter.doCancelFindPrinter();
        r0 = r6.mSearchThread;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0042, code lost:
        if (r0 == null) goto L_0x0098;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0048, code lost:
        if (r0.isAlive() == false) goto L_0x0098;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x004a, code lost:
        r6.mSearchThread.interrupt();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:18:?, code lost:
        epson.print.Util.EPLog.m305d(TAG, "mSearchThread.join() enter");
        r6.mSearchThread.join(1000);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:20:0x0069, code lost:
        if (java.lang.Thread.State.RUNNABLE.equals(r6.mSearchThread.getState()) == false) goto L_0x008c;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x006b, code lost:
        r0 = r2 + 1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x006f, code lost:
        if (r2 <= 60) goto L_0x0079;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:0x0071, code lost:
        epson.print.Util.EPLog.m318w(TAG, "mSearchThread.join() timeout");
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x0079, code lost:
        epson.print.Util.EPLog.m305d(TAG, "retry doCancelFindPrinter()");
        r6.mPrinter.doCancelFindPrinter();
        r6.mSearchThread.join(1000);
        r2 = r0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:25:0x008c, code lost:
        epson.print.Util.EPLog.m305d(TAG, "mSearchThread.join() leave");
     */
    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0094, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0095, code lost:
        r0.printStackTrace();
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void interruptSearch() {
        /*
            r6 = this;
            java.lang.String r0 = "MaintainPrinterSearchActivity"
            java.lang.String r1 = "interruptSearch()"
            epson.print.Util.EPLog.m305d(r0, r1)
            android.os.Handler r0 = r6.mHandler
            r1 = 1
            r0.removeMessages(r1)
            android.os.Handler r0 = r6.mHandler
            r2 = 13
            r0.removeMessages(r2)
            android.os.Handler r0 = r6.mHandler
            r2 = 0
            r0.removeMessages(r2)
            android.os.Handler r0 = r6.mHandler
            r3 = 8
            r0.removeMessages(r3)
            java.lang.Object r0 = mLock
            monitor-enter(r0)
            com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r4 = r6.searchWiFiDirectPrinter     // Catch:{ all -> 0x009e }
            if (r4 == 0) goto L_0x0030
            com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r4 = r6.searchWiFiDirectPrinter     // Catch:{ all -> 0x009e }
            r4.interrupt()     // Catch:{ all -> 0x009e }
            r4 = 0
            r6.searchWiFiDirectPrinter = r4     // Catch:{ all -> 0x009e }
        L_0x0030:
            r6.isSearchSimpleAp = r2     // Catch:{ all -> 0x009e }
            boolean r4 = r6.isFinishSearchPrinter     // Catch:{ all -> 0x009e }
            if (r4 != r1) goto L_0x0038
            monitor-exit(r0)     // Catch:{ all -> 0x009e }
            return
        L_0x0038:
            r6.isFinishSearchPrinter = r1     // Catch:{ all -> 0x009e }
            monitor-exit(r0)     // Catch:{ all -> 0x009e }
            com.epson.mobilephone.common.maintain2.MaintainPrinter2 r0 = r6.mPrinter
            r0.doCancelFindPrinter()
            java.lang.Thread r0 = r6.mSearchThread
            if (r0 == 0) goto L_0x0098
            boolean r0 = r0.isAlive()
            if (r0 == 0) goto L_0x0098
            java.lang.Thread r0 = r6.mSearchThread
            r0.interrupt()
            java.lang.String r0 = "MaintainPrinterSearchActivity"
            java.lang.String r1 = "mSearchThread.join() enter"
            epson.print.Util.EPLog.m305d(r0, r1)     // Catch:{ InterruptedException -> 0x0094 }
            java.lang.Thread r0 = r6.mSearchThread     // Catch:{ InterruptedException -> 0x0094 }
            r4 = 1000(0x3e8, double:4.94E-321)
            r0.join(r4)     // Catch:{ InterruptedException -> 0x0094 }
        L_0x005d:
            java.lang.Thread$State r0 = java.lang.Thread.State.RUNNABLE     // Catch:{ InterruptedException -> 0x0094 }
            java.lang.Thread r1 = r6.mSearchThread     // Catch:{ InterruptedException -> 0x0094 }
            java.lang.Thread$State r1 = r1.getState()     // Catch:{ InterruptedException -> 0x0094 }
            boolean r0 = r0.equals(r1)     // Catch:{ InterruptedException -> 0x0094 }
            if (r0 == 0) goto L_0x008c
            int r0 = r2 + 1
            r1 = 60
            if (r2 <= r1) goto L_0x0079
            java.lang.String r0 = "MaintainPrinterSearchActivity"
            java.lang.String r1 = "mSearchThread.join() timeout"
            epson.print.Util.EPLog.m318w((java.lang.String) r0, (java.lang.String) r1)     // Catch:{ InterruptedException -> 0x0094 }
            goto L_0x008c
        L_0x0079:
            java.lang.String r1 = "MaintainPrinterSearchActivity"
            java.lang.String r2 = "retry doCancelFindPrinter()"
            epson.print.Util.EPLog.m305d(r1, r2)     // Catch:{ InterruptedException -> 0x0094 }
            com.epson.mobilephone.common.maintain2.MaintainPrinter2 r1 = r6.mPrinter     // Catch:{ InterruptedException -> 0x0094 }
            r1.doCancelFindPrinter()     // Catch:{ InterruptedException -> 0x0094 }
            java.lang.Thread r1 = r6.mSearchThread     // Catch:{ InterruptedException -> 0x0094 }
            r1.join(r4)     // Catch:{ InterruptedException -> 0x0094 }
            r2 = r0
            goto L_0x005d
        L_0x008c:
            java.lang.String r0 = "MaintainPrinterSearchActivity"
            java.lang.String r1 = "mSearchThread.join() leave"
            epson.print.Util.EPLog.m305d(r0, r1)     // Catch:{ InterruptedException -> 0x0094 }
            goto L_0x0098
        L_0x0094:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0098:
            android.widget.ProgressBar r0 = r6.mProgressBar
            r0.setVisibility(r3)
            return
        L_0x009e:
            r1 = move-exception
            monitor-exit(r0)     // Catch:{ all -> 0x009e }
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.MaintainPrinterSearchActivity.interruptSearch():void");
    }

    public void displaySearchResult() {
        if (!mIsClickSelect) {
            boolean z = false;
            if (mBuilder.getData().size() <= 0) {
                ((TextView) mLayout.findViewById(R.id.empty)).setText(R.string.str_printer_search_result_none);
                if (this.printer_location == 1 && mActivityForegroundLifetime) {
                    if (WiFiDirectManager.getCurSSID(this) == null) {
                        z = true;
                    }
                    PrinterNotFoundDialogCreator.getPrinterNotFoundDialog(this, z, 1).show(getSupportFragmentManager(), DIALOG_TAG_PRINTER_NOT_FOUND);
                }
            } else if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
                ((TextView) mLayout.findViewById(R.id.empty)).setText(getString(R.string.numberOfPrintersAvailable));
            } else {
                ((TextView) mLayout.findViewById(R.id.empty)).setText(String.format(getString(R.string.numberOfPrintersAvailable), new Object[]{Integer.valueOf(mBuilder.getData().size())}));
            }
        }
        mProgressBar.setVisibility(8);
        searchButtonSetEnabled(true);
    }

    protected Dialog onCreateDialog(int i) {
        String str;
        Dialog onCreateDialog = super.onCreateDialog(i);
        if (i != R.string.EPS_ERR_PRINTER_NOT_FOUND_RESEARCH) {
            switch (i) {
                case R.string.EPS_PRNERR_COMM1 /*2131624360*/:
                    return Utils.makeMessageBox(this, getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_TITLE), getString(i), getString(R.string.str_ok));
                case R.string.EPS_PRNERR_COMM1_NOWIFI /*2131624361*/:
                    return Utils.makeMessageBox(this, getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_TITLE), getString(R.string.EPS_PRNERR_COMM1_NOWIFI), getString(R.string.str_ok));
                default:
                    return onCreateDialog;
            }
        } else {
            String string = getString(i);
            String ssid = Utils.getSSID(this);
            if (!Utils.isConnectedWifi(this) || ssid == null) {
                str = getString(R.string.EPS_PRNERR_COMM4);
            } else {
                str = String.format(string, new Object[]{ssid});
            }
            return Utils.makeMessageBox(this, getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_TITLE), str, getString(R.string.str_ok));
        }
    }

    private void dismissPrinterNotFoundDialog() {
        DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(DIALOG_TAG_PRINTER_NOT_FOUND);
        if (dialogFragment != null) {
            dialogFragment.dismiss();
        }
    }

    /* access modifiers changed from: package-private */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0012 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void removeAllDialog() {
        /*
            r1 = this;
            r0 = 2131624360(0x7f0e01a8, float:1.8875898E38)
            r1.removeDialog(r0)     // Catch:{ IllegalArgumentException -> 0x0006 }
        L_0x0006:
            r0 = 2131624125(0x7f0e00bd, float:1.887542E38)
            r1.removeDialog(r0)     // Catch:{ IllegalArgumentException -> 0x000c }
        L_0x000c:
            r0 = 2131624361(0x7f0e01a9, float:1.88759E38)
            r1.removeDialog(r0)     // Catch:{ IllegalArgumentException -> 0x0012 }
        L_0x0012:
            r1.dismissPrinterNotFoundDialog()     // Catch:{ Exception -> 0x0015 }
        L_0x0015:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.MaintainPrinterSearchActivity.removeAllDialog():void");
    }

    public void searchButtonSetEnabled(boolean z) {
        mSearchButton.setVisibility(0);
        if (z) {
            mSearchButton.setEnabled(true);
        } else {
            mSearchButton.setEnabled(false);
        }
    }

    /* access modifiers changed from: package-private */
    public void commitEPPrinterInfo() {
        EPPrinterManager ePPrinterManager = new EPPrinterManager(mContext);
        ePPrinterManager.commitIPPrinterInfo();
        ePPrinterManager.commitRemotePrinterInfo();
    }

    public void onLocalPositiveCallback(int i) {
        if (i == 1) {
            startActivity(PrinterNotFoundDialogCreator.getStartIntent(this));
        }
    }

    private void callBackFuncs() {
        mBleFind = new BLEUtility.BleWorkCallback() {
            public void call(Object obj) {
                ArrayList arrayList = (ArrayList) obj;
                EpLog.m69d(" ★★　mDevicelist " + arrayList.size());
                if (MaintainPrinterSearchActivity.this.printer_location == 1) {
                    MaintainPrinterSearchActivity.mBleButton.setVisibility(0);
                }
                MaintainPrinterSearchActivity.mBleButton.setTag(arrayList);
            }
        };
    }
}
