/
Control.cs
executable file
·372 lines (332 loc) · 13.9 KB
/
Control.cs
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
* Copyright(c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
using System.Windows.Input;
using Tizen.System;
namespace Tizen.NUI.Components
{
/// <summary>
/// The control component is base class of tv nui components. It's abstract class, so can't instantiate and can only be inherited.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class Control : VisualView
{
/// <summary>
/// FeedbackProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty FeedbackProperty = BindableProperty.Create(nameof(Feedback), typeof(bool), typeof(Control), default(bool), propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (Control)bindable;
if (newValue != null)
{
instance.InternalFeedback = (bool)newValue;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Control)bindable;
return instance.InternalFeedback;
});
/// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
/// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(Button), null,
propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).CommandCanExecuteChanged(bindable, EventArgs.Empty));
private bool onThemeChangedEventOverrideChecker;
private Feedback feedback = null;
static Control()
{
ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance);
}
/// <summary>
/// This is used to improve theme performance.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
static public new void Preload()
{
DefaultThemeCreator.Preload();
}
/// <summary>
/// Construct an empty Control.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public Control() : this((ControlStyle)null)
{
}
/// <summary>
/// Construct with style.
/// </summary>
/// <param name="style">Create control with style.</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public Control(ControlStyle style) : base(style)
{
}
/// <summary>
/// Construct with style name
/// </summary>
/// <param name="styleName">The name of style in the current theme to be applied</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public Control(string styleName) : base(ThemeManager.GetInitialStyleWithoutClone(styleName) ?? throw new InvalidOperationException($"There is no style {styleName}"))
{
this.styleName = styleName;
SetThemeApplied();
}
/// <summary>
/// Enable/Disable a sound feedback when tap gesture detected.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool Feedback
{
get
{
return (bool)GetValue(FeedbackProperty);
}
set
{
SetValue(FeedbackProperty, value);
NotifyPropertyChanged();
}
}
private bool InternalFeedback
{
get => feedback != null;
set
{
if (value == (feedback != null))
{
return;
}
if (value)
{
try
{
feedback = new Feedback();
this.TouchEvent += OnTouchPlayFeedback;
}
catch (NotSupportedException e)
{
Log.Error("NUI", $"[ERROR] No support of Feedback: {e}");
}
catch (InvalidOperationException e)
{
Log.Error("NUI", $"[ERROR] Fail to initialize Feedback: {e}");
}
}
else
{
this.TouchEvent -= OnTouchPlayFeedback;
feedback = null;
}
}
}
private bool OnTouchPlayFeedback(object source, TouchEventArgs e)
{
try
{
if (Feedback && e?.Touch.GetState(0) == PointStateType.Down)
{
if (feedback != null && feedback.IsSupportedPattern(FeedbackType.Sound, "Tap"))
{
feedback.Play(FeedbackType.Sound, "Tap");
}
}
}
catch (NotSupportedException ex)
{
Log.Error("NUI", $"[ERROR] No support of Feedback: {ex}");
}
catch (InvalidOperationException ex)
{
Log.Error("NUI", $"[ERROR] Fail to initialize Feedback: {ex}");
}
return false;
}
/// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
/// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
public object CommandParameter
{
get { return GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}
/// <summary>
/// Whether focusable when touch
/// </summary>
/// <since_tizen> 6 </since_tizen>
internal bool StateFocusableOnTouchMode { get; set; }
internal bool IsFocused { get; set; } = false;
internal void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
{
ICommand cmd = Command;
if (cmd != null)
cmd.CanExecute(CommandParameter);
}
internal void OnCommandChanged()
{
if (Command != null)
{
Command.CanExecuteChanged += CommandCanExecuteChanged;
CommandCanExecuteChanged(this, EventArgs.Empty);
}
}
/// <summary>
/// Dispose Control and all children on it.
/// </summary>
/// <param name="type">Dispose type.</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
feedback = null;
this.TouchEvent -= OnTouchPlayFeedback;
if (type == DisposeTypes.Explicit)
{
}
base.Dispose(type);
}
/// <inheritdoc/>
public override void OnInitialize()
{
base.OnInitialize();
LeaveRequired = true;
StateFocusableOnTouchMode = false;
EnableControlState = true;
}
/// <summary>
/// Called after a key event is received by the view that has had its focus set.
/// </summary>
/// <param name="key">The key event.</param>
/// <returns>True if the key event should be consumed.</returns>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool OnKey(Key key)
{
return false;
}
/// <summary>
/// Called after the size negotiation has been finished for this control.<br />
/// The control is expected to assign this given size to itself or its children.<br />
/// Should be overridden by derived classes if they need to layout views differently after certain operations like add or remove views, resize, or after changing specific properties.<br />
/// As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored).<br />
/// </summary>
/// <param name="size">The allocated size.</param>
/// <param name="container">The control should add views to this container that it is not able to allocate a size for.</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnRelayout(Vector2 size, RelayoutContainer container)
{
base.OnRelayout(size, container);
OnUpdate();
}
/// <summary>
/// Called when the control gain key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is gained.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnFocusGained()
{
IsFocused = true;
}
/// <summary>
/// Called when the control loses key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is lost.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnFocusLost()
{
IsFocused = false;
}
/// <summary>
/// Update by style.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void OnUpdate()
{
}
/// <summary>
/// Theme change callback when theme is changed, this callback will be trigger.
/// Note that it is deprecated API.Please use OnThemeChanged instead.
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="e">The event data</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
{
onThemeChangedEventOverrideChecker = false;
}
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override ViewStyle CreateViewStyle()
{
return new ControlStyle();
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void OnThemeChanged(object sender, ThemeChangedEventArgs e)
{
// TODO Remove checker after update Tizen.FH.NUI.
onThemeChangedEventOverrideChecker = true;
OnThemeChangedEvent(sender, new StyleManager.ThemeChangeEventArgs { CurrentTheme = e.ThemeId });
if (onThemeChangedEventOverrideChecker) return;
// If the OnThemeChangedEvent is not implemented, ApplyStyle()
base.OnThemeChanged(sender, e);
}
/// <summary>
/// when the derived class of Control is used as container and itself is not Focusable, this can be used when calling SetCurrentFocusView()
/// this can return Focusable View inside of itself. this can be utilized when default algorithm is enabled and when the case of setting first key focus in container.
/// </summary>
/// <returns>Focusable View inside of container</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
protected internal virtual View PassFocusableViewInsideIfNeeded()
{
return this;
}
}
}