FourSwitchVideoFragment.java 源代码


package main.NVR.live.nvrvideofragment;

import activity.ImagePagerActivity;
import activity.setting.WiFiSettingActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import base.HiFragment;
import base.MyApplication;
import bean.MyCamera;
import butterknife.ButterKnife;
import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadField;
import com.heytap.mcssdk.a.a;
import com.hichip.NVR.HiNVRDev;
import com.hichip.NVR.callback.INVRPlayStateCallback;
import com.hichip.NVR.content.HiChipNVRDefines;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.callback.ICameraPlayStateCallback;
import com.hichip.campro.R;
import com.hichip.control.HiCamera;
import common.ConstantCommand;
import common.HiDataValue;
import common.MyLiveViewGLMonitor;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import main.MainActivity;
import main.NVR.live.LiveViewNVRActivity;
import main.NVR.live.nvrvideofragment.FourSwitchVideoFragment;
import org.apache.poi.xwpf.converter.xhtml.internal.styles.CSSStylePropertyConstants;
import org.mozilla.universalchardet.prober.HebrewProber;
import utils.HiLogcatUtil;
import utils.HiTools;
import utils.MyToast;
import utils.SystemUtils;

public class FourSwitchVideoFragment extends HiFragment implements View.OnClickListener, ICameraIOSessionCallback, ICameraPlayStateCallback, INVRPlayStateCallback, View.OnTouchListener {
    public static final int MY_PERMISSION_REQUEST_CODE = 10023;
    public ImageView iv_full_screen;
    ImageView iv_loading1;
    ImageView iv_loading1_bg;
    ImageView iv_loading2;
    ImageView iv_loading2_bg;
    ImageView iv_loading3;
    ImageView iv_loading3_bg;
    ImageView iv_loading4;
    ImageView iv_loading4_bg;
    MyLiveViewGLMonitor live_monitor1;
    MyLiveViewGLMonitor live_monitor2;
    MyLiveViewGLMonitor live_monitor3;
    MyLiveViewGLMonitor live_monitor4;
    public LinearLayout ll_content;
    public LinearLayout ll_recording1;
    public LinearLayout ll_recording2;
    public LinearLayout ll_recording3;
    public LinearLayout ll_recording4;
    public LinearLayout ll_row1;
    private LiveViewNVRActivity mAct;
    private int mHeight;
    private MyCamera mMyCamera;
    private int msavesch;
    private int msavescw;
    public RelativeLayout rl_camera1_bg;
    public RelativeLayout rl_camera2_bg;
    public RelativeLayout rl_camera3_bg;
    public RelativeLayout rl_camera4_bg;
    public TextView tv_camera1_status;
    public TextView tv_camera2_status;
    public TextView tv_camera3_status;
    public TextView tv_camera4_status;
    TextView tv_record_time1;
    TextView tv_record_time2;
    TextView tv_record_time3;
    TextView tv_record_time4;
    private boolean isVisibleToUser = false;
    private SimpleDateFormat sdf = new SimpleDateFormat("mm:ss", Locale.getDefault());
    public Handler mTimeHandler = new AnonymousClass6();
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case HiDataValue.HANDLE_MESSAGE_PLAY_STATE:
                    FourSwitchVideoFragment.this.handMsgPlayState(message);
                    return;
                case HiDataValue.HANDLE_MESSAGE_SESSION_STATE:
                    FourSwitchVideoFragment.this.handMsgSessionState(message);
                    return;
                case HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL:
                    FourSwitchVideoFragment.this.handMsgReceiveIoctrl(message);
                    return;
                case 288:
                    MyToast.showToast(FourSwitchVideoFragment.this.getActivity(), FourSwitchVideoFragment.this.getString(R.string.failed_recording));
                    return;
                case WiFiSettingActivity.SET_WIFI_END:
                    MyToast.showToast(FourSwitchVideoFragment.this.getActivity(), FourSwitchVideoFragment.this.getString(R.string.failed_recording));
                    return;
                case ConstantCommand.HI_P2P_GET_DEVICE_WORKING_MODE:
                    FourSwitchVideoFragment.this.mAct.dismissjuHuaDialog();
                    FourSwitchVideoFragment.this.startActivity(new Intent(FourSwitchVideoFragment.this.getActivity(), (Class<?>) MainActivity.class));
                    return;
                default:
                    return;
            }
        }
    };
    public boolean isChangeMotionPosition = true;

    public void handMsgSessionState(Message message) {
    }

    @Override
    public void onClick(View view) {
    }

    @Override
    public void receiveSessionState(HiCamera hiCamera, int i) {
    }

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.nvrfragment_live_foursw_tab, (ViewGroup) null);
        ButterKnife.bind(this, inflate);
        HiLogcatUtil.e("FourSwitchVideoFragment");
        initViewAndData();
        setListeners();
        return inflate;
    }

    public static FourSwitchVideoFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt(ImagePagerActivity.INDEX, i);
        FourSwitchVideoFragment fourSwitchVideoFragment = new FourSwitchVideoFragment();
        fourSwitchVideoFragment.setArguments(bundle);
        return fourSwitchVideoFragment;
    }

    private void setListeners() {
        this.iv_full_screen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (FourSwitchVideoFragment.this.getResources().getConfiguration().orientation == 1) {
                    FourSwitchVideoFragment.this.getActivity().setRequestedOrientation(0);
                    FourSwitchVideoFragment.this.iv_full_screen.setVisibility(8);
                }
            }
        });
        this.live_monitor1.setOnTouchListener(this);
        this.live_monitor2.setOnTouchListener(this);
        this.live_monitor3.setOnTouchListener(this);
        this.live_monitor4.setOnTouchListener(this);
    }

    private void initViewAndData() {
        this.mAct = (LiveViewNVRActivity) getActivity();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        this.mAct.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        this.msavescw = displayMetrics.widthPixels;
        this.msavesch = this.mAct.mMonitorHeight;
        if (this.isVisibleToUser) {
            notifyButtonStatus(false);
            StartVideo_UIStatus(0, 4, 4, 1);
            StartVideo(0, 4, 4, 1);
            SetCameraVis();
        }
    }

    public void onResumePlay() {
        notifyButtonStatus(false);
        this.ll_content.setVisibility(0);
        SetParams();
        this.mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                FourSwitchVideoFragment.this.StartVideo_UIStatus(0, 4, 4, 1);
                FourSwitchVideoFragment.this.StartVideo(0, 4, 4, 1);
                FourSwitchVideoFragment.this.SetCameraVis();
            }
        }, 400L);
    }

    public void StartVideo_UIStatus(int i, int i2, int i3, int i4) {
        if (this.mMyCamera == null || !isAdded()) {
            return;
        }
        this.live_monitor1.setCamera(this.mMyCamera);
        this.live_monitor2.setCamera(this.mMyCamera);
        this.live_monitor3.setCamera(this.mMyCamera);
        this.live_monitor4.setCamera(this.mMyCamera);
        this.mAct.initMonitor(this.mMyCamera, this.live_monitor1, 0);
        this.mAct.initMonitor(this.mMyCamera, this.live_monitor2, 1);
        this.mAct.initMonitor(this.mMyCamera, this.live_monitor3, 2);
        this.mAct.initMonitor(this.mMyCamera, this.live_monitor4, 3);
        MyCamera myCamera = this.mMyCamera;
        if (myCamera == null || myCamera.mhiNvrdev == null) {
            return;
        }
        this.mMyCamera.registerIOSessionListener(this);
        this.mMyCamera.mhiNvrdev.registerPlayNVRStateListener(this);
        if (this.mMyCamera.mNVRChildDev[0].status == 2) {
            this.mAct.showLoadingView(this.iv_loading1);
        }
        if (this.mMyCamera.mNVRChildDev[1].status == 2) {
            this.mAct.showLoadingView(this.iv_loading2);
        }
        if (this.mMyCamera.mNVRChildDev[2].status == 2) {
            this.mAct.showLoadingView(this.iv_loading3);
        }
        if (this.mMyCamera.mNVRChildDev[3].status == 2) {
            this.mAct.showLoadingView(this.iv_loading4);
        }
        for (int i5 = 0; i5 < this.mMyCamera.getmNvrChannelMaxNum(); i5++) {
            HiLogcatUtil.e(i5 + ":GetAndChangeStatus:" + this.mMyCamera.mNVRChildDev[i5].status + ":::" + this.mAct.nvrchnstate[i5] + ":::" + i4);
            if (this.mMyCamera.mNVRChildDev[i5].status != 2) {
                this.mAct.nvrchnstate[i5] = true;
            }
        }
        GetAndChangeStatus(0, 4);
        this.mMyCamera.mhiNvrdev.ResumeLiveShow(this.mAct.isShowVideo);
    }

    public void StartVideo(int i, int i2, int i3, int i4) {
        if (this.mMyCamera == null) {
            return;
        }
        int i5 = 0;
        for (int i6 = i; i6 < i2; i6++) {
            if (2 == this.mMyCamera.mNVRChildDev[i6].status) {
                i5 |= HiDataValue.func_nvr_list[i6];
            }
        }
        if (this.mMyCamera.mhiNvrdev != null) {
            this.mMyCamera.mhiNvrdev.isExitLive = false;
            this.mMyCamera.mhiNvrdev.SetHiCameraInit(this.mMyCamera.mNvrMaxChn);
            this.mMyCamera.mhiNvrdev.SetHiCameraMonitor(this.mMyCamera.mNvrmonitor);
        }
        HiLogcatUtil.e(i5 + ":::" + Integer.toHexString(i5));
        if (i5 > 0) {
            this.mAct.SetStreamCtrl(i, i2, i5, i3);
            int i7 = 15;
            if (i4 == 2) {
                i7 = HebrewProber.NORMAL_NUN;
            } else if (i4 == 3) {
                i7 = 3840;
            }
            this.mMyCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_REALSTREAM, HiChipNVRDefines.PLATFORM_S_LIVE_REQ.parseContent(1, i7, 0, i5));
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (FourSwitchVideoFragment.this.mAct.monitor_position <= -1 || FourSwitchVideoFragment.this.mAct.monitor_position >= FourSwitchVideoFragment.this.mMyCamera.getmNvrChannelMaxNum()) {
                    FourSwitchVideoFragment.this.mAct.SetButtonEnable(false);
                } else {
                    FourSwitchVideoFragment.this.mAct.SetButtonEnable(true);
                }
            }
        }, 100L);
    }

    public void initHeight(int i) {
        this.mHeight = i;
    }

    public void setmMyCamera(MyCamera myCamera) {
        this.mMyCamera = myCamera;
    }

    @Override
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (getResources().getConfiguration().orientation == 2) {
            this.iv_full_screen.setVisibility(8);
        }
    }

    public void SetCameraBg(boolean z) {
        this.rl_camera1_bg.setBackgroundColor(MyApplication.getInstance().getResources().getColor(R.color.colorBlack));
        this.rl_camera2_bg.setBackgroundColor(MyApplication.getInstance().getResources().getColor(R.color.colorBlack));
        this.rl_camera3_bg.setBackgroundColor(MyApplication.getInstance().getResources().getColor(R.color.colorBlack));
        this.rl_camera4_bg.setBackgroundColor(MyApplication.getInstance().getResources().getColor(R.color.colorBlack));
        this.live_monitor1.setZOrderMediaOverlay(false);
        this.live_monitor2.setZOrderMediaOverlay(false);
        this.live_monitor3.setZOrderMediaOverlay(false);
        this.live_monitor4.setZOrderMediaOverlay(false);
        this.live_monitor1.setVisibility(8);
        this.live_monitor2.setVisibility(8);
        this.live_monitor3.setVisibility(8);
        this.live_monitor4.setVisibility(8);
        this.mAct.dismissLoadingView(this.iv_loading1, this.iv_loading1_bg);
        this.tv_camera1_status.setVisibility(8);
        this.mAct.dismissLoadingView(this.iv_loading2, this.iv_loading2_bg);
        this.tv_camera2_status.setVisibility(8);
        this.mAct.dismissLoadingView(this.iv_loading3, this.iv_loading3_bg);
        this.tv_camera3_status.setVisibility(8);
        this.mAct.dismissLoadingView(this.iv_loading4, this.iv_loading4_bg);
        this.tv_camera4_status.setVisibility(8);
    }

    public void SetCameraVis() {
        this.live_monitor1.setZOrderMediaOverlay(true);
        this.live_monitor2.setZOrderMediaOverlay(true);
        this.live_monitor3.setZOrderMediaOverlay(true);
        this.live_monitor4.setZOrderMediaOverlay(true);
        this.live_monitor1.setVisibility(0);
        this.live_monitor2.setVisibility(0);
        this.live_monitor3.setVisibility(0);
        this.live_monitor4.setVisibility(0);
        this.iv_loading1_bg.setVisibility(0);
        this.iv_loading2_bg.setVisibility(0);
        this.iv_loading3_bg.setVisibility(0);
        this.iv_loading4_bg.setVisibility(0);
    }

    @Override
    public void setUserVisibleHint(boolean z) {
        this.isVisibleToUser = z;
        HiLogcatUtil.e("FourSwitchVideoFragment  setUserVisibleHint" + z + "::" + this.ll_content);
        if (z) {
            if (this.ll_content == null || this.mMyCamera == null) {
                return;
            }
            notifyButtonStatus(false);
            this.ll_content.setVisibility(0);
            SetParams();
            this.mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    FourSwitchVideoFragment.this.StartVideo_UIStatus(0, 4, 4, 1);
                    FourSwitchVideoFragment.this.StartVideo(0, 4, 4, 1);
                    FourSwitchVideoFragment.this.SetCameraVis();
                }
            }, 400L);
            return;
        }
        if (this.ll_content == null || this.mMyCamera == null) {
            return;
        }
        this.mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                FourSwitchVideoFragment.this.SetCameraBg(true);
            }
        }, 200L);
        this.mMyCamera.unregisterIOSessionListener(this);
        this.mMyCamera.mhiNvrdev.unregisterPlayNVRStateListener(this);
    }

    public void showRecordTime(int i) {
        if (i == 0) {
            this.ll_recording1.setVisibility(0);
        } else if (i == 1) {
            this.ll_recording2.setVisibility(0);
        } else if (i == 2) {
            this.ll_recording3.setVisibility(0);
        } else if (i == 3) {
            this.ll_recording4.setVisibility(0);
        }
        Message message = new Message();
        message.what = 1110;
        message.arg1 = i;
        this.mTimeHandler.sendMessage(message);
    }

    public void dismissRecordTime(int i) {
        if (i == 0) {
            this.ll_recording1.setVisibility(8);
        }
        if (i == 1) {
            this.ll_recording2.setVisibility(8);
        }
        if (i == 2) {
            this.ll_recording3.setVisibility(8);
        }
        if (i == 3) {
            this.ll_recording4.setVisibility(8);
        }
        this.mAct.mStartRecordTime[i] = 0;
        Handler handler = this.mTimeHandler;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
    }

    public class AnonymousClass6 extends Handler {
        AnonymousClass6() {
        }

        @Override
        public void handleMessage(Message message) {
            if (message.what == 1110) {
                final int i = message.arg1;
                int[] iArr = FourSwitchVideoFragment.this.mAct.mStartRecordTime;
                iArr[i] = iArr[i] + 1000;
                if (i == 0) {
                    FourSwitchVideoFragment.this.tv_record_time1.setText(FourSwitchVideoFragment.this.sdf.format(new Date(FourSwitchVideoFragment.this.mAct.mStartRecordTime[i])));
                    if (FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] >= FourSwitchVideoFragment.this.mAct.videoSplitTime && FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] % FourSwitchVideoFragment.this.mAct.videoSplitTime == 0) {
                        FourSwitchVideoFragment.this.mMyCamera.mhiNvrdev.HiNVR_StopRecord(i);
                        FourSwitchVideoFragment.this.tv_record_time1.postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                FourSwitchVideoFragment.AnonymousClass6.this.lambda$handleMessage$0$FourSwitchVideoFragment$6(i);
                            }
                        }, 1000L);
                    }
                } else if (i == 1) {
                    FourSwitchVideoFragment.this.tv_record_time2.setText(FourSwitchVideoFragment.this.sdf.format(new Date(FourSwitchVideoFragment.this.mAct.mStartRecordTime[i])));
                    if (FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] >= FourSwitchVideoFragment.this.mAct.videoSplitTime && FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] % FourSwitchVideoFragment.this.mAct.videoSplitTime == 0) {
                        FourSwitchVideoFragment.this.mMyCamera.mhiNvrdev.HiNVR_StopRecord(i);
                        FourSwitchVideoFragment.this.tv_record_time2.postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                FourSwitchVideoFragment.AnonymousClass6.this.lambda$handleMessage$1$FourSwitchVideoFragment$6(i);
                            }
                        }, 1000L);
                    }
                } else if (i == 2) {
                    FourSwitchVideoFragment.this.tv_record_time3.setText(FourSwitchVideoFragment.this.sdf.format(new Date(FourSwitchVideoFragment.this.mAct.mStartRecordTime[i])));
                    if (FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] >= FourSwitchVideoFragment.this.mAct.videoSplitTime && FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] % FourSwitchVideoFragment.this.mAct.videoSplitTime == 0) {
                        FourSwitchVideoFragment.this.mMyCamera.mhiNvrdev.HiNVR_StopRecord(i);
                        FourSwitchVideoFragment.this.tv_record_time3.postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                FourSwitchVideoFragment.AnonymousClass6.this.lambda$handleMessage$2$FourSwitchVideoFragment$6(i);
                            }
                        }, 1000L);
                    }
                } else if (i == 3) {
                    FourSwitchVideoFragment.this.tv_record_time4.setText(FourSwitchVideoFragment.this.sdf.format(new Date(FourSwitchVideoFragment.this.mAct.mStartRecordTime[i])));
                    if (FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] >= FourSwitchVideoFragment.this.mAct.videoSplitTime && FourSwitchVideoFragment.this.mAct.mStartRecordTime[i] % FourSwitchVideoFragment.this.mAct.videoSplitTime == 0) {
                        FourSwitchVideoFragment.this.mMyCamera.mhiNvrdev.HiNVR_StopRecord(i);
                        FourSwitchVideoFragment.this.tv_record_time4.postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                FourSwitchVideoFragment.AnonymousClass6.this.lambda$handleMessage$3$FourSwitchVideoFragment$6(i);
                            }
                        }, 1000L);
                    }
                }
                Message obtain = Message.obtain();
                obtain.what = 1110;
                obtain.arg1 = i;
                FourSwitchVideoFragment.this.mTimeHandler.sendMessageDelayed(obtain, 1000L);
            }
        }

        public void lambda$handleMessage$0$FourSwitchVideoFragment$6(int i) {
            FourSwitchVideoFragment.this.mAct.dealWithRecord4(i);
        }

        public void lambda$handleMessage$1$FourSwitchVideoFragment$6(int i) {
            FourSwitchVideoFragment.this.mAct.dealWithRecord4(i);
        }

        public void lambda$handleMessage$2$FourSwitchVideoFragment$6(int i) {
            FourSwitchVideoFragment.this.mAct.dealWithRecord4(i);
        }

        public void lambda$handleMessage$3$FourSwitchVideoFragment$6(int i) {
            FourSwitchVideoFragment.this.mAct.dealWithRecord4(i);
        }
    }

    public void handMsgReceiveIoctrl(Message message) {
        if (message.arg2 == 0) {
            byte[] byteArray = message.getData().getByteArray("data");
            if (message.arg1 != 268435477) {
                return;
            }
            HiChipNVRDefines.PLATFORM_S_NVR_S_CHANNELSTATUS platform_s_nvr_s_channelstatus = new HiChipNVRDefines.PLATFORM_S_NVR_S_CHANNELSTATUS(byteArray);
            if (platform_s_nvr_s_channelstatus.u32chn >= this.mMyCamera.mNVRChildDev.length || platform_s_nvr_s_channelstatus.u32chn <= -1) {
                return;
            }
            this.mMyCamera.mNVRChildDev[platform_s_nvr_s_channelstatus.u32chn].status = platform_s_nvr_s_channelstatus.status;
            this.mMyCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_GET_CHANNELDEVICE, HiChipNVRDefines.PLATFORM_S_CHANNELDEVICE_REQ.parseContent(platform_s_nvr_s_channelstatus.u32chn));
            if (platform_s_nvr_s_channelstatus.u32chn <= -1 || platform_s_nvr_s_channelstatus.u32chn >= 8) {
                return;
            }
            if (platform_s_nvr_s_channelstatus.status == 0 || platform_s_nvr_s_channelstatus.status == 1 || platform_s_nvr_s_channelstatus.status == 4) {
                GetAndChangeStatus(platform_s_nvr_s_channelstatus.u32chn, platform_s_nvr_s_channelstatus.u32chn + 1);
                if (this.isVisibleToUser) {
                    if (platform_s_nvr_s_channelstatus.u32chn == 0) {
                        this.rl_camera1_bg.setBackgroundColor(getActivity().getResources().getColor(R.color.colorBlack));
                        return;
                    }
                    if (platform_s_nvr_s_channelstatus.u32chn == 1) {
                        this.rl_camera2_bg.setBackgroundColor(getActivity().getResources().getColor(R.color.colorBlack));
                        return;
                    } else if (platform_s_nvr_s_channelstatus.u32chn == 2) {
                        this.rl_camera3_bg.setBackgroundColor(getActivity().getResources().getColor(R.color.colorBlack));
                        return;
                    } else {
                        if (platform_s_nvr_s_channelstatus.u32chn == 3) {
                            this.rl_camera4_bg.setBackgroundColor(getActivity().getResources().getColor(R.color.colorBlack));
                            return;
                        }
                        return;
                    }
                }
                return;
            }
            return;
        }
        LiveViewNVRActivity liveViewNVRActivity = this.mAct;
        if (liveViewNVRActivity != null) {
            liveViewNVRActivity.dismissjuHuaDialog();
        }
    }

    public void handMsgPlayState(Message message) {
        Bundle data = message.getData();
        int i = data.getInt(a.k);
        String string = data.getString(TTDownloadField.TT_FILE_NAME);
        int i2 = data.getInt("nvrnum");
        if (i != -5 && i != -4) {
            if (i == 0) {
                HiLogcatUtil.d(" PLAY_STATE_START ");
                notifyButtonStatus(true);
                if (i2 < this.mMyCamera.getmNvrChannelMaxNum() && i2 > -1) {
                    this.mAct.nvrplaystate[i2] = true;
                }
                MyCamera myCamera = this.mMyCamera;
                Bitmap snapshot_EXT = myCamera != null ? myCamera.mhiNvrdev.getSnapshot_EXT(i2, 1, 640, 352) : null;
                if (snapshot_EXT != null) {
                    HiTools.saveNVRSnapshot(snapshot_EXT, this.mMyCamera, getActivity(), i2);
                }
                this.mAct.mIsSwitchResolution = false;
                ChangeMonitorStatus(i2, i2 + 1);
                if (i2 == 0) {
                    this.mAct.dismissLoadingView(this.iv_loading1, this.iv_loading1_bg);
                    this.tv_camera1_status.setVisibility(8);
                    return;
                }
                if (i2 == 1) {
                    this.mAct.dismissLoadingView(this.iv_loading2, this.iv_loading2_bg);
                    this.tv_camera2_status.setVisibility(8);
                    return;
                } else if (i2 == 2) {
                    this.mAct.dismissLoadingView(this.iv_loading3, this.iv_loading3_bg);
                    this.tv_camera3_status.setVisibility(8);
                    return;
                } else {
                    if (i2 != 3) {
                        return;
                    }
                    this.mAct.dismissLoadingView(this.iv_loading4, this.iv_loading4_bg);
                    this.tv_camera4_status.setVisibility(8);
                    return;
                }
            }
            if (i != 6) {
                if (i == 3) {
                    if (TextUtils.isEmpty(string)) {
                        return;
                    }
                    this.mAct.grabRecordSnapshot(i2, string);
                    return;
                } else {
                    if (i == 4 && !TextUtils.isEmpty(this.mAct.recordFile)) {
                        File file = new File(this.mAct.recordFile);
                        if (file.length() <= 1024 && file.isFile() && file.exists()) {
                            file.delete();
                            return;
                        }
                        return;
                    }
                    return;
                }
            }
        }
        HiLogcatUtil.d(" PLAY_STATE_DISPLAY_ERROR  OR OTHER");
        this.mAct.finish();
        MyToast.showToast(getActivity(), getString(R.string.video_exception));
    }

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

    @Override
    public void callbackState(HiNVRDev hiNVRDev, int i, int i2, int i3, int i4) {
        HiLogcatUtil.e(i + "::" + i2 + "::" + i3 + "::" + i4);
        Bundle bundle = new Bundle();
        bundle.putInt("nvrnum", i);
        bundle.putInt(a.k, i2);
        bundle.putInt(CSSStylePropertyConstants.WIDTH, i3);
        bundle.putInt(CSSStylePropertyConstants.HEIGHT, i4);
        Message obtainMessage = this.mHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_PLAY_STATE;
        obtainMessage.setData(bundle);
        this.mHandler.sendMessage(obtainMessage);
    }

    @Override
    public void callbackRecordState(HiNVRDev hiNVRDev, int i, int i2, int i3, int i4, String str) {
        HiLogcatUtil.e(i + "::" + i2 + "::" + i3 + "::" + i4 + "::" + str);
        if (i < 0) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putInt("nvrnum", i);
        bundle.putInt(a.k, i2);
        bundle.putInt(CSSStylePropertyConstants.WIDTH, i3);
        bundle.putInt(CSSStylePropertyConstants.HEIGHT, i4);
        bundle.putString(TTDownloadField.TT_FILE_NAME, str);
        Message obtainMessage = this.mHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_PLAY_STATE;
        obtainMessage.setData(bundle);
        this.mHandler.sendMessage(obtainMessage);
    }

    @Override
    public void callbackPlayUTC(HiNVRDev hiNVRDev, int i, int i2) {
        Bundle bundle = new Bundle();
        bundle.putInt("nvrnum", i);
        bundle.putInt("mtine", i2);
        Message obtainMessage = this.mHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_PLAY_UTC;
        obtainMessage.setData(bundle);
        this.mHandler.sendMessage(obtainMessage);
    }

    public boolean GetChnStatus(int i, int i2) {
        while (i < i2) {
            if (this.mMyCamera.mNVRChildDev[i].status == 2) {
                return true;
            }
            i++;
        }
        return false;
    }

    public void GetAndChangeStatus(int i, int i2) {
        MyCamera myCamera;
        if (isAdded() && this.mAct != null && (myCamera = this.mMyCamera) != null && myCamera.mNVRChildDev != null && i < 8 && i > -1 && i2 <= 8 && i2 > -1) {
            boolean z = false;
            for (int i3 = i; i3 < i2; i3++) {
                HiLogcatUtil.e(i3 + ":GetAndChangeStatus:" + this.mMyCamera.mNVRChildDev[i3].status + ":::" + this.mAct.nvrchnstate[i3] + "::::" + this.mAct.nvrplaystate[i3]);
                if (this.mMyCamera.mNVRChildDev[i3].status == 2 && this.mAct.nvrchnstate[i3]) {
                    this.mAct.nvrchnstate[i3] = false;
                }
                if (this.mMyCamera.mNVRChildDev[i3].status == 0) {
                    ChangeStatus(i3, 0);
                } else if (this.mMyCamera.mNVRChildDev[i3].status == 2) {
                    if (!this.mAct.nvrplaystate[i3]) {
                        if (this.mAct.nvrchnstate[i3]) {
                            ChangeStatus(i3, 1);
                        } else {
                            ChangeStatus(i3, 2);
                        }
                    }
                    z = true;
                } else {
                    ChangeStatus(i3, 1);
                }
            }
            ChangeMonitorStatus(i, i2);
            if (z) {
                return;
            }
            notifyButtonStatus(true);
        }
    }

    private void ChangeMonitorStatus(int i, int i2) {
        MyCamera myCamera;
        if (isAdded() && this.mAct != null && (myCamera = this.mMyCamera) != null && myCamera.mNVRChildDev != null && this.mMyCamera.mNVRChildDev.length >= i && this.mMyCamera.mNVRChildDev.length >= i2 && i < 8 && i > -1 && i2 <= 8 && i2 > -1) {
            while (i < i2) {
                if (this.mMyCamera.mNVRChildDev[i].status == 2 && this.mAct.nvrplaystate[i]) {
                    if (i == 0) {
                        this.live_monitor1.SetPayState(true);
                    } else if (i == 1) {
                        this.live_monitor2.SetPayState(true);
                    } else if (i == 2) {
                        this.live_monitor3.SetPayState(true);
                    } else if (i == 3) {
                        this.live_monitor4.SetPayState(true);
                    }
                } else if (i == 0) {
                    this.live_monitor1.SetPayState(false);
                } else if (i == 1) {
                    this.live_monitor2.SetPayState(false);
                } else if (i == 2) {
                    this.live_monitor3.SetPayState(false);
                } else if (i == 3) {
                    this.live_monitor4.SetPayState(false);
                }
                i++;
            }
        }
    }

    private void ChangeStatus(int i, int i2) {
        HiLogcatUtil.e(i + "::::" + i2 + ":GetAndChangeStatus:" + this.mMyCamera.mNVRChildDev[i].status + ":::" + this.mAct.nvrchnstate[i] + "::::" + this.mAct.nvrplaystate[i]);
        if (i2 == 0 || i2 == 1) {
            HiLogcatUtil.e(i + "");
            String[] stringArray = getResources().getStringArray(R.array.connect_nvrstate);
            if (i == 0) {
                this.iv_loading1_bg.setVisibility(0);
                this.iv_loading1_bg.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.videoclip, null));
                this.mAct.dismissLoadingView(this.iv_loading1);
                this.tv_camera1_status.setVisibility(0);
                this.tv_camera1_status.setText(stringArray[i2]);
                return;
            }
            if (i == 1) {
                this.iv_loading2_bg.setVisibility(0);
                this.iv_loading2_bg.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.videoclip, null));
                this.mAct.dismissLoadingView(this.iv_loading2);
                this.tv_camera2_status.setVisibility(0);
                this.tv_camera2_status.setText(stringArray[i2]);
                return;
            }
            if (i == 2) {
                this.iv_loading3_bg.setVisibility(0);
                this.iv_loading3_bg.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.videoclip, null));
                this.mAct.dismissLoadingView(this.iv_loading3);
                this.tv_camera3_status.setVisibility(0);
                this.tv_camera3_status.setText(stringArray[i2]);
                return;
            }
            if (i != 3) {
                return;
            }
            this.iv_loading4_bg.setVisibility(0);
            this.iv_loading4_bg.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.videoclip, null));
            this.mAct.dismissLoadingView(this.iv_loading4);
            this.tv_camera4_status.setVisibility(0);
            this.tv_camera4_status.setText(stringArray[i2]);
            return;
        }
        if (i2 != 2 || this.mAct.nvrchnstate[i]) {
            return;
        }
        HiLogcatUtil.e(i + "");
        if (i == 0) {
            this.mAct.initBackground(0, this.iv_loading1_bg);
            this.iv_loading1_bg.setVisibility(0);
            this.tv_camera1_status.setVisibility(8);
            return;
        }
        if (i == 1) {
            this.mAct.initBackground(1, this.iv_loading2_bg);
            this.iv_loading2_bg.setVisibility(0);
            this.tv_camera2_status.setVisibility(8);
        } else if (i == 2) {
            this.mAct.initBackground(2, this.iv_loading3_bg);
            this.iv_loading3_bg.setVisibility(0);
            this.tv_camera3_status.setVisibility(8);
        } else {
            if (i != 3) {
                return;
            }
            this.mAct.initBackground(3, this.iv_loading4_bg);
            this.iv_loading4_bg.setVisibility(0);
            this.tv_camera4_status.setVisibility(8);
        }
    }

    public void handLandScape(boolean z, int i, int i2) {
        this.msavescw = i;
        this.msavesch = i2;
        SetParams();
    }

    public void handPortrait(boolean z, int i, int i2) {
        this.msavescw = i;
        this.msavesch = i2;
        SetParams();
    }

    public void SetParams() {
        ChangeParams();
    }

    public void ChangeParams() {
        int i;
        int i2;
        if (getResources().getConfiguration().orientation == 1) {
            i = this.mAct.realSize.x;
            i2 = this.mAct.mMonitorHeight;
        } else {
            if (HiTools.isAllScreenDevice(getActivity())) {
                i = this.mAct.realSize.y - HiTools.getStatusBarHeight(getActivity());
                Display defaultDisplay = getActivity().getWindowManager().getDefaultDisplay();
                Point point = new Point();
                defaultDisplay.getSize(point);
                if (SystemUtils.isSamSungMobile(getActivity())) {
                    if (HiDataValue.isNavigationBarExist) {
                        i = point.x + HiTools.getNavigationBarHeight(getActivity());
                    } else if (i != point.x) {
                        i = point.x;
                    }
                } else if (i < point.x) {
                    i = point.x;
                }
            } else {
                i = this.mAct.realSize.y;
            }
            i2 = this.mAct.realSize.x;
        }
        HiLogcatUtil.e("handScape" + i + "----------" + i2);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(this.ll_content.getLayoutParams());
        layoutParams.height = i2;
        layoutParams.width = i;
        this.ll_content.setLayoutParams(layoutParams);
        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(this.ll_content.getLayoutParams());
        RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(this.ll_content.getLayoutParams());
        int i3 = i2 / 2;
        layoutParams3.height = i3;
        layoutParams2.height = i3;
        int i4 = i / 2;
        layoutParams3.width = i4;
        layoutParams2.width = i4;
        this.rl_camera1_bg.setLayoutParams(layoutParams2);
        this.rl_camera2_bg.setLayoutParams(layoutParams2);
        this.rl_camera3_bg.setLayoutParams(layoutParams2);
        this.rl_camera4_bg.setLayoutParams(layoutParams2);
        layoutParams3.width -= HiTools.dip2px(this.mAct, 2.0f);
        layoutParams3.height -= HiTools.dip2px(this.mAct, 2.0f);
        this.live_monitor1.setLayoutParams(layoutParams3);
        this.live_monitor2.setLayoutParams(layoutParams3);
        this.live_monitor3.setLayoutParams(layoutParams3);
        this.live_monitor4.setLayoutParams(layoutParams3);
    }

    @Override
    public void onPause() {
        super.onPause();
        MyCamera myCamera = this.mMyCamera;
        if (myCamera == null) {
            return;
        }
        myCamera.unregisterIOSessionListener(this);
        this.mMyCamera.mhiNvrdev.unregisterPlayNVRStateListener(this);
    }

    public void clearSelectMonitor() {
        this.rl_camera1_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        this.rl_camera2_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        this.rl_camera3_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        this.rl_camera4_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            if (this.iv_full_screen.getVisibility() == 0) {
                this.iv_full_screen.setVisibility(8);
            } else if (getResources().getConfiguration().orientation == 1) {
                this.iv_full_screen.setVisibility(0);
            }
            switch (view.getId()) {
                case R.id.live_monitor1:
                    if (!this.mAct.nvrplaystate[0]) {
                        return false;
                    }
                    if (this.mAct.monitor_position == 0) {
                        this.isChangeMotionPosition = false;
                    } else {
                        this.isChangeMotionPosition = true;
                    }
                    this.mAct.monitor_position = 0;
                    if (this.mAct.monitor_position >= 0 || this.mAct.monitor_position > this.mMyCamera.getmNvrChannelMaxNum() - 1) {
                    }
                    break;
                case R.id.live_monitor10:
                case R.id.live_monitor12:
                default:
                    if (this.mAct.monitor_position >= 0) {
                        break;
                    }
                    break;
                case R.id.live_monitor2:
                    if (!this.mAct.nvrplaystate[1]) {
                        return false;
                    }
                    if (this.mAct.monitor_position == 1) {
                        this.isChangeMotionPosition = false;
                    } else {
                        this.isChangeMotionPosition = true;
                    }
                    this.mAct.monitor_position = 1;
                    if (this.mAct.monitor_position >= 0) {
                    }
                    break;
                case R.id.live_monitor3:
                    if (!this.mAct.nvrplaystate[2]) {
                        return false;
                    }
                    if (this.mAct.monitor_position == 2) {
                        this.isChangeMotionPosition = false;
                    } else {
                        this.isChangeMotionPosition = true;
                    }
                    this.mAct.monitor_position = 2;
                    if (this.mAct.monitor_position >= 0) {
                    }
                    break;
                case R.id.live_monitor4:
                    if (!this.mAct.nvrplaystate[3]) {
                        return false;
                    }
                    if (this.mAct.monitor_position == 3) {
                        this.isChangeMotionPosition = false;
                    } else {
                        this.isChangeMotionPosition = true;
                    }
                    this.mAct.monitor_position = 3;
                    if (this.mAct.monitor_position >= 0) {
                    }
                    break;
            }
        }
        return false;
    }

    private void notifyButtonStatus(boolean z) {
        this.mAct.iv_setting.setEnabled(z);
        this.mAct.iv_playback.setEnabled(z);
        this.mAct.iv_viewnumswitch4.setEnabled(z);
        this.mAct.iv_viewnumswitch8.setEnabled(z);
        this.mAct.iv_viewnumswitch9.setEnabled(z);
        this.mAct.iv_viewnumswitch10.setEnabled(z);
        this.mAct.setCanScrollViewpager(z);
        this.mAct.isReadyPlay = z;
        this.mAct.iv_full_screen.setClickable(z);
        this.mAct.setViewWhetherClick(z);
        this.mAct.iv_ting_light.setClickable(z);
        if (z) {
            this.mAct.dismissPlaceLoadingView();
            this.mAct.dismissLoadingView();
        }
    }

    public void onSingleTapConfirmed(int i) {
        if (i == 0) {
            this.rl_camera1_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorRed));
            this.rl_camera2_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera3_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera4_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        } else if (i == 1) {
            this.rl_camera1_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera2_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorRed));
            this.rl_camera3_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera4_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        } else if (i == 2) {
            this.rl_camera1_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera2_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera3_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorRed));
            this.rl_camera4_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
        } else if (i == 3) {
            this.rl_camera1_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera2_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera3_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            this.rl_camera4_bg.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorRed));
        }
        HiLogcatUtil.e("dealWith" + this.mAct.monitor_position + " :" + this.mAct.isArraryListenPause[this.mAct.monitor_position] + "::" + this.mAct.isArraryNeedReOpenListen[this.mAct.monitor_position] + "::" + this.mAct.isArraryRecord[this.mAct.monitor_position] + "::" + this.mAct.isArraryTalk[this.mAct.monitor_position] + "::" + this.mAct.isArraryListen[this.mAct.monitor_position]);
        this.mAct.SetButtonEnable(true);
        this.mAct.SetFunRTLBg();
        if (this.isChangeMotionPosition) {
            this.mAct.notifySelectMonitorMirrorStatus();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MyLiveViewGLMonitor myLiveViewGLMonitor = this.live_monitor1;
        if (myLiveViewGLMonitor != null) {
            myLiveViewGLMonitor.FreeMonitor();
            this.live_monitor1 = null;
        }
        MyLiveViewGLMonitor myLiveViewGLMonitor2 = this.live_monitor2;
        if (myLiveViewGLMonitor2 != null) {
            myLiveViewGLMonitor2.FreeMonitor();
            this.live_monitor2 = null;
        }
        MyLiveViewGLMonitor myLiveViewGLMonitor3 = this.live_monitor3;
        if (myLiveViewGLMonitor3 != null) {
            myLiveViewGLMonitor3.FreeMonitor();
            this.live_monitor3 = null;
        }
        MyLiveViewGLMonitor myLiveViewGLMonitor4 = this.live_monitor4;
        if (myLiveViewGLMonitor4 != null) {
            myLiveViewGLMonitor4.FreeMonitor();
            this.live_monitor4 = null;
        }
    }
}