From b775010cd32d466fcd4676a966f66b32205b6237 Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Thu, 18 Jun 2020 17:20:34 +0900 Subject: [PATCH] Adds SelectModeCell for CircleListView (#332) --- .../CircleListViewRenderer.cs | 29 +++++++- .../SelectModeImageCellRenderer.cs | 72 +++++++++++++++++++ .../SelectModeTextCellRenderer.cs | 71 ++++++++++++++++++ .../SingleTextCellRenderer.cs | 3 +- .../CircleListView.cs | 12 ++++ .../ISelectModeCell.cs | 34 +++++++++ .../ItemLongPressedEventArgs.cs | 47 ++++++++++++ .../SelectModeCell.cs | 31 ++++++++ .../SelectModeImageCell.cs | 65 +++++++++++++++++ .../SelectModeTextCell.cs | 65 +++++++++++++++++ .../SingleTextCell.cs | 4 +- .../WearableUIGallery/TC/TCActionButton.xaml | 1 + .../WearableUIGallery/TC/TCRadioViewModel.cs | 17 ++++- .../TC/TCSelectModeImageCell.xaml | 41 +++++++++++ .../TC/TCSelectModeImageCell.xaml.cs | 42 +++++++++++ .../TC/TCSelectModeTextCell.xaml | 41 +++++++++++ .../TC/TCSelectModeTextCell.xaml.cs | 42 +++++++++++ .../TC/TCSingleTextCell.xaml | 7 +- .../TC/TCSingleTextCell.xaml.cs | 12 ++++ .../WearableUIGallery/TCData.cs | 2 + .../WearableUIGallery.csproj | 6 ++ 21 files changed, 632 insertions(+), 12 deletions(-) create mode 100644 src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeImageCellRenderer.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeTextCellRenderer.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/ISelectModeCell.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/SelectModeCell.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/SelectModeImageCell.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/SelectModeTextCell.cs create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCSelectModeImageCell.xaml create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCSelectModeImageCell.xaml.cs create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCSelectModeTextCell.xaml create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCSelectModeTextCell.xaml.cs diff --git a/src/Tizen.Wearable.CircularUI.Forms.Renderer/CircleListViewRenderer.cs b/src/Tizen.Wearable.CircularUI.Forms.Renderer/CircleListViewRenderer.cs index b035f8f5..a1601f82 100644 --- a/src/Tizen.Wearable.CircularUI.Forms.Renderer/CircleListViewRenderer.cs +++ b/src/Tizen.Wearable.CircularUI.Forms.Renderer/CircleListViewRenderer.cs @@ -14,10 +14,11 @@ * limitations under the License. */ +using ElmSharp; using Xamarin.Forms; using Xamarin.Forms.Platform.Tizen; using XForms = Xamarin.Forms.Forms; - +using NListView = Xamarin.Forms.Platform.Tizen.Native.ListView; using CircleListView = Tizen.Wearable.CircularUI.Forms.CircleListView; [assembly: ExportRenderer(typeof(CircleListView), typeof(Tizen.Wearable.CircularUI.Forms.Renderer.CircleListViewRenderer))] @@ -36,7 +37,31 @@ public CircleListViewRenderer() protected override Xamarin.Forms.Platform.Tizen.Native.ListView CreateNativeControl() { - return _listView = new WatchListView(XForms.NativeParent, this.GetSurface()); + _listView = new WatchListView(XForms.NativeParent, this.GetSurface()); + _listView.ItemLongPressed += OnItemLongPressed; + return _listView; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (_listView != null) + { + _listView.ItemLongPressed -= OnItemLongPressed; + } + } + base.Dispose(disposing); + } + + void OnItemLongPressed(object sender, GenListItemEventArgs args) + { + if (args.Item.Data is NListView.ItemContext itemContext) + { + var obj = itemContext.Cell.BindingContext; + var index = Element.TemplatedItems.GetGlobalIndexOfItem(obj); + Element.NotifyItemLongPressed(obj, index); + } } void UpdateBarColor() diff --git a/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeImageCellRenderer.cs b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeImageCellRenderer.cs new file mode 100644 index 00000000..16a9e749 --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeImageCellRenderer.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Collections.Generic; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Tizen; +using ElmSharp; +using Tizen.Wearable.CircularUI.Forms; +using Tizen.Wearable.CircularUI.Forms.Renderer; +using ECheck = ElmSharp.Check; + +[assembly: ExportRenderer(typeof(SelectModeImageCell), typeof(SelectModeImageCellRenderer))] +namespace Tizen.Wearable.CircularUI.Forms.Renderer +{ + public class SelectModeImageCellRenderer : ImageCellRenderer + { + protected SelectModeImageCellRenderer(string style) : base(style) + { + ImagePart = "elm.swallow.icon"; + SelectionPart = "elm.swallow.center_check"; + } + + public SelectModeImageCellRenderer() : this("1icon_2text") + { + } + + protected string SelectionPart { get; set; } + + protected override EvasObject OnGetContent(Cell cell, string part) + { + if (cell is ISelectModeCell selectCell && selectCell.IsSelectionModeEnabled && part == SelectionPart) + { + var check = new CheckBox() + { + BindingContext = cell, + Parent = cell.Parent + }; + check.SetBinding(CheckBox.IsCheckedProperty, new Binding(SelectModeTextCell.IsSelectedProperty.PropertyName)); + var nativeView = Platform.GetOrCreateRenderer(check).NativeView; + if (nativeView is ECheck widget) + widget.Style = "genlist/select_mode"; + nativeView.PropagateEvents = false; + nativeView.RepeatEvents = false; + return nativeView; + } + return base.OnGetContent(cell, part); + } + + protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) + { + if (property == SelectModeCell.IsSelectedProperty.PropertyName || + property == SelectModeCell.IsSelectionModeEnabledProperty.PropertyName) + { + return true; + } + return base.OnCellPropertyChanged(cell, property, realizedView); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeTextCellRenderer.cs b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeTextCellRenderer.cs new file mode 100644 index 00000000..77864ade --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SelectModeTextCellRenderer.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Collections.Generic; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Tizen; +using ElmSharp; +using Tizen.Wearable.CircularUI.Forms; +using Tizen.Wearable.CircularUI.Forms.Renderer; +using ECheck = ElmSharp.Check; + +[assembly: ExportRenderer(typeof(SelectModeTextCell), typeof(SelectModeTextCellRenderer))] +namespace Tizen.Wearable.CircularUI.Forms.Renderer +{ + public class SelectModeTextCellRenderer : TextCellRenderer + { + protected SelectModeTextCellRenderer(string style) : base(style) + { + SelectionPart = "elm.swallow.center_check"; + } + + public SelectModeTextCellRenderer() : this("1icon_2text") + { + } + + protected string SelectionPart { get; set; } + + protected override EvasObject OnGetContent(Cell cell, string part) + { + if (cell is ISelectModeCell selectCell && selectCell.IsSelectionModeEnabled && part == SelectionPart) + { + var check = new CheckBox() + { + BindingContext = cell, + Parent = cell.Parent + }; + check.SetBinding(CheckBox.IsCheckedProperty, new Binding(SelectModeTextCell.IsSelectedProperty.PropertyName)); + var nativeView = Platform.GetOrCreateRenderer(check).NativeView; + if (nativeView is ECheck widget) + widget.Style = "genlist/select_mode"; + nativeView.PropagateEvents = false; + nativeView.RepeatEvents = false; + return nativeView; + } + return null; + } + + protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) + { + if (property == SelectModeCell.IsSelectedProperty.PropertyName || + property == SelectModeCell.IsSelectionModeEnabledProperty.PropertyName) + { + return true; + } + return base.OnCellPropertyChanged(cell, property, realizedView); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms.Renderer/SingleTextCellRenderer.cs b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SingleTextCellRenderer.cs index 8e2a9588..36653732 100644 --- a/src/Tizen.Wearable.CircularUI.Forms.Renderer/SingleTextCellRenderer.cs +++ b/src/Tizen.Wearable.CircularUI.Forms.Renderer/SingleTextCellRenderer.cs @@ -15,14 +15,13 @@ */ using Xamarin.Forms; -using Xamarin.Forms.Platform.Tizen; using Tizen.Wearable.CircularUI.Forms.Renderer; using Tizen.Wearable.CircularUI.Forms; [assembly: ExportRenderer(typeof(SingleTextCell), typeof(SingleTextCellRenderer))] namespace Tizen.Wearable.CircularUI.Forms.Renderer { - public class SingleTextCellRenderer : TextCellRenderer + public class SingleTextCellRenderer : SelectModeTextCellRenderer { protected SingleTextCellRenderer(string style) : base(style) { diff --git a/src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs b/src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs index b75795ed..7f88df7d 100644 --- a/src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs +++ b/src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs @@ -15,6 +15,7 @@ */ using System; +using System.ComponentModel; using Xamarin.Forms; namespace Tizen.Wearable.CircularUI.Forms @@ -59,5 +60,16 @@ public Color BarColor /// Gets or sets a CircleSurfaceProvider. /// public ICircleSurfaceProvider CircleSurfaceProvider { get; set; } + + /// + /// Event that is raised when a new item is long pressed. + /// + public event EventHandler ItemLongPressed; + + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemLongPressed(object item, int index) + { + ItemLongPressed?.Invoke(this, new ItemLongPressedEventArgs(item, index)); + } } } diff --git a/src/Tizen.Wearable.CircularUI.Forms/ISelectModeCell.cs b/src/Tizen.Wearable.CircularUI.Forms/ISelectModeCell.cs new file mode 100644 index 00000000..464c16cc --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/ISelectModeCell.cs @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.ComponentModel; +using System.Diagnostics; +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + [EditorBrowsable(EditorBrowsableState.Never)] + interface ISelectModeCell + { + bool IsSelected { get; set; } + bool IsSelectionModeEnabled { get; set; } + + void OnIsSelectedChanged(object sender, ToggledEventArgs e); + + event EventHandler SelectionChanged; + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs b/src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs new file mode 100644 index 00000000..1e89f15f --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Wearable.CircularUI.Forms +{ + /// + /// Event arguments for the ItemLongPressed event of CircleListView. + /// + public class ItemLongPressedEventArgs : EventArgs + { + /// + /// Creates a new ItemLongPressedEventArgs object. + /// + /// An item data of new long pressed item. + /// An index of new long pressed item. + public ItemLongPressedEventArgs(object item, int itemIndex) + { + Item = item; + ItemIndex = itemIndex; + } + + /// + /// Gets the data of new long pressed item + /// + public object Item { get; private set; } + + /// + /// Gets the index of new long pressed item + /// + public int ItemIndex { get; private set; } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/SelectModeCell.cs b/src/Tizen.Wearable.CircularUI.Forms/SelectModeCell.cs new file mode 100644 index 00000000..dd998bfc --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/SelectModeCell.cs @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + static class SelectModeCell + { + public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(ISelectModeCell.IsSelected), typeof(bool), typeof(ISelectModeCell), false, propertyChanged: (obj, oldValue, newValue) => + { + ISelectModeCell selectModetCell = (ISelectModeCell)obj; + selectModetCell.OnIsSelectedChanged(obj, new ToggledEventArgs((bool)newValue)); + }, defaultBindingMode: BindingMode.TwoWay); + + public static readonly BindableProperty IsSelectionModeEnabledProperty = BindableProperty.Create(nameof(ISelectModeCell.IsSelectionModeEnabled), typeof(bool), typeof(ISelectModeCell), default(bool)); + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/SelectModeImageCell.cs b/src/Tizen.Wearable.CircularUI.Forms/SelectModeImageCell.cs new file mode 100644 index 00000000..26fec5bc --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/SelectModeImageCell.cs @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + /// + /// An ImageCell supports a selection mode. + /// + public class SelectModeImageCell : ImageCell, ISelectModeCell + { + /// + /// Identifies the On bindable property. + /// + public static readonly BindableProperty IsSelectedProperty = SelectModeCell.IsSelectedProperty; + + /// + /// Identifies the Text bindable property. + /// + public static readonly BindableProperty IsSelectionModeEnabledProperty = SelectModeCell.IsSelectionModeEnabledProperty; + + /// + /// Gets or sets the state of the selection. This is a bindable property. + /// + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + + /// + /// Gets or sets whether to enable the selection mode or not. This is a bindable property. + /// + public bool IsSelectionModeEnabled + { + get { return (bool)GetValue(IsSelectionModeEnabledProperty); } + set { SetValue(IsSelectionModeEnabledProperty, value); } + } + + /// + /// Triggered when IsSelected changed. + /// + public event EventHandler SelectionChanged; + + void ISelectModeCell.OnIsSelectedChanged(object sender, ToggledEventArgs e) + { + SelectionChanged?.Invoke(sender, e); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/SelectModeTextCell.cs b/src/Tizen.Wearable.CircularUI.Forms/SelectModeTextCell.cs new file mode 100644 index 00000000..d918658e --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/SelectModeTextCell.cs @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + /// + /// A TextCell supports a selection mode. + /// + public class SelectModeTextCell : TextCell, ISelectModeCell + { + /// + /// Identifies the On bindable property. + /// + public static readonly BindableProperty IsSelectedProperty = SelectModeCell.IsSelectedProperty; + + /// + /// Identifies the Text bindable property. + /// + public static readonly BindableProperty IsSelectionModeEnabledProperty = SelectModeCell.IsSelectionModeEnabledProperty; + + /// + /// Gets or sets the state of the selection. This is a bindable property. + /// + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + + /// + /// Gets or sets whether to enable the selection mode or not. This is a bindable property. + /// + public bool IsSelectionModeEnabled + { + get { return (bool)GetValue(IsSelectionModeEnabledProperty); } + set { SetValue(IsSelectionModeEnabledProperty, value); } + } + + /// + /// Triggered when IsSelected changed. + /// + public event EventHandler SelectionChanged; + + void ISelectModeCell.OnIsSelectedChanged(object sender, ToggledEventArgs e) + { + SelectionChanged?.Invoke(sender, e); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/SingleTextCell.cs b/src/Tizen.Wearable.CircularUI.Forms/SingleTextCell.cs index 0f3366a8..a8e2e851 100644 --- a/src/Tizen.Wearable.CircularUI.Forms/SingleTextCell.cs +++ b/src/Tizen.Wearable.CircularUI.Forms/SingleTextCell.cs @@ -14,14 +14,12 @@ * limitations under the License. */ -using Xamarin.Forms; - namespace Tizen.Wearable.CircularUI.Forms { /// /// A Cell with a signle text. The Detail property is always ignored. /// - public class SingleTextCell : TextCell + public class SingleTextCell : SelectModeTextCell { } } diff --git a/test/WearableUIGallery/WearableUIGallery/TC/TCActionButton.xaml b/test/WearableUIGallery/WearableUIGallery/TC/TCActionButton.xaml index 769ca8cf..4934ee88 100644 --- a/test/WearableUIGallery/WearableUIGallery/TC/TCActionButton.xaml +++ b/test/WearableUIGallery/WearableUIGallery/TC/TCActionButton.xaml @@ -38,6 +38,7 @@