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 < 0 || selectedItemIndex >= instance.adapter.GetItemCount())
61 instance.SetListItemToSelected((uint)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;
138 static DropDown() { }
141 /// Creates a new instance of a DropDown.
143 /// <since_tizen> 6 </since_tizen>
144 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public DropDown() : base() { }
149 /// Creates a new instance of a DropDown with style.
151 /// <param name="style">Create DropDown by special style defined in UX.</param>
152 /// <since_tizen> 6 </since_tizen>
153 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public DropDown(string style) : base(style) { }
158 /// Creates a new instance of a DropDown with style.
160 /// <param name="dropDownStyle">Create DropDown by style customized by user.</param>
161 /// <since_tizen> 6 </since_tizen>
162 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public DropDown(DropDownStyle dropDownStyle) : base(dropDownStyle)
169 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
171 /// <since_tizen> 6 </since_tizen>
172 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public delegate void ClickEventHandler<ClickEventArgs>(object sender, ClickEventArgs e);
177 /// An event for the item clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
179 /// <since_tizen> 6 </since_tizen>
180 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public event ClickEventHandler<ItemClickEventArgs> ItemClickEvent;
185 /// List position in relation to the main button.
187 /// <since_tizen> 6 </since_tizen>
188 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public enum ListOrientation
195 /// <since_tizen> 6 </since_tizen>
196 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
197 [EditorBrowsable(EditorBrowsableState.Never)]
202 /// <since_tizen> 6 </since_tizen>
203 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
204 [EditorBrowsable(EditorBrowsableState.Never)]
208 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public new DropDownStyle Style => ViewStyle as DropDownStyle;
213 /// Space between button text and button icon in DropDown.
215 /// <since_tizen> 6 </since_tizen>
216 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
217 public int SpaceBetweenButtonTextAndIcon
219 get => (int)GetValue(SpaceBetweenButtonTextAndIconProperty);
220 set => SetValue(SpaceBetweenButtonTextAndIconProperty, value);
224 /// List relative orientation in DropDown.
226 /// <since_tizen> 6 </since_tizen>
227 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
228 public ListOrientation ListRelativeOrientation
230 get => (ListOrientation)GetValue(ListRelativeOrientationProperty);
231 set => SetValue(ListRelativeOrientationProperty, value);
237 /// <since_tizen> 6 </since_tizen>
238 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
239 public Extents ListMargin
243 Extents tmp = (Extents)GetValue(ListMarginProperty);
244 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);
246 set => SetValue(ListMarginProperty, value);
250 /// Selected item index in list.
252 /// <since_tizen> 6 </since_tizen>
253 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
254 public int SelectedItemIndex
256 get => (int)GetValue(SelectedItemIndexProperty);
257 set => SetValue(SelectedItemIndexProperty, value);
261 /// List padding in DropDown.
263 /// <since_tizen> 6 </since_tizen>
264 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
265 public Extents ListPadding
269 Extents tmp = (Extents)GetValue(ListPaddingProperty);
270 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);
272 set => SetValue(ListPaddingProperty, value);
276 /// Add list item by item data. The added item will be added to end of all items automatically.
278 /// <param name="itemData">Item data which will apply to tab item view.</param>
279 /// <since_tizen> 6 </since_tizen>
280 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public void AddItem(DropDownDataItem itemData)
284 // Add item to adaptor, will be added to list via AddItemAt during OnUpdate()
285 int insertionPosition = adapter.GetItemCount();
286 adapter.InsertData(insertionPosition, itemData);
290 /// Delete list item by index.
292 /// <param name="index">Position index where will be deleted.</param>
293 /// <since_tizen> 6 </since_tizen>
294 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
295 [EditorBrowsable(EditorBrowsableState.Never)]
296 public void DeleteItem(int index)
298 if (index < 0 || index >= adapter?.GetItemCount()) return;
299 if (null == dropDownMenuFullList) return;
301 if (selectedItemIndex == index)
303 selectedItemIndex = -1;
305 else if(selectedItemIndex > index)
310 adapter?.RemoveData(index);
312 if(index < dropDownMenuFullList.ChildCount)
314 View childToRemove = dropDownMenuFullList.GetChildAt((uint)index);
317 childToRemove.TouchEvent -= ListItemTouchEvent;
318 dropDownMenuFullList.Remove(childToRemove);
319 dropDownMenuFullList?.Layout?.RequestLayout();
325 /// Insert list item by item data. The inserted item will be added to the special position by index automatically.
327 /// <param name="item">Item data which will apply to tab item view.</param>
328 /// <param name="index">Position index where will be inserted.</param>
329 /// <since_tizen> 6 </since_tizen>
330 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
331 [EditorBrowsable(EditorBrowsableState.Never)]
332 public void InsertItem(DropDownDataItem item, int index)
334 if (index < 0 || index >= adapter.GetItemCount())
339 if (selectedItemIndex >= index)
344 adapter.InsertData(index, item);
348 /// Add scroll bar to list.
350 /// <param name="scrollBar">Scroll bar defined by user which will be added to list.</param>
351 /// <since_tizen> 6 </since_tizen>
352 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public void AttachScrollBar(ScrollBar scrollBar)
356 if (scrollableBase == null)
360 Tizen.Log.Error("DropDown","Feature unsupported");
364 /// Detach scroll bar to list.
366 /// <since_tizen> 6 </since_tizen>
367 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
368 [EditorBrowsable(EditorBrowsableState.Never)]
369 public void DetachScrollBar()
371 if (scrollableBase == null)
375 Tizen.Log.Error("DropDown","Feature unsupported");
378 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
379 [EditorBrowsable(EditorBrowsableState.Never)]
380 public override void ApplyStyle(ViewStyle viewStyle)
382 base.ApplyStyle(viewStyle);
384 DropDownStyle dropDownStyle = viewStyle as DropDownStyle;
385 if (null != dropDownStyle)
391 CreateListBackgroundImage();
392 if (null == scrollableBase) // scrollableBase used to test of ListContainer Setup invoked already
394 SetUpListContainer();
396 button.ApplyStyle(dropDownStyle.Button);
397 headerText.ApplyStyle(dropDownStyle.HeaderText);
398 listBackgroundImage.ApplyStyle(dropDownStyle.ListBackgroundImage);
404 /// Update DropDown by style.
406 /// <since_tizen> 6 </since_tizen>
407 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
408 [EditorBrowsable(EditorBrowsableState.Never)]
409 protected void UpdateDropDown()
411 if (null == scrollableBase || null == listBackgroundImage || null == dropDownMenuFullList) return;
412 if (null == Style.ListBackgroundImage.Size) return;
413 // Resize and position scrolling list within the drop down list container. Can be used to position list in relation to the background image.
414 scrollableBase.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
415 scrollableBase.Position2D = new Position2D(listPadding.Start, listPadding.Top);
417 int listBackgroundImageX = 0;
418 int listBackgroundImageY = 0;
419 if (listRelativeOrientation == ListOrientation.Left)
421 listBackgroundImageX = (int)listMargin.Start;
422 listBackgroundImageY = (int)listMargin.Top;
424 else if (listRelativeOrientation == ListOrientation.Right)
426 listBackgroundImageX = -(int)listMargin.End;
427 listBackgroundImageY = (int)listMargin.Top;
429 listBackgroundImage.Position2D = new Position2D(listBackgroundImageX, listBackgroundImageY);
430 dropDownMenuFullList?.Layout?.RequestLayout();
436 protected override void OnUpdate()
438 float buttonTextWidth = 0;
439 if (null != buttonText)
441 buttonText.Text = Style.Button.Text.Text.All;
442 buttonText.PointSize = Style.Button.Text.PointSize?.GetValue(ControlState) ?? StyleManager.PointSizeNormal;
443 buttonTextWidth = buttonText.NaturalSize.Width;
445 float fitWidth = (Style.Button.Icon.Size?.Width ?? 48) + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
446 fitWidth += (button.IconPadding.Start + button.IconPadding.End);
447 button.Size.Width = Math.Max(button.Size.Width, fitWidth);
450 int numberOfItemsToAdd = adapter.GetItemCount();
452 if (adapter.AdapterPurge == true)
454 adapter.AdapterPurge = false;
455 for (int i = 0; i < numberOfItemsToAdd; i++)
457 AddItemAt(adapter.GetData(i), i);
460 // Set selection icon on View
461 if (selectedItemIndex > 0)
463 SetListItemToSelected((uint)selectedItemIndex, selectedItemView);
468 /// Dispose DropDown and all children on it.
470 /// <param name="type">Dispose type.</param>
471 /// <since_tizen> 6 </since_tizen>
472 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
473 [EditorBrowsable(EditorBrowsableState.Never)]
474 protected override void Dispose(DisposeTypes type)
481 if (type == DisposeTypes.Explicit)
483 Utility.Dispose(headerText);
484 Utility.Dispose(buttonText);
485 Utility.Dispose(button);
486 Utility.Dispose(scrollableBase);
487 Utility.Dispose(dropDownMenuFullList);
488 Utility.Dispose(listBackgroundImage);
495 /// Get DropDown style.
497 /// <returns>The default dropdown style.</returns>
498 /// <since_tizen> 6 </since_tizen>
499 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
500 [EditorBrowsable(EditorBrowsableState.Never)]
501 protected override ViewStyle GetViewStyle()
503 return new DropDownStyle();
506 private void AddItemAt(DropDownDataItem itemData,int index)
508 ViewHolder viewHolder = adapter.OnCreateViewHolder();
509 if (!viewHolder.IsBound)
511 adapter.BindViewHolder(viewHolder, index);
512 viewHolder.IsBound = true;
515 if (tapGestureDetector == null)
517 tapGestureDetector = new TapGestureDetector();
519 View view = viewHolder.ItemView;
520 view.ApplyStyle(itemData.itemDataStyle);
521 view.TouchEvent += ListItemTouchEvent;
522 dropDownMenuFullList.Add(view);
525 private void OnClickEvent(object sender, ItemClickEventArgs e)
527 ItemClickEvent?.Invoke(sender, e);
530 private void CreateHeaderText()
532 if (null == headerText)
534 headerText = new TextLabel()
536 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
537 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
538 HorizontalAlignment = HorizontalAlignment.Center,
539 VerticalAlignment = VerticalAlignment.Center,
540 ParentOrigin = NUI.ParentOrigin.Center,
541 PivotPoint = NUI.ParentOrigin.Center,
542 PositionUsesPivotPoint = true,
544 headerText.Name = "DropDownHeaderText";
549 private void CreateButtonText()
551 if (null == buttonText)
553 buttonText = new TextLabel();
557 private void CreateButton()
561 button = new Button()
563 ParentOrigin = NUI.ParentOrigin.CenterLeft,
564 PivotPoint = NUI.PivotPoint.CenterLeft,
565 PositionUsesPivotPoint = true,
566 HeightResizePolicy = ResizePolicyType.FitToChildren,
567 IconRelativeOrientation = Button.IconOrientation.Right,
569 button.Name = "DropDownButton";
570 button.ClickEvent += ButtonClickEvent;
575 private void CreateListBackgroundImage()
577 if (null == listBackgroundImage)
579 listBackgroundImage = new ImageView
581 Name = "ListBackgroundImage",
582 PositionUsesPivotPoint = true,
583 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
584 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
585 WidthResizePolicy = ResizePolicyType.FitToChildren,
586 HeightResizePolicy = ResizePolicyType.FitToChildren,
588 Add(listBackgroundImage);
592 private void SetUpListContainer()
594 LinearLayout linear = new LinearLayout()
596 LinearOrientation = LinearLayout.Orientation.Vertical,
599 dropDownMenuFullList = new View()
602 Name = "DropDownMenuList",
603 WidthSpecification = LayoutParamPolicies.MatchParent,
604 HeightSpecification = LayoutParamPolicies.WrapContent,
608 scrollableBase = new ScrollableBase()
612 scrollableBase.Add(dropDownMenuFullList);
614 listBackgroundImage.Add(scrollableBase);
615 listBackgroundImage.Hide();
618 private View GetViewFromIndex(uint index)
620 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
622 return dropDownMenuFullList.GetChildAt(index);
630 private void SetListItemToSelected(DropDownItemView view)
632 if (dropDownMenuFullList == null || view == null || view == selectedItemView)
637 uint newSelectedIndex = 0;
638 for (; newSelectedIndex < dropDownMenuFullList.ChildCount; newSelectedIndex++)
640 var itemView = dropDownMenuFullList.GetChildAt(newSelectedIndex) as DropDownItemView;
641 if (itemView == view)
643 SetListItemToSelected(newSelectedIndex, view);
649 private void SetListItemToSelected(uint index)
651 if (dropDownMenuFullList == null || index == selectedItemIndex)
656 SetListItemToSelected(index, GetViewFromIndex(index) as DropDownItemView);
659 private void SetListItemToSelected(uint index, DropDownItemView view)
666 if (selectedItemView != null)
668 selectedItemView.IsSelected = false;
669 selectedItemView.ControlState = ControlStates.Normal;
670 adapter.GetData(selectedItemIndex).IsSelected = false;
673 if (view == null || index >= dropDownMenuFullList.ChildCount)
675 selectedItemIndex = -1;
676 selectedItemView = null;
680 selectedItemIndex = (int)index;
681 selectedItemView = view;
682 selectedItemView.ControlState = ControlStates.Selected;
683 selectedItemView.IsSelected = true;
684 adapter.GetData(selectedItemIndex).IsSelected = true;
685 dropDownMenuFullList.Layout?.RequestLayout();
688 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
690 PointStateType state = e.Touch.GetState(0);
691 DropDownItemView touchedView = sender as DropDownItemView;;
694 case PointStateType.Down:
695 if (touchedView != null)
697 touchedView.ControlState = ControlStates.Pressed;
699 itemPressed = true; // if matched with a Up then a click event.
701 case PointStateType.Motion:
702 if (touchedView != null)
704 touchedView.ControlState = ControlStates.Normal;
708 case PointStateType.Up:
709 if (touchedView != null)
711 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
714 Console.WriteLine("Tapped{0}", touchedView.Name);
715 SetListItemToSelected(touchedView);
716 button.Text = touchedView.Text;
718 listBackgroundImage.Hide();
728 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
731 listBackgroundImage.Show();
732 dropDownMenuFullList?.Layout?.RequestLayout();
733 listBackgroundImage.RaiseToTop();
738 #region ItemClickEventArgs
740 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
742 /// <since_tizen> 6 </since_tizen>
743 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
744 [EditorBrowsable(EditorBrowsableState.Never)]
745 public class ItemClickEventArgs : EventArgs
747 /// <summary> Clicked item index of DropDown's list </summary>
748 /// <since_tizen> 6 </since_tizen>
749 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
750 [EditorBrowsable(EditorBrowsableState.Never)]
752 /// <summary> Clicked item text string of DropDown's list </summary>
753 /// <since_tizen> 6 </since_tizen>
754 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
755 [EditorBrowsable(EditorBrowsableState.Never)]
760 #region DropDownDataItem
762 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
764 /// <since_tizen> 6 </since_tizen>
765 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
766 //[EditorBrowsable(EditorBrowsableState.Never)]
767 public class DropDownDataItem
769 internal DropDownItemStyle itemDataStyle = new DropDownItemStyle();
772 /// Creates a new instance of a DropDownItemData.
774 /// <since_tizen> 6 </since_tizen>
775 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
776 [EditorBrowsable(EditorBrowsableState.Never)]
777 public DropDownDataItem()
779 itemDataStyle = (DropDownItemStyle)StyleManager.Instance.GetComponentStyle(this.GetType());
784 /// Creates a new instance of a DropDownItemData with style.
786 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
787 /// <since_tizen> 6 </since_tizen>
788 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
789 [EditorBrowsable(EditorBrowsableState.Never)]
790 public DropDownDataItem(string style)
794 ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(style);
795 if(viewStyle == null)
797 throw new InvalidOperationException($"There is no style {style}");
799 itemDataStyle = viewStyle as DropDownItemStyle;
805 /// Creates a new instance of a DropDownItemData with style.
807 /// <param name="style">Create DropDownItemData by style customized by user.</param>
808 /// <since_tizen> 6 </since_tizen>
809 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
810 [EditorBrowsable(EditorBrowsableState.Never)]
811 public DropDownDataItem(DropDownItemStyle style)
813 itemDataStyle.CopyFrom(style);
818 /// DropDown item size.
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)]
827 return itemDataStyle.Size;
831 itemDataStyle.Size = value;
836 /// DropDown item background color selector.
838 /// <since_tizen> 6 </since_tizen>
839 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
840 [EditorBrowsable(EditorBrowsableState.Never)]
841 public Selector<Color> BackgroundColor
845 return itemDataStyle.BackgroundColor;
849 if (null == itemDataStyle?.BackgroundColor)
851 itemDataStyle.BackgroundColor = new Selector<Color>();
854 itemDataStyle.BackgroundColor.Clone(value);
859 /// DropDown item text string.
861 /// <since_tizen> 6 </since_tizen>
862 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
863 [EditorBrowsable(EditorBrowsableState.Never)]
868 return itemDataStyle.Text?.Text?.All;
872 if (null == itemDataStyle.Text.Text)
874 itemDataStyle.Text.Text = new Selector<string> { All = value };
878 itemDataStyle.Text.Text = value;
884 /// DropDown item text's point size.
886 /// <since_tizen> 6 </since_tizen>
887 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
888 [EditorBrowsable(EditorBrowsableState.Never)]
889 public float PointSize
893 return itemDataStyle.Text?.PointSize?.All ?? 0;
897 if (null == itemDataStyle.Text.PointSize)
899 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
903 itemDataStyle.Text.PointSize = value;
909 /// DropDown item text's font family.
911 /// <since_tizen> 6 </since_tizen>
912 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
913 [EditorBrowsable(EditorBrowsableState.Never)]
914 public string FontFamily
918 return itemDataStyle.Text.FontFamily?.All;
922 if (null == itemDataStyle.Text.FontFamily)
924 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
928 itemDataStyle.Text.FontFamily = value;
934 /// DropDown item text's position.
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 Position TextPosition
943 return itemDataStyle.Text?.Position;
947 itemDataStyle.Text.Position = value;
952 /// DropDown item's icon's resource url.
954 /// <since_tizen> 6 </since_tizen>
955 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
956 [EditorBrowsable(EditorBrowsableState.Never)]
957 public string IconResourceUrl
961 return itemDataStyle.Icon?.ResourceUrl?.All;
965 if (null == itemDataStyle.Icon.ResourceUrl)
967 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
971 itemDataStyle.Icon.ResourceUrl = value;
977 /// DropDown item's icon's size.
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)]
986 return itemDataStyle.Icon?.Size;
990 itemDataStyle.Icon.Size = value;
995 /// DropDown item's icon's position.
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 Position IconPosition
1004 return itemDataStyle.Icon.Position;
1008 itemDataStyle.Icon.Position = value;
1013 /// DropDown item's check image's resource url.
1015 /// <since_tizen> 6 </since_tizen>
1016 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1017 [EditorBrowsable(EditorBrowsableState.Never)]
1018 public string CheckImageResourceUrl
1022 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1026 if (null == itemDataStyle.CheckImage.ResourceUrl)
1028 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1032 itemDataStyle.CheckImage.ResourceUrl = value;
1038 /// DropDown item's check image's size.
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 Size CheckImageSize
1047 return itemDataStyle.CheckImage?.Size;
1051 itemDataStyle.CheckImage.Size = value;
1056 /// DropDown item's check image's right space.
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 int CheckImageGapToBoundary
1065 return itemDataStyle.CheckImageGapToBoundary;
1069 itemDataStyle.CheckImageGapToBoundary = value;
1074 /// Flag to decide DropDown item is selected or not.
1076 /// <since_tizen> 6 </since_tizen>
1077 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1078 [EditorBrowsable(EditorBrowsableState.Never)]
1079 public bool IsSelected
1083 return itemDataStyle.IsSelected;
1087 itemDataStyle.IsSelected = value;
1091 private void Initialize()
1093 if (itemDataStyle == null)
1095 throw new Exception("DropDownDataItem style parse error.");
1101 #region DropDownItemView
1102 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1103 [EditorBrowsable(EditorBrowsableState.Never)]
1104 internal class DropDownItemView : Control
1106 private TextLabel mText = null;
1107 private ImageView mIcon = null;
1108 private ImageView mCheck = null;
1110 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1111 [EditorBrowsable(EditorBrowsableState.Never)]
1112 public DropDownItemView() : base() { }
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 Selector<Color> BackgroundColorSelector { get; set; }
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)]
1124 return (null == mText) ? null : mText.Text;
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 string FontFamily
1139 return (null == mText) ? null : mText.FontFamily;
1144 mText.FontFamily = 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 float? PointSize
1154 return (null == mText) ? 0 : mText.PointSize;
1159 mText.PointSize = (float)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 Color TextColor
1169 return (null == mText) ? null : mText.TextColor;
1174 mText.TextColor = 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 Position TextPosition
1184 return (null == mText) ? null : mText.Position;
1189 mText.Position = 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 string IconResourceUrl
1199 return (null == mIcon) ? null : mIcon.ResourceUrl;
1204 mIcon.ResourceUrl = value;
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 Size IconSize
1214 return (null == mIcon) ? null : mIcon.Size;
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 Position IconPosition
1229 return (null == mIcon) ? null : mIcon.Position;
1234 mIcon.Position = 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 string CheckResourceUrl
1244 return (null == mCheck) ? null : mCheck.ResourceUrl;
1249 mCheck.ResourceUrl = 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 Position CheckPosition
1259 return (null == mCheck) ? null : mCheck.Position;
1264 mCheck.Position = 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 Size CheckImageSize
1274 return (null == mCheck) ? null : mCheck.Size;
1279 mCheck.Size = value;
1283 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1284 [EditorBrowsable(EditorBrowsableState.Never)]
1285 public bool IsSelected
1289 return (null == mCheck) ? false : mCheck.Visibility;
1305 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1306 [EditorBrowsable(EditorBrowsableState.Never)]
1307 protected override void Dispose(DisposeTypes type)
1314 if (type == DisposeTypes.Explicit)
1341 /// Get DropDownItemView style.
1343 /// <returns>The empty.</returns>
1344 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1345 [EditorBrowsable(EditorBrowsableState.Never)]
1346 protected override ViewStyle GetViewStyle()
1351 private void CreateIcon()
1355 mIcon = new ImageView()
1357 PositionUsesPivotPoint = true,
1358 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1359 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1365 private void CreateText()
1369 mText = new TextLabel()
1371 PositionUsesPivotPoint = true,
1372 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1373 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1374 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1375 HeightResizePolicy = ResizePolicyType.FillToParent,
1376 VerticalAlignment = VerticalAlignment.Center,
1377 HorizontalAlignment = HorizontalAlignment.Begin,
1383 private void CreateCheckImage()
1387 mCheck = new ImageView()
1389 PositionUsesPivotPoint = true,
1390 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1391 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1392 Name = "checkedImage",
1401 #region DropDownListBridge
1404 /// DropDownListBridge is bridge to connect item data and an item View.
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 class DropDownListBridge
1411 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1413 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1416 /// Creates a new instance of a DropDownListBridge.
1418 /// <since_tizen> 6 </since_tizen>
1419 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1420 [EditorBrowsable(EditorBrowsableState.Never)]
1421 public DropDownListBridge() { }
1424 /// Insert data. The inserted data will be added to the special position by index automatically.
1426 /// <param name="position">Position index where will be inserted.</param>
1427 /// <param name="data">Item data which will apply to tab item view.</param>
1428 /// <since_tizen> 6 </since_tizen>
1429 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1430 [EditorBrowsable(EditorBrowsableState.Never)]
1431 public void InsertData(int position, DropDownDataItem data)
1435 position = itemDataList.Count;
1437 itemDataList.Insert(position, data);
1438 AdapterPurge = true;
1442 /// Remove data by position.
1444 /// <param name="position">Position index where will be removed.</param>
1445 /// <since_tizen> 6 </since_tizen>
1446 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1447 [EditorBrowsable(EditorBrowsableState.Never)]
1448 public void RemoveData(int position)
1450 itemDataList.RemoveAt(position);
1451 AdapterPurge = true;
1455 /// Get data by position.
1457 /// <param name="position">Position index where will be gotten.</param>
1458 /// <since_tizen> 6 </since_tizen>
1459 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1460 [EditorBrowsable(EditorBrowsableState.Never)]
1461 public DropDownDataItem GetData(int position)
1463 return itemDataList[position];
1467 /// Get view holder by view type.
1469 /// <since_tizen> 6 </since_tizen>
1470 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1471 [EditorBrowsable(EditorBrowsableState.Never)]
1472 public ViewHolder OnCreateViewHolder()
1474 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1480 /// Bind ViewHolder with View.
1482 /// <param name="holder">View holder.</param>
1483 /// <param name="position">Position index of source data.</param>
1484 /// <since_tizen> 6 </since_tizen>
1485 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1486 [EditorBrowsable(EditorBrowsableState.Never)]
1487 public void BindViewHolder(ViewHolder holder, int position)
1489 if (null == holder) return;
1490 DropDownDataItem listItemData = itemDataList[position];
1491 if(listItemData == null)
1495 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1496 listItemView.Name = "Item" + position;
1497 if (listItemData.Size != null)
1499 if (listItemData.Size.Width > 0)
1501 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1505 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1508 if (listItemData.Size.Height > 0)
1510 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1514 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1518 if (listItemView != null)
1520 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1521 if (listItemData.Text != null)
1523 listItemView.Text = listItemData.Text;
1524 listItemView.PointSize = listItemData.PointSize;
1525 listItemView.FontFamily = listItemData.FontFamily;
1526 listItemView.TextPosition = listItemData.TextPosition;
1529 if (listItemData.IconResourceUrl != null)
1531 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1532 listItemView.IconSize = listItemData.IconSize;
1533 if (listItemView.IconSize != null)
1535 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1539 if (listItemData.CheckImageResourceUrl != null)
1541 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1543 if (null != listItemData.CheckImageSize)
1545 listItemView.CheckImageSize = listItemData.CheckImageSize;
1548 if (listItemView.CheckImageSize != null)
1550 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1554 listItemView.IsSelected = listItemData.IsSelected;
1559 /// Destroy view holder, it can be override.
1561 /// <param name="holder">View holder.</param>
1562 /// <since_tizen> 6 </since_tizen>
1563 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1564 [EditorBrowsable(EditorBrowsableState.Never)]
1565 public void OnDestroyViewHolder(ViewHolder holder)
1567 if (null == holder) return;
1568 if (holder.ItemView != null)
1570 holder.ItemView.Dispose();
1575 /// Get item count, it can be override.
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 int GetItemCount()
1582 return itemDataList.Count;
1591 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
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 class ViewHolder
1599 /// ViewHolder constructor.
1601 /// <param name="itemView">View</param>
1602 /// <since_tizen> 6 </since_tizen>
1603 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1604 [EditorBrowsable(EditorBrowsableState.Never)]
1605 public ViewHolder(View itemView)
1607 if (itemView == null)
1609 throw new ArgumentNullException("itemView may not be null");
1611 this.ItemView = itemView;
1615 /// Returns the view.
1617 /// <since_tizen> 6 </since_tizen>
1618 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1619 [EditorBrowsable(EditorBrowsableState.Never)]
1620 public View ItemView { get; }
1622 internal bool IsBound { get; set; }