package epson.print;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.epson.iprint.prtlogger.Analytics;
import com.epson.memcardacc.DirectorySelecterActivity;
import com.epson.mobilephone.common.ble.BleAsyncTask;
import com.epson.mobilephone.common.ble.BleWork;
import com.epson.mobilephone.common.guide.NoticeGuideActivity;
import com.epson.mobilephone.common.license.LicenseTopActivity;
import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
import com.epson.mobilephone.common.wifidirect.ActivityRequestLocationPermission;
import com.epson.mobilephone.common.wifidirect.NfcTagUtils;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;

import epson.common.Constants;
import epson.common.ExternalFileUtils;
import epson.common.InformationGuide;
import epson.common.IprintLicenseInfo;
import epson.common.IprintUserSurveyInfo;
import epson.common.Utils;
import epson.maintain.activity.MaintainActivity;
import epson.print.Util.BuyInkUrl;
import epson.print.Util.EPLog;
import epson.print.inkrpln.InkRplnInfoClient;
import epson.print.inkrpln.InkRplnRepository;
import epson.print.inkrpln.JumpUrlProgressActivity;
import epson.print.screen.PrintSetting;
import epson.server.utils.Define;
import epson.support.SupportActivity;

/**
 * 主页
 */
public class IprintHome extends ActivityIACommon implements CommonDefine {
    
    private static final int EPS_COMM_BID = 2;
    private static final int EPS_ERR_PRINTER_NOT_FOUND = -1300;
    private static final int EPS_PRB_BYID = 1;
    private static final int EPS_PRNERR_COMM = 102;
    public static final String MORE_APP_URL = "http://iprint.epsonconnect.com/app/index.htm";
    private static final int REQUEST_CODE_LICENSE_CHECK = 1;
    private static final int REQUEST_CODE_LOCATION_PERMISSION = 2;
    private static final int REQUEST_GUIDE_DISPLAY = 3;
    private static final int STRING_ID_READY_INK = 2131625026;
    private static final String TAG = "IprintHome";
    public static MaintainPrinter2 mPrinter;
    private final int Menu_Show_Support = 1;
    private final int PROBE_ERROR = 2;
    private final int PROBE_PRINTER = 0;
    private final int STATUS_ERROR = 3;
    private final int UPDATE_PRINTER_STATUS = 1;
    private boolean bRejectLocationPermission = false;
    String deviceID;
    boolean finishProbe;
    private boolean mActivityForeground;
    private ArrayList<Runnable> mForegroundRunnableList;
    
