package epson.maintain.activity;

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.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProviders;

import com.epson.iprint.prtlogger.Analytics;
import com.epson.mobilephone.common.escpr.MediaInfo;
import com.epson.mobilephone.common.maintain2.BatteryInfoEx;
import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
import com.epson.mobilephone.common.maintain2.MaintainPrinterInfo2;
import com.epson.mobilephone.common.wifidirect.MacAddrUtils;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;

import java.util.Arrays;

import epson.common.Constants;
import epson.common.DialogProgress;
import epson.common.EventWrapper;
import epson.common.IPAddressUtils;
import epson.common.Utils;
import epson.epsonconnectregistration.ActivityECConfiguration;
import epson.maintain.BatteryInfoAdapter;
import epson.print.ActivityIACommon;
import epson.print.CommonDefine;
import epson.print.MyPrinter;
import epson.print.R;
import epson.print.Util.AsyncTaskExecutor;
import epson.print.Util.EPLog;
import epson.print.inkrpln.InkRplnInfoClient;
import epson.print.inkrpln.InkRplnProgressDialog;
import epson.print.inkrpln.InkRplnRepository;
import epson.print.inkrpln.JumpUrlProgressActivity;
import epson.print.screen.WorkingDialog;
import epson.print.service.EpsonService;
import epson.print.service.IEpsonService;
import epson.print.service.IEpsonServiceCallback;

