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.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 androidx.fragment.app.DialogFragment;

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 java.util.ArrayList;
import java.util.Locale;

import epson.common.Constants;
import epson.common.ExternalFileUtils;
import epson.common.Utils;
import epson.print.ActivityIACommon;
import epson.print.CustomTitleDialogFragment;
import epson.print.EPPrinterManager;
import epson.print.MyPrinter;
import epson.print.R;
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;

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() {
        public boolean handleMessage(android.os.Message r8) {
            throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.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(View.GONE);
            ((TextView) mLayout.findViewById(R.id.empty)).setVisibility(View.GONE);
        }
        setNotFoundPrinterButton();
        setBleWifiSetupButton();
        setActionBar(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(View.GONE);
        mBleButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                interruptSearch();
                BleAsyncTask.blePrinterCheckStop();
                Intent intent = new Intent(getApplicationContext(), BleWorkActivity.class);
                intent.putParcelableArrayListExtra(ScannedDevice.TYPE, (ArrayList) mBleButton.getTag());
                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;
                startActivity(PrinterNotFoundDialogCreator.getStartIntent(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) {
                startWifiPrinterSelect();
            }
        });
    }

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

    private void addAboutRemoteButton() {
        mAboutRemoteButton = mLayout.findViewById(R.id.AboutRemoteFrame);
        mAboutRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                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(View.VISIBLE);
        mAddButton.setVisibility(View.GONE);
        mTextDetail.setVisibility(View.VISIBLE);
        mWiFiSettingButton.setVisibility(View.VISIBLE);
        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(View.GONE);
                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(View.VISIBLE);
                RelativeLayout relativeLayout = mBleButton;
                if (!(relativeLayout == null || relativeLayout.getTag() == null)) {
                    mBleButton.setVisibility(View.VISIBLE);
                    break;
                }
            case 2:
                mAddButton.setVisibility(View.VISIBLE);
                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(View.GONE);
                mWiFiSettingButton.setVisibility(View.GONE);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(View.GONE);
                RelativeLayout relativeLayout2 = mBleButton;
                if (relativeLayout2 != null) {
                    relativeLayout2.setVisibility(View.GONE);
                    break;
                }
                break;
            case 3:
                mAddButton.setVisibility(View.VISIBLE);
                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(View.GONE);
                mWiFiSettingButton.setVisibility(View.GONE);
                mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(View.GONE);
                RelativeLayout relativeLayout3 = mBleButton;
                if (relativeLayout3 != null) {
                    relativeLayout3.setVisibility(View.GONE);
                    break;
                }
                break;
        }
        mBuilder.build();
        mBuilder.refresh();
        mListView.setEmptyView(textView);
        if (this.printer_location == 2) {
            mAboutRemoteButton.setVisibility(View.VISIBLE);
        } else {
            mAboutRemoteButton.setVisibility(View.GONE);
        }
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (isFocused.booleanValue()) {
                    Boolean unused = isFocused = false;
                    MaintainPrinterSearchActivity maintainPrinterSearchActivity = MaintainPrinterSearchActivity.this;
                    mIsClickSelect = true;
                    Message obtainMessage = mHandler.obtainMessage();
                    obtainMessage.obj = mBuilder.getData().elementAt(i);
                    int access$400 = printer_location;
                    if (access$400 == 1) {
                        String ip = ((MyPrinter) obtainMessage.obj).getIp();
                        if (!WiFiControl.ConnectType.NONE.equals(WiFiDirectManager.getConnectType(this, ip))) {
                            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();
                    mHandler.sendMessageDelayed(obtainMessage, 100);
                }
            }
        });
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (printer_location == 1) {
                    return true;
                }
                int unused = mDeletePos = i;
                MaintainPrinterSearchActivity maintainPrinterSearchActivity = MaintainPrinterSearchActivity.this;
                registerForContextMenu(mListView);
                return false;
            }
        });
        mAddButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                switch (printer_location) {
                    case 2:
                        if (mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(mContext).setCancelable(false).setTitle(getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).show();
                            return;
                        } else if (getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).getBoolean(Constants.ENABLE_SHOW_WARNING, true)) {
                            AlertDialog.Builder cancelable = new AlertDialog.Builder(mContext).setCancelable(false);
                            cancelable.setMessage(getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(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;
                                    mHandler.sendMessage(message);
                                }
                            }).setNegativeButton(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;
                            mHandler.sendMessage(message);
                            return;
                        }
                    case 3:
                        if (mBuilder.getData().size() >= 32) {
                            new AlertDialog.Builder(mContext).setCancelable(false).setTitle(getString(R.string.epsonconnect_err_regist_remote_printer_max_size_title)).setMessage(getString(R.string.epsonconnect_err_regist_remote_printer_max_size)).setPositiveButton(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;
                        mHandler.sendMessage(message2);
                        return;
                    default:
                        return;
                }
            }
        });
        mSearchButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (printer_location == 1) {
                    mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mLocalButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (printer_location != 1) {
                    mAddButton.setVisibility(View.GONE);
                    ((TextView) mLayout.findViewById(R.id.empty)).setVisibility(View.VISIBLE);
                    interruptSearch();
                    int unused = printer_location = 1;
                    buildElements();
                    mHandler.sendEmptyMessageDelayed(1, 100);
                }
            }
        });
        mRemoteButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (printer_location != 2) {
                    int unused = printer_location = 2;
                    interruptSearch();
                    ((TextView) mLayout.findViewById(R.id.empty)).setVisibility(View.GONE);
                    mBuilder.refresh();
                    buildElements();
                    displaySearchResult();
                    mSearchButton.setVisibility(View.GONE);
                }
            }
        });
        mIpButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (printer_location != 3) {
                    int unused = printer_location = 3;
                    interruptSearch();
                    ((TextView) mLayout.findViewById(R.id.empty)).setVisibility(View.GONE);
                    mBuilder.refresh();
                    buildElements();
                    displaySearchResult();
                    mSearchButton.setVisibility(View.GONE);
                }
            }
        });
    }

    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.drawable.delete_file)).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Message obtainMessage = mHandler.obtainMessage();
                        obtainMessage.what = 6;
                        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.i(TAG, "onResume()");
        dismissPrinterNotFoundDialog();
        if (this.printer_location == 1) {
            mHandler.sendEmptyMessageDelayed(1, 300);
            EPLog.d(TAG, "Send CHECK_PRINTER Message.");
        }
        if (this.printer_location == 1 && mBleButton.getTag() == null && BleWork.isStartBleProcess(this, false)) {
            EPLog.e("blePrinterCheck");
            callBackFuncs();
            BleAsyncTask.blePrinterCheck(this, mBleFind);
        }
    }

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

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

    protected void onStop() {
        EPLog.i();
        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.i();
                finish();
                return;
            default:
                return;
        }
    }

    private void search() {
        interruptSearch();
        synchronized (mLock) {
            mBuilder.refresh();
            wiFiDirectPrinterListUtils.clearPrinterInfoList();
        }
        mIsClickSelect = false;
        isFinishSearchPrinter = false;
        searchButtonSetEnabled(false);
        mProgressBar.setVisibility(View.VISIBLE);
        ((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 (mLock) {
                    boolean unused = isFinishSearchPrinter = false;
                }
                mPrinter.doFindPrinter(EPS_PROTOCOL_ALL, 60);
                if (!isFinishSearchPrinter) {
                    synchronized (mLock) {
                        boolean unused2 = isFinishSearchPrinter = true;
                        if (!isSearchSimpleAp) {
                            mHandler.sendEmptyMessage(5);
                        }
                    }
                }
            }
        };
        mSearchThread.start();
    }

    public void interruptSearch() {
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.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(View.GONE);
        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();
        }
    }

    public void removeAllDialog() {
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.removeAllDialog():void");
    }

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

    private 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.d(" ★★　mDevicelist " + arrayList.size());
                if (printer_location == 1) {
                    mBleButton.setVisibility(View.VISIBLE);
                }
                mBleButton.setTag(arrayList);
            }
        };
    }
}
