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(nameof(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(nameof(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(nameof(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(nameof(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(nameof(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 ScrollableBase scrollableBase = 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 (scrollableBase == 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 (scrollableBase == 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 == scrollableBase) // scrollableBase 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 == scrollableBase || 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 scrollableBase.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
413 scrollableBase.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();
434 protected override void OnUpdate()
437 float buttonTextWidth = 0;
438 if (null != buttonText)
440 buttonText.Text = Style.Button.Text.Text.All;
441 buttonText.PointSize = Style.Button.Text.PointSize?.All ?? 20;
442 buttonTextWidth = buttonText.NaturalSize.Width;
444 iconWidth = Style.Button.Icon.Size?.Width ?? 48;
445 button.SizeWidth = iconWidth + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
447 int numberOfItemsToAdd = adapter.GetItemCount();
449 if (adapter.AdapterPurge == true)
451 adapter.AdapterPurge = false;
452 for (int i = 0; i < numberOfItemsToAdd; i++)
454 AddItemAt(adapter.GetData(i), i);
457 // Set selection icon on View
458 UpdateSelectedItem(selectedItemIndex);
462 /// Dispose DropDown and all children on it.
464 /// <param name="type">Dispose type.</param>
465 /// <since_tizen> 6 </since_tizen>
466 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
467 [EditorBrowsable(EditorBrowsableState.Never)]
468 protected override void Dispose(DisposeTypes type)
475 if (type == DisposeTypes.Explicit)
477 Utility.Dispose(headerText);
478 Utility.Dispose(buttonText);
479 Utility.Dispose(button);
480 Utility.Dispose(scrollableBase);
481 Utility.Dispose(dropDownMenuFullList);
482 Utility.Dispose(listBackgroundImage);
489 /// Get DropDown attribues.
491 /// <since_tizen> 6 </since_tizen>
492 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
493 [EditorBrowsable(EditorBrowsableState.Never)]
494 protected override ViewStyle GetViewStyle()
496 return new DropDownStyle();
499 private void AddItemAt(DropDownDataItem itemData,int index)
501 ViewHolder viewHolder = adapter.OnCreateViewHolder();
502 if (!viewHolder.IsBound)
504 adapter.BindViewHolder(viewHolder, index);
505 viewHolder.IsBound = true;
508 if (tapGestureDetector == null)
510 tapGestureDetector = new TapGestureDetector();
512 View view = viewHolder.ItemView;
513 view.TouchEvent += ListItemTouchEvent;
514 dropDownMenuFullList.Add(view);
517 private void OnClickEvent(object sender, ItemClickEventArgs e)
519 ItemClickEvent?.Invoke(sender, e);
522 private void CreateHeaderText()
524 if (null == headerText)
526 headerText = new TextLabel()
528 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
529 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
530 HorizontalAlignment = HorizontalAlignment.Center,
531 VerticalAlignment = VerticalAlignment.Center,
532 ParentOrigin = NUI.ParentOrigin.Center,
533 PivotPoint = NUI.ParentOrigin.Center,
534 PositionUsesPivotPoint = true,
536 headerText.Name = "DropDownHeaderText";
541 private void CreateButtonText()
543 if (null == buttonText)
545 buttonText = new TextLabel();
549 private void CreateButton()
553 button = new Button()
555 ParentOrigin = NUI.ParentOrigin.CenterLeft,
556 PivotPoint = NUI.PivotPoint.CenterLeft,
557 PositionUsesPivotPoint = true,
558 HeightResizePolicy = ResizePolicyType.FitToChildren,
559 IconRelativeOrientation = Button.IconOrientation.Right,
561 button.Name = "DropDownButton";
562 button.ClickEvent += ButtonClickEvent;
567 private void CreateListBackgroundImage()
569 if (null == listBackgroundImage)
571 listBackgroundImage = new ImageView
573 Name = "ListBackgroundImage",
574 PositionUsesPivotPoint = true,
575 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
576 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
577 WidthResizePolicy = ResizePolicyType.FitToChildren,
578 HeightResizePolicy = ResizePolicyType.FitToChildren,
580 Add(listBackgroundImage);
584 private void SetUpListContainer()
586 LinearLayout linear = new LinearLayout()
588 LinearOrientation = LinearLayout.Orientation.Vertical,
591 dropDownMenuFullList = new View()
594 Name = "DropDownMenuList",
595 WidthSpecification = LayoutParamPolicies.MatchParent,
596 HeightSpecification = LayoutParamPolicies.WrapContent,
600 scrollableBase = new ScrollableBase()
604 scrollableBase.Add(dropDownMenuFullList);
606 listBackgroundImage.Add(scrollableBase);
607 listBackgroundImage.Hide();
610 private View GetViewFromIndex(uint index)
612 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
614 return dropDownMenuFullList.GetChildAt(index);
622 private void SetListItemToSelected(DropDownItemView targetItemView)
624 // Set the DropDownItemView matching the targetItemView to selected.
625 if (selectedItemView!=targetItemView)
627 if (selectedItemView!=null)
629 // clear selection status of currently selected item view
630 selectedItemView.IsSelected = false;
632 // Set target item to selected
633 targetItemView.IsSelected = true;
634 selectedItemView = targetItemView;
638 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
640 PointStateType state = e.Touch.GetState(0);
641 DropDownItemView touchedView = sender as DropDownItemView;;
644 case PointStateType.Down:
645 if (touchedView != null && touchedView.BackgroundColorSelector != null)
647 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Pressed);
649 itemPressed = true; // if matched with a Up then a click event.
651 case PointStateType.Motion:
652 if (touchedView != null && touchedView.BackgroundColorSelector != null)
654 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Normal);
658 case PointStateType.Up:
659 if (touchedView != null && touchedView.BackgroundColorSelector != null)
661 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Selected);
663 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
666 Console.WriteLine("Tapped{0}", touchedView.Name);
667 SetListItemToSelected(touchedView);
668 button.Text = touchedView.Text;
670 listBackgroundImage.Hide();
680 private void UpdateSelectedItem(int index)
682 if (null == adapter) return;
683 if (null == dropDownMenuFullList) return;
684 if (selectedItemIndex != -1)
686 DropDownDataItem data = adapter.GetData(selectedItemIndex);
689 data.IsSelected = false;
691 DropDownItemView listItemView = dropDownMenuFullList.GetChildAt((uint)selectedItemIndex) as DropDownItemView;
692 data.IsSelected = false;
693 SetListItemToSelected(listItemView);
698 DropDownDataItem data = adapter.GetData(index);
701 data.IsSelected = true;
702 DropDownItemView listItemView = dropDownMenuFullList?.GetChildAt((uint)index) as DropDownItemView;
705 SetListItemToSelected(listItemView);
710 selectedItemIndex = index;
711 dropDownMenuFullList?.Layout?.RequestLayout();
714 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
717 listBackgroundImage.Show();
718 dropDownMenuFullList?.Layout?.RequestLayout();
719 listBackgroundImage.RaiseToTop();
724 #region ItemClickEventArgs
726 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
728 /// <since_tizen> 6 </since_tizen>
729 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
730 [EditorBrowsable(EditorBrowsableState.Never)]
731 public class ItemClickEventArgs : EventArgs
733 /// <summary> Clicked item index of DropDown's list </summary>
734 /// <since_tizen> 6 </since_tizen>
735 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
736 [EditorBrowsable(EditorBrowsableState.Never)]
738 /// <summary> Clicked item text string of DropDown's list </summary>
739 /// <since_tizen> 6 </since_tizen>
740 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
741 [EditorBrowsable(EditorBrowsableState.Never)]
746 #region DropDownDataItem
748 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
750 /// <since_tizen> 6 </since_tizen>
751 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
752 //[EditorBrowsable(EditorBrowsableState.Never)]
753 public class DropDownDataItem
755 private DropDownItemStyle itemDataStyle = new DropDownItemStyle();
758 /// Creates a new instance of a DropDownItemData.
760 /// <since_tizen> 6 </since_tizen>
761 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
762 [EditorBrowsable(EditorBrowsableState.Never)]
763 public DropDownDataItem()
769 /// Creates a new instance of a DropDownItemData with style.
771 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
772 /// <since_tizen> 6 </since_tizen>
773 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
774 [EditorBrowsable(EditorBrowsableState.Never)]
775 public DropDownDataItem(string style)
779 ViewStyle attributes = StyleManager.Instance.GetViewStyle(style);
780 if(attributes == null)
782 throw new InvalidOperationException($"There is no style {style}");
784 itemDataStyle = attributes as DropDownItemStyle;
790 /// Creates a new instance of a DropDownItemData with style.
792 /// <param name="style">Create DropDownItemData by style customized by user.</param>
793 /// <since_tizen> 6 </since_tizen>
794 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
795 [EditorBrowsable(EditorBrowsableState.Never)]
796 public DropDownDataItem(DropDownItemStyle style)
798 itemDataStyle.CopyFrom(style);
803 /// DropDown item size.
805 /// <since_tizen> 6 </since_tizen>
806 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
807 [EditorBrowsable(EditorBrowsableState.Never)]
812 return itemDataStyle.Size;
816 itemDataStyle.Size = value;
821 /// DropDown item background color selector.
823 /// <since_tizen> 6 </since_tizen>
824 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
825 [EditorBrowsable(EditorBrowsableState.Never)]
826 public Selector<Color> BackgroundColor
830 return itemDataStyle.BackgroundColor;
834 if (null == itemDataStyle?.BackgroundColor)
836 itemDataStyle.BackgroundColor = new Selector<Color>();
839 itemDataStyle.BackgroundColor.Clone(value);
844 /// DropDown item text string.
846 /// <since_tizen> 6 </since_tizen>
847 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
848 [EditorBrowsable(EditorBrowsableState.Never)]
853 return itemDataStyle.Text?.Text?.All;
857 if (null == itemDataStyle.Text.Text)
859 itemDataStyle.Text.Text = new Selector<string> { All = value };
863 itemDataStyle.Text.Text = value;
869 /// DropDown item text's point size.
871 /// <since_tizen> 6 </since_tizen>
872 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
873 [EditorBrowsable(EditorBrowsableState.Never)]
874 public float PointSize
878 return itemDataStyle.Text?.PointSize?.All ?? 0;
882 if (null == itemDataStyle.Text.PointSize)
884 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
888 itemDataStyle.Text.PointSize = value;
894 /// DropDown item text's font family.
896 /// <since_tizen> 6 </since_tizen>
897 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
898 [EditorBrowsable(EditorBrowsableState.Never)]
899 public string FontFamily
903 return itemDataStyle.Text.FontFamily?.All;
907 if (null == itemDataStyle.Text.FontFamily)
909 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
913 itemDataStyle.Text.FontFamily = value;
919 /// DropDown item text's position.
921 /// <since_tizen> 6 </since_tizen>
922 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
923 [EditorBrowsable(EditorBrowsableState.Never)]
924 public Position TextPosition
928 return itemDataStyle.Text?.Position;
932 itemDataStyle.Text.Position = value;
937 /// DropDown item's icon's resource url.
939 /// <since_tizen> 6 </since_tizen>
940 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
941 [EditorBrowsable(EditorBrowsableState.Never)]
942 public string IconResourceUrl
946 return itemDataStyle.Icon?.ResourceUrl?.All;
950 if (null == itemDataStyle.Icon.ResourceUrl)
952 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
956 itemDataStyle.Icon.ResourceUrl = value;
962 /// DropDown item's icon's size.
964 /// <since_tizen> 6 </since_tizen>
965 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
966 [EditorBrowsable(EditorBrowsableState.Never)]
971 return itemDataStyle.Icon?.Size;
975 itemDataStyle.Icon.Size = value;
980 /// DropDown item's icon's position.
982 /// <since_tizen> 6 </since_tizen>
983 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
984 [EditorBrowsable(EditorBrowsableState.Never)]
985 public Position IconPosition
989 return itemDataStyle.Icon.Position;
993 itemDataStyle.Icon.Position = value;
998 /// DropDown item's check image's resource url.
1000 /// <since_tizen> 6 </since_tizen>
1001 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1002 [EditorBrowsable(EditorBrowsableState.Never)]
1003 public string CheckImageResourceUrl
1007 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1011 if (null == itemDataStyle.CheckImage.ResourceUrl)
1013 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1017 itemDataStyle.CheckImage.ResourceUrl = value;
1023 /// DropDown item's check image's size.
1025 /// <since_tizen> 6 </since_tizen>
1026 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1027 [EditorBrowsable(EditorBrowsableState.Never)]
1028 public Size CheckImageSize
1032 return itemDataStyle.CheckImage?.Size;
1036 itemDataStyle.CheckImage.Size = value;
1041 /// DropDown item's check image's right space.
1043 /// <since_tizen> 6 </since_tizen>
1044 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1045 [EditorBrowsable(EditorBrowsableState.Never)]
1046 public int CheckImageGapToBoundary
1050 return itemDataStyle.CheckImageGapToBoundary;
1054 itemDataStyle.CheckImageGapToBoundary = value;
1059 /// Flag to decide DropDown item is selected or not.
1061 /// <since_tizen> 6 </since_tizen>
1062 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1063 [EditorBrowsable(EditorBrowsableState.Never)]
1064 public bool IsSelected
1068 return itemDataStyle.IsSelected;
1072 itemDataStyle.IsSelected = value;
1076 private void Initialize()
1078 if (itemDataStyle == null)
1080 throw new Exception("DropDownDataItem style parse error.");
1086 #region DropDownItemView
1087 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1088 [EditorBrowsable(EditorBrowsableState.Never)]
1089 internal class DropDownItemView : Control
1091 private TextLabel mText = null;
1092 private ImageView mIcon = null;
1093 private ImageView mCheck = null;
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 DropDownItemView() : base() { }
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)]
1101 public Selector<Color> BackgroundColorSelector { get; set; }
1103 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1104 [EditorBrowsable(EditorBrowsableState.Never)]
1109 return (null == mText) ? null : mText.Text;
1118 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1119 [EditorBrowsable(EditorBrowsableState.Never)]
1120 public string FontFamily
1124 return (null == mText) ? null : mText.FontFamily;
1129 mText.FontFamily = value;
1133 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1134 [EditorBrowsable(EditorBrowsableState.Never)]
1135 public float? PointSize
1139 return (null == mText) ? 0 : mText.PointSize;
1144 mText.PointSize = (float)value;
1148 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1149 [EditorBrowsable(EditorBrowsableState.Never)]
1150 public Color TextColor
1154 return (null == mText) ? null : mText.TextColor;
1159 mText.TextColor = value;
1163 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1164 [EditorBrowsable(EditorBrowsableState.Never)]
1165 public Position TextPosition
1169 return (null == mText) ? null : mText.Position;
1174 mText.Position = value;
1178 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1179 [EditorBrowsable(EditorBrowsableState.Never)]
1180 public string IconResourceUrl
1184 return (null == mIcon) ? null : mIcon.ResourceUrl;
1189 mIcon.ResourceUrl = value;
1193 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1194 [EditorBrowsable(EditorBrowsableState.Never)]
1195 public Size IconSize
1199 return (null == mIcon) ? null : mIcon.Size;
1208 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1209 [EditorBrowsable(EditorBrowsableState.Never)]
1210 public Position IconPosition
1214 return (null == mIcon) ? null : mIcon.Position;
1219 mIcon.Position = value;
1223 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1224 [EditorBrowsable(EditorBrowsableState.Never)]
1225 public string CheckResourceUrl
1229 return (null == mCheck) ? null : mCheck.ResourceUrl;
1234 mCheck.ResourceUrl = value;
1238 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1239 [EditorBrowsable(EditorBrowsableState.Never)]
1240 public Position CheckPosition
1244 return (null == mCheck) ? null : mCheck.Position;
1249 mCheck.Position = value;
1253 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1254 [EditorBrowsable(EditorBrowsableState.Never)]
1255 public Size CheckImageSize
1259 return (null == mCheck) ? null : mCheck.Size;
1264 mCheck.Size = value;
1268 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1269 [EditorBrowsable(EditorBrowsableState.Never)]
1270 public bool IsSelected
1274 return (null == mCheck) ? false : mCheck.Visibility;
1290 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1291 [EditorBrowsable(EditorBrowsableState.Never)]
1292 protected override void Dispose(DisposeTypes type)
1299 if (type == DisposeTypes.Explicit)
1325 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1326 [EditorBrowsable(EditorBrowsableState.Never)]
1327 protected override ViewStyle GetViewStyle()
1332 private void CreateIcon()
1336 mIcon = new ImageView()
1338 PositionUsesPivotPoint = true,
1339 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1340 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1346 private void CreateText()
1350 mText = new TextLabel()
1352 PositionUsesPivotPoint = true,
1353 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1354 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1355 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1356 HeightResizePolicy = ResizePolicyType.FillToParent,
1357 VerticalAlignment = VerticalAlignment.Center,
1358 HorizontalAlignment = HorizontalAlignment.Begin,
1364 private void CreateCheckImage()
1368 mCheck = new ImageView()
1370 PositionUsesPivotPoint = true,
1371 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1372 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1373 Name = "checkedImage",
1382 #region DropDownListBridge
1385 /// DropDownListBridge is bridge to connect item data and an item View.
1387 /// <since_tizen> 6 </since_tizen>
1388 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1389 [EditorBrowsable(EditorBrowsableState.Never)]
1390 public class DropDownListBridge
1392 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1394 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1397 /// Creates a new instance of a DropDownListBridge.
1399 /// <since_tizen> 6 </since_tizen>
1400 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1401 [EditorBrowsable(EditorBrowsableState.Never)]
1402 public DropDownListBridge() { }
1405 /// Insert data. The inserted data will be added to the special position by index automatically.
1407 /// <param name="position">Position index where will be inserted.</param>
1408 /// <param name="data">Item data which will apply to tab item view.</param>
1409 /// <since_tizen> 6 </since_tizen>
1410 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1411 [EditorBrowsable(EditorBrowsableState.Never)]
1412 public void InsertData(int position, DropDownDataItem data)
1416 position = itemDataList.Count;
1418 itemDataList.Insert(position, data);
1419 AdapterPurge = true;
1423 /// Remove data by position.
1425 /// <param name="position">Position index where will be removed.</param>
1426 /// <since_tizen> 6 </since_tizen>
1427 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1428 [EditorBrowsable(EditorBrowsableState.Never)]
1429 public void RemoveData(int position)
1431 itemDataList.RemoveAt(position);
1432 AdapterPurge = true;
1436 /// Get data by position.
1438 /// <param name="position">Position index where will be gotten.</param>
1439 /// <since_tizen> 6 </since_tizen>
1440 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1441 [EditorBrowsable(EditorBrowsableState.Never)]
1442 public DropDownDataItem GetData(int position)
1444 return itemDataList[position];
1448 /// Get view holder by view type.
1450 /// <since_tizen> 6 </since_tizen>
1451 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1452 [EditorBrowsable(EditorBrowsableState.Never)]
1453 public ViewHolder OnCreateViewHolder()
1455 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1461 /// Bind ViewHolder with View.
1463 /// <param name="holder">View holder.</param>
1464 /// <param name="position">Position index of source data.</param>
1465 /// <since_tizen> 6 </since_tizen>
1466 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1467 [EditorBrowsable(EditorBrowsableState.Never)]
1468 public void BindViewHolder(ViewHolder holder, int position)
1470 if (null == holder) return;
1471 DropDownDataItem listItemData = itemDataList[position];
1472 if(listItemData == null)
1476 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1477 listItemView.Name = "Item" + position;
1478 if (listItemData.Size != null)
1480 if (listItemData.Size.Width > 0)
1482 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1486 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1489 if (listItemData.Size.Height > 0)
1491 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1495 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1499 if (listItemView != null)
1501 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1502 if (listItemData.Text != null)
1504 listItemView.Text = listItemData.Text;
1505 listItemView.PointSize = listItemData.PointSize;
1506 listItemView.FontFamily = listItemData.FontFamily;
1507 listItemView.TextPosition = listItemData.TextPosition;
1510 if (listItemData.IconResourceUrl != null)
1512 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1513 listItemView.IconSize = listItemData.IconSize;
1514 if (listItemView.IconSize != null)
1516 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1520 if (listItemData.CheckImageResourceUrl != null)
1522 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1524 if (null != listItemData.CheckImageSize)
1526 listItemView.CheckImageSize = listItemData.CheckImageSize;
1529 if (listItemView.CheckImageSize != null)
1531 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1535 listItemView.IsSelected = listItemData.IsSelected;
1540 /// Destroy view holder, it can be override.
1542 /// <param name="holder">View holder.</param>
1543 /// <since_tizen> 6 </since_tizen>
1544 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1545 [EditorBrowsable(EditorBrowsableState.Never)]
1546 public void OnDestroyViewHolder(ViewHolder holder)
1548 if (null == holder) return;
1549 if (holder.ItemView != null)
1551 holder.ItemView.Dispose();
1556 /// Get item count, it can be override.
1558 /// <since_tizen> 6 </since_tizen>
1559 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1560 [EditorBrowsable(EditorBrowsableState.Never)]
1561 public int GetItemCount()
1563 return itemDataList.Count;
1572 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1574 /// <since_tizen> 6 </since_tizen>
1575 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1576 [EditorBrowsable(EditorBrowsableState.Never)]
1577 public class ViewHolder
1580 /// ViewHolder constructor.
1582 /// <param name="itemView">View</param>
1583 /// <since_tizen> 6 </since_tizen>
1584 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1585 [EditorBrowsable(EditorBrowsableState.Never)]
1586 public ViewHolder(View itemView)
1588 if (itemView == null)
1590 throw new ArgumentNullException("itemView may not be null");
1592 this.ItemView = itemView;
1596 /// Returns the view.
1598 /// <since_tizen> 6 </since_tizen>
1599 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1600 [EditorBrowsable(EditorBrowsableState.Never)]
1601 public View ItemView { get; }
1603 internal bool IsBound { get; set; }