summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Cells
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2016-12-16 11:00:07 +0900
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 13:34:24 +0900
commita2e67107402bc5a49d73cee9062bcd7dbe4069e7 (patch)
treeea6c6606567e8440397de192d47195194c0266dd /Xamarin.Forms.Platform.Tizen/Cells
parent509954d0a013acdf7508644c1fb394bea626e587 (diff)
downloadxamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.tar.gz
xamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.tar.bz2
xamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.zip
Add Tizen backend renderer
- Xamarin.Forms.Platform.Tizen has been added - Xamarin.Forms.Maps.Tizen has been added - RPM build spec has been added Change-Id: I0021e0f040d97345affc87512ee0f6ce437f4e6d
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Cells')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/CellRenderer.cs142
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs163
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/ImageCellRenderer.cs60
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs74
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs72
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs43
6 files changed, 554 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/CellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/CellRenderer.cs
new file mode 100644
index 00000000..1cda74c2
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/CellRenderer.cs
@@ -0,0 +1,142 @@
+using ElmSharp;
+using System.Collections.Generic;
+using EColor = ElmSharp.Color;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public abstract class CellRenderer : IRegisterable
+ {
+ const string _heightProperty = "Height";
+ protected static readonly EColor s_defaultTextColor = EColor.Black;
+ protected static readonly EColor s_defaultBackgroundColor = EColor.White;
+ readonly Dictionary<Cell, Dictionary<string, EvasObject>> _realizedNativeViews = new Dictionary<Cell, Dictionary<string, EvasObject>>();
+
+ protected CellRenderer(string style)
+ {
+ Class = new GenItemClass(style)
+ {
+ GetTextHandler = GetText,
+ GetContentHandler = GetContent,
+ DeleteHandler = ItemDeleted,
+ };
+ }
+
+ public GenItemClass Class
+ {
+ get;
+ private set;
+ }
+
+ protected virtual bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (property == _heightProperty)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ protected virtual Span OnGetText(Cell cell, string part)
+ {
+ return null;
+ }
+ protected virtual EvasObject OnGetContent(Cell cell, string part)
+ {
+ return null;
+ }
+ protected virtual void OnDeleted(Cell cell)
+ {
+ }
+
+ protected virtual void OnUnrealizedCell(Cell cell)
+ {
+ }
+
+ protected int FindCellContentHeight(Cell cell)
+ {
+ ViewCell viewCell = cell as ViewCell;
+ if (viewCell != null)
+ {
+ var parentWidth = (cell.Parent as VisualElement).Width;
+ var view = viewCell.View;
+ return (int)view.Measure(parentWidth, double.PositiveInfinity).Request.Height;
+ }
+ else
+ return -1;
+ }
+
+ static Native.Span ToNative(Span span)
+ {
+ var nativeSpan = new Native.Span();
+ nativeSpan.Text = span.Text;
+ nativeSpan.ForegroundColor = span.ForegroundColor.IsDefault ? s_defaultTextColor : span.ForegroundColor.ToNative();
+ nativeSpan.FontAttributes = span.FontAttributes;
+ nativeSpan.BackgroundColor = span.BackgroundColor.IsDefault ? s_defaultBackgroundColor : span.BackgroundColor.ToNative();
+ nativeSpan.FontSize = span.FontSize;
+ nativeSpan.FontFamily = span.FontFamily;
+ return nativeSpan;
+ }
+
+ internal void SendCellPropertyChanged(Cell cell, GenListItem item, string property)
+ {
+ Dictionary<string, EvasObject> realizedView = null;
+ _realizedNativeViews.TryGetValue(cell, out realizedView);
+
+ // just to prevent null reference exception in OnCellPropertyChanged
+ realizedView = realizedView ?? new Dictionary<string, EvasObject>();
+
+ if (property == Cell.IsEnabledProperty.PropertyName)
+ {
+ item.IsEnabled = cell.IsEnabled;
+ }
+ // if true was returned, item was updated
+ // if it's possible to update the cell property without Update(), return false
+ else if (OnCellPropertyChanged(cell, property, realizedView))
+ {
+ item.Update();
+ }
+ }
+
+ internal void SendUnrealizedCell(Cell cell)
+ {
+ _realizedNativeViews.Remove(cell);
+ OnUnrealizedCell(cell);
+ }
+
+ string GetText(object data, string part)
+ {
+ var span = OnGetText((data as Native.ListView.ItemContext).Cell, part);
+ return span != null ? ToNative(span).GetDecoratedText() : null;
+ }
+
+ EvasObject GetContent(object data, string part)
+ {
+ var cell = (data as Native.ListView.ItemContext).Cell;
+ EvasObject nativeView = OnGetContent(cell, part);
+ if (part != null && nativeView != null)
+ {
+ Dictionary<string, EvasObject> realizedView = null;
+ _realizedNativeViews.TryGetValue(cell, out realizedView);
+ if (realizedView == null)
+ {
+ realizedView = new Dictionary<string, EvasObject>();
+ _realizedNativeViews[cell] = realizedView;
+ }
+ realizedView[part] = nativeView;
+
+ nativeView.Deleted += (sender, e) =>
+ {
+ realizedView.Remove(part);
+ };
+ }
+ return nativeView;
+ }
+
+ void ItemDeleted(object data)
+ {
+ var cell = (data as Native.ListView.ItemContext).Cell;
+ _realizedNativeViews.Remove(cell);
+ OnDeleted(cell);
+ }
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
new file mode 100644
index 00000000..c07985f8
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
@@ -0,0 +1,163 @@
+using ElmSharp;
+using EColor = ElmSharp.Color;
+using EBox = ElmSharp.Box;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class EntryCellRenderer : ViewCellRenderer
+ {
+ const int _defaultHeight = 120;
+ readonly Dictionary<EvasObject, NativeEntryComponent> _realizedComponent = new Dictionary<EvasObject, NativeEntryComponent>();
+
+ public EntryCellRenderer()
+ {
+ }
+
+ protected override EvasObject OnGetContent(Cell cell, string part)
+ {
+ if (part == MainContentPart)
+ {
+ var entryCell = cell as EntryCell;
+ int height = (int)entryCell.RenderHeight;
+ height = height <= 0 ? FindCellContentHeight(entryCell) : height;
+ height = height <= 0 ? _defaultHeight : height;
+
+ // TODO
+ // Need to use Forms.Core element instead of using Elmsharp.
+ // if we use Forms element, easily binding data to view elements
+ var box = new EBox(Forms.Context.MainWindow)
+ {
+ IsHorizontal = true,
+ MinimumHeight = height,
+ };
+ box.SetAlignment(-1.0, -1.0); // fill
+ box.SetWeight(1.0, 1.0); // expand
+
+ var label = new Native.Label(box)
+ {
+ Text = entryCell.Label,
+ TextColor = GetLabelColor(entryCell),
+ };
+ label.SetAlignment(0.0, 0.5);
+ label.SetWeight(0.0, 1.0);
+
+ var entry = new Native.Entry(box)
+ {
+ IsSingleLine = true,
+ Text = entryCell.Text,
+ TextColor = s_defaultTextColor,
+ Placeholder = entryCell.Placeholder,
+ PlaceholderColor = s_defaultTextColor,
+ Keyboard = entryCell.Keyboard.ToNative(),
+ HorizontalTextAlignment = entryCell.HorizontalTextAlignment.ToNative(),
+ };
+ entry.SetAlignment(-1.0, 0.5);
+ entry.SetWeight(1.0, 1.0);
+
+ box.PackEnd(label);
+ box.PackEnd(entry);
+
+ label.Show();
+ entry.Show();
+
+ entry.TextChanged += (sender, e) =>
+ {
+ entryCell.Text = e.NewTextValue;
+ };
+ entry.Activated += (sender, e) =>
+ {
+ (cell as IEntryCellController).SendCompleted();
+ };
+ NativeEntryComponent component = new NativeEntryComponent()
+ {
+ Entry = entry,
+ Label = label,
+ };
+ _realizedComponent[box] = component;
+ box.Deleted += (sender, e) =>
+ {
+ _realizedComponent.Remove(box);
+ };
+ return box;
+ }
+ return null;
+ }
+
+ protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (!realizedView.ContainsKey(MainContentPart) || !_realizedComponent.ContainsKey(realizedView[MainContentPart]))
+ {
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+
+ NativeEntryComponent realizedCompoenet = _realizedComponent[realizedView[MainContentPart]];
+ EntryCell entryCell = (EntryCell)cell;
+
+ if (property == EntryCell.HorizontalTextAlignmentProperty.PropertyName)
+ {
+ var entry = realizedCompoenet.Entry;
+ if (entry != null)
+ {
+ entry.HorizontalTextAlignment = entryCell.HorizontalTextAlignment.ToNative();
+ }
+ }
+ else if (property == EntryCell.KeyboardProperty.PropertyName)
+ {
+ var entry = realizedCompoenet.Entry;
+ if (entry != null)
+ {
+ entry.Keyboard = entryCell.Keyboard.ToNative();
+ }
+ }
+ else if (property == EntryCell.PlaceholderProperty.PropertyName)
+ {
+ var entry = realizedCompoenet.Entry;
+ if (entry != null)
+ {
+ entry.Placeholder = entryCell.Placeholder;
+ }
+ }
+ else if (property == EntryCell.TextProperty.PropertyName)
+ {
+ var entry = realizedCompoenet.Entry;
+ if (entry != null)
+ {
+ entry.Text = entryCell.Text;
+ }
+ }
+ else if (property == EntryCell.LabelProperty.PropertyName)
+ {
+ var label = realizedCompoenet.Label;
+ if (label != null)
+ {
+ label.Text = entryCell.Label;
+ }
+ }
+ else if (property == EntryCell.LabelColorProperty.PropertyName)
+ {
+ var label = realizedCompoenet.Label;
+ if (label != null)
+ {
+ label.TextColor = GetLabelColor(entryCell);
+ }
+ }
+ else
+ {
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+ return false;
+ }
+
+ EColor GetLabelColor(EntryCell cell)
+ {
+ return cell.LabelColor.IsDefault ? s_defaultTextColor : cell.LabelColor.ToNative();
+ }
+
+ class NativeEntryComponent
+ {
+ public Native.Entry Entry { get; set; }
+ public Native.Label Label { get; set; }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/ImageCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/ImageCellRenderer.cs
new file mode 100644
index 00000000..9492e7c6
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/ImageCellRenderer.cs
@@ -0,0 +1,60 @@
+using ElmSharp;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class ImageCellRenderer : TextCellRenderer
+ {
+ const int _defaultHeight = 100;
+ Dictionary<EvasObject, Native.Image> _realizedViews = new Dictionary<EvasObject, Native.Image>();
+
+ public ImageCellRenderer() : this("type1")
+ {
+ ImagePart = "elm.swallow.icon";
+ }
+ protected ImageCellRenderer(string style) : base(style) { }
+
+ protected string ImagePart { get; set; }
+
+ protected override EvasObject OnGetContent(Cell cell, string part)
+ {
+ if (part == ImagePart)
+ {
+ var imgCell = cell as ImageCell;
+ var size = imgCell.RenderHeight;
+ if (size <= 0)
+ {
+ size = _defaultHeight;
+ }
+
+ var image = new Native.Image(Forms.Context.MainWindow)
+ {
+ MinimumWidth = (int)size,
+ MinimumHeight = (int)size
+ };
+ image.SetAlignment(-1.0, -1.0); // fill
+ image.SetWeight(1.0, 1.0); // expand
+
+ image.LoadFromImageSourceAsync(imgCell.ImageSource);
+ return image;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (property == ImageCell.ImageSourceProperty.PropertyName)
+ {
+ EvasObject image;
+ realizedView.TryGetValue(ImagePart, out image);
+ (image as Native.Image)?.LoadFromImageSourceAsync((cell as ImageCell)?.ImageSource);
+ return false;
+ }
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs
new file mode 100644
index 00000000..6c5a0380
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs
@@ -0,0 +1,74 @@
+using System.Collections.Generic;
+using ElmSharp;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class SwitchCellRenderer : CellRenderer
+ {
+ protected SwitchCellRenderer(string style) : base(style)
+ {
+ }
+ public SwitchCellRenderer() : this("end_icon")
+ {
+ MainPart = "elm.text";
+ SwitchPart = "elm.swallow.end";
+ }
+
+ protected string MainPart { get; set; }
+ protected string SwitchPart { get; set; }
+
+ protected override Span OnGetText(Cell cell, string part)
+ {
+ if (part == MainPart)
+ {
+ return new Span()
+ {
+ Text = (cell as SwitchCell).Text
+ };
+ }
+ return null;
+ }
+
+ protected override EvasObject OnGetContent(Cell cell, string part)
+ {
+ if (part == SwitchPart)
+ {
+ var switchCell = cell as SwitchCell;
+ var checkbox = new Check(Forms.Context.MainWindow)
+ {
+ Style = "on&off",
+ IsChecked = switchCell.On,
+ };
+
+ checkbox.StateChanged += (sender, e) =>
+ {
+ switchCell.On = e.NewState;
+ };
+
+ checkbox.SetAlignment(-1.0, -1.0); // fill
+ checkbox.SetWeight(1.0, 1.0); // expand
+ return checkbox;
+ }
+ return null;
+ }
+
+ protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (property == SwitchCell.OnProperty.PropertyName && realizedView.ContainsKey(SwitchPart))
+ {
+ var checkbox = realizedView[SwitchPart] as Check;
+ if (checkbox != null)
+ {
+ checkbox.IsChecked = (cell as SwitchCell).On;
+ }
+ return false;
+ }
+ else if (property == SwitchCell.TextProperty.PropertyName)
+ {
+ return true;
+ }
+
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs
new file mode 100644
index 00000000..2bea3848
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs
@@ -0,0 +1,72 @@
+using ElmSharp;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class TextCellRenderer : CellRenderer
+ {
+ public TextCellRenderer() : this("double_label") { }
+ protected TextCellRenderer(string style) : base(style)
+ {
+ MainPart = "elm.text";
+ DetailPart = "elm.text.sub";
+ }
+
+ protected string MainPart { get; set; }
+ protected string DetailPart { get; set; }
+
+ protected override Span OnGetText(Cell cell, string part)
+ {
+ var textCell = (TextCell)cell;
+ if (part == MainPart)
+ {
+ return OnMainText(textCell);
+ }
+ if (part == DetailPart)
+ {
+ return OnDetailText(textCell);
+ }
+ return null;
+ }
+
+ protected virtual Span OnMainText(TextCell cell)
+ {
+ return new Span()
+ {
+ Text = cell.Text,
+ ForegroundColor = cell.TextColor
+ };
+ }
+
+ protected virtual Span OnDetailText(TextCell cell)
+ {
+ return new Span()
+ {
+ Text = cell.Detail,
+ ForegroundColor = cell.DetailColor
+ };
+ }
+
+ protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (property == TextCell.TextProperty.PropertyName ||
+ property == TextCell.TextColorProperty.PropertyName ||
+ property == TextCell.DetailProperty.PropertyName ||
+ property == TextCell.DetailColorProperty.PropertyName)
+ {
+ return true;
+ }
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+ }
+
+ internal class GroupCellTextRenderer : TextCellRenderer
+ {
+
+ public GroupCellTextRenderer() : this("group_index")
+ {
+ DetailPart = "elm.text.end";
+ }
+ protected GroupCellTextRenderer(string style) : base(style) { }
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
new file mode 100644
index 00000000..69065c8a
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+using ElmSharp;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class ViewCellRenderer : CellRenderer
+ {
+ public ViewCellRenderer() : base("full")
+ {
+ MainContentPart = "elm.swallow.content";
+ }
+
+ protected string MainContentPart { get; set; }
+
+ protected override EvasObject OnGetContent(Cell cell, string part)
+ {
+ if (part == MainContentPart)
+ {
+ var viewCell = cell as ViewCell;
+ if (viewCell != null)
+ {
+ var renderer = Platform.GetOrCreateRenderer(viewCell.View);
+ int height = (int)viewCell.RenderHeight;
+ height = height <= 0 ? FindCellContentHeight(viewCell) : height;
+
+ renderer.NativeView.MinimumHeight = height;
+ return renderer.NativeView;
+ }
+ return null;
+ }
+ return null;
+ }
+
+ protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
+ {
+ if (property == "View")
+ {
+ return true;
+ }
+ return base.OnCellPropertyChanged(cell, property, realizedView);
+ }
+ }
+}