    Handler mHandler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message message) {
            
            EPLog.i(TAG, "HandlerCallback");
            
            switch (message.what) {
                case 0:
                    EPLog.i(TAG, "PROBE_PRINTER");
                    IprintHome iprintHome = IprintHome.this;
                    finishProbe = false;
                    if (task == null) {
                        IprintHome iprintHome2 = IprintHome.this;
                        iprintHome2.task = new ProbePrinter();
                        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
                        mHandler.sendEmptyMessage(1);
                        break;
                    }
                    break;
                case 1:
                    EPLog.i(TAG, "UPDATE_PRINTER_STATUS");
                    int[] unused = mPrinterStatus = mPrinter.getMPrinterInfor().getMStatus();
                    EpLog.d("status " + mPrinterStatus);
                    EpLog.d("printerLocation " + printerLocation);
                    EpLog.d("finishProbe" + finishProbe);
                    String str = "";
                    if (printerLocation == 1 && WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER) != null) {
                        str = getString(R.string.wifi_direct_status);
                    } else if (printerLocation == 1 || (printerLocation == 3 && Utils.isConnectedWifi(getApplicationContext()))) {
                        if (finishProbe) {
                            str = getString(R.string.printer_ready);
                        }
                    } else if (printerLocation != 2 && (printerLocation != 3 || Utils.isConnectedWifi(getApplicationContext()))) {
                        str = getString(R.string.not_select_status);
                    } else if (!Utils.isOnline(getApplicationContext())) {
                        str = getString(R.string.cannot_connect);
                    } else {
                        str = getString(R.string.remote_can_connect);
                    }
                    printerStatus.setText(str);
                    EPLog.i(TAG, "Stt title: " + str);
                    break;
                case 2:
                    printerStatus.setText(getString(R.string.comm_error));
                    EPLog.i(TAG, "Stt title: " + getString(R.string.comm_error));
                    break;
                case 3:
                    EPLog.i(TAG, "STATUS_ERROR");
                    int[] intArray = message.getData().getIntArray("STATUS_ERROR");
                    if (intArray == null) {
                        printerStatus.setText(getString(R.string.upon_error));
                        EPLog.i(TAG, "Stt titlef: " + getString(R.string.upon_error));
                        break;
                    } else {
                        EPLog.i(TAG, "statusError[0] : " + intArray[0]);
                        EPLog.i(TAG, "statusError[1] : " + intArray[1]);
                        if (intArray[0] != 2 && intArray[0] != 1 && intArray[0] != 3) {
                            if (intArray[0] != 4 || (intArray[1] != 102 && intArray[1] != -1300)) {
                                printerStatus.setText(getString(R.string.upon_error));
                                EPLog.i(TAG, "Stt title: " + getString(R.string.upon_error));
                                break;
                            } else {
                                printerStatus.setText(getString(R.string.comm_error));
                                EPLog.i(TAG, "Stt title: " + getString(R.string.comm_error));
                                break;
                            }
                        } else {
                            printerStatus.setText(getString(R.string.printer_ready));
                            EPLog.i(TAG, "Stt title: " + getString(R.string.printer_ready));
                            break;
                        }
                    }
                    break;
                default:
                    EPLog.i(TAG, DirectorySelecterActivity.PARAM_DEFAULT_DIR);
                    printerName.setText(getString(R.string.printer_not_select));
                    ((ImageView) findViewById(R.id.printer_icon)).setVisibility(View.GONE);
                    break;
            }
            return true;
        }
    });
    final IprintHomeMenuLogging mIprintHomeLogging = new IprintHomeMenuLogging();
    ViewGroup mLayout;
    private int[] mPrinterStatus;
    AsymmetricGridView menulist;
    int printerIcon;
    private String printerId;
    private String printerIp;
    private int printerLocation;
    TextView printerName;
    String printerSerial;
    TextView printerStatus;
    ProbePrinter task;
    epson.print.Util.Utils util = new epson.print.Util.Utils();

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        mLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.iprint_home_layout, (ViewGroup) null);
        menulist = (AsymmetricGridView) mLayout.findViewById(R.id.menu_list);
        printerName = (TextView) mLayout.findViewById(R.id.home_printer_name);
        printerStatus = (TextView) mLayout.findViewById(R.id.home_printer_status);
        setContentView((View) mLayout);
        setActionBar(R.string.app_name, false);
        if (mPrinter == null) {
            mPrinter = MaintainPrinter2.getInstance();
        }
        File file = new File(DEFAULT_FOLDER + ".print");
        if (file.exists()) {
            boolean isDirectory = file.isDirectory();
        } else {
            File file2 = new File(DEFAULT_FOLDER);
            file2.renameTo(new File(DEFAULT_FOLDER + ".print"));
        }
        ExternalFileUtils.getInstance(this).initTempViewDir();
        ExternalFileUtils.getInstance(this).initTempCRDir();
        ExternalFileUtils.getInstance(this).initPrintDir();
        if (Build.VERSION.SDK_INT >= 24) {
            deleteSharedPreferences(Define.SHARED_PREFERENCES_NAME2);
        } else {
            getSharedPreferences(Define.SHARED_PREFERENCES_NAME2, 3).edit().clear().commit();
        }
        mForegroundRunnableList = new ArrayList<>();
        mActivityForeground = true;
        findViewById(R.id.home_select_printer).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent(this, MaintainActivity.class);
                intent.setAction("android.intent.action.VIEW");
                startActivity(intent);
                Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_HOME_MAINTAIN);
            }
        });
        if (bundle == null) {
            startLicenseCheckActivity();
        } else if (!IprintLicenseInfo.isAgreedCurrentVersion(getApplicationContext())) {
            finish();
        }
    }

    private void startLicenseCheckActivity() {
        IprintLicenseInfo.beforeLicenseCheck(getApplicationContext());
        startActivityForResult(LicenseTopActivity.getStartIntent(getApplicationContext(), new IprintLicenseInfo(), new IprintUserSurveyInfo()), 1);
    }

    private void requestLocationPermission() {
        if (!bRejectLocationPermission && !ActivityRequestLocationPermission.canAccessWiFiInfo(this, 4) && BleWork.isStartBleProcess(this, true)) {
            ActivityRequestLocationPermission.requestLocationPermission((Activity) this, 2);
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        switch (i) {
            case 1:
                if (i2 != -1) {
                    finish();
                    return;
                } else {
                    startGuideActivity();
                    return;
                }
            case 2:
                if (i2 != -1) {
                    bRejectLocationPermission = true;
                    return;
                }
                return;
            case 3:
                requestLocationPermission();
                return;
            default:
                return;
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        EPLog.d(TAG, "onConfigurationChanged");
        super.onConfigurationChanged(configuration);
        updateMenu();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == R.id.information_setting) {
            callInformation();
        }
        return super.onOptionsItemSelected(menuItem);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.information_menu, menu);
        return true;
    }

    private void callInformation() {
        startActivity(new Intent(this, SupportActivity.class));
        Analytics.sendAction(this, Analytics.ACTION_ID_HOME_INFO);
    }

    protected void onResume() {
        EPLog.i(TAG, "onResume()");
        EpLog.i();
        super.onResume();
        ExternalFileUtils.getInstance(this).initTempViewDir();
        ExternalFileUtils.getInstance(this).initTempCRDir();
        ExternalFileUtils.getInstance(this).initPrintDir();
        new PrintSetting(this, (PrintSetting.Kind) null).resetPrintSettings();
        updatePrinterInfo();
        NfcTagUtils.enableForegroundDispatch(this, (IntentFilter[]) null, (String[][]) null);
        Analytics.countScreen(this, Analytics.SCREEN_ID_HOME);
        if (!executeForegroundQueue() && BleWork.isStartBleProcess(this, true)) {
            BleAsyncTask.blePrinterCheck(this);
        }
        mActivityForeground = true;
    }

    private boolean executeForegroundQueue() {
        boolean z = false;
        if (isFinishing()) {
            return false;
        }
        ListIterator<Runnable> listIterator = mForegroundRunnableList.listIterator();
        while (listIterator.hasNext()) {
            mHandler.post(listIterator.next());
            listIterator.remove();
            z = true;
        }
        return z;
    }

    public void onBackPressed() {
        moveTaskToBack(true);
    }

    public void onPause() {
        ProbePrinter probePrinter;
        EPLog.i(TAG, "onPause()");
        super.onPause();
        mHandler.removeMessages(0);
        mHandler.removeMessages(1);
        int i = printerLocation;
        if ((i == 1 || i == 3) && (probePrinter = task) != null) {
            probePrinter.cancelTask(true);
            task = null;
        }
        BleAsyncTask.blePrinterCheckStop();
        NfcTagUtils.disableForegroundDispatch(this);
        mActivityForeground = false;
    }

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

    protected void onDestroy() {
        super.onDestroy();
        mPrinter.doReleaseDriver();
    }

    protected void onNewIntent(Intent intent) {
        NfcTagUtils.EpsonNfcConnectInfo parseNECTag;
        super.onNewIntent(intent);
        if ("android.nfc.action.NDEF_DISCOVERED".equals(intent.getAction()) && (parseNECTag = NfcTagUtils.parseNECTag(this, intent)) != null && NfcTagUtils.isNeedChangePrinter(this, printerId, parseNECTag)) {
            Intent intent2 = new Intent();
            intent2.setClass(this, ActivityNfcPrinter.class);
            intent2.putExtra(ActivityNfcPrinter.CONNECTINFO, parseNECTag);
            startActivity(intent2);
        }
    }

    private void updatePrinterInfo() {
        EpLog.d(TAG, "updatePrinterInfo");
        MyPrinter curPrinter = MyPrinter.getCurPrinter(this);
        if (curPrinter.getName() != null) {
            printerName.setText(curPrinter.getUserDefName(this));
        } else {
            printerName.setText(getString(R.string.printer_not_select));
        }
        printerId = curPrinter.getPrinterId();
        printerIp = curPrinter.getIp();
        printerLocation = curPrinter.getLocation();
        printerSerial = curPrinter.getSerialNo();
        deviceID = curPrinter.getName();
        EpLog.d(TAG, "" + printerId + ":" + printerIp + ":" + printerLocation + ":" + printerSerial + ":" + deviceID);
        updatePrinterIcon();
        updateMenu();
        if (!(printerLocation == 1 && WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER) == null) && (printerLocation != 3 || !Utils.isConnectedWifi(getApplicationContext()))) {
            EpLog.d(TAG, "########################");
            mHandler.sendEmptyMessage(1);
            return;
        }
        EpLog.d(TAG, "@@@@@@@@@@@@@@@@@@@@@@");
        mHandler.sendEmptyMessage(0);
    }

    private void updatePrinterIcon() {
        if (printerName.getText().equals(getString(R.string.printer_not_select))) {
            ((ImageView) findViewById(R.id.printer_icon)).setVisibility(View.GONE);
            return;
        }
        ((ImageView) findViewById(R.id.printer_icon)).setVisibility(View.VISIBLE);
        switch (printerLocation) {
            case 1:
                ((ImageView) findViewById(R.id.printer_icon)).setImageResource(R.drawable.print_local);
                return;
            case 2:
                ((ImageView) findViewById(R.id.printer_icon)).setImageResource(R.drawable.print_remote);
                return;
            case 3:
                ((ImageView) findViewById(R.id.printer_icon)).setImageResource(R.drawable.print_ip);
                return;
            default:
                return;
        }
    }

    private class ProbePrinter extends AsyncTask<Void, Void, Boolean> {
        private ProbePrinter() {
        }

        protected void onPreExecute() {
            EPLog.i(TAG, "ProbePrinter onPreExecute");
            printerStatus.setText("");
        }

        protected Boolean doInBackground(Void... voidArr) {
            EPLog.i(TAG, "ProbePrinter doInBackground");
            mPrinter.doInitDriver(this, 2);
            if (printerLocation == 1 || printerLocation == 3) {
                if (printerId != null) {
                    int doProbePrinter = mPrinter.doProbePrinter(60, printerId, printerIp, printerLocation);
                    while (doProbePrinter != 0) {
                        try {
                            if (isCancelled()) {
                                break;
                            }
                            mHandler.sendEmptyMessage(2);
                            Thread.sleep(10000);
                            doProbePrinter = mPrinter.doProbePrinter(60, printerId, printerIp, printerLocation);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            return false;
                        }
                    }
                    finishProbe = true;
                    if (isCancelled()) {
                        EPLog.i(TAG, "Cancelled ProbePrinter");
                        return false;
                    }
                    int doSetPrinter = mPrinter.doSetPrinter();
                    EPLog.i(TAG, "Set Printer result: " + doSetPrinter);
                    if (doSetPrinter != 0) {
                        mHandler.sendEmptyMessage(2);
                        return false;
                    }
                    while (!isCancelled()) {
                        try {
                            int doGetStatus = mPrinter.doGetStatus();
                            EPLog.i(TAG, "Printer Status result: " + doGetStatus);
                            if (doGetStatus != 0) {
                                mHandler.sendEmptyMessage(2);
                            } else {
                                int[] unused = mPrinterStatus = mPrinter.getMPrinterInfor().getMStatus();
                                if (mPrinterStatus[0] != 0) {
                                    Message message = new Message();
                                    message.what = 3;
                                    Bundle bundle = new Bundle();
                                    bundle.putIntArray("STATUS_ERROR", mPrinterStatus);
                                    message.setData(bundle);
                                    mHandler.sendMessage(message);
                                } else {
                                    mHandler.sendEmptyMessage(1);
                                }
                            }
                            Thread.sleep(10000);
                        } catch (InterruptedException e2) {
                            EPLog.w("Background", "InterruptedException");
                            e2.printStackTrace();
                        }
                    }
                    EPLog.i(TAG, "task Cancelled");
                } else {
                    int unused2 = printerLocation = 0;
                }
            }
            return true;
        }

        public boolean cancelTask(boolean z) {
            EPLog.i(TAG, "ProbePrinter cancelTask IN");
            mPrinter.doCancelFindPrinter();
            EPLog.i(TAG, "ProbePrinter cancelTask OUT");
            return cancel(z);
        }

        protected void onPostExecute(Boolean bool) {
            EPLog.i(TAG, "ProbePrinter onPostExecute");
            if (bool.booleanValue()) {
                mHandler.sendEmptyMessage(1);
            }
        }
    }

    private void updateMenu() {
        Display defaultDisplay = getWindowManager().getDefaultDisplay();
        Point point = new Point();
        defaultDisplay.getSize(point);
        int i = point.x;
        int i2 = point.y;
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) menulist.getLayoutParams();
        int i3 = ((i) * 0.1d);
        marginLayoutParams.setMargins(i3, ((i2) * 0.025d), i3, 0);
        menulist.setLayoutParams(marginLayoutParams);
        final IconTextArrayAdapter iconTextArrayAdapter = new IconTextArrayAdapter(this, R.layout.menu_item_btn, makeMenu(), menulist);
        menulist.setAdapter((ListAdapter) iconTextArrayAdapter);
        menulist.setRequestedColumnCount(3);
        menulist.setRequestedHorizontalSpacing(com.felipecsl.asymmetricgridview.library.Utils.dpToPx(this, 3.0f));
        menulist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                Intent intent = new Intent();
                IconTextArrayItem iconTextArrayItem = (IconTextArrayItem) iconTextArrayAdapter.getItem(i);
                if (iconTextArrayItem == null) {
                    return;
                }
                if (!iconTextArrayItem.showMenu) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle(iconTextArrayItem.menuId);
                    if (printerLocation == 3) {
                        builder.setMessage(R.string.CannotIPMes);
                    } else if (printerLocation == 2) {
                        builder.setMessage(R.string.CannotRemoteMes);
                    } else {
                        return;
                    }
                    builder.setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    });
                    builder.show();
                } else if (getString(iconTextArrayItem.menuId).equalsIgnoreCase(getString(R.string.support_buy_ink))) {
                    getBuyInkTask().execute(new Void[0]);
                    Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_HOME_BUY_INK);
                } else if (iconTextArrayItem.menuId == R.string.ready_ink_button_name) {
                    Analytics.sendAction(getApplicationContext(), Analytics.ACTION_ID_HOME_READY_INK);
                    openReadyInkPage();
                } else {
                    if (getString(iconTextArrayItem.menuId).equalsIgnoreCase(getString(R.string.FunctionName_iPrint_MoreApps))) {
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(Uri.parse(MORE_APP_URL));
                        mIprintHomeLogging.countupMoreApp(this);
                    } else if (!iconTextArrayItem.ClassName.equalsIgnoreCase("")) {
                        if (!iconTextArrayItem.appId.equals("Creative") && !iconTextArrayItem.appId.equalsIgnoreCase("3DFramePrint") && !iconTextArrayItem.appId.equalsIgnoreCase("CameraCopy") && !iconTextArrayItem.appId.equalsIgnoreCase("MultiRollPrint") && !iconTextArrayItem.appId.equalsIgnoreCase("CardPrint") && !iconTextArrayItem.appId.equalsIgnoreCase("Nenga")) {
                            intent.setClassName(iconTextArrayItem.PackageName, iconTextArrayItem.ClassName);
                            mIprintHomeLogging.sendUiTapData(getApplicationContext(), iconTextArrayItem.ClassName);
                        } else if (iconTextArrayItem.isInstall) {
                            intent.setAction(iconTextArrayItem.ClassName);
                            intent.setFlags(270532608);
                            intent.putExtra(Constants.PRINTER_ID, printerId);
                            intent.putExtra(Constants.PRINTER_IP, printerIp);
                            intent.putExtra(Constants.PRINTER_NAME, deviceID);
                            intent.putExtra("PRINTER_SERIAL", printerSerial);
                            intent.putExtra("Function", iconTextArrayItem.key);
                            intent.putExtra("PRINTER_SSID", WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER));
                            mIprintHomeLogging.countUpInstalledOtherApps(this, iconTextArrayItem);
                        } else {
                            intent.setAction("android.intent.action.VIEW");
                            intent.setData(Uri.parse(iconTextArrayItem.googleStoreUrl));
                            mIprintHomeLogging.countUpNotInstalledOtherApps(this, iconTextArrayItem);
                        }
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException unused) {
                        Toast.makeText(this, R.string.upon_error, 0).show();
                    }
                }
            }
        });
    }

    private List<IconTextArrayItem> makeMenu() {
        ArrayList arrayList = new ArrayList();
        MenudataAdapter menudataAdapter = new MenudataAdapter();
        menudataAdapter.setContext(getApplicationContext());
        menudataAdapter.parseJSONFile();
        String str = deviceID;
        if (str == null || str.length() < 4 || MyPrinter.PRINTER_USB.equals(printerIp)) {
            deviceID = "DEFAULT";
        }
        ArrayList<IconTextArrayItem> MenuListfordeviceID = menudataAdapter.MenuListfordeviceID(deviceID, printerLocation, this);
        int i = 0;
        if (!isJapaneseDevice()) {
            int i2 = 0;
            while (true) {
                if (i2 >= MenuListfordeviceID.size()) {
                    break;
                } else if (MenuListfordeviceID.get(i2).appId.equalsIgnoreCase("CardPrint")) {
                    MenuListfordeviceID.remove(i2);
                    break;
                } else {
                    i2++;
                }
            }
        }
        while (true) {
            if (i >= MenuListfordeviceID.size()) {
                break;
            }
            if (MenuListfordeviceID.get(i).appId.equalsIgnoreCase("Nenga")) {
                MyPrinter curPrinter = MyPrinter.getCurPrinter(this);
                if (curPrinter.getPrinterId() == null || curPrinter.getLang() != 1 || !isJapaneseDevice() || MyPrinter.PRINTER_USB.equals(printerIp)) {
                    MenuListfordeviceID.remove(i);
                } else {
                    try {
                        if (201900000 > getPackageManager().getPackageInfo(MenuListfordeviceID.get(i).PackageName, 128).versionCode) {
                            MenuListfordeviceID.remove(i);
                            break;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
            i++;
        }
        MenuListfordeviceID.remove(i);
        arrayList.addAll(MenuListfordeviceID);
        addBuyInkOrReadyInkToMenu(arrayList);
        return arrayList;
    }

    private void addBuyInkOrReadyInkToMenu(@NonNull List<IconTextArrayItem> list) {
        switch (getBuyInkReadyInkButtonType()) {
            case 1:
                addReadyInkToMenuEnd(list);
                return;
            case 2:
                addReadyInkToMenuEnd(list);
                return;
            default:
                return;
        }
    }

    private int getBuyInkReadyInkButtonType() {
        InkRplnInfoClient.InkRsInfo info = new InkRplnRepository(false).getInfo(this);
        if (info == null) {
            return 0;
        }
        return info.getButtonType();
    }

    private void addReadyInkToMenuEnd(@NonNull List<IconTextArrayItem> list) {
        list.add(new IconTextArrayItem(R.drawable.image_ready_ink, R.string.ready_ink_button_name, ""));
    }

    private void addBuyInkToMenu(@NonNull List<IconTextArrayItem> list) {
        IconTextArrayItem iconTextArrayItem;
        if (printerLocation == 0) {
            iconTextArrayItem = new IconTextArrayItem(R.drawable.image_buyink_disabled, R.string.support_buy_ink, "");
            iconTextArrayItem.showMenu = false;
        } else {
            iconTextArrayItem = new IconTextArrayItem(R.drawable.image_buyink, R.string.support_buy_ink, "");
        }
        list.add(1, iconTextArrayItem);
    }

    class BuyInkTask extends AsyncTask<Void, Void, Void> {
        BuyInkTask() {
        }

        protected void onPreExecute() {
            if (task != null) {
                task.cancelTask(true);
                task = null;
            }
        }

        protected Void doInBackground(Void... voidArr) {
            startActivity(new Intent("android.intent.action.VIEW", Uri.parse(BuyInkUrl.urlSupport(getApplicationContext(), CommonDefine.URL_INK))));
            return null;
        }
    }

    private BuyInkTask getBuyInkTask() {
        return new BuyInkTask();
    }

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

    private boolean isJapaneseDevice() {
        return Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage());
    }

    public void startGuideActivity() {
        InformationGuide informationGuide = new InformationGuide(getApplicationContext());
        Intent intent = new Intent(this, NoticeGuideActivity.class);
        intent.putExtra(NoticeGuideActivity.KEY_HTML_PATH, informationGuide.getHtmlPath());
        intent.putExtra(NoticeGuideActivity.KEY_GUIDE_VER, InformationGuide.GUIDE_VER);
        intent.putExtra(NoticeGuideActivity.KEY_BOOT_MODE, NoticeGuideActivity.MODE_AUTO);
        startActivityForResult(intent, 3);
    }
}
