package epson.print.screen;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
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.TextView;

import com.epson.mobilephone.common.escpr.MediaInfo;
import com.epson.mobilephone.common.wifidirect.ActivityWiFiDirectStart;
import com.epson.mobilephone.common.wifidirect.ActivityiPrintConnect;
import com.epson.mobilephone.common.wifidirect.MacAddrUtils;
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.escprLib;

import java.util.ArrayList;
import java.util.Locale;

import epson.common.Constants;
import epson.common.Utils;
import epson.maintain.activity.PrinterNotFoundDialogCreator;
import epson.print.ActivityIACommon;
import epson.print.CommonDefine;
import epson.print.CustomLayoutDialogFragment;
import epson.print.CustomTitleDialogFragment;
import epson.print.MyPrinter;
import epson.print.R;
import epson.print.Util.EPLog;
import epson.print.service.EpsonService;
import epson.print.service.IEpsonService;
import epson.print.service.IEpsonServiceCallback;
import epson.print.widgets.AbstractListBuilder;
import epson.print.widgets.CustomTitleAlertDialogBuilder;
import epson.print.widgets.ListControlHelper;
import epson.print.widgets.PrinterInfoBuilder;
import epson.print.widgets.PrinterInfoECBuilder;
import epson.print.widgets.PrinterInfoIpBuilder;

