2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// DropDown is one kind of common component, a dropdown allows the user click dropdown button to choose one value from a list.
28 /// <since_tizen> 6 </since_tizen>
29 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class DropDown : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ListPaddingProperty = BindableProperty.Create("ListPadding", typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (DropDown)bindable;
40 instance.listPadding.CopyFrom((Extents)newValue);
41 instance.UpdateDropDown();
44 defaultValueCreator: (bindable) =>
46 var instance = (DropDown)bindable;
47 return instance.listPadding;
49 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public static readonly BindableProperty SelectedItemIndexProperty = BindableProperty.Create("SelectedItemIndex", typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
53 var instance = (DropDown)bindable;
56 int selectedItemIndex = (int)newValue;
57 if (selectedItemIndex == instance.selectedItemIndex || instance.adapter == null || selectedItemIndex >= instance.adapter.GetItemCount())
61 instance.UpdateSelectedItem(selectedItemIndex);
64 defaultValueCreator: (bindable) =>
66 var instance = (DropDown)bindable;
67 return instance.selectedItemIndex;
69 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static readonly BindableProperty ListMarginProperty = BindableProperty.Create("ListMargin", typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
73 var instance = (DropDown)bindable;
76 instance.listMargin.CopyFrom((Extents)newValue);
77 instance.UpdateDropDown();
80 defaultValueCreator: (bindable) =>
82 var instance = (DropDown)bindable;
83 return instance.listMargin;
85 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty ListRelativeOrientationProperty = BindableProperty.Create("ListRelativeOrientation", typeof(ListOrientation), typeof(DropDown), ListOrientation.Left, propertyChanged: (bindable, oldValue, newValue) =>
89 var instance = (DropDown)bindable;
92 instance.listRelativeOrientation = (ListOrientation)newValue;
93 instance.UpdateDropDown();
96 defaultValueCreator: (bindable) =>
98 var instance = (DropDown)bindable;
99 return instance.listRelativeOrientation;
101 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public static readonly BindableProperty SpaceBetweenButtonTextAndIconProperty = BindableProperty.Create("SpaceBetweenButtonTextAndIcon", typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
105 var instance = (DropDown)bindable;
106 if (newValue != null)
108 instance.spaceBetweenButtonTextAndIcon = (int)newValue;
111 defaultValueCreator: (bindable) =>
113 var instance = (DropDown)bindable;
114 return instance.spaceBetweenButtonTextAndIcon;
118 private Button button = null;
119 private TextLabel headerText = null;
120 private TextLabel buttonText = null;
121 private ImageView listBackgroundImage = null;
122 // Component that scrolls the child added to it.
123 private LayoutScroller layoutScroller = null;
124 // The LinearLayout container to house the items in the drop down list.
125 private View dropDownMenuFullList = null;
126 private DropDownListBridge adapter = new DropDownListBridge();
127 private DropDownItemView selectedItemView = null;
128 private TapGestureDetector tapGestureDetector = null;
130 private Extents listMargin = new Extents(0, 0, 0, 0);
131 private Extents listPadding = new Extents(0, 0, 0, 0);
132 private ListOrientation listRelativeOrientation = ListOrientation.Left;
133 private int selectedItemIndex = -1;
134 private int spaceBetweenButtonTextAndIcon = 0;
135 private bool itemPressed = false;
138 /// Creates a new instance of a DropDown.
140 /// <since_tizen> 6 </since_tizen>
141 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public DropDown() : base() { }
146 /// Creates a new instance of a DropDown with style.
148 /// <param name="style">Create DropDown by special style defined in UX.</param>
149 /// <since_tizen> 6 </since_tizen>
150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public DropDown(string style) : base(style) { }
155 /// Creates a new instance of a DropDown with attributes.
157 /// <param name="attributes">Create DropDown by attributes customized by user.</param>
158 /// <since_tizen> 6 </since_tizen>
159 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
160 [EditorBrowsable(EditorBrowsableState.Never)]
161 public DropDown(DropDownStyle attributes) : base(attributes)
166 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
168 /// <since_tizen> 6 </since_tizen>
169 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public delegate void ClickEventHandler<ClickEventArgs>(object sender, ClickEventArgs e);
174 /// An event for the item clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
176 /// <since_tizen> 6 </since_tizen>
177 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public event ClickEventHandler<ItemClickEventArgs> ItemClickEvent;
182 /// List position in relation to the main button.
184 /// <since_tizen> 6 </since_tizen>
185 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public enum ListOrientation
192 /// <since_tizen> 6 </since_tizen>
193 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
194 [EditorBrowsable(EditorBrowsableState.Never)]
199 /// <since_tizen> 6 </since_tizen>
200 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
201 [EditorBrowsable(EditorBrowsableState.Never)]
205 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public new DropDownStyle Style => ViewStyle as DropDownStyle;
210 /// Space between button text and button icon in DropDown.
212 /// <since_tizen> 6 </since_tizen>
213 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
214 public int SpaceBetweenButtonTextAndIcon
216 get => (int)GetValue(SpaceBetweenButtonTextAndIconProperty);
217 set => SetValue(SpaceBetweenButtonTextAndIconProperty, value);
221 /// List relative orientation in DropDown.
223 /// <since_tizen> 6 </since_tizen>
224 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
225 public ListOrientation ListRelativeOrientation
227 get => (ListOrientation)GetValue(ListRelativeOrientationProperty);
228 set => SetValue(ListRelativeOrientationProperty, value);
234 /// <since_tizen> 6 </since_tizen>
235 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
236 public Extents ListMargin
240 Extents tmp = (Extents)GetValue(ListMarginProperty);
241 return new Extents((ushort start, ushort end, ushort top, ushort bottom) => { ListMargin = new Extents(start, end, top, bottom); }, tmp.Start, tmp.End, tmp.Top, tmp.Bottom);
243 set => SetValue(ListMarginProperty, value);
247 /// Selected item index in list.
249 /// <since_tizen> 6 </since_tizen>
250 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
251 public int SelectedItemIndex
253 get => (int)GetValue(SelectedItemIndexProperty);
254 set => SetValue(SelectedItemIndexProperty, value);
258 /// List padding in DropDown.
260 /// <since_tizen> 6 </since_tizen>
261 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
262 public Extents ListPadding
266 Extents tmp = (Extents)GetValue(ListPaddingProperty);
267 return new Extents((ushort start, ushort end, ushort top, ushort bottom) => { ListPadding = new Extents(start, end, top, bottom); }, tmp.Start, tmp.End, tmp.Top, tmp.Bottom);
269 set => SetValue(ListPaddingProperty, value);
273 /// Add list item by item data. The added item will be added to end of all items automatically.
275 /// <param name="itemData">Item data which will apply to tab item view.</param>
276 /// <since_tizen> 6 </since_tizen>
277 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public void AddItem(DropDownDataItem itemData)
281 // Add item to adaptor, will be added to list via AddItemAt during OnUpdate()
282 int insertionPosition = adapter.GetItemCount();
283 adapter.InsertData(insertionPosition, itemData);
287 /// Delete list item by index.
289 /// <param name="index">Position index where will be deleted.</param>
290 /// <since_tizen> 6 </since_tizen>
291 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public void DeleteItem(int index)
295 if (index < 0 || index >= adapter?.GetItemCount()) return;
296 if (null == dropDownMenuFullList) return;
298 if (selectedItemIndex == index)
300 selectedItemIndex = -1;
302 else if(selectedItemIndex > index)
307 adapter?.RemoveData(index);
309 if(index < dropDownMenuFullList.ChildCount)
311 View childToRemove = dropDownMenuFullList.GetChildAt((uint)index);
314 childToRemove.TouchEvent -= ListItemTouchEvent;
315 dropDownMenuFullList.Remove(childToRemove);
316 dropDownMenuFullList?.Layout?.RequestLayout();
322 /// Insert list item by item data. The inserted item will be added to the special position by index automatically.
324 /// <param name="item">Item data which will apply to tab item view.</param>
325 /// <param name="index">Position index where will be inserted.</param>
326 /// <since_tizen> 6 </since_tizen>
327 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public void InsertItem(DropDownDataItem item, int index)
331 if (index < 0 || index >= adapter.GetItemCount())
336 if (selectedItemIndex >= index)
341 adapter.InsertData(index, item);
345 /// Add scroll bar to list.
347 /// <param name="scrollBar">Scroll bar defined by user which will be added to list.</param>
348 /// <since_tizen> 6 </since_tizen>
349 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
350 [EditorBrowsable(EditorBrowsableState.Never)]
351 public void AttachScrollBar(ScrollBar scrollBar)
353 if (layoutScroller == null)
357 Tizen.Log.Error("DropDown","Feature unsupported");
361 /// Detach scroll bar to list.
363 /// <since_tizen> 6 </since_tizen>
364 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
365 [EditorBrowsable(EditorBrowsableState.Never)]
366 public void DetachScrollBar()
368 if (layoutScroller == null)
372 Tizen.Log.Error("DropDown","Feature unsupported");
375 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public override void ApplyStyle(ViewStyle viewStyle)
379 base.ApplyStyle(viewStyle);
381 DropDownStyle dropDownStyle = viewStyle as DropDownStyle;
382 if (null != dropDownStyle)
388 CreateListBackgroundImage();
389 if (null == layoutScroller) // layoutScroller used to test of ListContainer Setup invoked already
391 SetUpListContainer();
393 button.ApplyStyle(dropDownStyle.Button);
394 headerText.ApplyStyle(dropDownStyle.HeaderText);
395 listBackgroundImage.ApplyStyle(dropDownStyle.ListBackgroundImage);
401 /// Update DropDown by attributes.
403 /// <since_tizen> 6 </since_tizen>
404 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 protected void UpdateDropDown()
408 if (null == layoutScroller || null == listBackgroundImage || null == dropDownMenuFullList) return;
409 if (null == Style.ListBackgroundImage.Size) return;
410 // Resize and position scrolling list within the drop down list container. Can be used to position list in relation to the background image.
411 layoutScroller.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
412 layoutScroller.Position2D = new Position2D(listPadding.Start, listPadding.Top);
414 int listBackgroundImageX = 0;
415 int listBackgroundImageY = 0;
416 if (listRelativeOrientation == ListOrientation.Left)
418 listBackgroundImageX = (int)listMargin.Start;
419 listBackgroundImageY = (int)listMargin.Top;
421 else if (listRelativeOrientation == ListOrientation.Right)
423 listBackgroundImageX = -(int)listMargin.End;
424 listBackgroundImageY = (int)listMargin.Top;
426 listBackgroundImage.Position2D = new Position2D(listBackgroundImageX, listBackgroundImageY);
427 dropDownMenuFullList?.Layout?.RequestLayout();
430 protected override void OnUpdate()
433 float buttonTextWidth = 0;
434 if (null != buttonText)
436 buttonText.Text = Style.Button.Text.Text.All;
437 buttonText.PointSize = Style.Button.Text.PointSize?.All ?? 20;
438 buttonTextWidth = buttonText.NaturalSize.Width;
440 iconWidth = Style.Button.Icon.Size?.Width ?? 48;
441 button.SizeWidth = iconWidth + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
443 int numberOfItemsToAdd = adapter.GetItemCount();
445 if (adapter.AdapterPurge == true)
447 adapter.AdapterPurge = false;
448 for (int i = 0; i < numberOfItemsToAdd; i++)
450 AddItemAt(adapter.GetData(i), i);
453 // Set selection icon on View
454 UpdateSelectedItem(selectedItemIndex);
458 /// Dispose DropDown and all children on it.
460 /// <param name="type">Dispose type.</param>
461 /// <since_tizen> 6 </since_tizen>
462 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
463 [EditorBrowsable(EditorBrowsableState.Never)]
464 protected override void Dispose(DisposeTypes type)
471 if (type == DisposeTypes.Explicit)
473 Utility.Dispose(headerText);
474 Utility.Dispose(buttonText);
475 Utility.Dispose(button);
476 Utility.Dispose(layoutScroller);
477 Utility.Dispose(dropDownMenuFullList);
478 Utility.Dispose(listBackgroundImage);
485 /// Get DropDown attribues.
487 /// <since_tizen> 6 </since_tizen>
488 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
489 [EditorBrowsable(EditorBrowsableState.Never)]
490 protected override ViewStyle GetViewStyle()
492 return new DropDownStyle();
495 private void AddItemAt(DropDownDataItem itemData,int index)
497 ViewHolder viewHolder = adapter.OnCreateViewHolder();
498 if (!viewHolder.IsBound)
500 adapter.BindViewHolder(viewHolder, index);
501 viewHolder.IsBound = true;
504 if (tapGestureDetector == null)
506 tapGestureDetector = new TapGestureDetector();
508 View view = viewHolder.ItemView;
509 view.TouchEvent += ListItemTouchEvent;
510 dropDownMenuFullList.Add(view);
513 private void OnClickEvent(object sender, ItemClickEventArgs e)
515 ItemClickEvent?.Invoke(sender, e);
518 private void CreateHeaderText()
520 if (null == headerText)
522 headerText = new TextLabel()
524 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
525 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
526 HorizontalAlignment = HorizontalAlignment.Center,
527 VerticalAlignment = VerticalAlignment.Center,
528 ParentOrigin = NUI.ParentOrigin.Center,
529 PivotPoint = NUI.ParentOrigin.Center,
530 PositionUsesPivotPoint = true,
532 headerText.Name = "DropDownHeaderText";
537 private void CreateButtonText()
539 if (null == buttonText)
541 buttonText = new TextLabel();
545 private void CreateButton()
549 button = new Button()
551 ParentOrigin = NUI.ParentOrigin.CenterLeft,
552 PivotPoint = NUI.PivotPoint.CenterLeft,
553 PositionUsesPivotPoint = true,
554 HeightResizePolicy = ResizePolicyType.FitToChildren,
555 IconRelativeOrientation = Button.IconOrientation.Right,
557 button.Name = "DropDownButton";
558 button.ClickEvent += ButtonClickEvent;
563 private void CreateListBackgroundImage()
565 if (null == listBackgroundImage)
567 listBackgroundImage = new ImageView
569 Name = "ListBackgroundImage",
570 PositionUsesPivotPoint = true,
571 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
572 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
573 WidthResizePolicy = ResizePolicyType.FitToChildren,
574 HeightResizePolicy = ResizePolicyType.FitToChildren,
576 Add(listBackgroundImage);
580 private void SetUpListContainer()
582 LinearLayout linear = new LinearLayout()
584 LinearOrientation = LinearLayout.Orientation.Vertical,
587 dropDownMenuFullList = new View()
590 Name = "DropDownMenuList",
591 WidthSpecification = LayoutParamPolicies.MatchParent,
592 HeightSpecification = LayoutParamPolicies.WrapContent,
596 layoutScroller = new LayoutScroller()
598 Name = "LayoutScroller",
600 layoutScroller.AddLayoutToScroll(dropDownMenuFullList);
602 listBackgroundImage.Add(layoutScroller);
603 listBackgroundImage.Hide();
606 private View GetViewFromIndex(uint index)
608 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
610 return dropDownMenuFullList.GetChildAt(index);
618 private void SetListItemToSelected(DropDownItemView targetItemView)
620 // Set the DropDownItemView matching the targetItemView to selected.
621 if (selectedItemView!=targetItemView)
623 if (selectedItemView!=null)
625 // clear selection status of currently selected item view
626 selectedItemView.IsSelected = false;
628 // Set target item to selected
629 targetItemView.IsSelected = true;
630 selectedItemView = targetItemView;
634 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
636 PointStateType state = e.Touch.GetState(0);
637 DropDownItemView touchedView = sender as DropDownItemView;;
640 case PointStateType.Down:
641 if (touchedView != null && touchedView.BackgroundColorSelector != null)
643 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Pressed);
645 itemPressed = true; // if matched with a Up then a click event.
647 case PointStateType.Motion:
648 if (touchedView != null && touchedView.BackgroundColorSelector != null)
650 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Normal);
654 case PointStateType.Up:
655 if (touchedView != null && touchedView.BackgroundColorSelector != null)
657 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Selected);
659 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
662 Console.WriteLine("Tapped{0}", touchedView.Name);
663 SetListItemToSelected(touchedView);
664 button.Text = touchedView.Text;
666 listBackgroundImage.Hide();
676 private void UpdateSelectedItem(int index)
678 if (null == adapter) return;
679 if (null == dropDownMenuFullList) return;
680 if (selectedItemIndex != -1)
682 DropDownDataItem data = adapter.GetData(selectedItemIndex);
685 data.IsSelected = false;
687 DropDownItemView listItemView = dropDownMenuFullList.GetChildAt((uint)selectedItemIndex) as DropDownItemView;
688 data.IsSelected = false;
689 SetListItemToSelected(listItemView);
694 DropDownDataItem data = adapter.GetData(index);
697 data.IsSelected = true;
698 DropDownItemView listItemView = dropDownMenuFullList?.GetChildAt((uint)index) as DropDownItemView;
701 SetListItemToSelected(listItemView);
706 selectedItemIndex = index;
707 dropDownMenuFullList?.Layout?.RequestLayout();
710 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
713 listBackgroundImage.Show();
714 dropDownMenuFullList?.Layout?.RequestLayout();
715 listBackgroundImage.RaiseToTop();
720 #region ItemClickEventArgs
722 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
724 /// <since_tizen> 6 </since_tizen>
725 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
726 [EditorBrowsable(EditorBrowsableState.Never)]
727 public class ItemClickEventArgs : EventArgs
729 /// <summary> Clicked item index of DropDown's list </summary>
730 /// <since_tizen> 6 </since_tizen>
731 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
732 [EditorBrowsable(EditorBrowsableState.Never)]
734 /// <summary> Clicked item text string of DropDown's list </summary>
735 /// <since_tizen> 6 </since_tizen>
736 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
737 [EditorBrowsable(EditorBrowsableState.Never)]
742 #region DropDownDataItem
744 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
746 /// <since_tizen> 6 </since_tizen>
747 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
748 //[EditorBrowsable(EditorBrowsableState.Never)]
749 public class DropDownDataItem
751 private DropDownItemStyle itemDataStyle = new DropDownItemStyle();
754 /// Creates a new instance of a DropDownItemData.
756 /// <since_tizen> 6 </since_tizen>
757 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
758 [EditorBrowsable(EditorBrowsableState.Never)]
759 public DropDownDataItem()
765 /// Creates a new instance of a DropDownItemData with style.
767 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
768 /// <since_tizen> 6 </since_tizen>
769 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
770 [EditorBrowsable(EditorBrowsableState.Never)]
771 public DropDownDataItem(string style)
775 ViewStyle attributes = StyleManager.Instance.GetViewStyle(style);
776 if(attributes == null)
778 throw new InvalidOperationException($"There is no style {style}");
780 itemDataStyle = attributes as DropDownItemStyle;
786 /// Creates a new instance of a DropDownItemData with style.
788 /// <param name="style">Create DropDownItemData by style customized by user.</param>
789 /// <since_tizen> 6 </since_tizen>
790 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
791 [EditorBrowsable(EditorBrowsableState.Never)]
792 public DropDownDataItem(DropDownItemStyle style)
794 itemDataStyle.CopyFrom(style);
799 /// DropDown item size.
801 /// <since_tizen> 6 </since_tizen>
802 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
803 [EditorBrowsable(EditorBrowsableState.Never)]
808 return itemDataStyle.Size;
812 itemDataStyle.Size = value;
817 /// DropDown item background color selector.
819 /// <since_tizen> 6 </since_tizen>
820 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
821 [EditorBrowsable(EditorBrowsableState.Never)]
822 public Selector<Color> BackgroundColor
826 return itemDataStyle.BackgroundColor;
830 if (null == itemDataStyle?.BackgroundColor)
832 itemDataStyle.BackgroundColor = new Selector<Color>();
835 itemDataStyle.BackgroundColor.Clone(value);
840 /// DropDown item text string.
842 /// <since_tizen> 6 </since_tizen>
843 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
844 [EditorBrowsable(EditorBrowsableState.Never)]
849 return itemDataStyle.Text?.Text?.All;
853 if (null == itemDataStyle.Text.Text)
855 itemDataStyle.Text.Text = new Selector<string> { All = value };
859 itemDataStyle.Text.Text = value;
865 /// DropDown item text's point size.
867 /// <since_tizen> 6 </since_tizen>
868 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
869 [EditorBrowsable(EditorBrowsableState.Never)]
870 public float PointSize
874 return itemDataStyle.Text?.PointSize?.All ?? 0;
878 if (null == itemDataStyle.Text.PointSize)
880 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
884 itemDataStyle.Text.PointSize = value;
890 /// DropDown item text's font family.
892 /// <since_tizen> 6 </since_tizen>
893 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
894 [EditorBrowsable(EditorBrowsableState.Never)]
895 public string FontFamily
899 return itemDataStyle.Text.FontFamily?.All;
903 if (null == itemDataStyle.Text.FontFamily)
905 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
909 itemDataStyle.Text.FontFamily = value;
915 /// DropDown item text's position.
917 /// <since_tizen> 6 </since_tizen>
918 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
919 [EditorBrowsable(EditorBrowsableState.Never)]
920 public Position TextPosition
924 return itemDataStyle.Text?.Position;
928 itemDataStyle.Text.Position = value;
933 /// DropDown item's icon's resource url.
935 /// <since_tizen> 6 </since_tizen>
936 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
937 [EditorBrowsable(EditorBrowsableState.Never)]
938 public string IconResourceUrl
942 return itemDataStyle.Icon?.ResourceUrl?.All;
946 if (null == itemDataStyle.Icon.ResourceUrl)
948 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
952 itemDataStyle.Icon.ResourceUrl = value;
958 /// DropDown item's icon's size.
960 /// <since_tizen> 6 </since_tizen>
961 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
962 [EditorBrowsable(EditorBrowsableState.Never)]
967 return itemDataStyle.Icon?.Size;
971 itemDataStyle.Icon.Size = value;
976 /// DropDown item's icon's position.
978 /// <since_tizen> 6 </since_tizen>
979 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
980 [EditorBrowsable(EditorBrowsableState.Never)]
981 public Position IconPosition
985 return itemDataStyle.Icon.Position;
989 itemDataStyle.Icon.Position = value;
994 /// DropDown item's check image's resource url.
996 /// <since_tizen> 6 </since_tizen>
997 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
998 [EditorBrowsable(EditorBrowsableState.Never)]
999 public string CheckImageResourceUrl
1003 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1007 if (null == itemDataStyle.CheckImage.ResourceUrl)
1009 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1013 itemDataStyle.CheckImage.ResourceUrl = value;
1019 /// DropDown item's check image's size.
1021 /// <since_tizen> 6 </since_tizen>
1022 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1023 [EditorBrowsable(EditorBrowsableState.Never)]
1024 public Size CheckImageSize
1028 return itemDataStyle.CheckImage?.Size;
1032 itemDataStyle.CheckImage.Size = value;
1037 /// DropDown item's check image's right space.
1039 /// <since_tizen> 6 </since_tizen>
1040 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1041 [EditorBrowsable(EditorBrowsableState.Never)]
1042 public int CheckImageGapToBoundary
1046 return itemDataStyle.CheckImageGapToBoundary;
1050 itemDataStyle.CheckImageGapToBoundary = value;
1055 /// Flag to decide DropDown item is selected or not.
1057 /// <since_tizen> 6 </since_tizen>
1058 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1059 [EditorBrowsable(EditorBrowsableState.Never)]
1060 public bool IsSelected
1064 return itemDataStyle.IsSelected;
1068 itemDataStyle.IsSelected = value;
1072 private void Initialize()
1074 if (itemDataStyle == null)
1076 throw new Exception("DropDownDataItem style parse error.");
1082 #region DropDownItemView
1083 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1084 [EditorBrowsable(EditorBrowsableState.Never)]
1085 internal class DropDownItemView : Control
1087 private TextLabel mText = null;
1088 private ImageView mIcon = null;
1089 private ImageView mCheck = null;
1091 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1092 [EditorBrowsable(EditorBrowsableState.Never)]
1093 public DropDownItemView() : base() { }
1095 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1096 [EditorBrowsable(EditorBrowsableState.Never)]
1097 public Selector<Color> BackgroundColorSelector { get; set; }
1099 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1100 [EditorBrowsable(EditorBrowsableState.Never)]
1105 return (null == mText) ? null : mText.Text;
1114 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1115 [EditorBrowsable(EditorBrowsableState.Never)]
1116 public string FontFamily
1120 return (null == mText) ? null : mText.FontFamily;
1125 mText.FontFamily = value;
1129 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1130 [EditorBrowsable(EditorBrowsableState.Never)]
1131 public float? PointSize
1135 return (null == mText) ? 0 : mText.PointSize;
1140 mText.PointSize = (float)value;
1144 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1145 [EditorBrowsable(EditorBrowsableState.Never)]
1146 public Color TextColor
1150 return (null == mText) ? null : mText.TextColor;
1155 mText.TextColor = value;
1159 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1160 [EditorBrowsable(EditorBrowsableState.Never)]
1161 public Position TextPosition
1165 return (null == mText) ? null : mText.Position;
1170 mText.Position = value;
1174 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1175 [EditorBrowsable(EditorBrowsableState.Never)]
1176 public string IconResourceUrl
1180 return (null == mIcon) ? null : mIcon.ResourceUrl;
1185 mIcon.ResourceUrl = value;
1189 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1190 [EditorBrowsable(EditorBrowsableState.Never)]
1191 public Size IconSize
1195 return (null == mIcon) ? null : mIcon.Size;
1204 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1205 [EditorBrowsable(EditorBrowsableState.Never)]
1206 public Position IconPosition
1210 return (null == mIcon) ? null : mIcon.Position;
1215 mIcon.Position = value;
1219 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1220 [EditorBrowsable(EditorBrowsableState.Never)]
1221 public string CheckResourceUrl
1225 return (null == mCheck) ? null : mCheck.ResourceUrl;
1230 mCheck.ResourceUrl = value;
1234 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1235 [EditorBrowsable(EditorBrowsableState.Never)]
1236 public Position CheckPosition
1240 return (null == mCheck) ? null : mCheck.Position;
1245 mCheck.Position = value;
1249 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1250 [EditorBrowsable(EditorBrowsableState.Never)]
1251 public Size CheckImageSize
1255 return (null == mCheck) ? null : mCheck.Size;
1260 mCheck.Size = value;
1264 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1265 [EditorBrowsable(EditorBrowsableState.Never)]
1266 public bool IsSelected
1270 return (null == mCheck) ? false : mCheck.Visibility;
1286 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1287 [EditorBrowsable(EditorBrowsableState.Never)]
1288 protected override void Dispose(DisposeTypes type)
1295 if (type == DisposeTypes.Explicit)
1321 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1322 [EditorBrowsable(EditorBrowsableState.Never)]
1323 protected override ViewStyle GetViewStyle()
1328 private void CreateIcon()
1332 mIcon = new ImageView()
1334 PositionUsesPivotPoint = true,
1335 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1336 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1342 private void CreateText()
1346 mText = new TextLabel()
1348 PositionUsesPivotPoint = true,
1349 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1350 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1351 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1352 HeightResizePolicy = ResizePolicyType.FillToParent,
1353 VerticalAlignment = VerticalAlignment.Center,
1354 HorizontalAlignment = HorizontalAlignment.Begin,
1360 private void CreateCheckImage()
1364 mCheck = new ImageView()
1366 PositionUsesPivotPoint = true,
1367 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1368 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1369 Name = "checkedImage",
1378 #region DropDownListBridge
1381 /// DropDownListBridge is bridge to connect item data and an item View.
1383 /// <since_tizen> 6 </since_tizen>
1384 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1385 [EditorBrowsable(EditorBrowsableState.Never)]
1386 public class DropDownListBridge
1388 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1390 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1393 /// Creates a new instance of a DropDownListBridge.
1395 /// <since_tizen> 6 </since_tizen>
1396 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1397 [EditorBrowsable(EditorBrowsableState.Never)]
1398 public DropDownListBridge() { }
1401 /// Insert data. The inserted data will be added to the special position by index automatically.
1403 /// <param name="position">Position index where will be inserted.</param>
1404 /// <param name="data">Item data which will apply to tab item view.</param>
1405 /// <since_tizen> 6 </since_tizen>
1406 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1407 [EditorBrowsable(EditorBrowsableState.Never)]
1408 public void InsertData(int position, DropDownDataItem data)
1412 position = itemDataList.Count;
1414 itemDataList.Insert(position, data);
1415 AdapterPurge = true;
1419 /// Remove data by position.
1421 /// <param name="position">Position index where will be removed.</param>
1422 /// <since_tizen> 6 </since_tizen>
1423 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1424 [EditorBrowsable(EditorBrowsableState.Never)]
1425 public void RemoveData(int position)
1427 itemDataList.RemoveAt(position);
1428 AdapterPurge = true;
1432 /// Get data by position.
1434 /// <param name="position">Position index where will be gotten.</param>
1435 /// <since_tizen> 6 </since_tizen>
1436 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1437 [EditorBrowsable(EditorBrowsableState.Never)]
1438 public DropDownDataItem GetData(int position)
1440 return itemDataList[position];
1444 /// Get view holder by view type.
1446 /// <since_tizen> 6 </since_tizen>
1447 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1448 [EditorBrowsable(EditorBrowsableState.Never)]
1449 public ViewHolder OnCreateViewHolder()
1451 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1457 /// Bind ViewHolder with View.
1459 /// <param name="holder">View holder.</param>
1460 /// <param name="position">Position index of source data.</param>
1461 /// <since_tizen> 6 </since_tizen>
1462 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1463 [EditorBrowsable(EditorBrowsableState.Never)]
1464 public void BindViewHolder(ViewHolder holder, int position)
1466 DropDownDataItem listItemData = itemDataList[position];
1467 if(listItemData == null)
1471 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1472 listItemView.Name = "Item" + position;
1473 if (listItemData.Size != null)
1475 if (listItemData.Size.Width > 0)
1477 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1481 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1484 if (listItemData.Size.Height > 0)
1486 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1490 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1494 if (listItemView != null)
1496 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1497 if (listItemData.Text != null)
1499 listItemView.Text = listItemData.Text;
1500 listItemView.PointSize = listItemData.PointSize;
1501 listItemView.FontFamily = listItemData.FontFamily;
1502 listItemView.TextPosition = listItemData.TextPosition;
1505 if (listItemData.IconResourceUrl != null)
1507 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1508 listItemView.IconSize = listItemData.IconSize;
1509 if (listItemView.IconSize != null)
1511 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1515 if (listItemData.CheckImageResourceUrl != null)
1517 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1519 if (null != listItemData.CheckImageSize)
1521 listItemView.CheckImageSize = listItemData.CheckImageSize;
1524 if (listItemView.CheckImageSize != null)
1526 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1530 listItemView.IsSelected = listItemData.IsSelected;
1535 /// Destroy view holder, it can be override.
1537 /// <param name="holder">View holder.</param>
1538 /// <since_tizen> 6 </since_tizen>
1539 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1540 [EditorBrowsable(EditorBrowsableState.Never)]
1541 public void OnDestroyViewHolder(ViewHolder holder)
1543 if (holder.ItemView != null)
1545 holder.ItemView.Dispose();
1550 /// Get item count, it can be override.
1552 /// <since_tizen> 6 </since_tizen>
1553 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1554 [EditorBrowsable(EditorBrowsableState.Never)]
1555 public int GetItemCount()
1557 return itemDataList.Count;
1566 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1568 /// <since_tizen> 6 </since_tizen>
1569 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1570 [EditorBrowsable(EditorBrowsableState.Never)]
1571 public class ViewHolder
1574 /// ViewHolder constructor.
1576 /// <param name="itemView">View</param>
1577 /// <since_tizen> 6 </since_tizen>
1578 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1579 [EditorBrowsable(EditorBrowsableState.Never)]
1580 public ViewHolder(View itemView)
1582 if (itemView == null)
1584 throw new ArgumentNullException("itemView may not be null");
1586 this.ItemView = itemView;
1590 /// Returns the view.
1592 /// <since_tizen> 6 </since_tizen>
1593 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1594 [EditorBrowsable(EditorBrowsableState.Never)]
1595 public View ItemView { get; }
1597 internal bool IsBound { get; set; }