NVRSettingSearchChnDevActivity.java 源代码


package main.NVR.Setting;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import base.HiActivity;
import bean.MyCamera;
import com.hichip.NVR.content.HiChipNVRDefines;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.campro.R;
import com.hichip.control.HiCamera;
import com.hichip.tools.Packet;
import com.xiaomi.mipush.sdk.Constants;
import common.ConstantCommand;
import common.HiDataValue;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import main.MainActivity;
import utils.HiLogcatUtil;
import utils.HiTools;
import utils.MyToast;

public class NVRSettingSearchChnDevActivity extends HiActivity implements View.OnClickListener, ICameraIOSessionCallback, AdapterView.OnItemClickListener {
    private static final int FAST_CLICK_DELAY_TIME = 1000;
    private static final Pattern PATTERN = Pattern.compile("^((2([0-4]\\d|5[0-5])|[01]?\\d{1,2})\\.){3}(2([0-4]\\d|5[0-5])|[01]?\\d{1,2})$");
    private static final int REQUESTCODE_CHANGE = 111;
    private NVRDeviceAdapter adapter;
    HiChipNVRDefines.PLATFORM_S_CHNINFO_D chninfo;
    ImageView iv_return;
    ImageView iv_select_chndev;
    private MyCamera mMyCamera;
    TextView nvrcam_no_dev_list;
    ListView nvrcam_setting_dev_list;
    private int setAdapterOrFresh;
    TextView title_middle;
    TextView tv_right;
    ArrayList<HiChipNVRDefines.PLATFORM_S_CHNINFO_D> eqBaseList = new ArrayList<>();
    private boolean isAllSelect = false;
    private boolean isNo_Select = false;
    private int mNeedAdd_Num = 0;
    private int maagertype = 0;
    private Handler mIOHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            MyCamera myCamera = (MyCamera) message.obj;
            switch (message.what) {
                case HiDataValue.HANDLE_MESSAGE_SESSION_STATE:
                    NVRSettingSearchChnDevActivity.this.handSessionState(message, myCamera);
                    return;
                case HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL:
                    HiLogcatUtil.e("HANDLE_MESSAGE_RECEIVE_IOCTRL:" + myCamera.getUid() + Constants.COLON_SEPARATOR + message.arg1);
                    if (message.arg2 == 0) {
                        NVRSettingSearchChnDevActivity.this.handIOCTRLSuccess(message, myCamera);
                        return;
                    } else {
                        NVRSettingSearchChnDevActivity.this.handIOCTRLFail(message, myCamera);
                        return;
                    }
                case ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE:
                    NVRSettingSearchChnDevActivity.this.dismissjuHuaDialog();
                    NVRSettingSearchChnDevActivity.this.dismissLoadDialog();
                    MyToast.showToast(NVRSettingSearchChnDevActivity.this.getApplicationContext(), NVRSettingSearchChnDevActivity.this.getString(R.string.netword_abnormal));
                    NVRSettingSearchChnDevActivity.this.startActivity(new Intent(NVRSettingSearchChnDevActivity.this, (Class<?>) MainActivity.class), true);
                    return;
                case ConstantCommand.HI_P2P_SET_DEVICE_WORKING_MODE:
                    NVRSettingSearchChnDevActivity.this.dismissjuHuaDialog();
                    NVRSettingSearchChnDevActivity.this.dismissLoadDialog();
                    HiDataValue.isNeedkillNoMain = false;
                    NVRSettingSearchChnDevActivity.this.startActivity(new Intent(NVRSettingSearchChnDevActivity.this, (Class<?>) MainActivity.class), true);
                    return;
                default:
                    return;
            }
        }
    };
    int mAddretnum = 0;
    private List<ChnSearchInfo> mChandev_list = Collections.synchronizedList(new ArrayList());
    public List<ChnSearchInfo> add_video_list = new ArrayList();
    private List<HiChipNVRDefines.PLATFORM_S_DEVICEPARAM> mNVRDevlist = Collections.synchronizedList(new ArrayList());
    private long lastClickTime = 0;

    private void initViewAndData() {
    }

    @Override
    protected int setLayoutId() {
        return R.layout.activity_searchchndev;
    }

    @Override
    protected void init(Bundle bundle) {
        getIntentData();
        if (HiTools.cameraWhetherNull(this.mMyCamera, this)) {
            return;
        }
        initView();
        initViewAndData();
        setListeners();
    }

    private void getIntentData() {
        String stringExtra = getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
        this.chninfo = (HiChipNVRDefines.PLATFORM_S_CHNINFO_D) getIntent().getSerializableExtra("mNVRChnlist");
        List list = (List) getIntent().getSerializableExtra("mList");
        if (this.eqBaseList != null && list != null && list.size() > 0) {
            this.eqBaseList.addAll(list);
        }
        if (TextUtils.isEmpty(stringExtra)) {
            MyToast.showToast(this, "UID is Empty");
            finish();
            return;
        }
        Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            MyCamera next = it.next();
            if (stringExtra.equalsIgnoreCase(next.getUid())) {
                this.mMyCamera = next;
                break;
            }
        }
        if (HiTools.cameraWhetherNull(this.mMyCamera, this)) {
            return;
        }
        this.mNeedAdd_Num = this.mMyCamera.getmNvrChannelMaxNum();
        if (this.eqBaseList != null) {
            for (int i = 0; i < this.eqBaseList.size(); i++) {
                String string = Packet.getString(this.eqBaseList.get(i).szHostName);
                HiLogcatUtil.e(this.eqBaseList.size() + "::" + i + "::::" + this.eqBaseList.get(i).u32ChnNum + ":::" + string + ":::" + Packet.getString(this.eqBaseList.get(i).szAlias) + ":::" + Packet.getString(this.eqBaseList.get(i).szUUID));
                if (!TextUtils.isEmpty(string) && string.length() > 8) {
                    this.mNeedAdd_Num--;
                }
            }
        }
        if (this.mNeedAdd_Num <= 0) {
            this.isNo_Select = true;
        }
    }

    private void initView() {
        this.iv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NVRSettingSearchChnDevActivity.this.finish();
            }
        });
        this.title_middle.setText(getString(R.string.nvrsetting_camerafun));
        this.tv_right.setText(getString(R.string.finish));
        this.tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (NVRSettingSearchChnDevActivity.this.add_video_list.size() > 0) {
                    NVRSettingSearchChnDevActivity.this.maagertype = 0;
                    if (NVRSettingSearchChnDevActivity.this.add_video_list.size() == 1) {
                        NVRSettingSearchChnDevActivity.this.Hi_ChangeChn();
                        return;
                    }
                    NVRSettingSearchChnDevActivity.this.showjuHuaDialog(false);
                    if (NVRSettingSearchChnDevActivity.this.eqBaseList != null) {
                        int i = 0;
                        for (int i2 = 0; i2 < NVRSettingSearchChnDevActivity.this.eqBaseList.size(); i2++) {
                            String string = Packet.getString(NVRSettingSearchChnDevActivity.this.eqBaseList.get(i2).szHostName);
                            HiLogcatUtil.e(NVRSettingSearchChnDevActivity.this.eqBaseList.size() + "::" + i2 + "::::" + NVRSettingSearchChnDevActivity.this.eqBaseList.get(i2).u32ChnNum + ":::" + string + ":::" + Packet.getString(NVRSettingSearchChnDevActivity.this.eqBaseList.get(i2).szAlias) + ":::" + Packet.getString(NVRSettingSearchChnDevActivity.this.eqBaseList.get(i2).szUUID));
                            if (TextUtils.isEmpty(string) || string.length() < 8) {
                                if (NVRSettingSearchChnDevActivity.this.add_video_list.size() <= i) {
                                    return;
                                }
                                HiChipNVRDefines.PLATFORM_S_CHNINFO_D platform_s_chninfo_d = new HiChipNVRDefines.PLATFORM_S_CHNINFO_D(new byte[700]);
                                HiChipNVRDefines.PLATFORM_S_DEVICEPARAM chninfo = NVRSettingSearchChnDevActivity.this.add_video_list.get(i).getChninfo();
                                platform_s_chninfo_d.cmdflag = NVRSettingSearchChnDevActivity.this.maagertype;
                                if (NVRSettingSearchChnDevActivity.this.maagertype == 0 || 1 == NVRSettingSearchChnDevActivity.this.maagertype) {
                                    platform_s_chninfo_d.u32enable = 1;
                                }
                                platform_s_chninfo_d.u32ChnNum = NVRSettingSearchChnDevActivity.this.eqBaseList.get(i2).u32ChnNum;
                                Arrays.fill(platform_s_chninfo_d.szAlias, (byte) 0);
                                Arrays.fill(platform_s_chninfo_d.szUserName, (byte) 0);
                                Arrays.fill(platform_s_chninfo_d.szPassword, (byte) 0);
                                System.arraycopy(HiDataValue.START_WITH_IPCAM.getBytes(), 0, platform_s_chninfo_d.szAlias, 0, HiDataValue.START_WITH_IPCAM.getBytes().length);
                                System.arraycopy("admin".getBytes(), 0, platform_s_chninfo_d.szUserName, 0, "admin".getBytes().length);
                                System.arraycopy("admin".getBytes(), 0, platform_s_chninfo_d.szPassword, 0, "admin".getBytes().length);
                                platform_s_chninfo_d.bAliasEnable = 0;
                                platform_s_chninfo_d.eIpcType = 0;
                                platform_s_chninfo_d.u32Port = chninfo.u32HttpPort;
                                Arrays.fill(platform_s_chninfo_d.szHostName, (byte) 0);
                                System.arraycopy(chninfo.szHostName, 0, platform_s_chninfo_d.szHostName, 0, chninfo.szHostName.length);
                                platform_s_chninfo_d.u32Port = chninfo.u32HttpPort;
                                platform_s_chninfo_d.u32Protocol = chninfo.u32Flag;
                                Arrays.fill(platform_s_chninfo_d.szUUID, (byte) 0);
                                Arrays.fill(platform_s_chninfo_d.szMac, (byte) 0);
                                System.arraycopy(chninfo.szUID, 0, platform_s_chninfo_d.szUUID, 0, chninfo.szUID.length);
                                System.arraycopy(chninfo.szMacAddr, 0, platform_s_chninfo_d.szMac, 0, chninfo.szMacAddr.length);
                                if (NVRSettingSearchChnDevActivity.this.maagertype != 1) {
                                    NVRSettingSearchChnDevActivity nVRSettingSearchChnDevActivity = NVRSettingSearchChnDevActivity.this;
                                    HiTools.RemoveImageFromUrlNVRchn(nVRSettingSearchChnDevActivity, nVRSettingSearchChnDevActivity.mMyCamera, platform_s_chninfo_d.u32ChnNum);
                                }
                                HiLogcatUtil.e(NVRSettingSearchChnDevActivity.this.mMyCamera.getUid() + "HI_NVR_P2P_PLATFORM_GET_DEVICELIST" + Packet.getString(platform_s_chninfo_d.szUUID) + Packet.getString(platform_s_chninfo_d.szUserName) + Packet.getString(platform_s_chninfo_d.szPassword) + "::" + platform_s_chninfo_d.u32Protocol);
                                NVRSettingSearchChnDevActivity.this.mMyCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_SET_CHANNELDEVICE, platform_s_chninfo_d.parseContent());
                                NVRSettingSearchChnDevActivity.this.mMyCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_GET_CHANNELDEVICE, HiChipNVRDefines.PLATFORM_S_CHANNELDEVICE_REQ.parseContent(platform_s_chninfo_d.u32ChnNum));
                                i++;
                            }
                        }
                        return;
                    }
                    return;
                }
                HiLogcatUtil.e("NVRSettingSearchChnDevActivity finish");
                NVRSettingSearchChnDevActivity.this.finish();
            }
        });
        this.nvrcam_setting_dev_list.setVisibility(0);
        NVRDeviceAdapter nVRDeviceAdapter = this.adapter;
        if (nVRDeviceAdapter != null) {
            nVRDeviceAdapter.notifyDataSetChanged();
        } else {
            NVRDeviceAdapter nVRDeviceAdapter2 = new NVRDeviceAdapter(this);
            this.adapter = nVRDeviceAdapter2;
            this.nvrcam_setting_dev_list.setAdapter((ListAdapter) nVRDeviceAdapter2);
        }
        this.nvrcam_setting_dev_list.setVisibility(4);
    }

    public void Hi_ChangeChn() {
        if (this.eqBaseList != null) {
            for (int i = 0; i < this.eqBaseList.size(); i++) {
                HiChipNVRDefines.PLATFORM_S_CHNINFO_D platform_s_chninfo_d = this.eqBaseList.get(i);
                HiLogcatUtil.e(this.eqBaseList.size() + "::" + i + "::::" + this.eqBaseList.get(i).u32ChnNum + ":::");
                if (platform_s_chninfo_d != null) {
                    String string = Packet.getString(platform_s_chninfo_d.szHostName);
                    HiLogcatUtil.e(this.eqBaseList.size() + "::" + i + "::::" + this.eqBaseList.get(i).u32ChnNum + ":::" + string + ":::" + Packet.getString(platform_s_chninfo_d.szAlias) + ":::" + Packet.getString(platform_s_chninfo_d.szUUID));
                    if (TextUtils.isEmpty(string) || string.length() < 8) {
                        HiChipNVRDefines.PLATFORM_S_CHNINFO_D platform_s_chninfo_d2 = new HiChipNVRDefines.PLATFORM_S_CHNINFO_D(new byte[700]);
                        HiChipNVRDefines.PLATFORM_S_DEVICEPARAM chninfo = this.add_video_list.get(0).getChninfo();
                        platform_s_chninfo_d2.cmdflag = this.maagertype;
                        int i2 = this.maagertype;
                        if (i2 == 0 || 1 == i2) {
                            platform_s_chninfo_d2.u32enable = 1;
                        }
                        platform_s_chninfo_d2.u32ChnNum = i;
                        Arrays.fill(platform_s_chninfo_d2.szAlias, (byte) 0);
                        Arrays.fill(platform_s_chninfo_d2.szUserName, (byte) 0);
                        Arrays.fill(platform_s_chninfo_d2.szPassword, (byte) 0);
                        System.arraycopy(HiDataValue.START_WITH_IPCAM.getBytes(), 0, platform_s_chninfo_d2.szAlias, 0, HiDataValue.START_WITH_IPCAM.getBytes().length);
                        System.arraycopy("admin".getBytes(), 0, platform_s_chninfo_d2.szUserName, 0, "admin".getBytes().length);
                        System.arraycopy("admin".getBytes(), 0, platform_s_chninfo_d2.szPassword, 0, "admin".getBytes().length);
                        platform_s_chninfo_d2.bAliasEnable = 0;
                        platform_s_chninfo_d2.eIpcType = 0;
                        platform_s_chninfo_d2.u32Port = chninfo.u32HttpPort;
                        Arrays.fill(platform_s_chninfo_d2.szHostName, (byte) 0);
                        System.arraycopy(chninfo.szHostName, 0, platform_s_chninfo_d2.szHostName, 0, chninfo.szHostName.length);
                        platform_s_chninfo_d2.u32Port = chninfo.u32HttpPort;
                        platform_s_chninfo_d2.u32Protocol = chninfo.u32Flag;
                        Arrays.fill(platform_s_chninfo_d2.szUUID, (byte) 0);
                        Arrays.fill(platform_s_chninfo_d2.szMac, (byte) 0);
                        System.arraycopy(chninfo.szUID, 0, platform_s_chninfo_d2.szUUID, 0, chninfo.szUID.length);
                        System.arraycopy(chninfo.szMacAddr, 0, platform_s_chninfo_d2.szMac, 0, chninfo.szMacAddr.length);
                        HiLogcatUtil.e(this.mMyCamera.getUid() + "HI_NVR_P2P_PLATFORM_GET_DEVICELIST" + Packet.getString(platform_s_chninfo_d2.szUUID) + Packet.getString(platform_s_chninfo_d2.szUserName) + Packet.getString(platform_s_chninfo_d2.szPassword) + "::" + platform_s_chninfo_d2.u32Protocol);
                        Bundle bundle = new Bundle();
                        bundle.putString(HiDataValue.EXTRAS_KEY_UID, this.mMyCamera.getUid());
                        bundle.putSerializable("mNVRChnlist", platform_s_chninfo_d2);
                        Intent intent = new Intent();
                        intent.putExtras(bundle);
                        intent.setClass(this, NVRSettingModifychnActivity.class);
                        intent.putExtra("type", 3);
                        startActivityForResult(intent, 111);
                        finish();
                        return;
                    }
                }
            }
        }
    }

    private void setListeners() {
        this.nvrcam_setting_dev_list.setOnItemClickListener(this);
        this.iv_select_chndev.setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        MyCamera myCamera = this.mMyCamera;
        if (myCamera != null) {
            myCamera.registerIOSessionListener(this);
        }
        this.mIOHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (NVRSettingSearchChnDevActivity.this.mLoadDialoging == null || !NVRSettingSearchChnDevActivity.this.mLoadDialoging.isShowing()) {
                    return;
                }
                NVRSettingSearchChnDevActivity nVRSettingSearchChnDevActivity = NVRSettingSearchChnDevActivity.this;
                MyToast.showToast(nVRSettingSearchChnDevActivity, nVRSettingSearchChnDevActivity.getString(R.string.device_not_return));
                NVRSettingSearchChnDevActivity.this.dismissLoadDialog();
            }
        }, 10000L);
        showLoadDialog(getString(R.string.tips_loading) + "...", false, false);
        this.mLoadDialoging.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                NVRSettingSearchChnDevActivity.this.mIOHandler.removeCallbacksAndMessages(null);
            }
        });
        List<HiChipNVRDefines.PLATFORM_S_DEVICEPARAM> list = this.mNVRDevlist;
        if (list != null) {
            list.clear();
        }
        List<ChnSearchInfo> list2 = this.add_video_list;
        if (list2 != null) {
            list2.clear();
        }
        List<ChnSearchInfo> list3 = this.mChandev_list;
        if (list3 != null && list3.size() > 0) {
            this.mChandev_list.clear();
            NVRDeviceAdapter nVRDeviceAdapter = this.adapter;
            if (nVRDeviceAdapter != null) {
                nVRDeviceAdapter.notifyDataSetChanged();
            }
        }
        this.mMyCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_GET_DEVICELIST, null);
    }

    @Override
    public void onPause() {
        super.onPause();
        MyCamera myCamera = this.mMyCamera;
        if (myCamera != null) {
            myCamera.unregisterIOSessionListener(this);
        }
        Handler handler = this.mIOHandler;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        dismissjuHuaDialog();
        dismissLoadDialog();
        HiLogcatUtil.e("NVRSettingSearchChnDevActivity finish");
        finish();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() != R.id.iv_select_chndev) {
            return;
        }
        HiLogcatUtil.e("" + this.isAllSelect);
        if (!this.isAllSelect) {
            this.iv_select_chndev.setImageResource(R.mipmap.nvr_selectno);
            int i = 0;
            while (true) {
                if (i >= this.mChandev_list.size()) {
                    break;
                }
                ChnSearchInfo chnSearchInfo = this.mChandev_list.get(i);
                chnSearchInfo.setChecked(true);
                if (!this.add_video_list.contains(chnSearchInfo)) {
                    this.add_video_list.add(chnSearchInfo);
                }
                if (this.add_video_list.size() >= this.mNeedAdd_Num) {
                    this.isNo_Select = true;
                    break;
                }
                i++;
            }
            this.adapter.notifyDataSetChanged();
        } else {
            this.iv_select_chndev.setImageResource(R.mipmap.nvr_selectall);
            for (int i2 = 0; i2 < this.mChandev_list.size(); i2++) {
                ChnSearchInfo chnSearchInfo2 = this.mChandev_list.get(i2);
                chnSearchInfo2.setChecked(false);
                if (this.add_video_list.contains(chnSearchInfo2)) {
                    this.add_video_list.remove(chnSearchInfo2);
                }
            }
            this.isNo_Select = false;
            this.adapter.notifyDataSetChanged();
        }
        HiLogcatUtil.e("" + this.isAllSelect + ":::" + this.add_video_list.size() + ":::" + this.mChandev_list.size());
        this.isAllSelect = true ^ this.isAllSelect;
    }

    public void handSessionState(Message message, MyCamera myCamera) {
        int i = message.arg1;
        if (i == 0) {
            if (myCamera == null) {
                return;
            }
            myCamera.ischangepwd = false;
            HiLogcatUtil.i("--CameraFragment p2p DISCONNECTED--:" + myCamera.getUid());
            this.mIOHandler.sendEmptyMessageDelayed(ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE, 1000L);
            return;
        }
        if (i != 3) {
            if (i == 4 && myCamera != null) {
                myCamera.ischangepwd = false;
                HiLogcatUtil.i("--CameraFragment p2p 登录成功--:" + myCamera.getUid());
                return;
            }
            return;
        }
        if (myCamera == null) {
            return;
        }
        myCamera.ischangepwd = false;
        if (myCamera.isHintPsw() == 0) {
            myCamera.setHintPsw(-1);
        }
        myCamera.setNeedUpServer(true);
        HiLogcatUtil.e("--CameraFragment p2p 密码错误--:" + myCamera.getUid());
    }

    public void handIOCTRLSuccess(Message message, MyCamera myCamera) {
        byte[] byteArray = message.getData().getByteArray("data");
        HiDataValue.CameraList.indexOf(myCamera);
        if (byteArray == null) {
            return;
        }
        switch (message.arg1) {
            case HiChipNVRDefines.HI_NVR_P2P_PLATFORM_GET_DEVICELIST:
                HiChipNVRDefines.PLATFORM_S_DEVICELIST_REP platform_s_devicelist_rep = new HiChipNVRDefines.PLATFORM_S_DEVICELIST_REP(byteArray);
                HiLogcatUtil.e(myCamera.getUid() + "HI_NVR_P2P_PLATFORM_GET_DEVICELIST" + platform_s_devicelist_rep.total + "::" + platform_s_devicelist_rep.index + "::" + platform_s_devicelist_rep.endflag + "::" + platform_s_devicelist_rep.count);
                int i = platform_s_devicelist_rep.endflag;
                for (int i2 = platform_s_devicelist_rep.count; i2 > 0; i2 += -1) {
                    HiChipNVRDefines.PLATFORM_S_DEVICEPARAM platform_s_deviceparam = new HiChipNVRDefines.PLATFORM_S_DEVICEPARAM(byteArray, ((platform_s_devicelist_rep.count - i2) * 296) + 12);
                    String encoding = HiTools.getEncoding(platform_s_deviceparam.szUID);
                    this.mNVRDevlist.add(platform_s_deviceparam);
                    this.mChandev_list.add(new ChnSearchInfo(platform_s_deviceparam));
                    HiLogcatUtil.e(myCamera.getUid() + "HI_NVR_P2P_PLATFORM_GET_DEVICELIST" + encoding + "::::" + HiTools.getEncoding(platform_s_deviceparam.szHostName));
                }
                if (i == 3) {
                    this.nvrcam_setting_dev_list.setVisibility(0);
                    HiLogcatUtil.e(myCamera.getUid() + "HI_NVR_P2P_PLATFORM_GET_DEVICELIST" + this.mNVRDevlist.size());
                    if (this.mNVRDevlist.size() == 0) {
                        this.nvrcam_setting_dev_list.setVisibility(8);
                        this.nvrcam_no_dev_list.setVisibility(0);
                    } else {
                        this.nvrcam_setting_dev_list.setVisibility(0);
                        this.nvrcam_no_dev_list.setVisibility(8);
                    }
                    sortListExt();
                    NVRDeviceAdapter nVRDeviceAdapter = this.adapter;
                    if (nVRDeviceAdapter != null) {
                        nVRDeviceAdapter.notifyDataSetChanged();
                        this.adapter.setSelecteMode(true);
                    }
                    dismissLoadDialog();
                    return;
                }
                return;
            case HiChipNVRDefines.HI_NVR_P2P_PLATFORM_SET_CHANNELDEVICE:
                List<ChnSearchInfo> list = this.add_video_list;
                if (list == null || list.size() == 0) {
                    dismissjuHuaDialog();
                    HiLogcatUtil.e("NVRSettingSearchChnDevActivity finish");
                    finish();
                    return;
                }
                this.mAddretnum++;
                HiLogcatUtil.e(this.mAddretnum + "::::" + this.add_video_list.size());
                if (this.mAddretnum == this.add_video_list.size()) {
                    dismissjuHuaDialog();
                    HiLogcatUtil.e("NVRSettingSearchChnDevActivity finish");
                    finish();
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void sortListExt() {
        List<ChnSearchInfo> list = this.mChandev_list;
        if (list == null || list.size() <= 1) {
            return;
        }
        Collections.sort(this.mChandev_list, new Comparator<ChnSearchInfo>() {
            @Override
            public int compare(ChnSearchInfo chnSearchInfo, ChnSearchInfo chnSearchInfo2) {
                return (int) (NVRSettingSearchChnDevActivity.ipToLong(Packet.getString(chnSearchInfo.getChninfo().szHostName)).longValue() - NVRSettingSearchChnDevActivity.ipToLong(Packet.getString(chnSearchInfo2.getChninfo().szHostName)).longValue());
            }
        });
    }

    public static Long ipToLong(String str) {
        if (!PATTERN.matcher(str).find()) {
            throw new RuntimeException("ip 格式不正确");
        }
        String[] split = str.split("\\.");
        return Long.valueOf((Long.parseLong(split[0]) << 24) + (Long.parseLong(split[1]) << 16) + (Long.parseLong(split[2]) << 8) + Long.parseLong(split[3]));
    }

    private static int stringToInt(String str) throws UnknownHostException {
        if (str == null) {
            return 0;
        }
        try {
            String[] split = str.split("\\.");
            if (split.length != 4) {
                throw new UnknownHostException(str);
            }
            int parseInt = Integer.parseInt(split[0]);
            int parseInt2 = Integer.parseInt(split[1]) << 8;
            return (Integer.parseInt(split[3]) << 24) | parseInt | parseInt2 | (Integer.parseInt(split[2]) << 16);
        } catch (NumberFormatException unused) {
            throw new UnknownHostException(str);
        }
    }

    public void handIOCTRLFail(Message message, MyCamera myCamera) {
        dismissjuHuaDialog();
        if (message.arg1 != 268435465) {
            return;
        }
        MyToast.showToast(this, getString(R.string.set_fail));
    }

    @Override
    public void receiveSessionState(HiCamera hiCamera, int i) {
        Message obtainMessage = this.mIOHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_SESSION_STATE;
        obtainMessage.arg1 = i;
        obtainMessage.obj = hiCamera;
        this.mIOHandler.sendMessage(obtainMessage);
    }

    @Override
    public void receiveIOCtrlData(HiCamera hiCamera, int i, byte[] bArr, int i2) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("data", bArr);
        Message obtainMessage = this.mIOHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL;
        obtainMessage.obj = hiCamera;
        obtainMessage.arg1 = i;
        obtainMessage.arg2 = i2;
        obtainMessage.setData(bundle);
        this.mIOHandler.sendMessage(obtainMessage);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        List<ChnSearchInfo> list = this.mChandev_list;
        if (list == null || list.size() <= i) {
            return;
        }
        NVRDeviceAdapter nVRDeviceAdapter = this.adapter;
        if (nVRDeviceAdapter != null && !nVRDeviceAdapter.isSelecteMode()) {
            if (System.currentTimeMillis() - this.lastClickTime < 1000) {
                return;
            }
            this.lastClickTime = System.currentTimeMillis();
            this.adapter.setClickItemPosition(i);
            this.adapter.notifyDataSetChanged();
        }
        ChnSearchInfo chnSearchInfo = this.mChandev_list.get(i);
        NVRDeviceAdapter nVRDeviceAdapter2 = this.adapter;
        if (nVRDeviceAdapter2 == null || !nVRDeviceAdapter2.isSelecteMode()) {
            return;
        }
        NVRDeviceAdapter.ViewHolder viewHolder = (NVRDeviceAdapter.ViewHolder) view.getTag();
        if (!this.isNo_Select || viewHolder.cb_checkRight.isChecked()) {
            viewHolder.cb_checkRight.setChecked(!viewHolder.cb_checkRight.isChecked());
            if (viewHolder.cb_checkRight.isChecked()) {
                chnSearchInfo.setChecked(true);
                this.add_video_list.add(chnSearchInfo);
                viewHolder.cb_checkRight.setVisibility(0);
            } else {
                this.add_video_list.remove(chnSearchInfo);
                chnSearchInfo.setChecked(false);
                viewHolder.cb_checkRight.setVisibility(8);
            }
            if (this.add_video_list.size() >= this.mNeedAdd_Num) {
                this.isNo_Select = true;
                this.isAllSelect = true;
            } else {
                this.isNo_Select = false;
                this.isAllSelect = false;
            }
            this.adapter.notifyDataSetChanged();
        }
    }

    public class NVRDeviceAdapter extends BaseAdapter {
        private int clickPosition = -10;
        private boolean isSelecteMode = false;
        private LayoutInflater mInflater;

        @Override
        public long getItemId(int i) {
            return i;
        }

        public NVRDeviceAdapter(Context context) {
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            if (NVRSettingSearchChnDevActivity.this.mChandev_list == null) {
                return 0;
            }
            return NVRSettingSearchChnDevActivity.this.mChandev_list.size();
        }

        @Override
        public Object getItem(int i) {
            return NVRSettingSearchChnDevActivity.this.mChandev_list.get(i);
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder viewHolder;
            ChnSearchInfo chnSearchInfo = (ChnSearchInfo) NVRSettingSearchChnDevActivity.this.mChandev_list.get(i);
            if (view == null) {
                view = this.mInflater.inflate(R.layout.list_nvrchn, (ViewGroup) null);
                viewHolder = new ViewHolder();
                viewHolder.ll_setting1_CamearMan = (LinearLayout) view.findViewById(R.id.ll_setting1_CamearMan);
                viewHolder.cb_checkLeft = (CheckBox) view.findViewById(R.id.cb_checkLeft);
                viewHolder.iv_chn_head = (ImageView) view.findViewById(R.id.iv_chn_head);
                viewHolder.tv_chn_hostname = (TextView) view.findViewById(R.id.tv_chn_hostname);
                viewHolder.tv_nvrchanname = (TextView) view.findViewById(R.id.tv_nvrchanname);
                viewHolder.iv_chn_arrow = (ImageView) view.findViewById(R.id.iv_chn_arrow);
                viewHolder.cb_checkRight = (CheckBox) view.findViewById(R.id.cb_checkRight);
                view.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) view.getTag();
            }
            viewHolder.tv_nvrchanname.setVisibility(8);
            viewHolder.cb_checkLeft.setVisibility(8);
            viewHolder.cb_checkRight.setVisibility(8);
            viewHolder.iv_chn_arrow.setVisibility(8);
            if (chnSearchInfo.isChecked()) {
                viewHolder.cb_checkRight.setChecked(true);
                viewHolder.cb_checkRight.setVisibility(0);
            } else {
                viewHolder.cb_checkRight.setChecked(false);
                viewHolder.cb_checkRight.setVisibility(8);
            }
            if (!NVRSettingSearchChnDevActivity.this.isNo_Select) {
                viewHolder.tv_chn_hostname.setTextColor(Color.parseColor("#444444"));
                viewHolder.cb_checkRight.setEnabled(true);
                viewHolder.cb_checkRight.setAlpha(1.0f);
            } else if (chnSearchInfo.isChecked()) {
                viewHolder.tv_chn_hostname.setTextColor(Color.parseColor("#444444"));
                viewHolder.cb_checkRight.setEnabled(true);
                viewHolder.cb_checkRight.setAlpha(1.0f);
                viewHolder.cb_checkRight.setVisibility(0);
            } else {
                viewHolder.tv_chn_hostname.setTextColor(Color.parseColor("#bbbbbbbb"));
                viewHolder.cb_checkRight.setEnabled(false);
                viewHolder.cb_checkRight.setAlpha(0.2f);
                viewHolder.cb_checkRight.setVisibility(8);
            }
            if (viewHolder != null && NVRSettingSearchChnDevActivity.this.mChandev_list != null && NVRSettingSearchChnDevActivity.this.mChandev_list.size() > 0 && i <= NVRSettingSearchChnDevActivity.this.mChandev_list.size() - 1) {
                HiChipNVRDefines.PLATFORM_S_DEVICEPARAM chninfo = chnSearchInfo.getChninfo();
                viewHolder.tv_chn_hostname.setText(HiTools.getEncoding(chninfo.szHostName));
                HiTools.getEncoding(chninfo.szDevName);
            }
            return view;
        }

        public void setClickItemPosition(int i) {
            this.clickPosition = i;
        }

        public boolean isSelecteMode() {
            return this.isSelecteMode;
        }

        public void setSelecteMode(boolean z) {
            this.isSelecteMode = z;
        }

        public final class ViewHolder {
            CheckBox cb_checkLeft;
            CheckBox cb_checkRight;
            ImageView iv_chn_arrow;
            ImageView iv_chn_head;
            LinearLayout ll_setting1_CamearMan;
            TextView tv_chn_hostname;
            TextView tv_nvrchanname;

            public ViewHolder() {
            }
        }
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        HiLogcatUtil.e(i2 + "::::" + i);
        if (i2 == -1 && i == 111) {
            HiLogcatUtil.e(i2 + "::::" + i);
            if (intent.getExtras() == null) {
                return;
            }
            HiLogcatUtil.e(i2 + "::::" + i);
            HiChipNVRDefines.PLATFORM_S_CHNINFO_D platform_s_chninfo_d = (HiChipNVRDefines.PLATFORM_S_CHNINFO_D) getIntent().getSerializableExtra("mNVRgetChn");
            if (platform_s_chninfo_d != null) {
                HiLogcatUtil.e(platform_s_chninfo_d.szUserName + "::::" + platform_s_chninfo_d.szPassword);
            }
        }
    }
}