public class SearchPrinterScr 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 int DIALOG_INFORM = 0;
    private static final String DIALOG_TAG_PRINTER_NOT_FOUND = "printer_not_found_dialog";
    private static final String EXTRA_PRINTER = "myprinter";
    private static final String EXTRA_SIMPLEAP = "simpleap";
    private static final int Menu_Delete = 1;
    private static final int Menu_Edit = 2;
    private static final String TAG = "SearchPrinterScr";
    private static boolean foundPrinter = false;
    private static final Object mLock = new Object();
    private final int CANCEL_FIND_PRINTER = 2;
    private final int CONNECT_SIMPLEAP = 10;
    private final int DELETE_PRINTER = 7;
    private final int EDIT_IPPRINTER = 11;
    private final int EDIT_PRINTER = 8;
    private final int FOUND_SIMPLEAP = 9;
    private final int INFORM_DIALOG = 5;
    private final String PRINTER_COMMON_DEVICENAME = "common_devicename";
    private final String PRINTER_ID = "id";
    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 = 12;
    private final int SEARCH_PRINTER = 1;
    private final int SEARCH_PRINTER_P2P = 14;
    private final int SELECT_PRINTER = 4;
    private final int SHOW_PRINTER_NOT_FOUND_DIALOG = 13;
    private final int UPDATE_PRINTER = 3;
    private boolean bCheckWiFiStatus = false;
    private String connectionInfo = null;
    int curError;
    ListControlHelper helper = null;
    private boolean isDialogOpen = false;
    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;
    AbstractListBuilder mBuilder;
    private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
        public void onGetInkState() throws RemoteException {
        }

        public void onGetStatusState() throws RemoteException {
        }

        public void onNotifyEndJob(int i) throws RemoteException {
        }

        public void onNotifyProgress(int i, int i2) throws RemoteException {
        }

        public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
            EPLog.i(str);
            int access$200 = SearchPrinterScr.this.printer_location;
            if (access$200 == 1) {
                Message obtain = Message.obtain();
                obtain.what = 3;
                Bundle bundle = new Bundle();
                bundle.putString("name", str);
                bundle.putString(escprLib.PRINTER_IP, str2);
                bundle.putString("id", str3);
                bundle.putString(escprLib.PRINTER_SERIAL_NO, str4);
                bundle.putString("common_devicename", str5);
                obtain.setData(bundle);
                SearchPrinterScr.this.mHandler.sendMessage(obtain);
            } else if (access$200 == 3) {
                MyPrinter unused = SearchPrinterScr.this.probedPrinter = new MyPrinter(str, str2, str3, str4);
            }
        }

        public void onNotifyContinueable(int i) throws RemoteException {
            if (SearchPrinterScr.this.progress != null && SearchPrinterScr.this.progress.isShowing()) {
                SearchPrinterScr.this.progress.dismiss();
            }
            if (SearchPrinterScr.this.selectedPrinter != null && SearchPrinterScr.this.probedPrinter != null && SearchPrinterScr.this.printer_location == 3) {
                if (SearchPrinterScr.this.probedPrinter.getPrinterId().equals(SearchPrinterScr.this.selectedPrinter.getPrinterId())) {
                    Message obtainMessage = SearchPrinterScr.this.mHandler.obtainMessage();
                    obtainMessage.what = 4;
                    obtainMessage.obj = SearchPrinterScr.this.selectedPrinter;
                    SearchPrinterScr.this.mHandler.sendMessage(obtainMessage);
                    return;
                }
                SearchPrinterScr searchPrinterScr = SearchPrinterScr.this;
                searchPrinterScr.curError = -500001;
                searchPrinterScr.mHandler.sendEmptyMessage(5);
            }
        }

        public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
            if (!SearchPrinterScr.this.isSearchSimpleAp) {
                synchronized (SearchPrinterScr.mLock) {
                    boolean unused = SearchPrinterScr.foundPrinter = Utils.getPrefBoolean(SearchPrinterScr.this.getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH);
                    if ((i2 == -1300 || i2 == -1351) && !SearchPrinterScr.foundPrinter) {
                        i2 = -1100;
                    } else if ((i2 == -1300 || i2 == -1351 || i2 == -1100) && SearchPrinterScr.foundPrinter) {
                        i2 = -11001;
                    }
                }
                SearchPrinterScr searchPrinterScr = SearchPrinterScr.this;
                searchPrinterScr.curError = i2;
                searchPrinterScr.mHandler.sendEmptyMessage(13);
                if (SearchPrinterScr.this.progress != null && SearchPrinterScr.this.progress.isShowing()) {
                    SearchPrinterScr.this.progress.dismiss();
                }
                Boolean unused2 = SearchPrinterScr.this.isFocused = true;
            }
        }
    };
    private Context mContext = null;
    private int mDeletePos = -1;
    private ServiceConnection mEpsonConnection = new ServiceConnection() {
        public void onServiceDisconnected(ComponentName componentName) {
            try {
                SearchPrinterScr.this.mEpsonService.unregisterCallback(SearchPrinterScr.this.mCallback);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            IEpsonService unused = SearchPrinterScr.this.mEpsonService = null;
        }

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IEpsonService unused = SearchPrinterScr.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
            if (SearchPrinterScr.this.mEpsonService != null) {
                try {
                    SearchPrinterScr.this.mEpsonService.registerCallback(SearchPrinterScr.this.mCallback);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    private IEpsonService mEpsonService = null;
    Handler mHandler = new Handler(new Handler.Callback() {
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r10v46, resolved type: java.lang.Object} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v22, resolved type: epson.print.MyPrinter} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r10v60, resolved type: java.lang.Object} */
        /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v29, 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 r10) {
            /*
                r9 = this;
                int r0 = r10.what
                r1 = 8
                r2 = 0
                r3 = -1
                r4 = 0
                r5 = 1
                switch(r0) {
                    case 1: goto L_0x036b;
                    case 2: goto L_0x0365;
                    case 3: goto L_0x02c1;
                    case 4: goto L_0x0247;
                    case 5: goto L_0x0219;
                    case 6: goto L_0x000b;
                    case 7: goto L_0x0166;
                    case 8: goto L_0x0122;
                    case 9: goto L_0x00c6;
                    case 10: goto L_0x000b;
                    case 11: goto L_0x0080;
                    case 12: goto L_0x0036;
                    case 13: goto L_0x002b;
                    case 14: goto L_0x000d;
                    default: goto L_0x000b;
                }
            L_0x000b:
                goto L_0x0379
            L_0x000d:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                android.os.Handler r0 = r10.mHandler
                r1 = 9
                r2 = 60
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r0 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.searchWiFiDirectPrinter(r10, r0, r1, r2)
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask unused = r10.searchWiFiDirectPrinter = r0
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                com.epson.mobilephone.common.wifidirect.SearchWiFiDirectPrinterTask r10 = r10.searchWiFiDirectPrinter
                if (r10 != 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean unused = r10.isSearchSimpleAp = r4
                goto L_0x0379
            L_0x002b:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                android.support.v4.app.DialogFragment r0 = r10.getPrinterNotFoundDialog()
                r10.showPrinterNotFoundDialog(r0)
                goto L_0x0379
            L_0x0036:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                java.lang.Object r10 = r10.obj
                epson.print.MyPrinter r10 = (epson.print.MyPrinter) r10
                epson.print.MyPrinter unused = r0.selectedPrinter = r10
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.MyPrinter unused = r10.probedPrinter = r2
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.screen.WorkingDialog r10 = r10.progress
                if (r10 != 0) goto L_0x0053
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.screen.WorkingDialog r0 = new epson.print.screen.WorkingDialog
                r0.<init>(r10)
                r10.progress = r0
            L_0x0053:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.screen.WorkingDialog r10 = r10.progress
                r10.show()
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this     // Catch:{ RemoteException -> 0x007a }
                epson.print.service.IEpsonService r10 = r10.mEpsonService     // Catch:{ RemoteException -> 0x007a }
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this     // Catch:{ RemoteException -> 0x007a }
                epson.print.MyPrinter r0 = r0.selectedPrinter     // Catch:{ RemoteException -> 0x007a }
                java.lang.String r0 = r0.getPrinterId()     // Catch:{ RemoteException -> 0x007a }
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this     // Catch:{ RemoteException -> 0x007a }
                epson.print.MyPrinter r1 = r1.selectedPrinter     // Catch:{ RemoteException -> 0x007a }
                java.lang.String r1 = r1.getIp()     // Catch:{ RemoteException -> 0x007a }
                r2 = 2
                r10.searchPrinters(r0, r1, r2)     // Catch:{ RemoteException -> 0x007a }
                goto L_0x0379
            L_0x007a:
                r10 = move-exception
                r10.printStackTrace()
                goto L_0x0379
            L_0x0080:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                r0.interruptSearch()
                java.lang.Object r0 = r10.obj
                if (r0 == 0) goto L_0x008e
                java.lang.Object r10 = r10.obj
                r2 = r10
                epson.print.MyPrinter r2 = (epson.print.MyPrinter) r2
            L_0x008e:
                android.content.Intent r10 = new android.content.Intent
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                java.lang.Class<epson.print.screen.ActivityIpPrinterSetting> r1 = epson.print.screen.ActivityIpPrinterSetting.class
                r10.<init>(r0, r1)
                android.os.Bundle r0 = new android.os.Bundle
                r0.<init>()
                if (r2 == 0) goto L_0x00ae
                java.lang.String r1 = r2.getIp()
                if (r1 == 0) goto L_0x00ae
                java.lang.String r1 = "PRINTER_KEY"
                java.lang.String r2 = r2.getPrinterId()
                r0.putString(r1, r2)
                goto L_0x00b5
            L_0x00ae:
                java.lang.String r1 = "PRINTER_IP"
                java.lang.String r2 = ""
                r0.putString(r1, r2)
            L_0x00b5:
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this
                int unused = r1.mDeletePos = r3
                r10.putExtras(r0)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                r1 = 11
                r0.startActivityForResult(r10, r1)
                goto L_0x0379
            L_0x00c6:
                android.os.Bundle r10 = r10.getData()
                if (r10 == 0) goto L_0x00f7
                boolean r0 = r10.isEmpty()
                if (r0 != 0) goto L_0x00f7
                java.lang.String r0 = "ssid"
                java.lang.String r0 = r10.getString(r0)
                java.lang.String r1 = "name"
                java.lang.String r1 = r10.getString(r1)
                java.lang.String r2 = "addr_infra"
                java.lang.String r10 = r10.getString(r2)
                if (r1 != 0) goto L_0x00e7
                r1 = r0
            L_0x00e7:
                epson.print.MyPrinter r2 = new epson.print.MyPrinter
                java.lang.String r3 = ""
                r2.<init>(r1, r0, r10, r3)
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this
                com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils r1 = r1.wiFiDirectPrinterListUtils
                r1.addPrinter(r2, r4, r0, r10)
                goto L_0x0379
            L_0x00f7:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean unused = r10.isSearchSimpleAp = r4
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean r10 = r10.isFinishSearchPrinter
                if (r10 == 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.displaySearchResult()
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r10 = r10.mBuilder
                java.util.Vector r10 = r10.getData()
                int r10 = r10.size()
                if (r10 != 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                android.os.Handler r10 = r10.mHandler
                r0 = 13
                r10.sendEmptyMessage(r0)
                goto L_0x0379
            L_0x0122:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                r0.interruptSearch()
                java.lang.Object r0 = r10.obj
                if (r0 == 0) goto L_0x0130
                java.lang.Object r10 = r10.obj
                r2 = r10
                epson.print.MyPrinter r2 = (epson.print.MyPrinter) r2
            L_0x0130:
                android.content.Intent r10 = new android.content.Intent
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                java.lang.Class<epson.print.screen.ActivityPrinterSetting> r5 = epson.print.screen.ActivityPrinterSetting.class
                r10.<init>(r0, r5)
                android.os.Bundle r0 = new android.os.Bundle
                r0.<init>()
                if (r2 == 0) goto L_0x0150
                java.lang.String r5 = r2.getEmailAddress()
                if (r5 == 0) goto L_0x0150
                java.lang.String r5 = "PRINTER_EMAIL_ADDRESS"
                java.lang.String r2 = r2.getEmailAddress()
                r0.putString(r5, r2)
                goto L_0x0157
            L_0x0150:
                java.lang.String r2 = "PRINTER_EMAIL_ADDRESS"
                java.lang.String r5 = ""
                r0.putString(r2, r5)
            L_0x0157:
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.this
                int unused = r2.mDeletePos = r3
                r10.putExtras(r0)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                r0.startActivityForResult(r10, r1)
                goto L_0x0379
            L_0x0166:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                int r10 = r10.mDeletePos
                if (r10 < 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                int r10 = r10.printer_location
                switch(r10) {
                    case 2: goto L_0x01bc;
                    case 3: goto L_0x0179;
                    default: goto L_0x0177;
                }
            L_0x0177:
                goto L_0x01fe
            L_0x0179:
                epson.print.EPPrinterManager r10 = new epson.print.EPPrinterManager
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                android.content.Context r0 = r0.mContext
                r10.<init>(r0)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.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()
                r10.deleteIpPrinterInfo(r0)
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r10 = r10.mBuilder
                android.widget.BaseAdapter r10 = r10.getAdapter()
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.this
                int r2 = r2.mDeletePos
                r0.remove(r2)
                r10.notifyDataSetChanged()
                goto L_0x01fe
            L_0x01bc:
                epson.print.EPPrinterManager r10 = new epson.print.EPPrinterManager
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                android.content.Context r0 = r0.mContext
                r10.<init>(r0)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.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()
                r10.deleteRemotePrinterInfo(r0)
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r10 = r10.mBuilder
                android.widget.BaseAdapter r10 = r10.getAdapter()
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                epson.print.widgets.AbstractListBuilder r0 = r0.mBuilder
                java.util.Vector r0 = r0.getData()
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.this
                int r2 = r2.mDeletePos
                r0.remove(r2)
                r10.notifyDataSetChanged()
            L_0x01fe:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.displaySearchResult()
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                int r10 = r10.printer_location
                if (r10 == r5) goto L_0x0212
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                android.widget.Button r10 = r10.mSearchButton
                r10.setVisibility(r1)
            L_0x0212:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                int unused = r10.mDeletePos = r3
                goto L_0x0379
            L_0x0219:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean r10 = r10.isDialogOpen
                if (r10 != 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean unused = r10.isDialogOpen = r5
                java.lang.String r10 = "SearchPrinterScr"
                java.lang.StringBuilder r0 = new java.lang.StringBuilder
                r0.<init>()
                java.lang.String r1 = "mHandler curError = "
                r0.append(r1)
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this
                int r1 = r1.curError
                r0.append(r1)
                java.lang.String r0 = r0.toString()
                epson.print.Util.EPLog.i(r10, r0)
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.showDialog(r4)
                goto L_0x0379
            L_0x0247:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                boolean r0 = r0.isFinishSearchPrinter
                if (r0 != 0) goto L_0x0257
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                epson.print.service.IEpsonService r0 = r0.mEpsonService
                if (r0 != 0) goto L_0x025f
            L_0x0257:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                boolean r0 = r0.isSearchSimpleAp
                if (r0 == 0) goto L_0x0282
            L_0x025f:
                java.lang.String r0 = "SearchPrinterScr"
                java.lang.String r1 = "cancelSearch for SELECT_PRINTER"
                epson.print.Util.EPLog.i(r0, r1)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                r0.interruptSearch()
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                android.os.Handler r0 = r0.mHandler
                int r1 = r10.what
                java.lang.Object r10 = r10.obj
                android.os.Message r10 = r0.obtainMessage(r1, r10)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this
                android.os.Handler r0 = r0.mHandler
                r1 = 200(0xc8, double:9.9E-322)
                r0.sendMessageDelayed(r10, r1)
                goto L_0x0379
            L_0x0282:
                java.lang.Object r10 = r10.obj
                epson.print.MyPrinter r10 = (epson.print.MyPrinter) r10
                android.content.Intent r0 = new android.content.Intent
                r0.<init>()
                java.lang.String r1 = "myprinter"
                r0.putExtra(r1, r10)
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this
                int r1 = r1.printer_location
                if (r1 != r5) goto L_0x02ae
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this
                java.lang.String r10 = r10.getPrinterId()
                java.lang.String r10 = com.epson.mobilephone.common.wifidirect.MacAddrUtils.getMacAddressFromPrinterId(r10)
                java.lang.String r10 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.getCurConnectInfo(r1, r10)
                if (r10 == 0) goto L_0x02b5
                java.lang.String r1 = "simpleap"
                r0.putExtra(r1, r10)
                goto L_0x02b5
            L_0x02ae:
                java.lang.String r10 = "simpleap"
                java.lang.String r1 = ""
                r0.putExtra(r10, r1)
            L_0x02b5:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.setResult(r3, r0)
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.finish()
                goto L_0x0379
            L_0x02c1:
                android.os.Bundle r10 = r10.getData()
                java.lang.String r0 = "name"
                java.lang.String r0 = r10.getString(r0)
                if (r0 == 0) goto L_0x033f
                java.lang.String r1 = "FINISH"
                boolean r0 = r0.contentEquals(r1)
                if (r0 != 0) goto L_0x033f
                java.lang.Object r0 = epson.print.screen.SearchPrinterScr.mLock
                monitor-enter(r0)
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this     // Catch:{ all -> 0x033c }
                java.util.ArrayList r1 = r1.printerList     // Catch:{ all -> 0x033c }
                java.lang.String r2 = "id"
                java.lang.String r2 = r10.getString(r2)     // Catch:{ all -> 0x033c }
                boolean r1 = r1.contains(r2)     // Catch:{ all -> 0x033c }
                if (r1 == 0) goto L_0x02ef
                monitor-exit(r0)     // Catch:{ all -> 0x033c }
                goto L_0x0379
            L_0x02ef:
                epson.print.MyPrinter r1 = new epson.print.MyPrinter     // Catch:{ all -> 0x033c }
                java.lang.String r2 = "name"
                java.lang.String r2 = r10.getString(r2)     // Catch:{ all -> 0x033c }
                java.lang.String r6 = "ip"
                java.lang.String r6 = r10.getString(r6)     // Catch:{ all -> 0x033c }
                java.lang.String r7 = "id"
                java.lang.String r7 = r10.getString(r7)     // Catch:{ all -> 0x033c }
                java.lang.String r8 = "serial_no"
                java.lang.String r8 = r10.getString(r8)     // Catch:{ all -> 0x033c }
                r1.<init>(r2, r6, r7, r8)     // Catch:{ all -> 0x033c }
                java.lang.String r2 = "common_devicename"
                java.lang.String r2 = r10.getString(r2)     // Catch:{ all -> 0x033c }
                r1.setCommonDeviceName(r2)     // Catch:{ all -> 0x033c }
                epson.print.screen.SearchPrinterScr r2 = epson.print.screen.SearchPrinterScr.this     // Catch:{ all -> 0x033c }
                com.epson.mobilephone.common.wifidirect.WiFiDirectPrinterListUtils r2 = r2.wiFiDirectPrinterListUtils     // Catch:{ all -> 0x033c }
                java.lang.String r6 = r1.getIp()     // Catch:{ all -> 0x033c }
                java.lang.String r7 = r1.getPrinterId()     // Catch:{ all -> 0x033c }
                java.lang.String r7 = com.epson.mobilephone.common.wifidirect.MacAddrUtils.getMacAddressFromPrinterId(r7)     // Catch:{ all -> 0x033c }
                r2.addPrinter(r1, r3, r6, r7)     // Catch:{ all -> 0x033c }
                epson.print.screen.SearchPrinterScr r1 = epson.print.screen.SearchPrinterScr.this     // Catch:{ all -> 0x033c }
                java.util.ArrayList r1 = r1.printerList     // Catch:{ all -> 0x033c }
                java.lang.String r2 = "id"
                java.lang.String r10 = r10.getString(r2)     // Catch:{ all -> 0x033c }
                r1.add(r10)     // Catch:{ all -> 0x033c }
                boolean unused = epson.print.screen.SearchPrinterScr.foundPrinter = r5     // Catch:{ all -> 0x033c }
                monitor-exit(r0)     // Catch:{ all -> 0x033c }
                goto L_0x0379
            L_0x033c:
                r10 = move-exception
                monitor-exit(r0)     // Catch:{ all -> 0x033c }
                throw r10
            L_0x033f:
                java.lang.Object r10 = epson.print.screen.SearchPrinterScr.mLock
                monitor-enter(r10)
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this     // Catch:{ all -> 0x0362 }
                boolean r0 = r0.isFinishSearchPrinter     // Catch:{ all -> 0x0362 }
                if (r0 == 0) goto L_0x034e
                monitor-exit(r10)     // Catch:{ all -> 0x0362 }
                goto L_0x0379
            L_0x034e:
                epson.print.screen.SearchPrinterScr r0 = epson.print.screen.SearchPrinterScr.this     // Catch:{ all -> 0x0362 }
                boolean unused = r0.isFinishSearchPrinter = r5     // Catch:{ all -> 0x0362 }
                monitor-exit(r10)     // Catch:{ all -> 0x0362 }
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                boolean r10 = r10.isSearchSimpleAp
                if (r10 != 0) goto L_0x0379
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.displaySearchResult()
                goto L_0x0379
            L_0x0362:
                r0 = move-exception
                monitor-exit(r10)     // Catch:{ all -> 0x0362 }
                throw r0
            L_0x0365:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.interruptSearch()
                goto L_0x0379
            L_0x036b:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                int r10 = r10.printer_location
                if (r10 == r5) goto L_0x0374
                goto L_0x0379
            L_0x0374:
                epson.print.screen.SearchPrinterScr r10 = epson.print.screen.SearchPrinterScr.this
                r10.search()
            L_0x0379:
                return r4
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.print.screen.SearchPrinterScr.C234613.handleMessage(android.os.Message):boolean");
        }
    });
    RadioButton mIpButton;
    boolean mIsClickSelect = false;
    ViewGroup mLayout;
    private TextView mListEmptyMessageTextView;
    private ListView mListView;
    RadioButton mLocalButton;
    ProgressBar mProgressBar;
    RadioButton mRemoteButton;
    Button mSearchButton;
    TextView mTextDetail;
    View mWiFiSettingButton;
    private String printerEmailAddress = "";
    private String printerId = "";
    private String printerKey = "";
    private ArrayList<String> printerList = new ArrayList<>();
    private volatile int printer_location = 0;
    private MyPrinter probedPrinter = null;
    WorkingDialog progress;
    private SearchWiFiDirectPrinterTask searchWiFiDirectPrinter = null;
    private MyPrinter selectedPrinter = null;
    WiFiDirectPrinterListUtils wiFiDirectPrinterListUtils = null;

    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;
        }
        if (this.mEpsonService == null) {
            bindService(new Intent(this, EpsonService.class), mEpsonConnection, 1);
        }
        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);
        Intent intent = getIntent();
        printer_location = intent.getIntExtra(Constants.PRINTER_LOCATION, 1);
        if (this.printer_location == 0) {
            printer_location = 1;
        }
        switch (this.printer_location) {
            case 2:
                printerEmailAddress = intent.getStringExtra(Constants.PRINTER_EMAIL_ADDRESS);
                break;
            case 3:
                printerKey = intent.getStringExtra(Constants.PRINTER_ID);
                break;
            default:
                printerId = intent.getStringExtra(Constants.PRINTER_ID);
                connectionInfo = intent.getStringExtra(EXTRA_SIMPLEAP);
                break;
        }
        buildElements();
        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);
    }

    private void setBleWifiSetupButton() {
        mLayout.findViewById(R.id.ble_wifi_setting).setVisibility(8);
    }

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

    private 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) {
                SearchPrinterScr.this.startWifiPrinterSelect();
            }
        });
    }

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

    private void addAboutRemoteButton() {
        mAboutRemoteButton = mLayout.findViewById(R.id.AboutRemoteFrame);
        mAboutRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                SearchPrinterScr.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.drawable.printer_selector_icon_local);
        Utils.setDrawble2TextView(this, mIpButton, R.drawable.printer_selector_icon_ip);
        Utils.setDrawble2TextView(this, mRemoteButton, R.drawable.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);
                mBuilder.setResource(WiFiDirectPrinterListUtils.getCurPrinterString(this, printerId, connectionInfo));
                helper = new ListControlHelper((PrinterInfoBuilder) mBuilder);
                wiFiDirectPrinterListUtils = new WiFiDirectPrinterListUtils(this, mBuilder.getData(), helper, connectionInfo);
                mLocalButton.setChecked(true);
                mTextDetail.setText(R.string.str_detailtext_local);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).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);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
                mWiFiSettingButton.setVisibility(8);
                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);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
                mWiFiSettingButton.setVisibility(8);
                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 (SearchPrinterScr.this.isFocused.booleanValue()) {
                    Boolean unused = SearchPrinterScr.this.isFocused = false;
                    SearchPrinterScr searchPrinterScr = SearchPrinterScr.this;
                    searchPrinterScr.mIsClickSelect = true;
                    Message obtainMessage = searchPrinterScr.mHandler.obtainMessage();
                    obtainMessage.obj = SearchPrinterScr.this.mBuilder.getData().elementAt(i);
                    int access$200 = SearchPrinterScr.this.printer_location;
                    if (access$200 == 1) {
                        String ip = ((MyPrinter) obtainMessage.obj).getIp();
                        if (!WiFiControl.ConnectType.NONE.equals(WiFiDirectManager.getConnectType(SearchPrinterScr.this, ip))) {
                            SearchPrinterScr.this.interruptSearch();
                            WiFiDirectManager.connect(SearchPrinterScr.this, ip, 10);
                        } else {
                            obtainMessage.what = 4;
                        }
                    } else if (access$200 != 3) {
                        obtainMessage.what = 4;
                    } else {
                        obtainMessage.what = 12;
                    }
                    SearchPrinterScr.this.mHandler.sendMessageDelayed(obtainMessage, 100);
                }
            }
        });
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (SearchPrinterScr.this.printer_location == 1) {
                    return true;
                }
                int unused = SearchPrinterScr.this.mDeletePos = i;
                SearchPrinterScr searchPrinterScr = SearchPrinterScr.this;
                searchPrinterScr.registerForContextMenu(searchPrinterScr.mListView);
                return false;
            }
        });
        mAddButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                switch (SearchPrinterScr.this.printer_location) {
                    case 2:
                        if (SearchPrinterScr.this.mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(SearchPrinterScr.this.mContext).setCancelable(false).setTitle(SearchPrinterScr.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(SearchPrinterScr.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(SearchPrinterScr.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        } else if (SearchPrinterScr.this.getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).getBoolean(Constants.ENABLE_SHOW_WARNING, true)) {
                            AlertDialog.Builder cancelable = new AlertDialog.Builder(SearchPrinterScr.this.mContext).setCancelable(false);
                            cancelable.setMessage(SearchPrinterScr.this.getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + SearchPrinterScr.this.getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(SearchPrinterScr.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Message message = new Message();
                                    message.what = 8;
                                    message.obj = null;
                                    SearchPrinterScr.this.mHandler.sendMessage(message);
                                }
                            }).setNegativeButton(SearchPrinterScr.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 = 8;
                            message.obj = null;
                            SearchPrinterScr.this.mHandler.sendMessage(message);
                            return;
                        }
                    case 3:
                        if (SearchPrinterScr.this.mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(SearchPrinterScr.this.mContext).setCancelable(false).setTitle(SearchPrinterScr.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(SearchPrinterScr.this.getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(SearchPrinterScr.this.getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        }
                        Message message2 = new Message();
                        message2.what = 11;
                        message2.obj = null;
                        SearchPrinterScr.this.mHandler.sendMessage(message2);
                        return;
                    default:
                        return;
                }
            }
        });
        mSearchButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (SearchPrinterScr.this.printer_location == 1) {
                    SearchPrinterScr.this.mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mLocalButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (SearchPrinterScr.this.printer_location != 1) {
                    SearchPrinterScr.this.mAddButton.setVisibility(8);
                    ((TextView) SearchPrinterScr.this.mLayout.findViewById(R.id.empty)).setVisibility(0);
                    SearchPrinterScr.this.interruptSearch();
                    int unused = SearchPrinterScr.this.printer_location = 1;
                    SearchPrinterScr.this.buildElements();
                    SearchPrinterScr.this.mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (SearchPrinterScr.this.printer_location != 2) {
                    int unused = SearchPrinterScr.this.printer_location = 2;
                    SearchPrinterScr.this.interruptSearch();
                    ((TextView) SearchPrinterScr.this.mLayout.findViewById(R.id.empty)).setVisibility(8);
                    SearchPrinterScr.this.mBuilder.refresh();
                    SearchPrinterScr.this.buildElements();
                    SearchPrinterScr.this.displaySearchResult();
                    SearchPrinterScr.this.mSearchButton.setVisibility(8);
                }
            }
        });
        mIpButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (SearchPrinterScr.this.printer_location != 3) {
                    int unused = SearchPrinterScr.this.printer_location = 3;
                    SearchPrinterScr.this.interruptSearch();
                    ((TextView) SearchPrinterScr.this.mLayout.findViewById(R.id.empty)).setVisibility(8);
                    SearchPrinterScr.this.mBuilder.refresh();
                    SearchPrinterScr.this.buildElements();
                    SearchPrinterScr.this.displaySearchResult();
                    SearchPrinterScr.this.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(this.mContext).setCancelable(false).setTitle(getString(R.string.delete_file)).setIcon(getResources().getDrawable(R.drawable.delete_file)).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Message obtainMessage = SearchPrinterScr.this.mHandler.obtainMessage();
                        obtainMessage.what = 7;
                        SearchPrinterScr.this.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 = 8;
                        break;
                    case 3:
                        message.what = 11;
                        break;
                }
                message.obj = mBuilder.getData().elementAt(this.mDeletePos);
                mHandler.sendMessage(message);
                break;
        }
        return true;
    }

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

    public void onBackPressed() {
        super.onBackPressed();
        interruptSearch();
        finish();
    }

    protected void onResume() {
        super.onResume();
        EPLog.d(TAG, "onResume()");
        mActivityForegroundLifetime = true;
        dismissPrinterNotFoundDialog();
        if (this.printer_location == 1) {
            mHandler.sendEmptyMessageDelayed(1, 100);
            EPLog.d(TAG, "Send CHECK_PRINTER Message.");
        }
    }

    protected void onPause() {
        EPLog.d(TAG, "onPause()");
        super.onPause();
        mActivityForegroundLifetime = false;
        interruptSearch();
        removeAllDialog();
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        interruptSearch();
        switch (i) {
            case 8:
                if (i2 == -1) {
                    Intent intent2 = new Intent();
                    intent2.putExtra(EXTRA_PRINTER, (MyPrinter) intent.getParcelableExtra(ActivityPrinterSetting.KEY_MYPRINTER));
                    setResult(-1, intent2);
                    finish();
                    return;
                }
                return;
            case 10:
                if (i2 == -1) {
                    MyPrinter myPrinter = new MyPrinter(intent.getStringExtra("name"), intent.getStringExtra(escprLib.PRINTER_IP), intent.getStringExtra("id"), intent.getStringExtra(escprLib.PRINTER_SERIAL_NO));
                    Intent intent3 = new Intent();
                    intent3.putExtra(EXTRA_PRINTER, myPrinter);
                    String curConnectInfo = WiFiDirectManager.getCurConnectInfo(this, MacAddrUtils.getMacAddressFromPrinterId(myPrinter.getPrinterId()));
                    if (this.printer_location != 1 || curConnectInfo == null) {
                        intent3.putExtra(EXTRA_SIMPLEAP, "");
                    } else {
                        intent3.putExtra(EXTRA_SIMPLEAP, curConnectInfo);
                    }
                    intent.getBooleanExtra(ActivityiPrintConnect.FINISH_EAYSETUP, false);
                    setResult(-1, intent3);
                    finish();
                    return;
                }
                isFocused = true;
                mIsClickSelect = false;
                return;
            case 11:
                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);
                    Intent intent4 = new Intent();
                    intent4.putExtra(EXTRA_PRINTER, myPrinter2);
                    setResult(-1, intent4);
                    finish();
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void search() {
        interruptSearch();
        synchronized (mLock) {
            printerList.clear();
            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(14, 5000);
            isSearchSimpleAp = true;
        } else if (WiFiDirectManager.isWifiEnabled(this)) {
            mHandler.sendEmptyMessage(14);
            isSearchSimpleAp = true;
        } else {
            boolean z = bCheckWiFiStatus;
            if (!z && !z) {
                bCheckWiFiStatus = true;
                WiFiDirectManager.enableWiFi(this, -1);
                return;
            }
        }
        WiFiDirectManager.setPriorityToSimpleAP(this, true);
        if (this.mEpsonService != null) {
            try {
                synchronized (mLock) {
                    isFinishSearchPrinter = false;
                }
                mEpsonService.searchPrinters((String) null, (String) null, 1);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            mHandler.sendEmptyMessageDelayed(1, 100);
        }
    }

    private void interruptSearch() {
        EPLog.d(TAG, "interruptSearch()");
        mHandler.removeMessages(1);
        mHandler.removeMessages(14);
        mHandler.removeMessages(3);
        mHandler.removeMessages(9);
        mHandler.removeMessages(13);
        SearchWiFiDirectPrinterTask searchWiFiDirectPrinterTask = searchWiFiDirectPrinter;
        if (searchWiFiDirectPrinterTask != null) {
            searchWiFiDirectPrinterTask.interrupt();
            searchWiFiDirectPrinter = null;
        }
        isSearchSimpleAp = false;
        IEpsonService iEpsonService = mEpsonService;
        if (iEpsonService != null) {
            try {
                iEpsonService.cancelSearchPrinter();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
        WorkingDialog workingDialog = progress;
        if (workingDialog != null && workingDialog.isShowing()) {
            progress.dismiss();
        }
        isFocused = true;
    }

    public void displaySearchResult() {
        if (!this.mIsClickSelect) {
            if (this.mBuilder.getData().size() <= 0) {
                ((TextView) mLayout.findViewById(R.id.empty)).setText(getString(R.string.EPS_PRNERR_COMM_TITLE1));
            } 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(this.mBuilder.getData().size())}));
            }
        }
        mBuilder.getAdapter().notifyDataSetChanged();
        mProgressBar.setVisibility(8);
        searchButtonSetEnabled(true);
        isFinishSearchPrinter = true;
    }

    private DialogFragment getPrinterNotFoundDialog() {
        String str;
        boolean prefBoolean = Utils.getPrefBoolean(getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH);
        int i = R.string.EPS_PRNERR_COMM_TITLE4;
        if (prefBoolean) {
            curError = -11001;
            String ssid = Utils.getSSID(this);
            if (!Utils.isConnectedWifi(this) || ssid == null) {
                return CustomLayoutDialogFragment.newInstance(1, getString(R.string.EPS_PRNERR_COMM4), (int) R.string.EPS_PRNERR_COMM_TITLE4, 0, (int) R.string.str_btn_close);
            }
            str = String.format(getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_RESEARCH2), new Object[]{ssid});
        } else {
            curError = -1100;
            i = R.string.EPS_PRNERR_COMM_TITLE1;
            str = getString(R.string.EPS_PRNERR_COMM1);
        }
        return CustomLayoutDialogFragment.newInstance(1, str + "\n\n" + getString(R.string.confirm_browse_wlan_setup_info), i, (int) R.string.browse_site, (int) R.string.str_btn_close);
    }

    private void showPrinterNotFoundDialog(DialogFragment dialogFragment) {
        if (this.mActivityForegroundLifetime) {
            dialogFragment.show(getSupportFragmentManager(), DIALOG_TAG_PRINTER_NOT_FOUND);
        }
    }

    protected Dialog onCreateDialog(int i) {
        if (i != 0) {
            return null;
        }
        EPLog.i(TAG, "DIALOG_INFORM curError = " + curError);
        int i2 = curError;
        if (i2 == -1100 || i2 == -11001) {
            if (Utils.getPrefBoolean(getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH)) {
                curError = -11001;
            } else {
                curError = -1100;
            }
        }
        Integer[] stringId = MediaInfo.ErrorTable.getStringId(this.curError);
        if (stringId == null) {
            stringId = new Integer[]{Integer.valueOf(R.string.NOT_IMPLEMENT), Integer.valueOf(R.string.NOT_IMPLEMENT_TITLE)};
        }
        String string = getString(stringId[0].intValue());
        String ssid = Utils.getSSID(this);
        if (Utils.isConnectedWifi(this) && curError == -11001 && ssid != null) {
            string = String.format(getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_RESEARCH), new Object[]{ssid});
        }
        return new CustomTitleAlertDialogBuilder(this).setTitle((CharSequence) getString(stringId[1].intValue())).setMessage(string).setCancelable(false).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                SearchPrinterScr.this.removeDialog(0);
                boolean unused = SearchPrinterScr.this.isDialogOpen = false;
            }
        }).create();
    }

    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:3:0x0004 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void removeAllDialog() {
        /*
            r1 = this;
            r0 = 0
            r1.removeDialog(r0)     // Catch:{ IllegalArgumentException -> 0x0004 }
        L_0x0004:
            r1.dismissPrinterNotFoundDialog()     // Catch:{ Exception -> 0x0007 }
        L_0x0007:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.screen.SearchPrinterScr.removeAllDialog():void");
    }

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

    private void unbindEpsonService() {
        if (this.mEpsonService != null) {
            if (!this.isFinishSearchPrinter) {
                mHandler.sendEmptyMessageDelayed(2, 200);
            }
            try {
                mEpsonService.unregisterCallback(this.mCallback);
                unbindService(this.mEpsonConnection);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

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

    public void onLocalNegativeCallback(int i) {
        isDialogOpen = false;
    }
}