public class MaintainActivity extends ActivityIACommon implements View.OnClickListener, MediaInfo {
    private static final int CANCEL_LOADCONFIG = 14;
    private static final int CLEANING_ERROR = 10;
    private static final int DELAY_TIME_MAINTAIN = 10;
    private static final String DIALOG_PROGRESS = "dialog_progress";
    private static final String DIALOG_TAG_NOZZLE_GUIDANCE = "dialog_nozzle_guidance";
    private static final int EC_BUTTON_HIDE = 2;
    private static final int EC_BUTTON_INVALID = 1;
    private static final int EC_BUTTON_VALID = 0;
    private static final int EPS_COMM_BID = 2;
    private static final int EPS_ERR_COMM_ERROR = -1100;
    private static final int EPS_LANG_ESCPR = 1;
    private static final int EPS_MNT_CLEANING = 2;
    private static final int EPS_MNT_NOZZLE = 3;
    private static final int EPS_PRNERR_CEMPTY = 103;
    private static final int EPS_PRNERR_CFAIL = 104;
    private static final int EPS_PRNERR_COMM = 102;
    private static final int EPS_PRNERR_DISABEL_CLEANING = 108;
    private static final int EPS_PRNERR_INKOUT = 6;
    private static final String[] GAGA_DEVICE_ID_ARRAY = {"LX-10000F", "LX-7000F", "WF-C20590 Series", "WF-C17590 Series", "LX-10000FK", "LX-10010MF", "WF-M20590 Series", "LX-10050KF", "LX-10050MF", "LX-6050MF", "LX-7550MF", "WF-C20600 Series", "WF-C20750 Series", "WF-C21000 Series"};
    private static final int GET_PRINTER_NAME = 8;
    private static final int HANDLE_ERROR = 4;
    public static final int ITEM_HEIGHT = 40;
    private static final int LOGIN_STATUS_COMM_ERROR = -1;
    private static final int LOGIN_STATUS_LOGIN_FAILED = -2;
    private static final int LOGIN_STATUS_LOGIN_SUCCEEDED = 0;
    private static final int MAINTAIN_OK = 1;
    private static final int MAINTAIN_START = 0;
    private static final int MAX_WAIT_CONNECTING_3G = 10;
    private static final int MESSAGE_MAINTENANCE_BOX_INFO = 16;
    private static final int NO_PRINTER_NAME = 9;
    private static final String PREFS_NAME = "PrintSetting";
    private static final int PROBE_ERROR = 7;
    private static final String PROBE_RESULT = "PROBE_ERROR";
    private static final int REQUEST_CODE_INK_DS_DIALOG = 100;
    private static final int REQUEST_CODE_SELECT_PRINTER = 101;
    private static final int START_LOADCONFIG = 6;
    private static final String TAG = "MAINTAIN";
    private static final int UPDATE_BATTERY = 15;
    private static final int UPDATE_INK = 3;
    private static final int UPDATE_MAINTENANCE_LABEL = 11;
    private static final int UPDATE_SELECTED_PRINTER = 5;
    private static final int UPDATE_STT = 2;
    private static boolean isMessageScreenShowing = false;
    private Switch btnToggleAlert;
    private Switch btnTogglePreview;
    private Dialog customPro;
    private int escprSetPrinterSuccessed = -1;
    private boolean isGotError = false;
    private boolean isKeepSimpleAPConnection = false;
    private boolean isRemotePrinter = false;
    boolean isResearchScanner = false;
    private boolean isTryConnectSimpleAp = false;
    private View mAlertMesseageSeparater;
    private LinearLayout mAlertMesseageView;
    private Thread mBackGround;
    private LinearLayout mBuyInkGroup;
    private int mBuyInkGroupVisibility;
    private View mBuyInkSeparator;
    private LinearLayout mBuyInkView;
    private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
        public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
        }

        public void onGetInkState() throws RemoteException {
        }

        public void onGetStatusState() throws RemoteException {
        }

        public void onNotifyContinueable(int i) throws RemoteException {
        }

        public void onNotifyEndJob(int i) throws RemoteException {
        }

        public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
        }

        public void onNotifyProgress(int i, int i2) throws RemoteException {
        }
    };
    private LinearLayout mCleanCheckView;
    private Context mContext = null;
    private Display mDisplay;
    private Thread mDoMaintainThread;
    private LinearLayout mEpsonConnectView;
    private ServiceConnection mEpsonConnection = new ServiceConnection() {
        public void onServiceDisconnected(ComponentName componentName) {
            try {
                MaintainActivity.mEpsonService.unregisterCallback(MaintainActivity.mCallback);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            IEpsonService unused = MaintainActivity.mEpsonService = null;
        }

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IEpsonService unused = MaintainActivity.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
            if (MaintainActivity.mEpsonService != null) {
                try {
                    MaintainActivity.mEpsonService.registerCallback(MaintainActivity.mCallback);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    private IEpsonService mEpsonService = null;
    private TextView mFWUpdateText;
    private LinearLayout mFWUpdateView;
    boolean mHavePrinter = false;
    private TextView mHeadCleanText;
    private LinearLayout mHeadCleanView;
    private LinearLayout mInkDsView;
    private LinearLayout mInkView;
    private volatile boolean mIsCancelProbe = false;
    private Boolean mIsNozzleCheckEnable = true;
    private volatile boolean mIsStillUpdate = true;
    boolean mIsStop = false;
    private LinearLayout mLLSerialNo;
    private View mLoadConPro;
    private Thread mLoadConfigThread;
    private TextView mMaintenanceBoxText;
    private LinearLayout mMaintenanceBoxView;
    private TextView mNozzleCheckText;
    private LinearLayout mNozzleCheckView;
    private View mOnlineRegistrationSeparator;
    private LinearLayout mOnlineRegistrationView;
    private View mPrintHistorySeparator;
    private LinearLayout mPrintHistoryView;
    private LinearLayout mPrintPreviewView;
    private MaintainPrinter2 mPrinter = MaintainPrinter2.getInstance();
    private View mPrinterSettingSeparator;
    private LinearLayout mPrinterSettingView;
    private int[] mPrinterStatus;
    boolean mStartSearch = false;
    private TextView mTextMaintenance;
    private TextView mTvPrinterName;
    private TextView mTvPrinterStatus;
    private TextView mTvPrinterStatusDetail;
    private TextView mTvSerialNo;
    private Handler mUiHandler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case 0:
                    MaintainActivity.this.showProDia();
                    break;
                case 1:
                    EPLog.i("Maintain", "********Maintain finish********");
                    MaintainActivity.this.interrupMaintainThread();
                    MaintainActivity.this.cancelProDia();
                    break;
                case 2:
                    MaintainActivity.this.updateStatus(message.getData().getInt("GET_STT_RESULT"));
                    break;
                case 3:
                    MaintainActivity.this.updateInkInfo(message.getData().getInt("GET_INK_RESULT"));
                    break;
                case 4:
                    MaintainActivity.this.interrupMaintainThread();
                    break;
                case 5:
                    MaintainActivity.this.updateSelectedPrinter();
                    break;
                case 6:
                    MaintainActivity.this.showLoadProgressBar();
                    MaintainActivity.this.setButtonClickable(false);
                    MaintainActivity.this.setEpsonConnectButton(1);
                    break;
                case 7:
                    MaintainActivity.this.handlerError(message.getData().getInt(MaintainActivity.PROBE_RESULT), true);
                    break;
                case 8:
                    MaintainActivity.mTvPrinterName.setText(MaintainActivity.this.printerName);
                    switch (MaintainActivity.this.printerLocation) {
                        case 2:
                            ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setVisibility(View.VISIBLE);
                            ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.drawable.print_remote);
                            break;
                        case 3:
                            ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setVisibility(View.VISIBLE);
                            ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.drawable.print_ip);
                            break;
                        default:
                            if (!MaintainActivity.this.printerName.equals("")) {
                                ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setVisibility(View.VISIBLE);
                                ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.drawable.print_local);
                                break;
                            } else {
                                ((ImageView) MaintainActivity.this.findViewById(R.id.imageViewPrinterLocation)).setVisibility(View.GONE);
                                break;
                            }
                    }
                case 9:
                    MaintainActivity.mUiHandler.sendEmptyMessage(11);
                    MaintainActivity.this.hideLoadProgressBar();
                    MaintainActivity.this.stopLoadConfigThread();
                    break;
                case 10:
                    MaintainActivity.this.setupErrorMessage(10);
                    MaintainActivity.this.interrupMaintainThread();
                    break;
                case 11:
                    MaintainActivity.this.updateButton();
                    break;
                case 14:
                    MaintainActivity.this.hideLoadProgressBar();
                    break;
                case 15:
                    MaintainActivity.this.updateBatteryInfoEx(message.getData().getInt("GET_BATTERY_RESULT"), (BatteryInfoEx) message.getData().getParcelable("GET_BATTERY_INFO"));
                    break;
                case 16:
                    MaintainActivity.this.updateMaintenanceBoxInfo((int[]) message.obj);
                    break;
            }
            return false;
        }
    });
    private View mVSerialSeparator;
    private boolean mWaiteInkDsDialog;
    private MaintainBuyInkOnlineRegTask modelBuyInkOnlineRegTask;
    private String printerId = "";
    private String printerIp = "";
    private int printerLocation = 1;
    private String printerName = "";
    private int serverLoginStatus = -2;

    private static int calcInkWidth(int i, float f) {
        if (i <= 0) {
            i = 1;
        } else if (i > 100) {
            i = 100;
        }
        int i2 = ((f / 100.0f) * ((float) i));
        if (i2 > 0) {
            return i2;
        }
        return 1;
    }

    private boolean isMaintenanceBoxStatusDisplayX(int i) {
        switch (i) {
            case -2:
            case -1:
                return true;
            default:
                return false;
        }
    }

    protected void onCreate(Bundle bundle) {
        EPLog.i(TAG, "onCreate IN");
        super.onCreate(bundle);
        setContentView(R.layout.maintain);
        mContext = this;
        mBuyInkGroupVisibility = 0;
        setActionBar(R.string.str_maintenance, true);
        if (mEpsonService == null) {
            bindService(new Intent(this, EpsonService.class), mEpsonConnection, 1);
        }
        mDisplay = getWindowManager().getDefaultDisplay();
        findViewById(R.id.printer).setOnClickListener(this);
        mTvPrinterName = (TextView) findViewById(R.id.printer_name);
        mVSerialSeparator = findViewById(R.id.serial_separator);
        mLLSerialNo = (LinearLayout) findViewById(R.id.serial);
        mTvSerialNo = (TextView) findViewById(R.id.serial_no);
        mTvPrinterStatus = (TextView) findViewById(R.id.printer_status);
        mTvPrinterStatusDetail = (TextView) findViewById(R.id.printer_status_detail);
        mTextMaintenance = (TextView) findViewById(R.id.text_maintenance);
        mInkView = (LinearLayout) findViewById(R.id.ink_view_ln);
        mMaintenanceBoxText = (TextView) findViewById(R.id.maintenance_box_text);
        mMaintenanceBoxView = (LinearLayout) findViewById(R.id.maintenance_box_info_layout);
        mCleanCheckView = (LinearLayout) findViewById(R.id.clean_check);
        mHeadCleanView = (LinearLayout) findViewById(R.id.head_clean_view);
        mHeadCleanView.setOnClickListener(this);
        mHeadCleanText = (TextView) findViewById(R.id.head_clean_text);
        mNozzleCheckView = (LinearLayout) findViewById(R.id.nozzle_check_view);
        mNozzleCheckView.setOnClickListener(this);
        mNozzleCheckText = (TextView) findViewById(R.id.nozzle_check_text);
        mFWUpdateView = (LinearLayout) findViewById(R.id.fwupdate_view);
        mFWUpdateView.setOnClickListener(this);
        mFWUpdateText = (TextView) findViewById(R.id.fwupdate_text);
        btnTogglePreview = (Switch) findViewById(R.id.togglePreview);
        btnTogglePreview.setOnClickListener(this);
        btnToggleAlert = (Switch) findViewById(R.id.toggleAlert);
        btnToggleAlert.setOnClickListener(this);
        mPrinterSettingView = (LinearLayout) findViewById(R.id.printer_setting);
        mPrinterSettingView.setOnClickListener(this);
        mEpsonConnectView = (LinearLayout) findViewById(R.id.epsonconnect_option);
        mEpsonConnectView.setOnClickListener(this);
        mPrintHistoryView = (LinearLayout) findViewById(R.id.print_history);
        mPrintHistoryView.setOnClickListener(this);
        mOnlineRegistrationView = (LinearLayout) findViewById(R.id.online_registration);
        mOnlineRegistrationView.setOnClickListener(this);
        mBuyInkGroup = (LinearLayout) findViewById(R.id.mentenance_buy_ink_frame);
        mBuyInkView = (LinearLayout) findViewById(R.id.mentenance_buy_ink);
        mBuyInkView.setOnClickListener(this);
        mBuyInkSeparator = findViewById(R.id.buy_ink_separator);
        mInkDsView = (LinearLayout) findViewById(R.id.maintenance_inkds);
        mInkDsView.setOnClickListener(this);
        mPrintPreviewView = (LinearLayout) findViewById(R.id.print_preview);
        mAlertMesseageView = (LinearLayout) findViewById(R.id.alert_messeage);
        mPrinterSettingSeparator = findViewById(R.id.printer_setting_separator);
        mPrintHistorySeparator = findViewById(R.id.print_history_separator);
        mOnlineRegistrationSeparator = findViewById(R.id.online_registration_separator);
        mAlertMesseageSeparater = findViewById(R.id.comm_messeage_separator);
        mPrinterSettingView.setEnabled(false);
        ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
        ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
        mVSerialSeparator.setVisibility(View.GONE);
        mLLSerialNo.setVisibility(View.GONE);
        EPLog.i(TAG, "onCreate :: doInitDriver");
        mPrinter.doInitDriver(this, 2);
        isResearchScanner = Utils.getPrefBoolean(getApplicationContext(), Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_RESEACH);
        if (MyPrinter.getCurPrinter(this).getName() == null) {
            startSelectPrinterActivity();
        }
        mWaiteInkDsDialog = false;
        modelBuyInkOnlineRegTask = (MaintainBuyInkOnlineRegTask) ViewModelProviders.m2of((FragmentActivity) this).get(MaintainBuyInkOnlineRegTask.class);
        modelBuyInkOnlineRegTask.getUriEvent().observe(this, new Observer() {
            public final void onChanged(Object obj) {
                MaintainActivity.lambda$onCreate$0(MaintainActivity.this, (EventWrapper) obj);
            }
        });
    }

    public static /* synthetic */ void lambda$onCreate$0(MaintainActivity maintainActivity, EventWrapper eventWrapper) {
        if (!eventWrapper.hasBeenHandled()) {
            maintainActivity.dismissDialog(DIALOG_PROGRESS);
            maintainActivity.startActivity(new Intent("android.intent.action.VIEW", (Uri) eventWrapper.getEventContent()));
        }
    }

    private void startLoadConThread() {
        mIsCancelProbe = false;
        mLoadConfigThread = new Thread(new Runnable() {
            /* JADX WARNING: Code restructure failed: missing block: B:83:0x01e6, code lost:
                return;
             */
            /* Code decompiled incorrectly, please refer to instructions dump. */
            public synchronized void run() {
                /*
                    r8 = this;
                    monitor-enter(r8)
                    java.lang.String r0 = "MAINTAIN"
                    java.lang.String r1 = "new load Config thread"
                    epson.print.Util.EPLog.i(r0, r1)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r1 = 6
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    r0 = 500(0x1f4, double:2.47E-321)
                    java.lang.Thread.sleep(r0)     // Catch:{ InterruptedException -> 0x01e7 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    r0.loadConfig()     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r1 = 8
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r0 = r0.mIsCancelProbe     // Catch:{ all -> 0x01f0 }
                    if (r0 == 0) goto L_0x0034
                    r8.hideLoadProgress()     // Catch:{ all -> 0x01f0 }
                    monitor-exit(r8)
                    return
                L_0x0034:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r2 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r2 = epson.print.MyPrinter.isRemotePrinter(r2)     // Catch:{ all -> 0x01f0 }
                    boolean unused = r0.isRemotePrinter = r2     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r0 = r0.isRemotePrinter     // Catch:{ all -> 0x01f0 }
                    r2 = -1
                    r3 = 0
                    r4 = 1
                    if (r0 != r4) goto L_0x00ae
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    r1 = -2
                    int unused = r0.serverLoginStatus = r1     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    r0 = 0
                L_0x0051:
                    epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    epson.print.service.IEpsonService r5 = r5.mEpsonService     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    if (r5 != 0) goto L_0x006b
                    epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    boolean r5 = r5.mIsCancelProbe     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    if (r5 != 0) goto L_0x006b
                    r5 = 100
                    java.lang.Thread.sleep(r5)     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    int r0 = r0 + r4
                    r5 = 10
                    if (r0 < r5) goto L_0x0051
                L_0x006b:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    epson.print.service.IEpsonService r0 = r0.mEpsonService     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    if (r0 == 0) goto L_0x009e
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    epson.print.service.IEpsonService r0 = r0.mEpsonService     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    int r0 = r0.ensureLogin(r4)     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    if (r0 != 0) goto L_0x0085
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    int unused = r0.serverLoginStatus = r3     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    goto L_0x009e
                L_0x0085:
                    r3 = -1100(0xfffffffffffffbb4, float:NaN)
                    if (r0 != r3) goto L_0x008f
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    int unused = r0.serverLoginStatus = r2     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    goto L_0x009e
                L_0x008f:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    int unused = r0.serverLoginStatus = r1     // Catch:{ InterruptedException -> 0x009a, RemoteException -> 0x0095 }
                    goto L_0x009e
                L_0x0095:
                    r0 = move-exception
                    r0.printStackTrace()     // Catch:{ all -> 0x01f0 }
                    goto L_0x009e
                L_0x009a:
                    r0 = move-exception
                    r0.printStackTrace()     // Catch:{ all -> 0x01f0 }
                L_0x009e:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r1 = 11
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    r8.hideLoadProgress()     // Catch:{ all -> 0x01f0 }
                    monitor-exit(r8)
                    return
                L_0x00ae:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r0 = r0.mIsCancelProbe     // Catch:{ all -> 0x01f0 }
                    if (r0 == 0) goto L_0x00bb
                    r8.hideLoadProgress()     // Catch:{ all -> 0x01f0 }
                    monitor-exit(r8)
                    return
                L_0x00bb:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r0 = r0.printerId     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = ""
                    boolean r0 = r0.equals(r5)     // Catch:{ all -> 0x01f0 }
                    if (r0 != 0) goto L_0x01cf
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r0 = r0.printerName     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = ""
                    boolean r0 = r0.equals(r5)     // Catch:{ all -> 0x01f0 }
                    if (r0 != 0) goto L_0x01cf
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    int r0 = r0.printerLocation     // Catch:{ all -> 0x01f0 }
                    if (r0 != r4) goto L_0x0108
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = "printer"
                    boolean r0 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.isNeedConnect(r0, r5)     // Catch:{ all -> 0x01f0 }
                    if (r0 != 0) goto L_0x00ef
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean unused = r0.isTryConnectSimpleAp = r3     // Catch:{ all -> 0x01f0 }
                    goto L_0x0108
                L_0x00ef:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r0 = r0.isTryConnectSimpleAp     // Catch:{ all -> 0x01f0 }
                    if (r0 != 0) goto L_0x0108
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean unused = r0.isTryConnectSimpleAp = r4     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = "printer"
                    boolean r0 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.reconnect(r0, r5, r2)     // Catch:{ all -> 0x01f0 }
                    if (r0 == 0) goto L_0x0108
                    monitor-exit(r8)
                    return
                L_0x0108:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    java.lang.String r0 = "startLoadConThread"
                    java.lang.String r1 = "mPrinter.doProbePrinter"
                    epson.print.Util.EPLog.i(r0, r1)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    com.epson.mobilephone.common.maintain2.MaintainPrinter2 r0 = r0.mPrinter     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r1 = r1.printerId     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = r5.printerIp     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r6 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    int r6 = r6.printerLocation     // Catch:{ all -> 0x01f0 }
                    r7 = 60
                    int r0 = r0.doProbePrinter(r7, r1, r5, r6)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    int unused = r1.escprSetPrinterSuccessed = r2     // Catch:{ all -> 0x01f0 }
                L_0x013b:
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    boolean r1 = r1.mIsCancelProbe     // Catch:{ InterruptedException -> 0x018e }
                    if (r1 != 0) goto L_0x0192
                    if (r0 != 0) goto L_0x0146
                    goto L_0x0192
                L_0x0146:
                    android.os.Message r1 = new android.os.Message     // Catch:{ InterruptedException -> 0x018e }
                    r1.<init>()     // Catch:{ InterruptedException -> 0x018e }
                    r2 = 7
                    r1.what = r2     // Catch:{ InterruptedException -> 0x018e }
                    android.os.Bundle r2 = new android.os.Bundle     // Catch:{ InterruptedException -> 0x018e }
                    r2.<init>()     // Catch:{ InterruptedException -> 0x018e }
                    java.lang.String r5 = "PROBE_ERROR"
                    r2.putInt(r5, r0)     // Catch:{ InterruptedException -> 0x018e }
                    r1.setData(r2)     // Catch:{ InterruptedException -> 0x018e }
                    epson.maintain.activity.MaintainActivity r2 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    android.os.Handler r2 = r2.mUiHandler     // Catch:{ InterruptedException -> 0x018e }
                    r2.sendMessage(r1)     // Catch:{ InterruptedException -> 0x018e }
                    r1 = 4000(0xfa0, double:1.9763E-320)
                    java.lang.Thread.sleep(r1)     // Catch:{ InterruptedException -> 0x018e }
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    boolean r1 = r1.mIsCancelProbe     // Catch:{ InterruptedException -> 0x018e }
                    if (r1 != 0) goto L_0x013b
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    com.epson.mobilephone.common.maintain2.MaintainPrinter2 r1 = r1.mPrinter     // Catch:{ InterruptedException -> 0x018e }
                    epson.maintain.activity.MaintainActivity r2 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    java.lang.String r2 = r2.printerId     // Catch:{ InterruptedException -> 0x018e }
                    epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    java.lang.String r5 = r5.printerIp     // Catch:{ InterruptedException -> 0x018e }
                    epson.maintain.activity.MaintainActivity r6 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x018e }
                    int r6 = r6.printerLocation     // Catch:{ InterruptedException -> 0x018e }
                    int r0 = r1.doProbePrinter(r7, r2, r5, r6)     // Catch:{ InterruptedException -> 0x018e }
                    goto L_0x013b
                L_0x018e:
                    r1 = move-exception
                    r1.printStackTrace()     // Catch:{ all -> 0x01f0 }
                L_0x0192:
                    java.lang.String r1 = "MAINTAIN"
                    java.lang.StringBuilder r2 = new java.lang.StringBuilder     // Catch:{ all -> 0x01f0 }
                    r2.<init>()     // Catch:{ all -> 0x01f0 }
                    java.lang.String r5 = "Probe Printer result: "
                    r2.append(r5)     // Catch:{ all -> 0x01f0 }
                    r2.append(r0)     // Catch:{ all -> 0x01f0 }
                    java.lang.String r2 = r2.toString()     // Catch:{ all -> 0x01f0 }
                    epson.print.Util.EPLog.i(r1, r2)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r1 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    boolean r1 = r1.mIsCancelProbe     // Catch:{ all -> 0x01f0 }
                    if (r1 != 0) goto L_0x01e5
                    if (r0 != 0) goto L_0x01e5
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    com.epson.mobilephone.common.maintain2.MaintainPrinter2 r0 = r0.mPrinter     // Catch:{ all -> 0x01f0 }
                    r0.setMSearchPos(r3)     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    int unused = r0.escprSetPrinterSuccessed = r3     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    r0.mHavePrinter = r4     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r1 = 5
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    goto L_0x01e5
                L_0x01cf:
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    r0.mHavePrinter = r3     // Catch:{ all -> 0x01f0 }
                    epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this     // Catch:{ all -> 0x01f0 }
                    android.os.Handler r0 = r0.mUiHandler     // Catch:{ all -> 0x01f0 }
                    r1 = 9
                    r0.sendEmptyMessage(r1)     // Catch:{ all -> 0x01f0 }
                    java.lang.String r0 = "MAINTAIN"
                    java.lang.String r1 = "not select printer"
                    epson.print.Util.EPLog.i(r0, r1)     // Catch:{ all -> 0x01f0 }
                L_0x01e5:
                    monitor-exit(r8)
                    return
                L_0x01e7:
                    r0 = move-exception
                    r0.printStackTrace()     // Catch:{ all -> 0x01f0 }
                    r8.hideLoadProgress()     // Catch:{ all -> 0x01f0 }
                    monitor-exit(r8)
                    return
                L_0x01f0:
                    r0 = move-exception
                    monitor-exit(r8)
                    throw r0
                */
                throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.MaintainActivity.C20151.run():void");
            }

            private void hideLoadProgress() {
                MaintainActivity.mUiHandler.sendEmptyMessage(14);
            }
        }, "load-config");
        mLoadConfigThread.start();
    }

    private void updateButton() {
        switch (this.printerLocation) {
            case 0:
                mTvPrinterName.setText(getString(R.string.str_lbl_title_scan));
                ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setVisibility(View.GONE);
                mTvPrinterStatus.setText(R.string.EPS_PRNERR_NOT_SELECTED_TITTLE);
                mTvPrinterStatusDetail.setText(R.string.EPS_PRNERR_NOT_SELECTED);
                LinearLayout linearLayout = mInkView;
                if (linearLayout != null) {
                    linearLayout.removeAllViews();
                }
                mTextMaintenance.setVisibility(View.VISIBLE);
                mCleanCheckView.setVisibility(View.VISIBLE);
                mPrinterSettingView.setVisibility(View.VISIBLE);
                mHeadCleanView.setEnabled(false);
                mNozzleCheckView.setEnabled(false);
                mFWUpdateView.setEnabled(false);
                mPrinterSettingView.setEnabled(false);
                ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
                localSetBuyInkGroupVisibility(8);
                mOnlineRegistrationSeparator.setVisibility(View.GONE);
                mOnlineRegistrationView.setVisibility(View.GONE);
                mPrinterSettingSeparator.setVisibility(View.GONE);
                mPrintPreviewView.setVisibility(View.GONE);
                mAlertMesseageSeparater.setVisibility(View.GONE);
                mAlertMesseageView.setVisibility(View.GONE);
                mPrintHistorySeparator.setVisibility(View.GONE);
                mPrintHistoryView.setVisibility(View.GONE);
                mMaintenanceBoxText.setVisibility(View.GONE);
                mMaintenanceBoxView.setVisibility(View.GONE);
                return;
            case 1:
                if (mPrinter.doGetLang() != 1) {
                    mTextMaintenance.setVisibility(View.GONE);
                    mCleanCheckView.setVisibility(View.GONE);
                    mOnlineRegistrationSeparator.setVisibility(View.GONE);
                    mOnlineRegistrationView.setVisibility(View.GONE);
                } else {
                    mTextMaintenance.setVisibility(View.VISIBLE);
                    mCleanCheckView.setVisibility(View.VISIBLE);
                    mOnlineRegistrationSeparator.setVisibility(View.VISIBLE);
                    mOnlineRegistrationView.setVisibility(View.VISIBLE);
                    mOnlineRegistrationView.setEnabled(true);
                }
                updateBuyInkGroupForLocalOrIPPrinter();
                mPrinterSettingView.setVisibility(View.VISIBLE);
                mPrinterSettingSeparator.setVisibility(View.GONE);
                mPrintPreviewView.setVisibility(View.GONE);
                mAlertMesseageSeparater.setVisibility(View.GONE);
                mAlertMesseageView.setVisibility(View.GONE);
                mPrintHistorySeparator.setVisibility(View.GONE);
                mPrintHistoryView.setVisibility(View.GONE);
                if (this.escprSetPrinterSuccessed == 0) {
                    mHeadCleanView.setEnabled(true);
                    mNozzleCheckView.setEnabled(true);
                    mFWUpdateView.setEnabled(true);
                    mPrinterSettingView.setEnabled(true);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.black));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.VISIBLE);
                    setEpsonConnectButton(0);
                } else {
                    mHeadCleanView.setEnabled(false);
                    mNozzleCheckView.setEnabled(false);
                    mFWUpdateView.setEnabled(false);
                    mPrinterSettingView.setEnabled(false);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
                    setEpsonConnectButton(1);
                }
                if (MyPrinter.PRINTER_USB.equals(this.printerIp)) {
                    mFWUpdateView.setVisibility(View.GONE);
                    mPrinterSettingSeparator.setVisibility(View.GONE);
                    mPrinterSettingView.setVisibility(View.GONE);
                    return;
                }
                return;
            case 2:
                localSetBuyInkGroupVisibility(0);
                mBuyInkView.setVisibility(View.VISIBLE);
                mPrinterSettingSeparator.setVisibility(View.VISIBLE);
                mPrinterSettingView.setVisibility(View.VISIBLE);
                mPrintPreviewView.setVisibility(View.VISIBLE);
                mAlertMesseageSeparater.setVisibility(View.VISIBLE);
                mAlertMesseageView.setVisibility(View.VISIBLE);
                mPrintHistorySeparator.setVisibility(View.VISIBLE);
                mPrintHistoryView.setVisibility(View.VISIBLE);
                setEpsonConnectButton(2);
                LinearLayout linearLayout2 = mInkView;
                if (linearLayout2 != null) {
                    linearLayout2.removeAllViews();
                }
                TextView textView = new TextView(mContext);
                textView.setTextColor(getResources().getColor(R.color.black));
                textView.setTextSize(16.0f);
                textView.setText(getString(R.string.epsonconnect_str_status_inkinfo_error));
                mInkView.addView(textView);
                SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0);
                boolean z = sharedPreferences.getBoolean(Constants.ENABLE_SHOW_PREVIEW, true);
                boolean z2 = sharedPreferences.getBoolean(Constants.ENABLE_SHOW_WARNING, true);
                if (z) {
                    btnTogglePreview.setChecked(true);
                } else {
                    btnTogglePreview.setChecked(false);
                }
                if (z2) {
                    btnToggleAlert.setChecked(true);
                } else {
                    btnToggleAlert.setChecked(false);
                }
                BatteryInfoAdapter.BatteryInfoManager.clearBatteryList(this);
                mTextMaintenance.setVisibility(View.GONE);
                mCleanCheckView.setVisibility(View.GONE);
                mOnlineRegistrationSeparator.setVisibility(View.GONE);
                mOnlineRegistrationView.setVisibility(View.GONE);
                mMaintenanceBoxText.setVisibility(View.GONE);
                mMaintenanceBoxView.setVisibility(View.GONE);
                int i = serverLoginStatus;
                if (i == 0) {
                    mTvPrinterStatus.setText(getString(R.string.EPS_PRNST_IDLE_TITLE));
                    mTvPrinterStatusDetail.setText(getString(R.string.EPS_PRNST_IDLE_MSG));
                    mPrintHistoryView.setEnabled(true);
                    ((TextView) findViewById(R.id.text_print_history)).setTextColor(mContext.getResources().getColor(R.color.black));
                    ((ImageView) findViewById(R.id.print_history_arrow)).setVisibility(View.VISIBLE);
                    mPrinterSettingView.setEnabled(true);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.black));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.VISIBLE);
                    return;
                } else if (i == -1) {
                    mTvPrinterStatus.setText(getString(R.string.EC_ERR_COMM_ERROR_TITLE));
                    mTvPrinterStatusDetail.setText(getString(R.string.EC_ERR_COMM_ERROR));
                    mPrintHistoryView.setEnabled(false);
                    ((TextView) findViewById(R.id.text_print_history)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                    ((ImageView) findViewById(R.id.print_history_arrow)).setVisibility(View.GONE);
                    mPrinterSettingView.setEnabled(false);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
                    return;
                } else {
                    mTvPrinterStatus.setText(R.string.epsonconnect_str_status_login_error_title);
                    mTvPrinterStatusDetail.setText(getString(R.string.epsonconnect_str_status_login_error));
                    mPrintHistoryView.setEnabled(false);
                    ((TextView) findViewById(R.id.text_print_history)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                    ((ImageView) findViewById(R.id.print_history_arrow)).setVisibility(View.GONE);
                    mPrinterSettingView.setEnabled(false);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
                    return;
                }
            case 3:
                if (mPrinter.doGetLang() != 1) {
                    mTextMaintenance.setVisibility(View.GONE);
                    mCleanCheckView.setVisibility(View.GONE);
                } else {
                    mTextMaintenance.setVisibility(View.VISIBLE);
                    mCleanCheckView.setVisibility(View.VISIBLE);
                }
                updateBuyInkGroupForLocalOrIPPrinter();
                mPrinterSettingView.setVisibility(View.VISIBLE);
                mPrinterSettingSeparator.setVisibility(View.GONE);
                mPrintPreviewView.setVisibility(View.GONE);
                mAlertMesseageSeparater.setVisibility(View.GONE);
                mAlertMesseageView.setVisibility(View.GONE);
                mPrintHistorySeparator.setVisibility(View.GONE);
                mPrintHistoryView.setVisibility(View.GONE);
                mOnlineRegistrationSeparator.setVisibility(View.GONE);
                mOnlineRegistrationView.setVisibility(View.GONE);
                if (this.escprSetPrinterSuccessed == 0) {
                    mHeadCleanView.setEnabled(true);
                    mNozzleCheckView.setEnabled(true);
                    mPrinterSettingView.setEnabled(true);
                    ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.black));
                    ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.VISIBLE);
                    setEpsonConnectButton(0);
                    return;
                }
                mHeadCleanView.setEnabled(false);
                mNozzleCheckView.setEnabled(false);
                mPrinterSettingView.setEnabled(false);
                ((TextView) findViewById(R.id.text_printer_setting)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                ((ImageView) findViewById(R.id.printer_setting_arrow)).setVisibility(View.GONE);
                setEpsonConnectButton(1);
                return;
            default:
                return;
        }
    }

    private void localSetBuyInkGroupVisibility(int i) {
        mBuyInkGroup.setVisibility(i);
        mBuyInkGroupVisibility = i;
    }

    private void updateBuyInkGroupForLocalOrIPPrinter() {
        int i;
        int i2;
        int i3;
        int i4 = 0;
        InkRplnInfoClient.InkRsInfo info = new InkRplnRepository(false).getInfo(this);
        if (info != null) {
            i = info.getButtonType();
        } else {
            i = 0;
        }
        int i5 = 8;
        switch (i) {
            case 1:
                i3 = 0;
                i2 = 8;
                break;
            case 2:
                i3 = 0;
                i5 = 0;
                i2 = 0;
                break;
            case 3:
                i3 = 8;
                i4 = 8;
                i2 = 8;
                break;
            default:
                i3 = 8;
                i5 = 0;
                i2 = 8;
                break;
        }
        localSetBuyInkGroupVisibility(i4);
        mBuyInkView.setVisibility(i5);
        mInkDsView.setVisibility(i3);
        mBuyInkSeparator.setVisibility(i2);
    }

    private void setupErrorMessage(int i) {
        Utils.makeMessageBox(this, getString(R.string.EPS_PRNERR_DISABEL_CLEANING_TITLE), getString(R.string.EPS_PRNERR_DISABEL_CLEANING_MSG), getString(R.string.str_cancel)).show();
    }

    public void onClick(View view) {
        int id = view.getId();
        int i = R.string.str_nozzle_check;
        switch (id) {
            case R.id.epsonconnect_option /*2131231020*/:
                Intent intent = new Intent(this, ActivityECConfiguration.class);
                intent.putExtra(ActivityECConfiguration.INTENT_EC_BLE_CONTENT, false);
                startActivity(intent);
                return;
            case R.id.fwupdate_view /*2131231071*/:
                Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_MAINTENANCE_FIRMWARE_UPDATE);
                Intent intent2 = new Intent(this, FirmwareUpdateActivity.class);
                intent2.putExtra(Constants.PRINTER_IP, printerIp);
                intent2.putExtra("PRINTER_MODEL_NAME", printerName);
                isKeepSimpleAPConnection = true;
                startActivity(intent2);
                return;
            case R.id.head_clean_view /*2131231097*/:
                Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_MAINTENANCE_HEAD_CLEANING);
                AlertDialog.Builder icon = new AlertDialog.Builder(this).setIcon(R.drawable.ic_action_warning);
                if (view.getId() != R.id.nozzle_check_view) {
                    i = R.string.str_head_clean;
                }
                icon.setTitle(i).setPositiveButton(R.string.str_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        MaintainActivity.this.performMaintain(2);
                    }
                }).setNegativeButton(R.string.str_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }).show();
                return;
            case R.id.maintenance_inkds /*2131231241*/:
                Analytics.sendAction(this, Analytics.ACTION_ID_MAINTENANCE_READY_INK);
                startBrowsReadyInkUrl();
                return;
            case R.id.mentenance_buy_ink /*2131231247*/:
                Analytics.sendAction(this, Analytics.ACTION_ID_MAINTENANCE_BUY_INK);
                showDialog(DIALOG_PROGRESS);
                BuyInkTask(1, printerIp);
                return;
            case R.id.nozzle_check_view /*2131231280*/:
                Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_MAINTENANCE_NOZZLE_CHECK);
                AlertDialog.Builder icon2 = new AlertDialog.Builder(this).setIcon(R.drawable.ic_action_warning);
                if (view.getId() != R.id.nozzle_check_view) {
                    i = R.string.str_head_clean;
                }
                icon2.setTitle(i).setPositiveButton(R.string.str_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        new NozzleCheckTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
                    }
                }).setNegativeButton(R.string.str_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }).show();
                return;
            case R.id.online_registration /*2131231289*/:
                showDialog(DIALOG_PROGRESS);
                OnlineRegTask(this.printerIp);
                return;
            case R.id.print_history /*2131231348*/:
                startActivity(new Intent(this, EccPrintLog.class));
                return;
            case R.id.printer /*2131231358*/:
                EPLog.d(TAG, "onClick() R.id.printer");
                new AsyncTask<Void, Void, Void>() {
                    WorkingDialog dialog = new WorkingDialog(MaintainActivity.this);

                    protected void onPreExecute() {
                        super.onPreExecute();
                        MaintainActivity.this.hideLoadProgressBar();
                        dialog.show();
                    }

                    protected Void doInBackground(Void... voidArr) {
                        MaintainActivity.this.stopLoadConfigThread();
                        MaintainActivity.this.endBackGroundThread();
                        MaintainActivity maintainActivity = MaintainActivity.this;
                        WiFiDirectManager.disconnect(maintainActivity, WiFiDirectManager.DEVICE_TYPE_PRINTER, maintainActivity.printerIp);
                        return null;
                    }

                    protected void onPostExecute(Void voidR) {
                        MaintainActivity.this.startSelectPrinterActivity();
                        dialog.dismiss();
                    }
                }.execute(new Void[0]);
                return;
            case R.id.printer_setting /*2131231369*/:
                switch (this.printerLocation) {
                    case 1:
                    case 3:
                        if (!WiFiDirectManager.isSimpleAP(this) || isKeepSimpleAPConnection) {
                            printerIp = mPrinter.doGetIp();
                            startActivity(new Intent("android.intent.action.VIEW", Uri.parse(IPAddressUtils.buildURL(Analytics.EXTENSION_STRING_WEB, printerIp, CommonDefine.SLASH))));
                            return;
                        }
                        new AlertDialog.Builder(mContext).setCancelable(false).setMessage(R.string.str_webconfig_warn_message).setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialogInterface, int i) {
                                boolean unused = MaintainActivity.this.isKeepSimpleAPConnection = true;
                                MaintainActivity maintainActivity = MaintainActivity.this;
                                String unused2 = maintainActivity.printerIp = maintainActivity.mPrinter.doGetIp();
                                MaintainActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(CommonDefine.HTTP_PREFIX + MaintainActivity.this.printerIp + CommonDefine.SLASH)));
                            }
                        }).create().show();
                        return;
                    case 2:
                        startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://www.epsonconnect.com/user/")));
                        return;
                    default:
                        return;
                }
            case R.id.toggleAlert /*2131231560*/:
                if (this.btnToggleAlert.isChecked()) {
                    SharedPreferences.Editor edit = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).edit();
                    edit.putBoolean(Constants.ENABLE_SHOW_WARNING, true);
                    edit.commit();
                    return;
                }
                SharedPreferences.Editor edit2 = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).edit();
                edit2.putBoolean(Constants.ENABLE_SHOW_WARNING, false);
                edit2.commit();
                return;
            case R.id.togglePreview /*2131231563*/:
                if (!this.btnTogglePreview.isChecked()) {
                    SharedPreferences.Editor edit3 = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).edit();
                    edit3.putBoolean(Constants.ENABLE_SHOW_PREVIEW, false);
                    edit3.commit();
                    return;
                } else if (!isMessageScreenShowing) {
                    showMessageDialog();
                    return;
                } else {
                    SharedPreferences.Editor edit4 = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).edit();
                    edit4.putBoolean(Constants.ENABLE_SHOW_PREVIEW, true);
                    edit4.commit();
                    return;
                }
            default:
                return;
        }
    }

    private void startSelectPrinterActivity() {
        mWaiteInkDsDialog = true;
        Intent intent = new Intent(this, MaintainPrinterSearchActivity.class);
        intent.putExtra(Constants.PRINTER_ID, printerId);
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, 101);
    }

    private void startBrowsReadyInkUrl() {
        startActivity(new Intent(this, JumpUrlProgressActivity.class));
    }

    private void showNozzleCheckGuidanceDialog() {
        if (!checkGaga()) {
            new NozzleGuidanceDialog().show(getSupportFragmentManager(), DIALOG_TAG_NOZZLE_GUIDANCE);
        }
    }

    private boolean checkGaga() {
        String printerDeviceId = MyPrinter.getPrinterDeviceId(this, false);
        if (printerDeviceId == null) {
            return false;
        }
        return Arrays.asList(GAGA_DEVICE_ID_ARRAY).contains(printerDeviceId);
    }

    private void showMessageDialog() {
        isMessageScreenShowing = true;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.epsonconnect_str_preview_warning) + "\n\n" + getString(R.string.epsonconnect_str_preview_warning2));
        C20299 r1 = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                SharedPreferences.Editor edit = MaintainActivity.this.getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).edit();
                edit.putBoolean(Constants.ENABLE_SHOW_PREVIEW, true);
                edit.commit();
            }
        };
        C201610 r2 = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                MaintainActivity.this.btnTogglePreview.setChecked(false);
            }
        };
        builder.setPositiveButton(R.string.str_yes, r1);
        builder.setNegativeButton(R.string.str_no, r2);
        builder.setCancelable(false);
        builder.show();
        isMessageScreenShowing = false;
    }

    private void showProDia() {
        if (this.customPro == null) {
            customPro = new CustomProDialog(this, R.style.AppTheme_Translucent, R.layout.maintain_executing_dialog);
        }
        customPro.show();
    }

    private void cancelProDia() {
        Dialog dialog = customPro;
        if (dialog != null && dialog.isShowing()) {
            customPro.cancel();
            customPro = null;
        }
    }

    private void showLoadProgressBar() {
        if (mLoadConPro == null) {
            mLoadConPro = findViewById(R.id.progress_status);
        }
        mLoadConPro.setVisibility(View.VISIBLE);
    }

    private void hideLoadProgressBar() {
        View view = mLoadConPro;
        if (view != null) {
            view.setVisibility(View.GONE);
        }
    }

    private void stopLoadConfigThread() {
        mIsCancelProbe = true;
        Thread thread = mLoadConfigThread;
        if (thread != null && thread.isAlive()) {
            mPrinter.doCancelFindPrinter();
            if (mEpsonService != null) {
                new AsyncTaskExecutor<Void, Void, Void>() {
                    protected Void doInBackground(Void... voidArr) {
                        try {
                            MaintainActivity.mEpsonService.EpsonConnectCancel();
                            return null;
                        } catch (RemoteException e) {
                            e.printStackTrace();
                            return null;
                        }
                    }
                }.executeOnExecutor(new Void[0]);
            }
            mLoadConfigThread.interrupt();
            mLoadConfigThread = null;
        }
    }

    private void startBackgroundThread() {
        mIsStillUpdate = true;
        mBackGround = new Thread(new Runnable() {
            public void run() {
                int doGetStatus = MaintainActivity.mPrinter.doGetStatus();
                Message message = new Message();
                message.what = 2;
                Bundle bundle = new Bundle();
                bundle.putInt("GET_STT_RESULT", doGetStatus);
                message.setData(bundle);
                MaintainActivity.mUiHandler.sendMessage(message);
                int doGetInkInfo = MaintainActivity.mPrinter.doGetInkInfo();
                Message message2 = new Message();
                message2.what = 3;
                Bundle bundle2 = new Bundle();
                bundle2.putInt("GET_INK_RESULT", doGetInkInfo);
                message2.setData(bundle2);
                MaintainActivity.mUiHandler.sendMessage(message2);
                BatteryInfoEx batteryInfoEx = new BatteryInfoEx();
                int batteryInfo = MaintainActivity.mPrinter.getBatteryInfo(batteryInfoEx);
                boolean z = batteryInfo == 0 && batteryInfoEx.powerSourceType != -1;
                Message message3 = new Message();
                message3.what = 15;
                Bundle bundle3 = new Bundle();
                bundle3.putInt("GET_BATTERY_RESULT", batteryInfo);
                bundle3.putParcelable("GET_BATTERY_INFO", batteryInfoEx);
                message3.setData(bundle3);
                MaintainActivity.mUiHandler.sendMessage(message3);
                int[] maintenanceBoxInformation = MaintainActivity.mPrinter.getMaintenanceBoxInformation();
                MaintainActivity maintainActivity = MaintainActivity.this;
                maintainActivity.sendMaintenanceBoxInfoMessage(maintainActivity.mUiHandler, maintenanceBoxInformation);
                while (MaintainActivity.mIsStillUpdate) {
                    try {
                        EPLog.i(MaintainActivity.TAG, "thread update stt running");
                        int doGetStatus2 = MaintainActivity.mPrinter.doGetStatus();
                        Message message4 = new Message();
                        message4.what = 2;
                        bundle3.putInt("GET_STT_RESULT", doGetStatus2);
                        Bundle bundle4 = new Bundle();
                        message4.setData(bundle4);
                        MaintainActivity.mUiHandler.sendMessage(message4);
                        if (z) {
                            int batteryInfo2 = MaintainActivity.mPrinter.getBatteryInfo(batteryInfoEx);
                            Message message5 = new Message();
                            message5.what = 15;
                            bundle3 = new Bundle();
                            bundle3.putInt("GET_BATTERY_RESULT", batteryInfo2);
                            bundle3.putParcelable("GET_BATTERY_INFO", batteryInfoEx);
                            message5.setData(bundle3);
                            MaintainActivity.mUiHandler.sendMessage(message5);
                        } else {
                            bundle3 = bundle4;
                        }
                        MaintainActivity.this.sendMaintenanceBoxInfoMessage(MaintainActivity.mUiHandler, MaintainActivity.mPrinter.getMaintenanceBoxInformation());
                        Thread.sleep(4000);
                    } catch (InterruptedException e) {
                        EPLog.w("startBackgroundThread", "InterruptedException");
                        e.printStackTrace();
                        return;
                    }
                }
            }
        }, "status-update");
        mBackGround.setPriority(5);
        mBackGround.start();
    }

    private void sendMaintenanceBoxInfoMessage(Handler handler, int[] iArr) {
        mUiHandler.removeMessages(16);
        handler.sendMessage(handler.obtainMessage(16, 0, 0, iArr));
    }

    private void endBackGroundThread() {
        mIsStillUpdate = false;
        Thread thread = mBackGround;
        if (thread != null && thread.isAlive()) {
            mBackGround.interrupt();
            try {
                mBackGround.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mBackGround = null;
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        IEpsonService iEpsonService;
        super.onActivityResult(i, i2, intent);
        switch (i) {
            case 100:
                onInkReplenishDialogEnd();
                return;
            case 101:
                MyPrinter curPrinter = MyPrinter.getCurPrinter(this);
                if (curPrinter.getName() == null) {
                    finish();
                    return;
                } else if (i2 == 1) {
                    if (MyPrinter.isRemotePrinter(getApplicationContext()) && (iEpsonService = mEpsonService) != null) {
                        try {
                            iEpsonService.refreshRemotePrinterLogin();
                        } catch (RemoteException unused) {
                        }
                    }
                    if (!isSimpleApOrP2p(curPrinter)) {
                        startInkDsDialog();
                        return;
                    } else {
                        onInkReplenishDialogEnd();
                        return;
                    }
                } else {
                    onInkReplenishDialogEnd();
                    return;
                }
            default:
                return;
        }
    }

    private boolean isSimpleApOrP2p(MyPrinter myPrinter) {
        return WiFiDirectManager.getCurConnectInfo(this, MacAddrUtils.getMacAddressFromPrinterId(myPrinter.getPrinterId())) != null;
    }

    private void onInkReplenishDialogEnd() {
        mWaiteInkDsDialog = false;
    }

    private void startInkDsDialog() {
        startActivityForResult(InkRplnProgressDialog.getStartIntent(this), 100);
    }

    private void updateSelectedPrinter() {
        hideLoadProgressBar();
        stopLoadConfigThread();
        mIsNozzleCheckEnable = true;
        escprSetPrinterSuccessed = mPrinter.doSetPrinter();
        int i = escprSetPrinterSuccessed;
        int i2 = 0;
        if (i == 0) {
            startBackgroundThread();
            mIsStillUpdate = true;
            setButtonClickable(true);
        } else {
            mIsStillUpdate = false;
            handlerError(i, false);
        }
        if (mPrinter.doGetLang() != 1) {
            mHeadCleanView.setVisibility(View.GONE);
            mNozzleCheckView.setVisibility(View.GONE);
            mFWUpdateView.setVisibility(View.GONE);
        } else {
            mHeadCleanView.setVisibility(View.VISIBLE);
            mNozzleCheckView.setVisibility(View.VISIBLE);
            LinearLayout linearLayout = mFWUpdateView;
            if (this.printerLocation != 1) {
                i2 = 8;
            }
            linearLayout.setVisibility(i2);
        }
        printerIp = mPrinter.doGetIp();
    }

    private synchronized void updateStatus(int i) {
        mUiHandler.sendEmptyMessage(11);
        if (i == 0) {
            if (isPrinterReady() != 1) {
                setButtonClickable(false);
            } else {
                setButtonClickable(true);
                int doGetInkInfo = mPrinter.doGetInkInfo();
                Message message = new Message();
                message.what = 3;
                Bundle bundle = new Bundle();
                bundle.putInt("GET_INK_RESULT", doGetInkInfo);
                message.setData(bundle);
                mUiHandler.sendMessage(message);
            }
            if (mPrinterStatus[0] == 4) {
                if (mPrinterStatus[1] == 102) {
                    escprSetPrinterSuccessed = -1;
                } else {
                    escprSetPrinterSuccessed = 0;
                }
                if (this.isRemotePrinter && mPrinterStatus[1] == 102) {
                    mUiHandler.sendEmptyMessage(11);
                } else {
                    setErrorStatus(mPrinterStatus[0], mPrinterStatus[1]);
                    if (mPrinterStatus[1] == 102) {
                        mInkView.removeAllViews();
                    }
                    if (mPrinterStatus[1] == 6 || mPrinterStatus[1] == 103 || mPrinterStatus[1] == 104) {
                        int doGetInkInfo2 = mPrinter.doGetInkInfo();
                        Message message2 = new Message();
                        message2.what = 3;
                        Bundle bundle2 = new Bundle();
                        bundle2.putInt("GET_INK_RESULT", doGetInkInfo2);
                        message2.setData(bundle2);
                        mUiHandler.sendMessage(message2);
                    }
                }
            } else {
                escprSetPrinterSuccessed = 0;
                Integer[] stringId = MediaInfo.StatusTable.getStringId(mPrinterStatus[0]);
                if (stringId != null) {
                    mTvPrinterStatus.setText(getString(stringId[0].intValue()));
                    mTvPrinterStatusDetail.setText(getString(stringId[1].intValue()));
                } else {
                    TextView textView = mTvPrinterStatus;
                    textView.setText("Stt Code: " + mPrinterStatus[0]);
                    TextView textView2 = mTvPrinterStatusDetail;
                    textView2.setText("Err Code: " + mPrinterStatus[1]);
                }
            }
        } else {
            handlerError(i, false);
        }
    }

    public void updateInkInfo(int i) {
        createInkView(mPrinter.getMPrinterInfor(), i);
    }

    private void updateBatteryInfoEx(int i, BatteryInfoEx batteryInfoEx) {
        int i2 = batteryInfoEx.number;
        int i3 = batteryInfoEx.powerSourceType;
        if (i != 0 || i2 <= 0 || i3 == -1) {
            BatteryInfoAdapter.BatteryInfoManager.clearBatteryList(this);
            return;
        }
        int[] iArr = batteryInfoEx.batteryState;
        int[] iArr2 = batteryInfoEx.batteryRemain;
        BatteryInfoAdapter.BatteryInfoManager.showPowerText(this);
        BatteryInfoAdapter.BatteryInfoManager.showBatteryList(this, i2, i3, iArr, iArr2);
    }

    private void updateMaintenanceBoxInfo(int[] iArr) {
        int i = mBuyInkGroupVisibility;
        if (iArr == null || iArr.length <= 0) {
            mMaintenanceBoxText.setVisibility(View.GONE);
            mMaintenanceBoxView.setVisibility(View.GONE);
            if (8 != mInkView.getVisibility()) {
                int i2 = mBuyInkGroupVisibility;
                return;
            }
            return;
        }
        mMaintenanceBoxText.setVisibility(View.VISIBLE);
        mMaintenanceBoxView.setVisibility(View.VISIBLE);
        mBuyInkGroup.setVisibility(i);
        LayoutInflater from = LayoutInflater.from(this);
        Point point = new Point();
        mDisplay.getSize(point);
        int i3 = (point.x - 30) / 2;
        mMaintenanceBoxView.removeAllViews();
        int length = iArr.length / 2;
        for (int i4 = 0; i4 < length; i4++) {
            int i5 = i4 * 2;
            int i6 = iArr[i5];
            int i7 = iArr[i5 + 1];
            View inflate = from.inflate(R.layout.ink_item, mMaintenanceBoxView, false);
            ((TextView) inflate.findViewById(R.id.ink_name)).setVisibility(View.GONE);
            ((RelativeLayout) inflate.findViewById(R.id.ink_holder)).getLayoutParams().width = i3;
            ViewGroup viewGroup = (ViewGroup) inflate.findViewById(R.id.ink_level);
            if (i7 <= 0 || isMaintenanceBoxStatusDisplayX(i6)) {
                viewGroup.getLayoutParams().width = 0;
                inflate.findViewById(R.id.ink_error).setVisibility(View.VISIBLE);
                viewGroup.setVisibility(4);
            } else {
                viewGroup.getLayoutParams().width = ((((float) (i3 - 4)) / 100.0f) * ((float) i7));
                viewGroup.setBackgroundResource(R.color.maintenance_box_info);
                viewGroup.setVisibility(View.VISIBLE);
            }
            mMaintenanceBoxView.addView(inflate);
        }
    }

    private void handlerError(int i, boolean z) {
        hideLoadProgressBar();
        if (i == -1351 || i == -1100) {
            i = -1300;
        }
        if (this.isRemotePrinter && i == -1300) {
            setButtonClickable(false);
            mUiHandler.sendEmptyMessage(11);
            return;
        }
        setErrorStatus(4, i);
        setButtonClickable(false);
        mUiHandler.sendEmptyMessage(11);
        if (!z) {
            return;
        }
        if (i == -1300 || i == -500001) {
            mInkView.removeAllViews();
        }
    }

    private void setErrorStatus(int i, int i2) {
        Integer[] stringId = MediaInfo.ErrorTable.getStringId(i2);
        if (stringId != null) {
            String[] replaceMessage = Utils.replaceMessage(stringId, i2, getApplicationContext());
            mTvPrinterStatus.setText(replaceMessage[1]);
            EPLog.i(TAG, "Stt title: " + replaceMessage[1]);
            String str = replaceMessage[0];
            mTvPrinterStatusDetail.setText(str);
            EPLog.i(TAG, "Stt detail: " + str);
            return;
        }
        TextView textView = mTvPrinterStatus;
        textView.setText("Stt Code: " + i);
        TextView textView2 = mTvPrinterStatusDetail;
        textView2.setText("Err Code: " + i2);
    }

    private int isPrinterReady() {
        mPrinterStatus = mPrinter.getMPrinterInfor().getMStatus();
        int[] iArr = mPrinterStatus;
        if (iArr[0] == 2 || iArr[0] == 1 || iArr[0] == 3) {
            return 0;
        }
        if (iArr[0] == 4) {
            return -1;
        }
        return 1;
    }

    private void interrupMaintainThread() {
        Thread thread = mDoMaintainThread;
        if (thread != null && thread.isAlive()) {
            mDoMaintainThread.interrupt();
            mDoMaintainThread = null;
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        EPLog.i(TAG, "onDestroy");
        IEpsonService iEpsonService = mEpsonService;
        if (iEpsonService != null) {
            try {
                iEpsonService.unregisterCallback(mCallback);
                unbindService(mEpsonConnection);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    protected void onResume() {
        EPLog.e("MaintainActivity", "onResume()");
        super.onResume();
        isKeepSimpleAPConnection = false;
        if (!mWaiteInkDsDialog) {
            startLoadConThread();
        }
    }

    protected void onPause() {
        EPLog.d("MaintainActivity", "onPause");
        mIsCancelProbe = true;
        hideLoadProgressBar();
        mPrinter.doCancelFindPrinter();
        stopLoadConfigThread();
        interrupMaintainThread();
        endBackGroundThread();
        mUiHandler.removeMessages(16);
        if (!this.isKeepSimpleAPConnection) {
            WiFiDirectManager.disconnect(this, WiFiDirectManager.DEVICE_TYPE_PRINTER, printerIp);
        }
        super.onPause();
    }

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

    private void performMaintain(final int i) {
        if (isPrinterReady() == 1) {
            mUiHandler.sendEmptyMessage(0);
            mDoMaintainThread = new Thread(new Runnable() {
                /* JADX WARNING: Removed duplicated region for block: B:35:0x0092 A[EDGE_INSN: B:35:0x0092->B:29:0x0092 ?: BREAK  , SYNTHETIC] */
                /* JADX WARNING: Removed duplicated region for block: B:37:0x002a A[SYNTHETIC] */
                /* Code decompiled incorrectly, please refer to instructions dump. */
                public void run() {
                    /*
                        r9 = this;
                        epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this
                        com.epson.mobilephone.common.maintain2.MaintainPrinter2 r0 = r0.mPrinter
                        int r1 = r3
                        int r0 = r0.doDoMainteCmd(r1)
                        r1 = 108(0x6c, float:1.51E-43)
                        r2 = 10
                        r3 = 1
                        r4 = 0
                        if (r0 != r1) goto L_0x0028
                        epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this
                        boolean unused = r5.isGotError = r3
                        r5 = 11
                        epson.maintain.activity.MaintainActivity r6 = epson.maintain.activity.MaintainActivity.this
                        android.os.Handler r6 = r6.mUiHandler
                        r6.sendEmptyMessage(r2)
                        r5 = 0
                        r6 = 11
                        goto L_0x002a
                    L_0x0028:
                        r5 = 1
                        r6 = 0
                    L_0x002a:
                        if (r5 != 0) goto L_0x002e
                        if (r6 > r2) goto L_0x0092
                    L_0x002e:
                        r7 = 1000(0x3e8, double:4.94E-321)
                        java.lang.Thread.sleep(r7)     // Catch:{ InterruptedException -> 0x009c }
                        int r6 = r6 + 1
                        if (r0 != r1) goto L_0x004a
                        epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x0046 }
                        boolean unused = r5.isGotError = r3     // Catch:{ InterruptedException -> 0x0046 }
                        epson.maintain.activity.MaintainActivity r5 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x0046 }
                        android.os.Handler r5 = r5.mUiHandler     // Catch:{ InterruptedException -> 0x0046 }
                        r5.sendEmptyMessage(r2)     // Catch:{ InterruptedException -> 0x0046 }
                        goto L_0x0092
                    L_0x0046:
                        r5 = move-exception
                        r7 = r5
                        r5 = 0
                        goto L_0x009d
                    L_0x004a:
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        com.epson.mobilephone.common.maintain2.MaintainPrinter2 r7 = r7.mPrinter     // Catch:{ InterruptedException -> 0x009c }
                        r7.doGetStatus()     // Catch:{ InterruptedException -> 0x009c }
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        int[] r7 = r7.mPrinterStatus     // Catch:{ InterruptedException -> 0x009c }
                        r7 = r7[r4]     // Catch:{ InterruptedException -> 0x009c }
                        r8 = 4
                        if (r7 != r8) goto L_0x006d
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        boolean unused = r7.isGotError = r3     // Catch:{ InterruptedException -> 0x009c }
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        android.os.Handler r7 = r7.mUiHandler     // Catch:{ InterruptedException -> 0x009c }
                        r7.sendEmptyMessage(r8)     // Catch:{ InterruptedException -> 0x009c }
                        goto L_0x0072
                    L_0x006d:
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        boolean unused = r7.isGotError = r4     // Catch:{ InterruptedException -> 0x009c }
                    L_0x0072:
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        int[] r7 = r7.mPrinterStatus     // Catch:{ InterruptedException -> 0x009c }
                        r7 = r7[r4]     // Catch:{ InterruptedException -> 0x009c }
                        if (r7 == 0) goto L_0x0089
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        int[] r7 = r7.mPrinterStatus     // Catch:{ InterruptedException -> 0x009c }
                        r5 = r7[r4]     // Catch:{ InterruptedException -> 0x009c }
                        if (r5 != r8) goto L_0x0087
                        goto L_0x0089
                    L_0x0087:
                        r5 = 1
                        goto L_0x008a
                    L_0x0089:
                        r5 = 0
                    L_0x008a:
                        epson.maintain.activity.MaintainActivity r7 = epson.maintain.activity.MaintainActivity.this     // Catch:{ InterruptedException -> 0x009c }
                        boolean r7 = r7.isGotError     // Catch:{ InterruptedException -> 0x009c }
                        if (r7 == 0) goto L_0x002a
                    L_0x0092:
                        epson.maintain.activity.MaintainActivity r0 = epson.maintain.activity.MaintainActivity.this
                        android.os.Handler r0 = r0.mUiHandler
                        r0.sendEmptyMessage(r3)
                        return
                    L_0x009c:
                        r7 = move-exception
                    L_0x009d:
                        r7.printStackTrace()
                        goto L_0x002a
                    */
                    throw new UnsupportedOperationException("Method not decompiled: epson.maintain.activity.MaintainActivity.C201913.run():void");
                }
            });
            mDoMaintainThread.start();
        }
    }

    private void loadConfig() {
        MyPrinter curPrinter = MyPrinter.getCurPrinter(this);
        printerName = curPrinter.getUserDefName(this);
        if (this.printerName == null) {
            printerName = "";
        }
        printerId = curPrinter.getPrinterId();
        if (this.printerId == null) {
            printerId = "";
        }
        printerIp = curPrinter.getIp();
        if (this.printerIp == null) {
            printerIp = "";
        }
        printerLocation = curPrinter.getLocation();
    }

    public void createInkView(MaintainPrinterInfo2 maintainPrinterInfo2, int i) {
        MaintainPrinterInfo2 maintainPrinterInfo22 = maintainPrinterInfo2;
        LayoutInflater from = LayoutInflater.from(this);
        Point point = new Point();
        mDisplay.getSize(point);
        int i2 = (point.x - 30) / 2;
        LinearLayout linearLayout = mInkView;
        if (linearLayout != null) {
            linearLayout.removeAllViews();
        }
        int inkNum = maintainPrinterInfo2.getInkNum();
        if (inkNum > 0) {
            findViewById(R.id.ink_text).setVisibility(View.VISIBLE);
            mInkView.setVisibility(View.VISIBLE);
            mBuyInkGroup.setVisibility(mBuyInkGroupVisibility);
            for (int i3 = 0; i3 < inkNum; i3++) {
                int inkRemainingAmount = maintainPrinterInfo22.getInkRemainingAmount(i3);
                int inkName = maintainPrinterInfo22.getInkName(i3);
                Integer[] colorName = MediaInfo.ColorTable.getColorName(inkName);
                if (colorName == null) {
                    EPLog.i("colorNo = " + inkName);
                    colorName = MediaInfo.ColorTable.getColorName(Constants.ColorName.EPS_COLOR_WHITE.ordinal());
                    if (colorName != null) {
                        colorName[1] = 0;
                    } else {
                        return;
                    }
                } else {
                    logColorInfo(inkName, colorName);
                }
                View inflate = from.inflate(R.layout.ink_item, (ViewGroup) null);
                TextView textView = (TextView) inflate.findViewById(R.id.ink_name);
                if (colorName[1].intValue() != 0) {
                    textView.setText(colorName[1].intValue());
                } else {
                    textView.setText("");
                }
                ((RelativeLayout) inflate.findViewById(R.id.ink_holder)).getLayoutParams().width = i2;
                ViewGroup viewGroup = (ViewGroup) inflate.findViewById(R.id.ink_level);
                float f = (float) (i2 - 4);
                if (maintainPrinterInfo22.getInkStatus(i3) == -4 || i != 0) {
                    viewGroup.getLayoutParams().width = 0;
                    viewGroup.setVisibility(4);
                    if (maintainPrinterInfo22.getInkStatus(i3) != -4) {
                        inflate.findViewById(R.id.ink_error).setVisibility(View.VISIBLE);
                    }
                } else {
                    viewGroup.getLayoutParams().width = calcInkWidth(inkRemainingAmount, f);
                    if (!(maintainPrinterInfo22.getInkStatus(i3) == 0 || maintainPrinterInfo22.getInkStatus(i3) == 1 || maintainPrinterInfo22.getInkStatus(i3) == 2)) {
                        viewGroup.getLayoutParams().width = 0;
                    }
                    if (checkIfWhite(colorName[0].intValue())) {
                        View findViewById = inflate.findViewById(R.id.white_ink_level);
                        findViewById.setBackgroundResource(colorName[0].intValue());
                        findViewById.setVisibility(View.VISIBLE);
                    } else {
                        viewGroup.setBackgroundResource(colorName[0].intValue());
                    }
                    viewGroup.setVisibility(View.VISIBLE);
                    if (inkRemainingAmount <= 0) {
                        inflate.findViewById(R.id.ink_error).setVisibility(View.VISIBLE);
                    }
                }
                mInkView.addView(inflate);
            }
            return;
        }
        findViewById(R.id.ink_text).setVisibility(View.GONE);
        mInkView.setVisibility(View.GONE);
    }

    private boolean checkIfWhite(@ColorRes int i) {
        try {
            return (getResources().getColor(i) & ViewCompat.MEASURED_SIZE_MASK) == 16777215;
        } catch (Resources.NotFoundException unused) {
            return false;
        }
    }

    private void logColorInfo(int i, @NonNull Integer[] numArr) {
        String str;
        String str2;
        String str3;
        int intValue = numArr[1].intValue();
        int intValue2 = numArr[0].intValue();
        int intValue3 = numArr[2].intValue();
        StringBuilder sb = new StringBuilder();
        sb.append("colorNo = ");
        sb.append(i);
        sb.append(":");
        if (intValue == 0) {
            str = "--";
        } else {
            str = getString(numArr[1].intValue());
        }
        sb.append(str);
        sb.append(":");
        if (intValue2 == 0) {
            str2 = "--";
        } else {
            str2 = String.format("#%06X", new Object[]{Integer.valueOf(16777215 & ContextCompat.getColor(this, numArr[0].intValue()))});
        }
        sb.append(str2);
        sb.append(":");
        if (intValue3 == 0) {
            str3 = "--";
        } else {
            str3 = getString(numArr[2].intValue());
        }
        sb.append(str3);
        EPLog.i(sb.toString());
    }

    private class CustomProDialog extends Dialog {
        private int mLayoutId;

        CustomProDialog(Context context, int i, int i2) {
            super(context, i);
            mLayoutId = i2;
            setCancelable(false);
        }

        protected void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            requestWindowFeature(1);
            View inflate = getLayoutInflater().inflate(mLayoutId, (ViewGroup) null);
            if (mLayoutId == R.layout.maintain_executing_dialog) {
                ((Button) inflate.findViewById(R.id.close_btn)).setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                        CustomProDialog.this.cancel();
                        MaintainActivity.this.interrupMaintainThread();
                    }
                });
            }
            setContentView(inflate);
        }
    }

    private void setButtonClickable(boolean z) {
        mNozzleCheckView.setClickable(z);
        mHeadCleanView.setClickable(z);
        mFWUpdateView.setClickable(z);
        if (z) {
            if (!mIsNozzleCheckEnable.booleanValue()) {
                mNozzleCheckText.setTextColor(mContext.getResources().getColor(R.color.light_gray));
            } else {
                mNozzleCheckText.setTextColor(mContext.getResources().getColor(R.color.black));
            }
            mHeadCleanText.setTextColor(mContext.getResources().getColor(R.color.black));
            mFWUpdateText.setTextColor(mContext.getResources().getColor(R.color.black));
            return;
        }
        mNozzleCheckText.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        mHeadCleanText.setTextColor(mContext.getResources().getColor(R.color.light_gray));
        mFWUpdateText.setTextColor(mContext.getResources().getColor(R.color.light_gray));
    }

    private void setEpsonConnectButton(int i) {
        switch (i) {
            case 0:
                mEpsonConnectView.setClickable(true);
                mEpsonConnectView.setEnabled(true);
                ((TextView) findViewById(R.id.text_epson_connect)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((ImageView) findViewById(R.id.epsonconnect_arrow)).setVisibility(View.VISIBLE);
                findViewById(R.id.epsonconnect_separator).setVisibility(View.VISIBLE);
                mEpsonConnectView.setVisibility(View.VISIBLE);
                return;
            case 1:
                mEpsonConnectView.setClickable(false);
                mEpsonConnectView.setEnabled(false);
                ((TextView) findViewById(R.id.text_epson_connect)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                ((ImageView) findViewById(R.id.epsonconnect_arrow)).setVisibility(View.GONE);
                findViewById(R.id.epsonconnect_separator).setVisibility(View.VISIBLE);
                mEpsonConnectView.setVisibility(View.VISIBLE);
                return;
            case 2:
                mEpsonConnectView.setClickable(false);
                mEpsonConnectView.setEnabled(false);
                ((TextView) findViewById(R.id.text_epson_connect)).setTextColor(mContext.getResources().getColor(R.color.light_gray));
                ((ImageView) findViewById(R.id.epsonconnect_arrow)).setVisibility(View.GONE);
                findViewById(R.id.epsonconnect_separator).setVisibility(View.GONE);
                mEpsonConnectView.setVisibility(View.GONE);
                return;
            default:
                return;
        }
    }

    private void startBrowseNozzleCheckGuidance() {
        showDialog(DIALOG_PROGRESS);
        BuyInkTask(2, printerIp);
    }

    private void BuyInkTask(int i, String str) {
        if (modelBuyInkOnlineRegTask.getReady()) {
            modelBuyInkOnlineRegTask.loadData(i, str);
        }
    }

    private void OnlineRegTask(String str) {
        if (modelBuyInkOnlineRegTask.getReady()) {
            modelBuyInkOnlineRegTask.loadData(str);
        }
    }

    public static boolean disableSimpleApAndWait(Context context, String str) {
        if (!WiFiDirectManager.disconnect(context, WiFiDirectManager.DEVICE_TYPE_PRINTER, str)) {
            return false;
        }
        int i = 0;
        while (i < 10) {
            try {
                if (Utils.isOnline(context)) {
                    return true;
                }
                EPLog.d(TAG, "Wait Connection 3G");
                i++;
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }

    private void showDialog(String str) {
        DialogProgress newInstance = DialogProgress.newInstance(str, 0, getString(R.string.str_wait));
        newInstance.setCancelable(false);
        newInstance.show(getSupportFragmentManager(), str);
    }

    private void dismissDialog(String str) {
        DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(str);
        if (dialogFragment != null) {
            dialogFragment.dismiss();
        }
    }

    private class NozzleCheckTask extends AsyncTask<Void, Void, Integer> {
        private NozzleCheckTask() {
        }

        protected void onPreExecute() {
            MaintainActivity.this.showProDia();
        }

        protected Integer doInBackground(Void... voidArr) {
            return Integer.valueOf(MaintainActivity.mPrinter.doDoMainteCmd(3));
        }

        protected void onPostExecute(Integer num) {
            MaintainActivity.this.cancelProDia();
            if (num.intValue() == 108) {
                MaintainActivity.this.setupErrorMessage(10);
            } else {
                MaintainActivity.this.showNozzleCheckGuidanceDialog();
            }
        }
    }
}
