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 Scrollable scrollable = null;
125 // The LinearLayout container to house the items in the drop down list.
126 private View dropDownMenuFullList = null;
127 private DropDownListBridge adapter = new DropDownListBridge();
128 private DropDownItemView selectedItemView = null;
129 private TapGestureDetector tapGestureDetector = null;
131 private Extents listMargin = new Extents(0, 0, 0, 0);
132 private Extents listPadding = new Extents(0, 0, 0, 0);
133 private ListOrientation listRelativeOrientation = ListOrientation.Left;
134 private int selectedItemIndex = -1;
135 private int spaceBetweenButtonTextAndIcon = 0;
136 private bool itemPressed = false;
139 /// Creates a new instance of a DropDown.
141 /// <since_tizen> 6 </since_tizen>
142 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public DropDown() : base() { }
147 /// Creates a new instance of a DropDown with style.
149 /// <param name="style">Create DropDown by special style defined in UX.</param>
150 /// <since_tizen> 6 </since_tizen>
151 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 public DropDown(string style) : base(style) { }
156 /// Creates a new instance of a DropDown with attributes.
158 /// <param name="attributes">Create DropDown by attributes customized by user.</param>
159 /// <since_tizen> 6 </since_tizen>
160 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public DropDown(DropDownStyle attributes) : base(attributes)
167 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
169 /// <since_tizen> 6 </since_tizen>
170 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public delegate void ClickEventHandler<ClickEventArgs>(object sender, ClickEventArgs e);
175 /// An event for the item clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
177 /// <since_tizen> 6 </since_tizen>
178 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public event ClickEventHandler<ItemClickEventArgs> ItemClickEvent;
183 /// List position in relation to the main button.
185 /// <since_tizen> 6 </since_tizen>
186 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 public enum ListOrientation
193 /// <since_tizen> 6 </since_tizen>
194 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
195 [EditorBrowsable(EditorBrowsableState.Never)]
200 /// <since_tizen> 6 </since_tizen>
201 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
202 [EditorBrowsable(EditorBrowsableState.Never)]
206 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public new DropDownStyle Style => ViewStyle as DropDownStyle;
211 /// Space between button text and button icon in DropDown.
213 /// <since_tizen> 6 </since_tizen>
214 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
215 public int SpaceBetweenButtonTextAndIcon
217 get => (int)GetValue(SpaceBetweenButtonTextAndIconProperty);
218 set => SetValue(SpaceBetweenButtonTextAndIconProperty, value);
222 /// List relative orientation in DropDown.
224 /// <since_tizen> 6 </since_tizen>
225 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
226 public ListOrientation ListRelativeOrientation
228 get => (ListOrientation)GetValue(ListRelativeOrientationProperty);
229 set => SetValue(ListRelativeOrientationProperty, value);
235 /// <since_tizen> 6 </since_tizen>
236 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
237 public Extents ListMargin
241 Extents tmp = (Extents)GetValue(ListMarginProperty);
242 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);
244 set => SetValue(ListMarginProperty, value);
248 /// Selected item index in list.
250 /// <since_tizen> 6 </since_tizen>
251 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
252 public int SelectedItemIndex
254 get => (int)GetValue(SelectedItemIndexProperty);
255 set => SetValue(SelectedItemIndexProperty, value);
259 /// List padding in DropDown.
261 /// <since_tizen> 6 </since_tizen>
262 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
263 public Extents ListPadding
267 Extents tmp = (Extents)GetValue(ListPaddingProperty);
268 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);
270 set => SetValue(ListPaddingProperty, value);
274 /// Add list item by item data. The added item will be added to end of all items automatically.
276 /// <param name="itemData">Item data which will apply to tab item view.</param>
277 /// <since_tizen> 6 </since_tizen>
278 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public void AddItem(DropDownDataItem itemData)
282 // Add item to adaptor, will be added to list via AddItemAt during OnUpdate()
283 int insertionPosition = adapter.GetItemCount();
284 adapter.InsertData(insertionPosition, itemData);
288 /// Delete list item by index.
290 /// <param name="index">Position index where will be deleted.</param>
291 /// <since_tizen> 6 </since_tizen>
292 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
293 [EditorBrowsable(EditorBrowsableState.Never)]
294 public void DeleteItem(int index)
296 if (index < 0 || index >= adapter?.GetItemCount()) return;
297 if (null == dropDownMenuFullList) return;
299 if (selectedItemIndex == index)
301 selectedItemIndex = -1;
303 else if(selectedItemIndex > index)
308 adapter?.RemoveData(index);
310 if(index < dropDownMenuFullList.ChildCount)
312 View childToRemove = dropDownMenuFullList.GetChildAt((uint)index);
315 childToRemove.TouchEvent -= ListItemTouchEvent;
316 dropDownMenuFullList.Remove(childToRemove);
317 dropDownMenuFullList?.Layout?.RequestLayout();
323 /// Insert list item by item data. The inserted item will be added to the special position by index automatically.
325 /// <param name="item">Item data which will apply to tab item view.</param>
326 /// <param name="index">Position index where will be inserted.</param>
327 /// <since_tizen> 6 </since_tizen>
328 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public void InsertItem(DropDownDataItem item, int index)
332 if (index < 0 || index >= adapter.GetItemCount())
337 if (selectedItemIndex >= index)
342 adapter.InsertData(index, item);
346 /// Add scroll bar to list.
348 /// <param name="scrollBar">Scroll bar defined by user which will be added to list.</param>
349 /// <since_tizen> 6 </since_tizen>
350 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
351 [EditorBrowsable(EditorBrowsableState.Never)]
352 public void AttachScrollBar(ScrollBar scrollBar)
354 if (scrollable == null)
358 Tizen.Log.Error("DropDown","Feature unsupported");
362 /// Detach scroll bar to list.
364 /// <since_tizen> 6 </since_tizen>
365 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public void DetachScrollBar()
369 if (scrollable == null)
373 Tizen.Log.Error("DropDown","Feature unsupported");
376 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
377 [EditorBrowsable(EditorBrowsableState.Never)]
378 public override void ApplyStyle(ViewStyle viewStyle)
380 base.ApplyStyle(viewStyle);
382 DropDownStyle dropDownStyle = viewStyle as DropDownStyle;
383 if (null != dropDownStyle)
389 CreateListBackgroundImage();
390 if (null == scrollable) // scrollable used to test of ListContainer Setup invoked already
392 SetUpListContainer();
394 button.ApplyStyle(dropDownStyle.Button);
395 headerText.ApplyStyle(dropDownStyle.HeaderText);
396 listBackgroundImage.ApplyStyle(dropDownStyle.ListBackgroundImage);
402 /// Update DropDown by attributes.
404 /// <since_tizen> 6 </since_tizen>
405 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
406 [EditorBrowsable(EditorBrowsableState.Never)]
407 protected void UpdateDropDown()
409 if (null == scrollable || null == listBackgroundImage || null == dropDownMenuFullList) return;
410 if (null == Style.ListBackgroundImage.Size) return;
411 // Resize and position scrolling list within the drop down list container. Can be used to position list in relation to the background image.
412 scrollable.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
413 scrollable.Position2D = new Position2D(listPadding.Start, listPadding.Top);
415 int listBackgroundImageX = 0;
416 int listBackgroundImageY = 0;
417 if (listRelativeOrientation == ListOrientation.Left)
419 listBackgroundImageX = (int)listMargin.Start;
420 listBackgroundImageY = (int)listMargin.Top;
422 else if (listRelativeOrientation == ListOrientation.Right)
424 listBackgroundImageX = -(int)listMargin.End;
425 listBackgroundImageY = (int)listMargin.Top;
427 listBackgroundImage.Position2D = new Position2D(listBackgroundImageX, listBackgroundImageY);
428 dropDownMenuFullList?.Layout?.RequestLayout();
431 protected override void OnUpdate()
434 float buttonTextWidth = 0;
435 if (null != buttonText)
437 buttonText.Text = Style.Button.Text.Text.All;
438 buttonText.PointSize = Style.Button.Text.PointSize?.All ?? 20;
439 buttonTextWidth = buttonText.NaturalSize.Width;
441 iconWidth = Style.Button.Icon.Size?.Width ?? 48;
442 button.SizeWidth = iconWidth + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
444 int numberOfItemsToAdd = adapter.GetItemCount();
446 if (adapter.AdapterPurge == true)
448 adapter.AdapterPurge = false;
449 for (int i = 0; i < numberOfItemsToAdd; i++)
451 AddItemAt(adapter.GetData(i), i);
454 // Set selection icon on View
455 UpdateSelectedItem(selectedItemIndex);
459 /// Dispose DropDown and all children on it.
461 /// <param name="type">Dispose type.</param>
462 /// <since_tizen> 6 </since_tizen>
463 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
464 [EditorBrowsable(EditorBrowsableState.Never)]
465 protected override void Dispose(DisposeTypes type)
472 if (type == DisposeTypes.Explicit)
474 Utility.Dispose(headerText);
475 Utility.Dispose(buttonText);
476 Utility.Dispose(button);
477 Utility.Dispose(scrollable);
478 Utility.Dispose(dropDownMenuFullList);
479 Utility.Dispose(listBackgroundImage);
486 /// Get DropDown attribues.
488 /// <since_tizen> 6 </since_tizen>
489 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
490 [EditorBrowsable(EditorBrowsableState.Never)]
491 protected override ViewStyle GetViewStyle()
493 return new DropDownStyle();
496 private void AddItemAt(DropDownDataItem itemData,int index)
498 ViewHolder viewHolder = adapter.OnCreateViewHolder();
499 if (!viewHolder.IsBound)
501 adapter.BindViewHolder(viewHolder, index);
502 viewHolder.IsBound = true;
505 if (tapGestureDetector == null)
507 tapGestureDetector = new TapGestureDetector();
509 View view = viewHolder.ItemView;
510 view.TouchEvent += ListItemTouchEvent;
511 dropDownMenuFullList.Add(view);
514 private void OnClickEvent(object sender, ItemClickEventArgs e)
516 ItemClickEvent?.Invoke(sender, e);
519 private void CreateHeaderText()
521 if (null == headerText)
523 headerText = new TextLabel()
525 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
526 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
527 HorizontalAlignment = HorizontalAlignment.Center,
528 VerticalAlignment = VerticalAlignment.Center,
529 ParentOrigin = NUI.ParentOrigin.Center,
530 PivotPoint = NUI.ParentOrigin.Center,
531 PositionUsesPivotPoint = true,
533 headerText.Name = "DropDownHeaderText";
538 private void CreateButtonText()
540 if (null == buttonText)
542 buttonText = new TextLabel();
546 private void CreateButton()
550 button = new Button()
552 ParentOrigin = NUI.ParentOrigin.CenterLeft,
553 PivotPoint = NUI.PivotPoint.CenterLeft,
554 PositionUsesPivotPoint = true,
555 HeightResizePolicy = ResizePolicyType.FitToChildren,
556 IconRelativeOrientation = Button.IconOrientation.Right,
558 button.Name = "DropDownButton";
559 button.ClickEvent += ButtonClickEvent;
564 private void CreateListBackgroundImage()
566 if (null == listBackgroundImage)
568 listBackgroundImage = new ImageView
570 Name = "ListBackgroundImage",
571 PositionUsesPivotPoint = true,
572 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
573 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
574 WidthResizePolicy = ResizePolicyType.FitToChildren,
575 HeightResizePolicy = ResizePolicyType.FitToChildren,
577 Add(listBackgroundImage);
581 private void SetUpListContainer()
583 LinearLayout linear = new LinearLayout()
585 LinearOrientation = LinearLayout.Orientation.Vertical,
588 dropDownMenuFullList = new View()
591 Name = "DropDownMenuList",
592 WidthSpecification = LayoutParamPolicies.MatchParent,
593 HeightSpecification = LayoutParamPolicies.WrapContent,
597 scrollable = new Scrollable()
601 scrollable.Add(dropDownMenuFullList);
603 listBackgroundImage.Add(scrollable);
604 listBackgroundImage.Hide();
607 private View GetViewFromIndex(uint index)
609 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
611 return dropDownMenuFullList.GetChildAt(index);
619 private void SetListItemToSelected(DropDownItemView targetItemView)
621 // Set the DropDownItemView matching the targetItemView to selected.
622 if (selectedItemView!=targetItemView)
624 if (selectedItemView!=null)
626 // clear selection status of currently selected item view
627 selectedItemView.IsSelected = false;
629 // Set target item to selected
630 targetItemView.IsSelected = true;
631 selectedItemView = targetItemView;
635 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
637 PointStateType state = e.Touch.GetState(0);
638 DropDownItemView touchedView = sender as DropDownItemView;;
641 case PointStateType.Down:
642 if (touchedView != null && touchedView.BackgroundColorSelector != null)
644 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Pressed);
646 itemPressed = true; // if matched with a Up then a click event.
648 case PointStateType.Motion:
649 if (touchedView != null && touchedView.BackgroundColorSelector != null)
651 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Normal);
655 case PointStateType.Up:
656 if (touchedView != null && touchedView.BackgroundColorSelector != null)
658 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Selected);
660 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
663 Console.WriteLine("Tapped{0}", touchedView.Name);
664 SetListItemToSelected(touchedView);
665 button.Text = touchedView.Text;
667 listBackgroundImage.Hide();
677 private void UpdateSelectedItem(int index)
679 if (null == adapter) return;
680 if (null == dropDownMenuFullList) return;
681 if (selectedItemIndex != -1)
683 DropDownDataItem data = adapter.GetData(selectedItemIndex);
686 data.IsSelected = false;
688 DropDownItemView listItemView = dropDownMenuFullList.GetChildAt((uint)selectedItemIndex) as DropDownItemView;
689 data.IsSelected = false;
690 SetListItemToSelected(listItemView);
695 DropDownDataItem data = adapter.GetData(index);
698 data.IsSelected = true;
699 DropDownItemView listItemView = dropDownMenuFullList?.GetChildAt((uint)index) as DropDownItemView;
702 SetListItemToSelected(listItemView);
707 selectedItemIndex = index;
708 dropDownMenuFullList?.Layout?.RequestLayout();
711 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
714 listBackgroundImage.Show();
715 dropDownMenuFullList?.Layout?.RequestLayout();
716 listBackgroundImage.RaiseToTop();
721 #region ItemClickEventArgs
723 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
725 /// <since_tizen> 6 </since_tizen>
726 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
727 [EditorBrowsable(EditorBrowsableState.Never)]
728 public class ItemClickEventArgs : EventArgs
730 /// <summary> Clicked item index of DropDown's list </summary>
731 /// <since_tizen> 6 </since_tizen>
732 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
733 [EditorBrowsable(EditorBrowsableState.Never)]
735 /// <summary> Clicked item text string of DropDown's list </summary>
736 /// <since_tizen> 6 </since_tizen>
737 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
738 [EditorBrowsable(EditorBrowsableState.Never)]
743 #region DropDownDataItem
745 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
747 /// <since_tizen> 6 </since_tizen>
748 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
749 //[EditorBrowsable(EditorBrowsableState.Never)]
750 public class DropDownDataItem
752 private DropDownItemStyle itemDataStyle = new DropDownItemStyle();
755 /// Creates a new instance of a DropDownItemData.
757 /// <since_tizen> 6 </since_tizen>
758 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 public DropDownDataItem()
766 /// Creates a new instance of a DropDownItemData with style.
768 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
769 /// <since_tizen> 6 </since_tizen>
770 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
771 [EditorBrowsable(EditorBrowsableState.Never)]
772 public DropDownDataItem(string style)
776 ViewStyle attributes = StyleManager.Instance.GetViewStyle(style);
777 if(attributes == null)
779 throw new InvalidOperationException($"There is no style {style}");
781 itemDataStyle = attributes as DropDownItemStyle;
787 /// Creates a new instance of a DropDownItemData with style.
789 /// <param name="style">Create DropDownItemData by style customized by user.</param>
790 /// <since_tizen> 6 </since_tizen>
791 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
792 [EditorBrowsable(EditorBrowsableState.Never)]
793 public DropDownDataItem(DropDownItemStyle style)
795 itemDataStyle.CopyFrom(style);
800 /// DropDown item size.
802 /// <since_tizen> 6 </since_tizen>
803 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
804 [EditorBrowsable(EditorBrowsableState.Never)]
809 return itemDataStyle.Size;
813 itemDataStyle.Size = value;
818 /// DropDown item background color selector.
820 /// <since_tizen> 6 </since_tizen>
821 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
822 [EditorBrowsable(EditorBrowsableState.Never)]
823 public Selector<Color> BackgroundColor
827 return itemDataStyle.BackgroundColor;
831 if (null == itemDataStyle?.BackgroundColor)
833 itemDataStyle.BackgroundColor = new Selector<Color>();
836 itemDataStyle.BackgroundColor.Clone(value);
841 /// DropDown item text string.
843 /// <since_tizen> 6 </since_tizen>
844 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
845 [EditorBrowsable(EditorBrowsableState.Never)]
850 return itemDataStyle.Text?.Text?.All;
854 if (null == itemDataStyle.Text.Text)
856 itemDataStyle.Text.Text = new Selector<string> { All = value };
860 itemDataStyle.Text.Text = value;
866 /// DropDown item text's point size.
868 /// <since_tizen> 6 </since_tizen>
869 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
870 [EditorBrowsable(EditorBrowsableState.Never)]
871 public float PointSize
875 return itemDataStyle.Text?.PointSize?.All ?? 0;
879 if (null == itemDataStyle.Text.PointSize)
881 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
885 itemDataStyle.Text.PointSize = value;
891 /// DropDown item text's font family.
893 /// <since_tizen> 6 </since_tizen>
894 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
895 [EditorBrowsable(EditorBrowsableState.Never)]
896 public string FontFamily
900 return itemDataStyle.Text.FontFamily?.All;
904 if (null == itemDataStyle.Text.FontFamily)
906 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
910 itemDataStyle.Text.FontFamily = value;
916 /// DropDown item text's position.
918 /// <since_tizen> 6 </since_tizen>
919 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
920 [EditorBrowsable(EditorBrowsableState.Never)]
921 public Position TextPosition
925 return itemDataStyle.Text?.Position;
929 itemDataStyle.Text.Position = value;
934 /// DropDown item's icon's resource url.
936 /// <since_tizen> 6 </since_tizen>
937 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
938 [EditorBrowsable(EditorBrowsableState.Never)]
939 public string IconResourceUrl
943 return itemDataStyle.Icon?.ResourceUrl?.All;
947 if (null == itemDataStyle.Icon.ResourceUrl)
949 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
953 itemDataStyle.Icon.ResourceUrl = value;
959 /// DropDown item's icon's size.
961 /// <since_tizen> 6 </since_tizen>
962 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
963 [EditorBrowsable(EditorBrowsableState.Never)]
968 return itemDataStyle.Icon?.Size;
972 itemDataStyle.Icon.Size = value;
977 /// DropDown item's icon's position.
979 /// <since_tizen> 6 </since_tizen>
980 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
981 [EditorBrowsable(EditorBrowsableState.Never)]
982 public Position IconPosition
986 return itemDataStyle.Icon.Position;
990 itemDataStyle.Icon.Position = value;
995 /// DropDown item's check image's resource url.
997 /// <since_tizen> 6 </since_tizen>
998 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
999 [EditorBrowsable(EditorBrowsableState.Never)]
1000 public string CheckImageResourceUrl
1004 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1008 if (null == itemDataStyle.CheckImage.ResourceUrl)
1010 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1014 itemDataStyle.CheckImage.ResourceUrl = value;
1020 /// DropDown item's check image's size.
1022 /// <since_tizen> 6 </since_tizen>
1023 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1024 [EditorBrowsable(EditorBrowsableState.Never)]
1025 public Size CheckImageSize
1029 return itemDataStyle.CheckImage?.Size;
1033 itemDataStyle.CheckImage.Size = value;
1038 /// DropDown item's check image's right space.
1040 /// <since_tizen> 6 </since_tizen>
1041 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1042 [EditorBrowsable(EditorBrowsableState.Never)]
1043 public int CheckImageGapToBoundary
1047 return itemDataStyle.CheckImageGapToBoundary;
1051 itemDataStyle.CheckImageGapToBoundary = value;
1056 /// Flag to decide DropDown item is selected or not.
1058 /// <since_tizen> 6 </since_tizen>
1059 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1060 [EditorBrowsable(EditorBrowsableState.Never)]
1061 public bool IsSelected
1065 return itemDataStyle.IsSelected;
1069 itemDataStyle.IsSelected = value;
1073 private void Initialize()
1075 if (itemDataStyle == null)
1077 throw new Exception("DropDownDataItem style parse error.");
1083 #region DropDownItemView
1084 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1085 [EditorBrowsable(EditorBrowsableState.Never)]
1086 internal class DropDownItemView : Control
1088 private TextLabel mText = null;
1089 private ImageView mIcon = null;
1090 private ImageView mCheck = null;
1092 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1093 [EditorBrowsable(EditorBrowsableState.Never)]
1094 public DropDownItemView() : base() { }
1096 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1097 [EditorBrowsable(EditorBrowsableState.Never)]
1098 public Selector<Color> BackgroundColorSelector { get; set; }
1100 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1101 [EditorBrowsable(EditorBrowsableState.Never)]
1106 return (null == mText) ? null : mText.Text;
1115 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1116 [EditorBrowsable(EditorBrowsableState.Never)]
1117 public string FontFamily
1121 return (null == mText) ? null : mText.FontFamily;
1126 mText.FontFamily = value;
1130 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1131 [EditorBrowsable(EditorBrowsableState.Never)]
1132 public float? PointSize
1136 return (null == mText) ? 0 : mText.PointSize;
1141 mText.PointSize = (float)value;
1145 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1146 [EditorBrowsable(EditorBrowsableState.Never)]
1147 public Color TextColor
1151 return (null == mText) ? null : mText.TextColor;
1156 mText.TextColor = value;
1160 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1161 [EditorBrowsable(EditorBrowsableState.Never)]
1162 public Position TextPosition
1166 return (null == mText) ? null : mText.Position;
1171 mText.Position = value;
1175 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1176 [EditorBrowsable(EditorBrowsableState.Never)]
1177 public string IconResourceUrl
1181 return (null == mIcon) ? null : mIcon.ResourceUrl;
1186 mIcon.ResourceUrl = value;
1190 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1191 [EditorBrowsable(EditorBrowsableState.Never)]
1192 public Size IconSize
1196 return (null == mIcon) ? null : mIcon.Size;
1205 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1206 [EditorBrowsable(EditorBrowsableState.Never)]
1207 public Position IconPosition
1211 return (null == mIcon) ? null : mIcon.Position;
1216 mIcon.Position = value;
1220 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1221 [EditorBrowsable(EditorBrowsableState.Never)]
1222 public string CheckResourceUrl
1226 return (null == mCheck) ? null : mCheck.ResourceUrl;
1231 mCheck.ResourceUrl = value;
1235 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1236 [EditorBrowsable(EditorBrowsableState.Never)]
1237 public Position CheckPosition
1241 return (null == mCheck) ? null : mCheck.Position;
1246 mCheck.Position = value;
1250 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1251 [EditorBrowsable(EditorBrowsableState.Never)]
1252 public Size CheckImageSize
1256 return (null == mCheck) ? null : mCheck.Size;
1261 mCheck.Size = value;
1265 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1266 [EditorBrowsable(EditorBrowsableState.Never)]
1267 public bool IsSelected
1271 return (null == mCheck) ? false : mCheck.Visibility;
1287 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1288 [EditorBrowsable(EditorBrowsableState.Never)]
1289 protected override void Dispose(DisposeTypes type)
1296 if (type == DisposeTypes.Explicit)
1322 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1323 [EditorBrowsable(EditorBrowsableState.Never)]
1324 protected override ViewStyle GetViewStyle()
1329 private void CreateIcon()
1333 mIcon = new ImageView()
1335 PositionUsesPivotPoint = true,
1336 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1337 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1343 private void CreateText()
1347 mText = new TextLabel()
1349 PositionUsesPivotPoint = true,
1350 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1351 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1352 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1353 HeightResizePolicy = ResizePolicyType.FillToParent,
1354 VerticalAlignment = VerticalAlignment.Center,
1355 HorizontalAlignment = HorizontalAlignment.Begin,
1361 private void CreateCheckImage()
1365 mCheck = new ImageView()
1367 PositionUsesPivotPoint = true,
1368 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1369 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1370 Name = "checkedImage",
1379 #region DropDownListBridge
1382 /// DropDownListBridge is bridge to connect item data and an item View.
1384 /// <since_tizen> 6 </since_tizen>
1385 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1386 [EditorBrowsable(EditorBrowsableState.Never)]
1387 public class DropDownListBridge
1389 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1391 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1394 /// Creates a new instance of a DropDownListBridge.
1396 /// <since_tizen> 6 </since_tizen>
1397 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1398 [EditorBrowsable(EditorBrowsableState.Never)]
1399 public DropDownListBridge() { }
1402 /// Insert data. The inserted data will be added to the special position by index automatically.
1404 /// <param name="position">Position index where will be inserted.</param>
1405 /// <param name="data">Item data which will apply to tab item view.</param>
1406 /// <since_tizen> 6 </since_tizen>
1407 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1408 [EditorBrowsable(EditorBrowsableState.Never)]
1409 public void InsertData(int position, DropDownDataItem data)
1413 position = itemDataList.Count;
1415 itemDataList.Insert(position, data);
1416 AdapterPurge = true;
1420 /// Remove data by position.
1422 /// <param name="position">Position index where will be removed.</param>
1423 /// <since_tizen> 6 </since_tizen>
1424 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1425 [EditorBrowsable(EditorBrowsableState.Never)]
1426 public void RemoveData(int position)
1428 itemDataList.RemoveAt(position);
1429 AdapterPurge = true;
1433 /// Get data by position.
1435 /// <param name="position">Position index where will be gotten.</param>
1436 /// <since_tizen> 6 </since_tizen>
1437 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1438 [EditorBrowsable(EditorBrowsableState.Never)]
1439 public DropDownDataItem GetData(int position)
1441 return itemDataList[position];
1445 /// Get view holder by view type.
1447 /// <since_tizen> 6 </since_tizen>
1448 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1449 [EditorBrowsable(EditorBrowsableState.Never)]
1450 public ViewHolder OnCreateViewHolder()
1452 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1458 /// Bind ViewHolder with View.
1460 /// <param name="holder">View holder.</param>
1461 /// <param name="position">Position index of source data.</param>
1462 /// <since_tizen> 6 </since_tizen>
1463 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1464 [EditorBrowsable(EditorBrowsableState.Never)]
1465 public void BindViewHolder(ViewHolder holder, int position)
1467 DropDownDataItem listItemData = itemDataList[position];
1468 if(listItemData == null)
1472 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1473 listItemView.Name = "Item" + position;
1474 if (listItemData.Size != null)
1476 if (listItemData.Size.Width > 0)
1478 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1482 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1485 if (listItemData.Size.Height > 0)
1487 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1491 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1495 if (listItemView != null)
1497 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1498 if (listItemData.Text != null)
1500 listItemView.Text = listItemData.Text;
1501 listItemView.PointSize = listItemData.PointSize;
1502 listItemView.FontFamily = listItemData.FontFamily;
1503 listItemView.TextPosition = listItemData.TextPosition;
1506 if (listItemData.IconResourceUrl != null)
1508 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1509 listItemView.IconSize = listItemData.IconSize;
1510 if (listItemView.IconSize != null)
1512 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1516 if (listItemData.CheckImageResourceUrl != null)
1518 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1520 if (null != listItemData.CheckImageSize)
1522 listItemView.CheckImageSize = listItemData.CheckImageSize;
1525 if (listItemView.CheckImageSize != null)
1527 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1531 listItemView.IsSelected = listItemData.IsSelected;
1536 /// Destroy view holder, it can be override.
1538 /// <param name="holder">View holder.</param>
1539 /// <since_tizen> 6 </since_tizen>
1540 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1541 [EditorBrowsable(EditorBrowsableState.Never)]
1542 public void OnDestroyViewHolder(ViewHolder holder)
1544 if (holder.ItemView != null)
1546 holder.ItemView.Dispose();
1551 /// Get item count, it can be override.
1553 /// <since_tizen> 6 </since_tizen>
1554 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1555 [EditorBrowsable(EditorBrowsableState.Never)]
1556 public int GetItemCount()
1558 return itemDataList.Count;
1567 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1569 /// <since_tizen> 6 </since_tizen>
1570 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1571 [EditorBrowsable(EditorBrowsableState.Never)]
1572 public class ViewHolder
1575 /// ViewHolder constructor.
1577 /// <param name="itemView">View</param>
1578 /// <since_tizen> 6 </since_tizen>
1579 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1580 [EditorBrowsable(EditorBrowsableState.Never)]
1581 public ViewHolder(View itemView)
1583 if (itemView == null)
1585 throw new ArgumentNullException("itemView may not be null");
1587 this.ItemView = itemView;
1591 /// Returns the view.
1593 /// <since_tizen> 6 </since_tizen>
1594 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1595 [EditorBrowsable(EditorBrowsableState.Never)]
1596 public View ItemView { get; }
1598 internal bool IsBound { get; set; }