2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// DropDown is one kind of common component, a dropdown allows the user click dropdown button to choose one value from a list.
28 /// <since_tizen> 6 </since_tizen>
29 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class DropDown : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ListPaddingProperty = BindableProperty.Create("ListPadding", typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (DropDown)bindable;
40 instance.listPadding.CopyFrom((Extents)newValue);
41 instance.UpdateDropDown();
44 defaultValueCreator: (bindable) =>
46 var instance = (DropDown)bindable;
47 return instance.listPadding;
49 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public static readonly BindableProperty SelectedItemIndexProperty = BindableProperty.Create("SelectedItemIndex", typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
53 var instance = (DropDown)bindable;
56 int selectedItemIndex = (int)newValue;
57 if (selectedItemIndex == instance.selectedItemIndex || instance.adapter == null || selectedItemIndex >= instance.adapter.GetItemCount())
61 instance.UpdateSelectedItem(selectedItemIndex);
64 defaultValueCreator: (bindable) =>
66 var instance = (DropDown)bindable;
67 return instance.selectedItemIndex;
69 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static readonly BindableProperty ListMarginProperty = BindableProperty.Create("ListMargin", typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
73 var instance = (DropDown)bindable;
76 instance.listMargin.CopyFrom((Extents)newValue);
77 instance.UpdateDropDown();
80 defaultValueCreator: (bindable) =>
82 var instance = (DropDown)bindable;
83 return instance.listMargin;
85 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty ListRelativeOrientationProperty = BindableProperty.Create("ListRelativeOrientation", typeof(ListOrientation), typeof(DropDown), ListOrientation.Left, propertyChanged: (bindable, oldValue, newValue) =>
89 var instance = (DropDown)bindable;
92 instance.listRelativeOrientation = (ListOrientation)newValue;
93 instance.UpdateDropDown();
96 defaultValueCreator: (bindable) =>
98 var instance = (DropDown)bindable;
99 return instance.listRelativeOrientation;
101 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public static readonly BindableProperty SpaceBetweenButtonTextAndIconProperty = BindableProperty.Create("SpaceBetweenButtonTextAndIcon", typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
105 var instance = (DropDown)bindable;
106 if (newValue != null)
108 instance.spaceBetweenButtonTextAndIcon = (int)newValue;
111 defaultValueCreator: (bindable) =>
113 var instance = (DropDown)bindable;
114 return instance.spaceBetweenButtonTextAndIcon;
118 private Button button = null;
119 private TextLabel headerText = null;
120 private TextLabel buttonText = null;
121 private ImageView listBackgroundImage = null;
122 // Component that scrolls the child added to it.
123 private LayoutScroller layoutScroller = null;
124 // The LinearLayout container to house the items in the drop down list.
125 private View dropDownMenuFullList = null;
126 private DropDownListBridge adapter = new DropDownListBridge();
127 private DropDownItemView selectedItemView = null;
128 private TapGestureDetector tapGestureDetector = null;
130 private Extents listMargin = new Extents(0, 0, 0, 0);
131 private Extents listPadding = new Extents(0, 0, 0, 0);
132 private ListOrientation listRelativeOrientation = ListOrientation.Left;
133 private int selectedItemIndex = -1;
134 private int spaceBetweenButtonTextAndIcon = 0;
135 private bool itemPressed = false;
138 /// Creates a new instance of a DropDown.
140 /// <since_tizen> 6 </since_tizen>
141 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public DropDown() : base() { }
146 /// Creates a new instance of a DropDown with style.
148 /// <param name="style">Create DropDown by special style defined in UX.</param>
149 /// <since_tizen> 6 </since_tizen>
150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public DropDown(string style) : base(style) { }
155 /// Creates a new instance of a DropDown with attributes.
157 /// <param name="attributes">Create DropDown by attributes customized by user.</param>
158 /// <since_tizen> 6 </since_tizen>
159 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
160 [EditorBrowsable(EditorBrowsableState.Never)]
161 public DropDown(DropDownStyle attributes) : base(attributes)
166 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
168 /// <since_tizen> 6 </since_tizen>
169 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public delegate void ClickEventHandler<ClickEventArgs>(object sender, ClickEventArgs e);
174 /// An event for the item clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
176 /// <since_tizen> 6 </since_tizen>
177 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public event ClickEventHandler<ItemClickEventArgs> ItemClickEvent;
182 /// List position in relation to the main button.
184 /// <since_tizen> 6 </since_tizen>
185 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public enum ListOrientation
192 /// <since_tizen> 6 </since_tizen>
193 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
194 [EditorBrowsable(EditorBrowsableState.Never)]
199 /// <since_tizen> 6 </since_tizen>
200 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
201 [EditorBrowsable(EditorBrowsableState.Never)]
205 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public new DropDownStyle Style => ViewStyle as DropDownStyle;
210 /// Space between button text and button icon in DropDown.
212 /// <since_tizen> 6 </since_tizen>
213 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
214 public int SpaceBetweenButtonTextAndIcon
216 get => (int)GetValue(SpaceBetweenButtonTextAndIconProperty);
217 set => SetValue(SpaceBetweenButtonTextAndIconProperty, value);
221 /// List relative orientation in DropDown.
223 /// <since_tizen> 6 </since_tizen>
224 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
225 public ListOrientation ListRelativeOrientation
227 get => (ListOrientation)GetValue(ListRelativeOrientationProperty);
228 set => SetValue(ListRelativeOrientationProperty, value);
234 /// <since_tizen> 6 </since_tizen>
235 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
236 public Extents ListMargin
240 Extents tmp = (Extents)GetValue(ListMarginProperty);
241 return new Extents((ushort start, ushort end, ushort top, ushort bottom) => { ListMargin = new Extents(start, end, top, bottom); }, tmp.Start, tmp.End, tmp.Top, tmp.Bottom);
243 set => SetValue(ListMarginProperty, value);
247 /// Selected item index in list.
249 /// <since_tizen> 6 </since_tizen>
250 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
251 public int SelectedItemIndex
253 get => (int)GetValue(SelectedItemIndexProperty);
254 set => SetValue(SelectedItemIndexProperty, value);
258 /// List padding in DropDown.
260 /// <since_tizen> 6 </since_tizen>
261 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
262 public Extents ListPadding
266 Extents tmp = (Extents)GetValue(ListPaddingProperty);
267 return new Extents((ushort start, ushort end, ushort top, ushort bottom) => { ListPadding = new Extents(start, end, top, bottom); }, tmp.Start, tmp.End, tmp.Top, tmp.Bottom);
269 set => SetValue(ListPaddingProperty, value);
273 /// Add list item by item data. The added item will be added to end of all items automatically.
275 /// <param name="itemData">Item data which will apply to tab item view.</param>
276 /// <since_tizen> 6 </since_tizen>
277 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public void AddItem(DropDownDataItem itemData)
281 // Add item to adaptor, will be added to list via AddItemAt during OnUpdate()
282 int insertionPosition = adapter.GetItemCount();
283 adapter.InsertData(insertionPosition, itemData);
287 /// Delete list item by index.
289 /// <param name="index">Position index where will be deleted.</param>
290 /// <since_tizen> 6 </since_tizen>
291 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public void DeleteItem(int index)
295 if(index < 0 || index >= adapter.GetItemCount())
300 if (selectedItemIndex == index)
302 selectedItemIndex = -1;
304 else if(selectedItemIndex > index)
309 adapter.RemoveData(index);
311 if(index < dropDownMenuFullList.ChildCount)
313 View childToRemove = dropDownMenuFullList.GetChildAt((uint)index);
316 childToRemove.TouchEvent -= ListItemTouchEvent;
317 dropDownMenuFullList.Remove(childToRemove);
318 dropDownMenuFullList?.Layout?.RequestLayout();
324 /// Insert list item by item data. The inserted item will be added to the special position by index automatically.
326 /// <param name="item">Item data which will apply to tab item view.</param>
327 /// <param name="index">Position index where will be inserted.</param>
328 /// <since_tizen> 6 </since_tizen>
329 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
330 [EditorBrowsable(EditorBrowsableState.Never)]
331 public void InsertItem(DropDownDataItem item, int index)
333 if (index < 0 || index >= adapter.GetItemCount())
338 if (selectedItemIndex >= index)
343 adapter.InsertData(index, item);
347 /// Add scroll bar to list.
349 /// <param name="scrollBar">Scroll bar defined by user which will be added to list.</param>
350 /// <since_tizen> 6 </since_tizen>
351 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
352 [EditorBrowsable(EditorBrowsableState.Never)]
353 public void AttachScrollBar(ScrollBar scrollBar)
355 if (layoutScroller == null)
359 Tizen.Log.Error("DropDown","Feature unsupported");
363 /// Detach scroll bar to list.
365 /// <since_tizen> 6 </since_tizen>
366 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
367 [EditorBrowsable(EditorBrowsableState.Never)]
368 public void DetachScrollBar()
370 if (layoutScroller == null)
374 Tizen.Log.Error("DropDown","Feature unsupported");
377 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
378 [EditorBrowsable(EditorBrowsableState.Never)]
379 public override void ApplyStyle(ViewStyle viewStyle)
381 base.ApplyStyle(viewStyle);
383 DropDownStyle dropDownStyle = viewStyle as DropDownStyle;
384 if (null != dropDownStyle)
390 CreateListBackgroundImage();
391 if (null == layoutScroller) // layoutScroller used to test of ListContainer Setup invoked already
393 SetUpListContainer();
395 button.ApplyStyle(Style.Button);
396 headerText.ApplyStyle(Style.HeaderText);
397 listBackgroundImage.ApplyStyle(Style.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 == layoutScroller || 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 layoutScroller.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
413 layoutScroller.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)
425 if (dropDownMenuFullList.Size2D != null)
427 listWidth = dropDownMenuFullList.Size2D.Width;
429 listBackgroundImageX = Size2D.Width - listWidth - (int)listMargin.End;
430 listBackgroundImageY = (int)listMargin.Top;
432 listBackgroundImage.Position2D = new Position2D(listBackgroundImageX, listBackgroundImageY);
433 dropDownMenuFullList?.Layout?.RequestLayout();
436 protected override void OnUpdate()
439 float buttonTextWidth = 0;
440 if (null != buttonText)
442 buttonText.Text = Style.Button.Text.Text.All;
443 buttonText.PointSize = Style.Button.Text.PointSize?.All ?? 20;
444 buttonTextWidth = buttonText.NaturalSize.Width;
446 iconWidth = Style.Button.Icon.Size?.Width ?? 48;
447 button.SizeWidth = iconWidth + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
449 int numberOfItemsToAdd = adapter.GetItemCount();
451 if (adapter.AdapterPurge == true)
453 adapter.AdapterPurge = false;
454 for (int i = 0; i < numberOfItemsToAdd; i++)
456 AddItemAt(adapter.GetData(i), i);
459 // Set selection icon on View
460 UpdateSelectedItem(selectedItemIndex);
464 /// Dispose DropDown and all children on it.
466 /// <param name="type">Dispose type.</param>
467 /// <since_tizen> 6 </since_tizen>
468 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
469 [EditorBrowsable(EditorBrowsableState.Never)]
470 protected override void Dispose(DisposeTypes type)
477 if (type == DisposeTypes.Explicit)
479 Utility.Dispose(headerText);
480 Utility.Dispose(buttonText);
481 Utility.Dispose(button);
482 Utility.Dispose(layoutScroller);
483 Utility.Dispose(dropDownMenuFullList);
484 Utility.Dispose(listBackgroundImage);
491 /// Get DropDown attribues.
493 /// <since_tizen> 6 </since_tizen>
494 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
495 [EditorBrowsable(EditorBrowsableState.Never)]
496 protected override ViewStyle GetViewStyle()
498 return new DropDownStyle();
501 private void AddItemAt(DropDownDataItem itemData,int index)
503 ViewHolder viewHolder = adapter.OnCreateViewHolder();
504 if (!viewHolder.IsBound)
506 adapter.BindViewHolder(viewHolder, index);
507 viewHolder.IsBound = true;
510 if (tapGestureDetector == null)
512 tapGestureDetector = new TapGestureDetector();
514 View view = viewHolder.ItemView;
515 view.TouchEvent += ListItemTouchEvent;
516 dropDownMenuFullList.Add(view);
519 private void OnClickEvent(object sender, ItemClickEventArgs e)
521 ItemClickEvent?.Invoke(sender, e);
524 private void CreateHeaderText()
526 if (null == headerText)
528 headerText = new TextLabel()
530 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
531 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
532 HorizontalAlignment = HorizontalAlignment.Center,
533 VerticalAlignment = VerticalAlignment.Center,
534 ParentOrigin = NUI.ParentOrigin.Center,
535 PivotPoint = NUI.ParentOrigin.Center,
536 PositionUsesPivotPoint = true,
538 headerText.Name = "DropDownHeaderText";
543 private void CreateButtonText()
545 if (null == buttonText)
547 buttonText = new TextLabel();
551 private void CreateButton()
555 button = new Button()
557 ParentOrigin = NUI.ParentOrigin.CenterLeft,
558 PivotPoint = NUI.PivotPoint.CenterLeft,
559 PositionUsesPivotPoint = true,
560 HeightResizePolicy = ResizePolicyType.FitToChildren,
561 IconRelativeOrientation = Button.IconOrientation.Right,
563 button.Name = "DropDownButton";
564 button.ClickEvent += ButtonClickEvent;
569 private void CreateListBackgroundImage()
571 if (null == listBackgroundImage)
573 listBackgroundImage = new ImageView
575 Name = "ListBackgroundImage",
576 PositionUsesPivotPoint = true,
577 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
578 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
579 WidthResizePolicy = ResizePolicyType.FitToChildren,
580 HeightResizePolicy = ResizePolicyType.FitToChildren,
582 Add(listBackgroundImage);
586 private void SetUpListContainer()
588 LinearLayout linear = new LinearLayout()
590 LinearOrientation = LinearLayout.Orientation.Vertical,
593 dropDownMenuFullList = new View()
596 Name = "DropDownMenuList",
597 WidthSpecification = LayoutParamPolicies.MatchParent,
598 HeightSpecification = LayoutParamPolicies.WrapContent,
602 layoutScroller = new LayoutScroller()
604 Name = "LayoutScroller",
606 layoutScroller.AddLayoutToScroll(dropDownMenuFullList);
608 listBackgroundImage.Add(layoutScroller);
609 listBackgroundImage.Hide();
612 private View GetViewFromIndex(uint index)
614 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
616 return dropDownMenuFullList.GetChildAt(index);
624 private void SetListItemToSelected(DropDownItemView targetItemView)
626 // Set the DropDownItemView matching the targetItemView to selected.
627 if (selectedItemView!=targetItemView)
629 if (selectedItemView!=null)
631 // clear selection status of currently selected item view
632 selectedItemView.IsSelected = false;
634 // Set target item to selected
635 targetItemView.IsSelected = true;
636 selectedItemView = targetItemView;
640 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
642 PointStateType state = e.Touch.GetState(0);
643 DropDownItemView touchedView = sender as DropDownItemView;;
646 case PointStateType.Down:
647 if (touchedView != null && touchedView.BackgroundColorSelector != null)
649 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Pressed);
651 itemPressed = true; // if matched with a Up then a click event.
653 case PointStateType.Motion:
654 if (touchedView != null && touchedView.BackgroundColorSelector != null)
656 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Normal);
660 case PointStateType.Up:
661 if (touchedView != null && touchedView.BackgroundColorSelector != null)
663 touchedView.BackgroundColor = touchedView.BackgroundColorSelector.GetValue(ControlStates.Selected);
665 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
668 Console.WriteLine("Tapped{0}", touchedView.Name);
669 SetListItemToSelected(touchedView);
670 button.Text = touchedView.Text;
672 listBackgroundImage.Hide();
682 private void UpdateSelectedItem(int index)
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.GetAttributes(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> BackgroundColorSelector
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)]
1122 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1123 [EditorBrowsable(EditorBrowsableState.Never)]
1124 public string FontFamily
1132 return mText.FontFamily;
1137 mText.FontFamily = value;
1141 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1142 [EditorBrowsable(EditorBrowsableState.Never)]
1143 public float? PointSize
1151 return mText.PointSize;
1156 mText.PointSize = (float)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 Color TextColor
1170 return mText.TextColor;
1175 mText.TextColor = value;
1179 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1180 [EditorBrowsable(EditorBrowsableState.Never)]
1181 public Position TextPosition
1189 return mText.Position;
1194 mText.Position = value;
1198 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1199 [EditorBrowsable(EditorBrowsableState.Never)]
1200 public string IconResourceUrl
1208 return mIcon.ResourceUrl;
1213 mIcon.ResourceUrl = value;
1217 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1218 [EditorBrowsable(EditorBrowsableState.Never)]
1219 public Size IconSize
1236 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1237 [EditorBrowsable(EditorBrowsableState.Never)]
1238 public Position IconPosition
1246 return mIcon.Position;
1251 mIcon.Position = value;
1255 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1256 [EditorBrowsable(EditorBrowsableState.Never)]
1257 public string CheckResourceUrl
1265 return mCheck.ResourceUrl;
1270 mCheck.ResourceUrl = value;
1274 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1275 [EditorBrowsable(EditorBrowsableState.Never)]
1276 public Position CheckPosition
1284 return mCheck.Position;
1289 mCheck.Position = value;
1293 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1294 [EditorBrowsable(EditorBrowsableState.Never)]
1295 public Size CheckImageSize
1308 mCheck.Size = value;
1312 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1313 [EditorBrowsable(EditorBrowsableState.Never)]
1314 public bool IsSelected
1322 return mCheck.Visibility;
1338 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1339 [EditorBrowsable(EditorBrowsableState.Never)]
1340 protected override void Dispose(DisposeTypes type)
1347 if (type == DisposeTypes.Explicit)
1373 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1374 [EditorBrowsable(EditorBrowsableState.Never)]
1375 protected override ViewStyle GetViewStyle()
1380 private void CreateIcon()
1384 mIcon = new ImageView()
1386 PositionUsesPivotPoint = true,
1387 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1388 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1394 private void CreateText()
1398 mText = new TextLabel()
1400 PositionUsesPivotPoint = true,
1401 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1402 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1403 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1404 HeightResizePolicy = ResizePolicyType.FillToParent,
1405 VerticalAlignment = VerticalAlignment.Center,
1406 HorizontalAlignment = HorizontalAlignment.Begin,
1412 private void CreateCheckImage()
1416 mCheck = new ImageView()
1418 PositionUsesPivotPoint = true,
1419 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1420 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1421 Name = "checkedImage",
1430 #region DropDownListBridge
1433 /// DropDownListBridge is bridge to connect item data and an item View.
1435 /// <since_tizen> 6 </since_tizen>
1436 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1437 [EditorBrowsable(EditorBrowsableState.Never)]
1438 public class DropDownListBridge
1440 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1442 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1445 /// Creates a new instance of a DropDownListBridge.
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 DropDownListBridge() { }
1453 /// Insert data. The inserted data will be added to the special position by index automatically.
1455 /// <param name="position">Position index where will be inserted.</param>
1456 /// <param name="data">Item data which will apply to tab item view.</param>
1457 /// <since_tizen> 6 </since_tizen>
1458 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1459 [EditorBrowsable(EditorBrowsableState.Never)]
1460 public void InsertData(int position, DropDownDataItem data)
1464 position = itemDataList.Count;
1466 itemDataList.Insert(position, data);
1467 AdapterPurge = true;
1471 /// Remove data by position.
1473 /// <param name="position">Position index where will be removed.</param>
1474 /// <since_tizen> 6 </since_tizen>
1475 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1476 [EditorBrowsable(EditorBrowsableState.Never)]
1477 public void RemoveData(int position)
1479 itemDataList.RemoveAt(position);
1480 AdapterPurge = true;
1484 /// Get data by position.
1486 /// <param name="position">Position index where will be gotten.</param>
1487 /// <since_tizen> 6 </since_tizen>
1488 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1489 [EditorBrowsable(EditorBrowsableState.Never)]
1490 public DropDownDataItem GetData(int position)
1492 return itemDataList[position];
1496 /// Get view holder by view type.
1498 /// <since_tizen> 6 </since_tizen>
1499 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1500 [EditorBrowsable(EditorBrowsableState.Never)]
1501 public ViewHolder OnCreateViewHolder()
1503 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1509 /// Bind ViewHolder with View.
1511 /// <param name="holder">View holder.</param>
1512 /// <param name="position">Position index of source data.</param>
1513 /// <since_tizen> 6 </since_tizen>
1514 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1515 [EditorBrowsable(EditorBrowsableState.Never)]
1516 public void BindViewHolder(ViewHolder holder, int position)
1518 DropDownDataItem listItemData = itemDataList[position];
1519 if(listItemData == null)
1523 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1524 listItemView.Name = "Item" + position;
1525 if (listItemData.Size != null)
1527 if (listItemData.Size.Width > 0)
1529 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1533 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1536 if (listItemData.Size.Height > 0)
1538 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1542 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1546 if (listItemView != null)
1548 listItemView.BackgroundColorSelector = listItemData.BackgroundColorSelector;
1549 if (listItemData.Text != null)
1551 listItemView.Text = listItemData.Text;
1552 listItemView.PointSize = listItemData.PointSize;
1553 listItemView.FontFamily = listItemData.FontFamily;
1554 listItemView.TextPosition = listItemData.TextPosition;
1557 if (listItemData.IconResourceUrl != null)
1559 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1560 listItemView.IconSize = listItemData.IconSize;
1561 if (listItemView.IconSize != null)
1563 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1567 if (listItemData.CheckImageResourceUrl != null)
1569 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1570 listItemView.CheckImageSize = listItemData.CheckImageSize;
1571 if (listItemView.CheckImageSize != null)
1573 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1577 listItemView.IsSelected = listItemData.IsSelected;
1582 /// Destroy view holder, it can be override.
1584 /// <param name="holder">View holder.</param>
1585 /// <since_tizen> 6 </since_tizen>
1586 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1587 [EditorBrowsable(EditorBrowsableState.Never)]
1588 public void OnDestroyViewHolder(ViewHolder holder)
1590 if (holder.ItemView != null)
1592 holder.ItemView.Dispose();
1597 /// Get item count, it can be override.
1599 /// <since_tizen> 6 </since_tizen>
1600 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1601 [EditorBrowsable(EditorBrowsableState.Never)]
1602 public int GetItemCount()
1604 return itemDataList.Count;
1613 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1615 /// <since_tizen> 6 </since_tizen>
1616 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1617 [EditorBrowsable(EditorBrowsableState.Never)]
1618 public class ViewHolder
1621 /// ViewHolder constructor.
1623 /// <param name="itemView">View</param>
1624 /// <since_tizen> 6 </since_tizen>
1625 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1626 [EditorBrowsable(EditorBrowsableState.Never)]
1627 public ViewHolder(View itemView)
1629 if (itemView == null)
1631 throw new ArgumentNullException("itemView may not be null");
1633 this.ItemView = itemView;
1637 /// Returns the view.
1639 /// <since_tizen> 6 </since_tizen>
1640 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1641 [EditorBrowsable(EditorBrowsableState.Never)]
1642 public View ItemView { get; }
1644 internal bool IsBound { get; set; }