Add Toast 64/116264/17
authorchungryeol lim <cdark.lim@samsung.com>
Thu, 23 Feb 2017 12:04:00 +0000 (21:04 +0900)
committerdarkleem <cdark.lim@samsung.com>
Thu, 23 Mar 2017 03:48:16 +0000 (12:48 +0900)
  - RFC-20

Change-Id: I3d78ed8dbc82fd9d4c76e92db46c354dc91a33b2

Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj
Tizen.Xamarin.Forms.Extension.Renderer/ToastImplementation.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/IToast.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/Properties/AssemblyInfo.cs
Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj
Tizen.Xamarin.Forms.Extension/Toast.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/ToastProxy.cs [new file with mode: 0644]

index dace14b..dd839e6 100755 (executable)
@@ -51,6 +51,7 @@
     <Compile Include="GridViewRenderer.cs" />\r
     <Compile Include="TizenExtension.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="ToastImplementation.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="Tizen.Xamarin.Forms.Extension.Renderer.project.json" />\r
@@ -81,4 +82,4 @@
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
   </PropertyGroup>\r
-</Project>\r
+</Project>
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/ToastImplementation.cs b/Tizen.Xamarin.Forms.Extension.Renderer/ToastImplementation.cs
new file mode 100644 (file)
index 0000000..549e352
--- /dev/null
@@ -0,0 +1,108 @@
+using System;
+using Tizen.Xamarin.Forms.Extension.Renderer;
+using Xamarin.Forms;
+using EPopup = ElmSharp.Popup;
+using TForms = Xamarin.Forms.Platform.Tizen.Forms;
+
+[assembly: Dependency(typeof(ToastImplementation))]
+
+namespace Tizen.Xamarin.Forms.Extension.Renderer
+{
+    internal class ToastImplementation : IToast, IDisposable
+    {
+        static readonly string DefaultStyle = "toast";
+        static readonly string DefaultPart = "default";
+
+        int _duration = 3000;
+        string _text = string.Empty;
+        EPopup _control = null;
+        bool _isDisposed = false;
+
+        public int Duration
+        {
+            get
+            {
+                return _duration;
+            }
+            set
+            {
+                _duration = value;
+                UpdateDuration();
+            }
+        }
+
+        public string Text
+        {
+            get
+            {
+                return _text;
+            }
+            set
+            {
+                _text = value;
+                UpdateText();
+            }
+        }
+
+        public ToastImplementation()
+        {
+            _control = new EPopup(TForms.Context.MainWindow)
+            {
+                Orientation = ElmSharp.PopupOrientation.Bottom,
+                Style = DefaultStyle,
+                AllowEvents = true,
+            };
+
+            UpdateText();
+            UpdateDuration();
+        }
+
+        ~ToastImplementation()
+        {
+            Dispose(false);
+        }
+
+        public void Show()
+        {
+            _control.Show();
+        }
+
+        public void Dismiss()
+        {
+            _control.Dismiss();
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void Dispose(bool isDisposing)
+        {
+            if (_isDisposed)
+                return;
+
+            if (isDisposing)
+            {
+                if (_control != null)
+                {
+                    _control.Unrealize();
+                    _control = null;
+                }
+            }
+
+            _isDisposed = true;
+        }
+
+        void UpdateDuration()
+        {
+            _control.Timeout = Duration / 1000.0;
+        }
+
+        void UpdateText()
+        {
+            _control.SetPartText(DefaultPart, Text);
+        }
+    }
+}
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension/IToast.cs b/Tizen.Xamarin.Forms.Extension/IToast.cs
new file mode 100644 (file)
index 0000000..620f83d
--- /dev/null
@@ -0,0 +1,28 @@
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// This interface which defines the ability to display simple text is used internally.
+    /// </summary>
+    internal interface IToast
+    {
+        /// <summary>
+        /// Gets or sets the duration.
+        /// </summary>
+        int Duration { get; set; }
+
+        /// <summary>
+        /// Gets or sets the Text.
+        /// </summary>
+        string Text { get; set; }
+
+        /// <summary>
+        /// Show the view for the specified duration.
+        /// </summary>
+        void Show();
+
+        /// <summary>
+        /// Dismiss the specified view.
+        /// </summary>
+        void Dismiss();
+    }
+}
\ No newline at end of file
index b298784..c9b1c03 100644 (file)
@@ -11,5 +11,4 @@ using System.Runtime.CompilerServices;
 [assembly: AssemblyTrademark("")]
 [assembly: CompilationRelaxations(8)]
 [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
-
-[assembly: InternalsVisibleTo("Tizen.Xamarin.Forms.Extension.Renderer")]
\ No newline at end of file
+[assembly: InternalsVisibleTo("Tizen.Xamarin.Forms.Extension.Renderer")]
index 4270d4c..7ea91d5 100644 (file)
@@ -76,6 +76,7 @@
     <Compile Include="GridViewEventArgs.cs" />\r
     <Compile Include="ILongTapGestureController.cs" />\r
     <Compile Include="ItemsView.cs" />\r
+    <Compile Include="IToast.cs" />\r
     <Compile Include="ListProxy.cs" />\r
     <Compile Include="LongTapGestureRecognizer.cs" />\r
     <Compile Include="LongTapUpdatedEventArgs.cs" />\r
@@ -85,6 +86,8 @@
     <Compile Include="SelectedEventArgs.cs" />\r
     <Compile Include="ReadOnlyListAdapter.cs" />\r
     <Compile Include="TemplatedItemsList.cs" />\r
+    <Compile Include="Toast.cs" />\r
+    <Compile Include="ToastProxy.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">\r
diff --git a/Tizen.Xamarin.Forms.Extension/Toast.cs b/Tizen.Xamarin.Forms.Extension/Toast.cs
new file mode 100644 (file)
index 0000000..1d578ff
--- /dev/null
@@ -0,0 +1,27 @@
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// The Toast class provides properties that show simple types of messages.
+    /// </summary>
+    /// <example>
+    /// <code>
+    /// Toast.DisplayText("Hello World", 3000)
+    /// </code>
+    /// </example>
+    public sealed class Toast
+    {
+        /// <summary>
+        /// It shows the simplest form of the message.
+        /// </summary>
+        /// <param name="text">The body text of the toast.</param>
+        /// <param name="duration">How long to display the text in milliseconds.</param>
+        public static void DisplayText(string text, int duration = 3000)
+        {
+            new ToastProxy
+            {
+                Text = text,
+                Duration = duration,
+            }.Show();
+        }
+    }
+}
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension/ToastProxy.cs b/Tizen.Xamarin.Forms.Extension/ToastProxy.cs
new file mode 100644 (file)
index 0000000..c2954c1
--- /dev/null
@@ -0,0 +1,57 @@
+using System;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// This Class is for internal use by toast.
+    /// </summary>
+    internal class ToastProxy : IToast
+    {
+        IToast _toastProxy = null;
+
+        public ToastProxy()
+        {
+            _toastProxy = DependencyService.Get<IToast>(DependencyFetchTarget.NewInstance);
+
+            if (_toastProxy == null)
+                throw new Exception("RealObject is null, Internal instance via DependecyService was not created.");
+        }
+
+        public int Duration
+        {
+            get
+            {
+                return _toastProxy.Duration;
+            }
+
+            set
+            {
+                _toastProxy.Duration = value;
+            }
+        }
+
+        public string Text
+        {
+            get
+            {
+                return _toastProxy.Text;
+            }
+
+            set
+            {
+                _toastProxy.Text = value;
+            }
+        }
+
+        public void Dismiss()
+        {
+            _toastProxy.Dismiss();
+        }
+
+        public void Show()
+        {
+            _toastProxy.Show();
+        }
+    }
+}
\ No newline at end of file