2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.Components
25 /// Use a toast to provide simple messages when the user does not need to make an additional action or confirmation.
26 /// Unlike other popups, a toast only has the body field as it is just used for providing simple feedback to user actions.
27 /// A toast will automatically disappear after a certain time.
29 /// <since_tizen> 6 </since_tizen>
30 [Obsolete("Deprecated in API8; Will be removed in API10")]
31 public class Toast : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty MessageProperty = BindableProperty.Create(nameof(Message), typeof(string), typeof(Toast), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (Toast)bindable;
40 instance.strText = (string)(newValue);
41 if (null != instance.textLabel)
43 instance.textLabel.Text = instance.strText;
47 defaultValueCreator: (bindable) =>
49 var instance = (Toast)bindable;
50 return instance.strText;
53 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public static readonly BindableProperty DurationProperty = BindableProperty.Create(nameof(Duration), typeof(uint), typeof(Toast), default(uint), propertyChanged: (bindable, oldValue, newValue) =>
57 var instance = (Toast)bindable;
60 instance.toastStyle.Duration = (uint)newValue;
61 if (instance.timer == null)
63 instance.timer = new Timer(instance.duration);
65 instance.timer.Interval = (uint)newValue;
68 defaultValueCreator: (bindable) =>
70 var instance = (Toast)bindable;
71 return instance.toastStyle.Duration ?? instance.duration;
74 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public static Toast FromText(string text, uint duration)
78 Toast toast = new Toast();
80 toast.Duration = duration;
84 private Window window = null;
85 /// <summary> text labels </summary>
86 protected TextLabel[] textLabels = null;
87 private TextLabel textLabel = null;
88 private string strText = null;
89 private Timer timer = null;
90 private readonly uint duration = 3000;
91 private ToastStyle toastStyle => ViewStyle as ToastStyle;
94 /// Return a copied Style instance of Toast
97 /// It returns copied Style instance and changing it does not effect to the Toast.
98 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
100 [EditorBrowsable(EditorBrowsableState.Never)]
101 public new ToastStyle Style
105 var result = new ToastStyle(toastStyle);
106 result.CopyPropertiesFromView(this);
107 result.Text.CopyPropertiesFromView(textLabel);
114 /// Construct Toast with null.
116 /// <since_tizen> 6 </since_tizen>
117 [Obsolete("Deprecated in API8; Will be removed in API10")]
118 public Toast() : base()
124 /// The constructor of the Toast class with specific Style.
126 /// <param name="toastStyle">Construct Style</param>
127 [EditorBrowsable(EditorBrowsableState.Never)]
128 public Toast(ToastStyle toastStyle) : base(toastStyle)
134 /// Constructor of the Toast class with special style.
136 /// <param name="style"> style name </param>
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public Toast(string style) : base(style)
144 /// Gets or sets the text array of toast.
146 /// <since_tizen> 6 </since_tizen>
147 [Obsolete("Deprecated in API8; Will be removed in API10")]
148 public string[] TextArray
155 /// Gets or sets text point size in toast.
157 /// <since_tizen> 6 </since_tizen>
158 [Obsolete("Deprecated in API8; Will be removed in API10")]
159 public float PointSize
163 return (float)textLabel?.PointSize;
167 if (null != textLabel)
169 textLabel.PointSize = value;
175 /// Gets or sets text font family in toast.
177 /// <since_tizen> 6 </since_tizen>
178 [Obsolete("Deprecated in API8; Will be removed in API10")]
179 public string FontFamily
183 return textLabel?.FontFamily;
187 if (null != textLabel)
189 textLabel.FontFamily = value;
195 /// Gets or sets text color in toast.
197 /// <since_tizen> 6 </since_tizen>
198 [Obsolete("Deprecated in API8; Will be removed in API10")]
199 public Color TextColor
203 return textLabel?.TextColor;
207 if (null != textLabel)
209 textLabel.TextColor = value;
215 /// Gets or sets text horizontal alignment in toast.
217 /// <since_tizen> 6 </since_tizen>
218 [Obsolete("Deprecated in API8; Will be removed in API10")]
219 public HorizontalAlignment TextAlignment
223 return textLabel?.HorizontalAlignment ?? HorizontalAlignment.Center;
227 if (null != textLabel)
229 textLabel.HorizontalAlignment = value;
234 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
235 [EditorBrowsable(EditorBrowsableState.Never)]
236 public void Post(Window win)
240 this.Position.X = (window.Size.Width - this.Size.Width) / 2;
241 this.Position.Y = (window.Size.Height - this.Size.Height) / 2;
246 /// Gets or sets the text toast.
248 /// <since_tizen> 6 </since_tizen>
249 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 public string Message
255 return (string)GetValue(MessageProperty);
259 SetValue(MessageProperty, value);
264 /// Gets or sets text padding in toast.
266 /// <since_tizen> 6 </since_tizen>
267 [Obsolete("Deprecated in API8; Will be removed in API10")]
268 public Extents TextPadding
272 return textLabel?.Padding;
276 if (null != value && null != textLabel)
278 textLabel.Padding.CopyFrom(value);
284 /// Gets or sets text line height in toast.
286 /// <since_tizen> 6 </since_tizen>
287 [Obsolete("Deprecated in API8; Will be removed in API10")]
288 public uint TextLineHeight { get; set; }
291 /// Gets or sets text line space in toast.
293 /// <since_tizen> 6 </since_tizen>
294 [Obsolete("Deprecated in API8; Will be removed in API10")]
295 public uint TextLineSpace { get; set; }
298 /// Gets or sets duration of toast.
300 /// <since_tizen> 6 </since_tizen>
301 [Obsolete("Deprecated in API8; Will be removed in API10")]
306 return (uint)GetValue(DurationProperty);
310 SetValue(DurationProperty, value);
315 /// Apply style to toast.
317 /// <param name="viewStyle">The style to apply.</param>
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public override void ApplyStyle(ViewStyle viewStyle)
321 WidthResizePolicy = ResizePolicyType.FitToChildren;
322 HeightResizePolicy = ResizePolicyType.FitToChildren;
324 base.ApplyStyle(viewStyle);
326 ToastStyle toastStyle = viewStyle as ToastStyle;
328 if (null != toastStyle)
330 if (null == textLabel)
332 textLabel = new TextLabel()
334 PositionUsesPivotPoint = true,
335 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
336 PivotPoint = Tizen.NUI.PivotPoint.Center,
337 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
338 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
339 HorizontalAlignment = HorizontalAlignment.Center,
340 VerticalAlignment = VerticalAlignment.Center,
341 TextColor = Color.White,
345 textLabel.ApplyStyle(toastStyle.Text);
350 /// Dispose ToastPopup.
352 /// <param name="type">dispose types.</param>
353 /// <since_tizen> 6 </since_tizen>
354 [Obsolete("Deprecated in API8; Will be removed in API10")]
355 protected override void Dispose(DisposeTypes type)
362 if (type == DisposeTypes.Explicit)
364 this.VisibilityChanged -= OnVisibilityChanged;
367 timer.Tick -= OnTick;
372 if (null != textLabel)
374 Utility.Dispose(textLabel);
384 /// <returns>The default toast style.</returns>
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 protected override ViewStyle CreateViewStyle()
388 return new ToastStyle();
391 private void Initialize()
393 if (null == textLabel)
395 textLabel = new TextLabel()
397 PositionUsesPivotPoint = true,
398 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
399 PivotPoint = Tizen.NUI.PivotPoint.Center,
400 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
401 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
402 HorizontalAlignment = HorizontalAlignment.Center,
403 VerticalAlignment = VerticalAlignment.Center,
404 TextColor = Color.White,
409 this.VisibilityChanged += OnVisibilityChanged;
410 timer = new Timer(toastStyle.Duration ?? duration);
411 timer.Tick += OnTick;
414 private bool OnTick(object sender, EventArgs e)
420 private void OnVisibilityChanged(object sender, VisibilityChangedEventArgs e)
422 if (true == e.Visibility)
429 window?.Remove(this);