[Tizen] Supports Picker.TitleColor, FontSize, FontFamily and FontAttributes (#4839)
authorKangho Hur <rookiejava+github@gmail.com>
Fri, 21 Dec 2018 09:04:30 +0000 (01:04 -0800)
committerStephane Delcroix <stephane@delcroix.org>
Fri, 21 Dec 2018 09:04:30 +0000 (10:04 +0100)
Xamarin.Forms.Platform.Tizen/Native/Dialog.cs
Xamarin.Forms.Platform.Tizen/Native/Watch/WatchDialog.cs
Xamarin.Forms.Platform.Tizen/Renderers/PickerRenderer.cs

index 15f70cd..00fc747 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using ElmSharp;
 using EButton = ElmSharp.Button;
+using EColor = ElmSharp.Color;
 
 namespace Xamarin.Forms.Platform.Tizen.Native
 {
@@ -27,6 +28,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                EvasObject _content;
                string _title;
                string _message;
+               EColor _titleColor = EColor.Default;
 
                /// <summary>
                ///  Creates a dialog window.
@@ -75,6 +77,22 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                        }
                }
 
+               public EColor TitleColor
+               {
+                       get
+                       {
+                               return _titleColor;
+                       }
+                       set
+                       {
+                               if (_titleColor != value)
+                               {
+                                       _titleColor = value;
+                                       ApplyTitleColor(value);
+                               }
+                       }
+               }
+
                /// <summary>
                /// Gets or sets the message to display in the dialog
                /// </summary>
@@ -221,6 +239,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                        SetPartText("title,text", title);
                }
 
+               protected virtual void ApplyTitleColor(EColor color)
+               {
+                       SetPartColor(Device.Idiom == TargetIdiom.TV ? "text_title" : "text_maintitle", color);
+               }
+
                /// <summary>
                /// Puts the button in one of the three available slots.
                /// </summary>
index 875d4e4..25da0e5 100644 (file)
@@ -78,6 +78,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native.Watch
                        _popupLayout.SetPartText("elm.text.title", title);
                }
 
