From 806109277e40a919d15c8cc3c9e783533a9ca1bf Mon Sep 17 00:00:00 2001 From: "sung-su.kim" Date: Wed, 11 Jan 2017 14:10:29 +0900 Subject: [PATCH] Add Background - 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 --- .../BackgroundRenderer.cs | 76 ++++++++++++++++++++++ .../Tizen.Xamarin.Forms.Extension.Renderer.csproj | 3 +- Tizen.Xamarin.Forms.Extension/Background.cs | 23 +++++++ Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs | 10 +++ .../Tizen.Xamarin.Forms.Extension.csproj | 2 + 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs mode change 100644 => 100755 Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj create mode 100755 Tizen.Xamarin.Forms.Extension/Background.cs create mode 100755 Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs mode change 100644 => 100755 Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs b/Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs new file mode 100755 index 0000000..0a75888 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension.Renderer/BackgroundRenderer.cs @@ -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 + { + public BackgroundRenderer() + { + } + + protected override void OnElementChanged(ElementChangedEventArgs 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; + } + } + } +} diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj b/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj old mode 100644 new mode 100755 index 8c1186d..b44db5e --- a/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj +++ b/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj @@ -36,6 +36,7 @@ 4 + @@ -71,4 +72,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) true - \ No newline at end of file + diff --git a/Tizen.Xamarin.Forms.Extension/Background.cs b/Tizen.Xamarin.Forms.Extension/Background.cs new file mode 100755 index 0000000..d4e66a7 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension/Background.cs @@ -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 index 0000000..bb5cdc3 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension/BackgroundOptions.cs @@ -0,0 +1,10 @@ +namespace Tizen.Xamarin.Forms.Extension +{ + public enum BackgroundOptions + { + Center, + Scale, + Stretch, + Tile + } +} diff --git a/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj b/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj old mode 100644 new mode 100755 index 41a6509..26c4f18 --- a/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj +++ b/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj @@ -53,6 +53,8 @@ + + -- 2.7.4