Add Background 35/108835/8
authorsung-su.kim <sung-su.kim@samsung.com>
Wed, 11 Jan 2017 05:10:29 +0000 (14:10 +0900)
committersung-su.kim <sung-su.kim@samsung.com>
Fri, 13 Jan 2017 06:10:26 +0000 (15:10 +0900)
- RFC:http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+3+-+Background
- Depends on:https://review.tizen.org/gerrit/#/c/109611/

Change-Id: I4241cb387ffda525f630155c379375b5920a5026

Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs [new file with mode: 0755]
Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj [changed mode: 0644->0755]
Tizen.Xamarin.Forms.Extension/Background.cs [new file with mode: 0755]
Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs [new file with mode: 0755]
Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj [changed mode: 0644->0755]

diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs b/Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs
new file mode 100755 (executable)
index 0000000..0a75888
--- /dev/null
@@ -0,0 +1,76 @@
+using System.ComponentModel;
+using Xamarin.Forms.Platform.Tizen;
+using Tizen.Xamarin.Forms.Extension;
+using Tizen.Xamarin.Forms.Extension.Renderer;
+using EBackground = ElmSharp.Background;
+using EBackgroundOptions = ElmSharp.BackgroundOptions;
+using TForms = Xamarin.Forms.Platform.Tizen.Forms;
+
+[assembly: ExportRenderer(typeof(Background), typeof(BackgroundRenderer))]
+namespace Tizen.Xamarin.Forms.Extension.Renderer
+{
+    public class BackgroundRenderer : ViewRenderer<Background, EBackground>
+    {
+        public BackgroundRenderer()
+        {
+        }
+
+        protected override void OnElementChanged(ElementChangedEventArgs<Background> e)
+        {
+            if (Control == null)
+            {
+                var background = new EBackground(TForms.Context.MainWindow);
+                SetNativeControl(background);
+            }
+            if (e.NewElement != null)
+            {
+                UpdateImage();
+                UpdateOption();
+            }
+            base.OnElementChanged(e);
+        }
+
+        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == Background.ImageProperty.PropertyName)
+            {
+                UpdateImage();
+            }
+            else if (e.PropertyName == Background.OptionProperty.PropertyName)
+            {
+                UpdateOption();
+            }
+            base.OnElementPropertyChanged(sender, e);
+        }
+
+        void UpdateImage()
+        {
+            Control.File = ResourcePath.GetPath(Element.Image.File);
+        }
+
+        void UpdateOption()
+        {
+            Control.BackgroundOption = ConvertToNativeBackgroundOptions(((Background)Element).Option);
+        }
+
+        EBackgroundOptions ConvertToNativeBackgroundOptions(BackgroundOptions option)
+        {
+            if (option == BackgroundOptions.Center)
+            {
+                return EBackgroundOptions.Center;
+            }
+            else if (option == BackgroundOptions.Stretch)
+            {
+                return EBackgroundOptions.Stretch;
+            }
+            else if (option == BackgroundOptions.Tile)
+            {
+                return EBackgroundOptions.Tile;
+            }
+            else
+            {
+                return EBackgroundOptions.Scale;
+            }
+        }
+    }
+}
old mode 100644 (file)
new mode 100755 (executable)
index 8c1186d..b44db5e
@@ -36,6 +36,7 @@
     <WarningLevel>4</WarningLevel>\r
   </PropertyGroup>\r
   <ItemGroup>\r
+    <Compile Include="BackgroundRenderer.cs" />\r
     <Compile Include="Cells\DoubleLabelCellRenderer.cs" />\r
     <Compile Include="Cells\MultilineCellRenderer.cs" />\r
     <Compile Include="Cells\TypeCellRenderer.cs" />\r
@@ -71,4 +72,4 @@
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
   </PropertyGroup>\r
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Tizen.Xamarin.Forms.Extension/Background.cs b/Tizen.Xamarin.Forms.Extension/Background.cs
new file mode 100755 (executable)
index 0000000..d4e66a7
--- /dev/null
@@ -0,0 +1,23 @@
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    public class Background : View
+    {
+        public static readonly BindableProperty ImageProperty = BindableProperty.Create("Image", typeof(FileImageSource), typeof(Background), default(FileImageSource));
+
+        public static readonly BindableProperty OptionProperty = BindableProperty.Create("Option", typeof(BackgroundOptions), typeof(Background), BackgroundOptions.Scale);
+
+        public FileImageSource Image
+        {
+            get { return (FileImageSource)GetValue(ImageProperty); }
+            set { SetValue(ImageProperty, value); }
+        }
+
+        public BackgroundOptions Option
+        {
+            get { return (BackgroundOptions)GetValue(OptionProperty); }
+            set { SetValue(OptionProperty, value); }
+        }
+    }
+}
diff --git a/Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs b/Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs
new file mode 100755 (executable)
index 0000000..bb5cdc3
--- /dev/null
@@ -0,0 +1,10 @@
+namespace Tizen.Xamarin.Forms.Extension
+{
+    public enum BackgroundOptions
+    {
+        Center,
+        Scale,
+        Stretch,
+        Tile
+    }
+}
old mode 100644 (file)
new mode 100755 (executable)
index 41a6509..26c4f18
@@ -53,6 +53,8 @@
     </NoWarn>\r
   </PropertyGroup>\r
   <ItemGroup>\r
+    <Compile Include="Background.cs" />\r
+    <Compile Include="BackgroundOptions.cs" />\r
     <Compile Include="Cells\Type1Cell.cs" />\r
     <Compile Include="Cells\DoubleLabelCell.cs" />\r
     <Compile Include="Cells\Type2Cell.cs" />\r