From 286749e81b33ee317cacb43d854a9f12db45de86 Mon Sep 17 00:00:00 2001 From: "shyun.min" Date: Tue, 18 Feb 2020 19:45:47 +0900 Subject: [PATCH] Add ShellItemWrapper for Shell in CircularUI --- Tizen.Appium.Forms/FormsAdapter.cs | 29 +++++++ Tizen.Appium.Forms/FormsElementList.cs | 11 ++- Tizen.Appium.Forms/ShellItemWrapper.cs | 86 +++++++++++++++++++ Tizen.Appium.Forms/Tizen.Appium.Forms.csproj | 10 ++- .../AppAdapter/BaseObjectList.cs | 15 +--- Tizen.Appium.Shared/AppAdapter/IObjectList.cs | 2 - .../InputGenerator/InputGenerator.cs | 2 +- 7 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 Tizen.Appium.Forms/ShellItemWrapper.cs mode change 100755 => 100644 Tizen.Appium.Shared/InputGenerator/InputGenerator.cs diff --git a/Tizen.Appium.Forms/FormsAdapter.cs b/Tizen.Appium.Forms/FormsAdapter.cs index d953a1a..58ad3d3 100644 --- a/Tizen.Appium.Forms/FormsAdapter.cs +++ b/Tizen.Appium.Forms/FormsAdapter.cs @@ -3,6 +3,10 @@ using Xamarin.Forms.Platform.Tizen; using Tizen.Appium.Forms; +#if WATCH +using CShellItemContext = Tizen.Wearable.CircularUI.Forms.Renderer.NavigationView.ItemContext; +#endif + namespace Tizen.Appium { public class FormsAdapter : BaseAdapter @@ -43,9 +47,34 @@ protected override void AdaptApp() { AddItemFromList(e.View); } +#if WATCH + if (e.View is Shell shell) + { + AddShellItems(shell); + } +#endif }; } +#if WATCH + void AddShellItems(Shell shell) + { + var naviView = (Platform.GetOrCreateRenderer(shell) as Wearable.CircularUI.Forms.Renderer.ShellRenderer)?.NavigationView; + if (naviView != null) + { + naviView.ItemRealized += (s, e) => + { + ObjectList.Add(e.Item.Data); + }; + + naviView.ItemUnrealized += (s, e) => + { + var id = (e.Item.Data as CShellItemContext)?.Source.GetId(); + ObjectList.RemoveById(id); + }; + } + } +#endif void AddItemFromList(VisualElement list) { var nativeView = (ElmSharp.GenList)Platform.GetOrCreateRenderer(list).NativeView; diff --git a/Tizen.Appium.Forms/FormsElementList.cs b/Tizen.Appium.Forms/FormsElementList.cs index 12d6736..69a95ff 100644 --- a/Tizen.Appium.Forms/FormsElementList.cs +++ b/Tizen.Appium.Forms/FormsElementList.cs @@ -1,6 +1,10 @@ using Xamarin.Forms; using ItemContext = Xamarin.Forms.Platform.Tizen.Native.ListView.ItemContext; +#if WATCH +using ShellItemContext = Tizen.Wearable.CircularUI.Forms.Renderer.NavigationView.ItemContext; +#endif + namespace Tizen.Appium.Forms { public class FormsElementList : BaseObjectList @@ -15,7 +19,12 @@ protected override IObjectWrapper CreateWrapper(object obj) { return new CellWrapper(ic); } - +#if WATCH + else if (obj is ShellItemContext sic) + { + return new ShellItemWrapper(sic); + } +#endif return null; } } diff --git a/Tizen.Appium.Forms/ShellItemWrapper.cs b/Tizen.Appium.Forms/ShellItemWrapper.cs new file mode 100644 index 0000000..7d71f27 --- /dev/null +++ b/Tizen.Appium.Forms/ShellItemWrapper.cs @@ -0,0 +1,86 @@ +using System; +using Xamarin.Forms; +using CShellItemContext = Tizen.Wearable.CircularUI.Forms.Renderer.NavigationView.ItemContext; + +namespace Tizen.Appium.Forms +{ + public class ShellItemWrapper : BaseObjectWrapper + { + WeakReference _ref; + string _id; + + public override string[] TextProperties => new string[] { "Title", "Text", "FormattedText" }; + public override string[] DisplayedTextProperies => new string[] { "Text", "Name", "FormattedText", "Title", "Detail" }; + + public override event EventHandler Deleted; + + public override string Id => _id; + + public override bool IsShown + { + get + { + return (Control != null) ? Control.GetIsShownProperty() : false; + } + } + + public override Element Control + { + get + { + return Context?.Source; + } + } + + public override Geometry Geometry + { + get + { + return TizenAppium.RunOnMainThread(() => + { + if (Control != null) + { + var trackObj = Context.Item.TrackObject; + if (trackObj != null) + { + return new Geometry(trackObj.Geometry.X, trackObj.Geometry.Y, trackObj.Geometry.Width, trackObj.Geometry.Height); + } + } + + return new Geometry(); + }); + } + } + + public override bool IsFocused + { + get + { + return (Control != null) ? Context.Item.IsSelected : false; + } + } + + CShellItemContext Context + { + get + { + CShellItemContext ic; + if(_ref.TryGetTarget(out ic)) + { + return ic; + } + + Deleted?.Invoke(this, EventArgs.Empty); + return null; + } + } + + public ShellItemWrapper(CShellItemContext ic) + { + _ref = new WeakReference(ic); + _id = ic.Source.GetId(); + + ic.Item.Deleted += (s, e) => Deleted?.Invoke(this, EventArgs.Empty); + } + } +} diff --git a/Tizen.Appium.Forms/Tizen.Appium.Forms.csproj b/Tizen.Appium.Forms/Tizen.Appium.Forms.csproj index 61a6326..d875696 100644 --- a/Tizen.Appium.Forms/Tizen.Appium.Forms.csproj +++ b/Tizen.Appium.Forms/Tizen.Appium.Forms.csproj @@ -16,7 +16,7 @@ - TRACE + TRACE;WATCH @@ -25,6 +25,14 @@ + + + + + + + + diff --git a/Tizen.Appium.Shared/AppAdapter/BaseObjectList.cs b/Tizen.Appium.Shared/AppAdapter/BaseObjectList.cs index 910f76b..4df2c0c 100644 --- a/Tizen.Appium.Shared/AppAdapter/BaseObjectList.cs +++ b/Tizen.Appium.Shared/AppAdapter/BaseObjectList.cs @@ -36,19 +36,13 @@ public void Add(object element) else { _list.TryUpdate(wrapper.Id, wrapper, _list[wrapper.Id]); - Log.Debug("[Updated] " + wrapper.Id + " object already exists. It wiill be upsted to element=" + element.GetType() + ", _elements.Count=" + _list.Count); + Log.Debug("[Updated] " + wrapper.Id + " object already exists. It wiill be updated to element=" + element.GetType() + ", _elements.Count=" + _list.Count); } } - public void Remove(object element) - { - var key = _list.Where(kv => kv.Value.EqualsTo(element)).FirstOrDefault().Key; - RemoveById(key); - } - public void RemoveById(string id) { - if (_list.ContainsKey(id)) + if (!string.IsNullOrEmpty(id) && _list.ContainsKey(id)) { IObjectWrapper wrapper; _list.TryRemove(id, out wrapper); @@ -78,11 +72,6 @@ public IObjectWrapper Get(string id) return null; } - public string GetIdByObject(object element) - { - return _list.FirstOrDefault(kv => kv.Value.EqualsTo(element)).Key; - } - public IEnumerable GetIdsByName(string name) { var selected = _list.Where(kv => kv.Value.IsShown && kv.Value.ContainsText(name)).Select(kv => kv.Value.Id); diff --git a/Tizen.Appium.Shared/AppAdapter/IObjectList.cs b/Tizen.Appium.Shared/AppAdapter/IObjectList.cs index 203f500..a1024bf 100644 --- a/Tizen.Appium.Shared/AppAdapter/IObjectList.cs +++ b/Tizen.Appium.Shared/AppAdapter/IObjectList.cs @@ -6,8 +6,6 @@ public interface IObjectList { void Add(object element); - void Remove(object element); - void RemoveById(string id); IObjectWrapper Get(string id); diff --git a/Tizen.Appium.Shared/InputGenerator/InputGenerator.cs b/Tizen.Appium.Shared/InputGenerator/InputGenerator.cs old mode 100755 new mode 100644 index e46ad0e..3f9bc20 --- a/Tizen.Appium.Shared/InputGenerator/InputGenerator.cs +++ b/Tizen.Appium.Shared/InputGenerator/InputGenerator.cs @@ -150,7 +150,7 @@ public bool TouchMove(int xDown, int yDown, int xUp, int yUp, int steps) public bool Drag(int xDown, int yDown, int xUp, int yUp) { #if WATCH - steps = 100; + _steps = 100; #endif var data = new Bundle();