use default orientation for toast
[platform/core/csapi/xamarin-forms-extension.git] / Tizen.Xamarin.Forms.Extension.Renderer / ToastImplementation.cs
1 using System;
2 using Tizen.Xamarin.Forms.Extension.Renderer;
3 using Xamarin.Forms;
4 using EPopup = ElmSharp.Popup;
5 using TForms = Xamarin.Forms.Platform.Tizen.Forms;
6
7 [assembly: Dependency(typeof(ToastImplementation))]
8
9 namespace Tizen.Xamarin.Forms.Extension.Renderer
10 {
11     internal class ToastImplementation : IToast, IDisposable
12     {
13         static readonly string DefaultStyle = "toast";
14         static readonly string DefaultPart = "default";
15
16         int _duration = 3000;
17         string _text = string.Empty;
18         EPopup _control = null;
19         bool _isDisposed = false;
20
21         public int Duration
22         {
23             get
24             {
25                 return _duration;
26             }
27             set
28             {
29                 _duration = value;
30                 UpdateDuration();
31             }
32         }
33
34         public string Text
35         {
36             get
37             {
38                 return _text;
39             }
40             set
41             {
42                 _text = value;
43                 UpdateText();
44             }
45         }
46
47         public ToastImplementation()
48         {
49             _control = new EPopup(TForms.Context.MainWindow)
50             {
51                 Style = DefaultStyle,
52                 AllowEvents = true,
53             };
54
55             UpdateText();
56             UpdateDuration();
57         }
58
59         ~ToastImplementation()
60         {
61             Dispose(false);
62         }
63
64         public void Show()
65         {
66             _control.Show();
67         }
68
69         public void Dismiss()
70         {
71             _control.Dismiss();
72         }
73
74         public void Dispose()
75         {
76             Dispose(true);
77             GC.SuppressFinalize(this);
78         }
79
80         protected virtual void Dispose(bool isDisposing)
81         {
82             if (_isDisposed)
83                 return;
84
85             if (isDisposing)
86             {
87                 if (_control != null)
88                 {
89                     _control.Unrealize();
90                     _control = null;
91                 }
92             }
93
94             _isDisposed = true;
95         }
96
97         void UpdateDuration()
98         {
99             _control.Timeout = Duration / 1000.0;
100         }
101
102         void UpdateText()
103         {
104             _control.SetPartText(DefaultPart, Text);
105         }
106     }
107 }