黄学彪
2019-10-28 8b4d79ca03495e522a1953e04ca17527f33c853a
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
152
153
154
155
156
157
158
159
160
161
162
using System;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.DoorLock
{
    public class RemotelyUnlock : DoorLockCommonLayout, ZigBee.Common.IStatus
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public RemotelyUnlock(ZigBee.Device.DoorLock doorLock)
        {
            this.doorLock = doorLock;
            BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
            ZigBee.Device.ZbGateway.StatusList.Add(this);
        }
 
        #region ◆ 变量申明__________________________
        ZigBee.Device.DoorLock doorLock;
        #endregion
 
        /// <summary>
        /// UI显示 
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.RemotelyUnlock));
 
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
 
            MidFrameLayoutContent();
        }
 
        public void MidFrameLayoutContent()
        {
            var passwordText = new EditText()
            {
                Y = Application.GetRealHeight(140),
                Width = Application.GetRealWidth(480 * 2),
                Height = Application.GetRealHeight(70),
                Gravity = Gravity.CenterHorizontal,
                //PlaceholderText = Language.StringByID(R.MyInternationalizationString.InputSixPassword),
                TextAlignment = TextAlignment.Center,
                TextColor = 0xff000000,
                //UnSelectedImagePath = "Register/Register_Password_kuang.png",
                //PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
                Radius = (uint)Application.GetRealHeight(0),
                //SecureTextEntry = true,
                TextSize = 15,
                BackgroundColor = 0xff00ff00,
            };
            this.midFrameLayout.AddChidren(passwordText);
 
            var btnTip = new Button()
            {
                Height = Application.GetRealHeight(60),
                Width = Application.GetRealWidth(60),
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(200),
                Enable = false,
                Visible = false,
            };
 
            this.midFrameLayout.AddChidren(btnTip);
            var btnLock = new Button()
            {
                Height = Application.GetRealHeight(500),
                Width = Application.GetRealWidth(501),
                //UnSelectedImagePath = "DoorLockPic/door_lock_close.png",
                //SelectedImagePath = "DoorLockPic/door_lock_open.png",
                BackgroundColor = 0xff00ffff,
                SelectedBackgroundColor = 0xff00ff00,
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(370),
                Enable = false,
            };
            this.midFrameLayout.AddChidren(btnLock);
            btnLock.MouseUpEventHandler += (sender, e) =>
            {
                btnLock.IsSelected = !btnLock.IsSelected;
            };
 
            passwordText.Text = getDynamicPassword();
            var delayTime = DateTime.Now.AddSeconds(+300);//5分钟内有效
            new System.Threading.Thread(() =>
            {
                while (true)
                {
                    if (DateTime.Now >= delayTime)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            passwordText.Text = "密码失效";
                        });
                    }
                }
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 重写移除方法
        /// </summary>
        public override void RemoveFromParent()
        {
            ZbGateway.StatusList.Remove(this);
            base.RemoveFromParent();
        }
 
        /// <summary>
        /// 生成6位动态密码
        /// </summary>
        /// <returns></returns>
        string getDynamicPassword()
        {
            var password = "";
            password = new Random().Next(100000, 999999).ToString();
            return password;
        }
 
        #region ◆ 接口实现__________________________
        /// <summary>
        /// 处理变化事件 --将弃用 改用DeviceInfoChange()
        /// </summary>
        /// <returns>The changed.</returns>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
 
        }
        /// <summary>
        /// 处理变化事件
        /// </summary>
        /// <param name="common"></param>
        /// <param name="typeTag"></param>
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
        /// <summary>
        /// Changeds the IL ogic status.
        /// </summary>
        /// <param name="logic">Logic.</param>
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
        /// <summary>
        /// Changeds the IS cene status.
        /// </summary>
        /// <param name="scene">Scene.</param>
        public void ChangedISceneStatus(Scene scene)
        {
        }
        #endregion
 
    }
}