xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
using System.Threading;
using Android.App;
using Android.Icu.Text;
using Android.OS;
using Android.Views;
using Android.Widget;
using Java.Util;
 
namespace HDL_ON_Android.LeChengView.Form
{
    public class MonitorFragment : Fragment, View.IOnClickListener
    {
 
        private View mView;
 
        // 截图
        private LinearLayout screenshotLayout;
        private ImageView screenImage;
        private TextView ScreenText;
 
        //开锁
        private LinearLayout unlockLayout;
        private ImageView unlockImag;
        private TextView unlockText;
 
        // 更新线程
        private Thread thread = null;
 
        private LeChengVideoActivity CurtActivity;
 
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
 
            CurtActivity = (LeChengVideoActivity)this.Activity;
        }
 
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            mView = inflater.Inflate(Resource.Layout.fragment_monitor, container, false);
 
            IniView();
 
            CurtActivity.Play();
            CurtActivity.OpenAudio();
 
            return mView;
        }
 
        private void IniView()
        {
            screenshotLayout = (LinearLayout)mView.FindViewById(Resource.Id.icon_sceenshotLayout);
            screenImage = (ImageView)mView.FindViewById(Resource.Id.icon_sceenshotImg);
            ScreenText = (TextView)mView.FindViewById(Resource.Id.icon_sceenshotText);
 
            unlockLayout = (LinearLayout)mView.FindViewById(Resource.Id.icon_unlockLayout);
            unlockImag = (ImageView)mView.FindViewById(Resource.Id.icon_unlockImg);
            unlockText = (TextView)mView.FindViewById(Resource.Id.icon_unlockText);
 
            unlockLayout.SetOnClickListener(this);
            screenshotLayout.SetOnClickListener(this);
        }
 
 
 
        /// <summary>
        /// 开锁
        /// </summary>
        private void Unlock()
        {
            //
            CurtActivity.Unlock();
            UpdataUnlockState();
        }
 
        /// <summary>
        /// 更新开锁按钮状态
        /// </summary>
        private void UpdataUnlockState()
        {
            try
            {
                //开锁成功,15秒内不给再点击按钮
                unlockLayout.Enabled = false;
                if (thread != null)
                {
                    try
                    {
                        thread.Interrupt();
                    }
                    catch { }
                    thread = null;
                }
 
                thread = new Thread(() =>
                {
                    try
                    {
                        Thread.Sleep(15 * 1000);
 
                        Activity.RunOnUiThread(() =>
                        {
                            if (unlockLayout != null)
                                unlockLayout.Enabled = true;
                        });
                    }
                    catch { }
                });
 
                thread.Start();
            }
            catch { }
        }
 
        public void OnClick(View v)
        {
            //
            if (v.Equals(unlockLayout))
            {
                //开锁
                Unlock();
            }
            else if (v.Equals(screenshotLayout))
            {
                //有视频过来可调用此接口进行拍照
                screenImage.Selected = true;
                SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
                string time = format.Format(new Date(SystemClock.CurrentThreadTimeMillis()));
                string ss = Android.OS.Environment.ExternalStorageDirectory.Path + "/DCIM/HDL";
                string path = ss + "/" + time + ".jpg";
                CurtActivity.SnapShot(path);
            }
        }
 
        public override void OnDestroy()
        {
            base.OnDestroy();
 
            if (thread != null)
            {
                try
                {
                    thread.Interrupt();
                }
                catch { }
                thread = null;
            }
        }
    }
}