+               protected override void ApplyTitleColor(EColor color)
+               {
+                       _popupLayout.SetPartColor("text_title", color);
+               }
+
                protected override void ApplyMessage(string message)
                {
                        _popupLayout.SetPartText("elm.text", message);
index fcfb6c8..9f04445 100644 (file)
@@ -1,24 +1,35 @@
 using System;
-using System.ComponentModel;
 using System.Collections.Generic;
+using Xamarin.Forms.Platform.Tizen.Native;
+using Xamarin.Forms.Platform.Tizen.Native.Watch;
 using ElmSharp;
-using EColor = ElmSharp.Color;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
-       public class PickerRenderer : ViewRenderer<Picker, Native.Button>
+       public class PickerRenderer : ViewRenderer<Picker, EditfieldEntry>
        {
-               internal List _list;
-               internal Native.Dialog _dialog;
+               List _list;
+               Dialog _dialog;
                Dictionary<ListItem, int> _itemToItemNumber = new Dictionary<ListItem, int>();
 
+               public PickerRenderer()
+               {
+                       RegisterPropertyHandler(Picker.SelectedIndexProperty, UpdateSelectedIndex);
+                       RegisterPropertyHandler(Picker.TextColorProperty, UpdateTextColor);
+                       RegisterPropertyHandler(Picker.FontSizeProperty, UpdateFontSize);
+                       RegisterPropertyHandler(Picker.FontFamilyProperty, UpdateFontFamily);
+                       RegisterPropertyHandler(Picker.FontAttributesProperty, UpdateFontAttributes);
+                       RegisterPropertyHandler(Picker.TitleProperty, UpdateTitle);
+                       RegisterPropertyHandler(Picker.TitleColorProperty, UpdateTitleColor);
+               }
+
                protected override void Dispose(bool disposing)
                {
                        if (disposing)
                        {
                                if (Control != null)
                                {
-                                       Control.Clicked -= OnClicked;
+                                       Control.TextBlockFocused -= OnTextBlockFocused;
                                        CleanView();
                                }
                        }
@@ -29,29 +40,18 @@ namespace Xamarin.Forms.Platform.Tizen
                {
                        if (Control == null)
                        {
-                               SetNativeControl (new Native.Button(Forms.NativeParent));
-                               Control.Clicked += OnClicked;
+                               var entry = new EditfieldEntry(Forms.NativeParent)
+                               {
+                                       IsSingleLine = true,
+                                       InputPanelShowByOnDemand = true,
+                               };
+                               entry.SetVerticalTextAlignment("elm.text", 0.5);
+                               entry.TextBlockFocused += OnTextBlockFocused;
+                               SetNativeControl(entry);
                        }
-
-                       UpdateSelectedIndex();
-                       UpdateTextColor();
                        base.OnElementChanged(e);
                }
 
-               protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
-               {
-                       base.OnElementPropertyChanged(sender, e);
-
-                       if (e.PropertyName == Picker.SelectedIndexProperty.PropertyName)
-                       {
-                               UpdateSelectedIndex();
-                       }
-                       else if (e.PropertyName == Picker.TextColorProperty.PropertyName)
-                       {
-                               UpdateTextColor();
-                       }
-               }
-
                void UpdateSelectedIndex()
                {
                        Control.Text = (Element.SelectedIndex == -1 || Element.Items == null ?
@@ -63,32 +63,74 @@ namespace Xamarin.Forms.Platform.Tizen
                        Control.TextColor = Element.TextColor.ToNative();
                }
 
-               void OnClicked(object sender, EventArgs e)
+               void UpdateFontSize()
                {
-                       int i = 0;
-                       _dialog = new Native.Dialog(Forms.NativeParent);
-                       _list = new List(_dialog);
-                       _dialog.AlignmentX = -1;
-                       _dialog.AlignmentY = -1;
-
-                       _dialog.Title = Element.Title;
-                       _dialog.Dismissed += OnDialogDismissed;
-                       _dialog.BackButtonPressed += (object senders, EventArgs es) =>
-                       {
-                               _dialog.Dismiss();
-                       };
+                       Control.FontSize = Element.FontSize;
+               }
 
-                       foreach (var s in Element.Items)
+               void UpdateFontFamily()
+               {
+                       Control.FontFamily = Element.FontFamily;
+               }
+
+               void UpdateFontAttributes()
+               {
+                       Control.FontAttributes = Element.FontAttributes;
+               }
+
+               void UpdateTitle()
+               {
+                       Control.Placeholder = Element.Title;
+               }
+
+               void UpdateTitleColor()
+               {
+                       Control.PlaceholderColor = Element.TitleColor.ToNative();
+               }
+
+               void OnTextBlockFocused(object sender, EventArgs e)
+               {
+                       // For EFL Entry, the event will occur even if it is currently disabled.
+                       // If the problem is resolved, no conditional statement is required.
+                       if (Element.IsEnabled)
                        {
-                               ListItem item = _list.Append(s);
-                               _itemToItemNumber[item] = i;
-                               i++;
-                       }
-                       _list.ItemSelected += OnItemSelected;
-                       _dialog.Content = _list;
+                               int i = 0;
+                               if (Device.Idiom == TargetIdiom.Watch)
+                               {
+                                       _dialog = new WatchDialog(Forms.NativeParent, false);
+                               }
+                               else
+                               {
+                                       _dialog = new Dialog(Forms.NativeParent);
+                               }
+                               _dialog.AlignmentX = -1;
+                               _dialog.AlignmentY = -1;
+                               _dialog.Title = Element.Title;
+                               _dialog.TitleColor = Element.TitleColor.ToNative();
+                               _dialog.Dismissed += OnDialogDismissed;
+                               _dialog.BackButtonPressed += (object senders, EventArgs es) =>
+                               {
+                                       _dialog.Dismiss();
+                               };
 
-                       _dialog.Show();
-                       _list.Show();
+                               _list = new List(_dialog);
+                               foreach (var s in Element.Items)
+                               {
+                                       ListItem item = _list.Append(s);
+                                       _itemToItemNumber[item] = i;
+                                       i++;
+                               }
+                               _list.ItemSelected += OnItemSelected;
+                               _dialog.Content = _list;
+
+                               // You need to call Show() after ui thread occupation because of EFL problem.
+                               // Otherwise, the content of the popup will not receive focus.
+                               Device.BeginInvokeOnMainThread(() =>
+                               {
+                                       _dialog.Show();
+                                       _list.Show();
+                               });
+                       }
                }
 
                void OnItemSelected(object senderObject, EventArgs ev)