-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadWebPinCode.cs
More file actions
226 lines (201 loc) · 8.18 KB
/
Copy pathHeadWebPinCode.cs
File metadata and controls
226 lines (201 loc) · 8.18 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
using System;
using System.Collections.Generic;
using System.Text;
using MediaPortal.Dialogs;
using MediaPortal.GUI.Library;
using Action = MediaPortal.GUI.Library.Action;
using System.ComponentModel;
namespace HeadWeb
{
public class GUIPinCode : GUIDialogWindow
{
public const int ID = 7773;
public GUIPinCode()
{
GetID = ID;
}
public override int GetID
{
get { return ID; }
}
[SkinControlAttribute(6)] protected GUILabelControl labelFeedback = null;
[SkinControlAttribute(100)] protected GUIImage imagePin1 = null;
[SkinControlAttribute(101)] protected GUIImage imagePin2 = null;
[SkinControlAttribute(102)] protected GUIImage imagePin3 = null;
[SkinControlAttribute(103)] protected GUIImage imagePin4 = null;
public string EnteredPinCode { get; set; }
public string MasterCode { get; set; }
public bool IsCorrect { get; set; }
/// <summary>
/// Message reported to user when Pin is incorrect
/// </summary>
public string Message { get; set; }
/// <summary>
/// MediaPortal will set #currentmodule with GetModuleName()
/// </summary>
/// <returns>Window Name</returns>
public override string GetModuleName()
{
return "PinCodeDialog";
}
public override void Reset()
{
base.Reset();
SetHeading("");
SetLine(1, "");
SetLine(2, "");
SetLine(3, "");
SetLine(4, "");
}
public override void DoModal(int ParentID)
{
LoadSkin();
AllocResources();
InitControls();
ClearPinCode();
base.DoModal(ParentID);
}
public override bool Init()
{
return Load(GUIGraphicsContext.Skin + @"\HeadWebPinCode.xml");
}
public override void OnAction(Action action)
{
switch (action.wID)
{
case Action.ActionType.REMOTE_1:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "1";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_2:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "2";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_3:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "3";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_4:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "4";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_5:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "5";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_6:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "6";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_7:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "7";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_8:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "8";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_9:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "9";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.REMOTE_0:
if (EnteredPinCode.Length >= 4) return;
EnteredPinCode = EnteredPinCode + "0";
UpdatePinCode(EnteredPinCode.Length);
break;
case Action.ActionType.ACTION_DELETE_ITEM:
case Action.ActionType.ACTION_MOVE_DOWN:
case Action.ActionType.ACTION_MOVE_LEFT:
if (EnteredPinCode.Length > 0)
{
EnteredPinCode = EnteredPinCode.Substring(0, EnteredPinCode.Length - 1);
UpdatePinCode(EnteredPinCode.Length);
}
break;
case Action.ActionType.ACTION_SELECT_ITEM:
PageDestroy();
return;
case Action.ActionType.ACTION_PREVIOUS_MENU:
case Action.ActionType.ACTION_CLOSE_DIALOG:
case Action.ActionType.ACTION_CONTEXT_MENU:
PageDestroy();
return;
}
base.OnAction(action);
}
protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
{
base.OnClicked(controlId, control, actionType);
}
public override bool OnMessage(GUIMessage message)
{
return base.OnMessage(message);
}
private void UpdatePinCode(int pinLength)
{
GUIImage[] imagePins = new GUIImage[4] { imagePin1, imagePin2, imagePin3, imagePin4 };
// Visually indicate to user the number of digits entered
ClearPinCode();
for (int i = 0; i < pinLength; i++)
{
imagePins[i].Visible = true;
}
// Check if PinCode entered is correct
if (pinLength == 4)
{
ConfirmPinCode();
}
}
private void ClearPinCode()
{
GUIImage[] imagePins = new GUIImage[4] { imagePin1, imagePin2, imagePin3, imagePin4 };
for (int i = 0; i < 4; i++)
{
imagePins[i].Visible = false;
}
IsCorrect = false;
if (labelFeedback != null) labelFeedback.Label = " ";
}
private void ConfirmPinCode()
{
// Show Feedback to user that PinCode is incorrect
// otherwise nothing more to do, exit
if (EnteredPinCode != MasterCode)
{
if (labelFeedback != null) labelFeedback.Label = Message;
}
else
{
IsCorrect = true;
PageDestroy();
return;
}
}
public void SetHeading(string HeadingLine)
{
GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0, 1, 0, 0, null);
msg.Label = HeadingLine;
OnMessage(msg);
}
public void SetLine(int LineNr, string Line)
{
if (LineNr < 1) return;
GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0, 1 + LineNr, 0, 0, null);
msg.Label = Line;
if ((msg.Label == string.Empty) || (msg.Label == "")) msg.Label = " ";
OnMessage(msg);
}
}
}