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;
694 data.IsSelected = false;
696 SetListItemToSelected(listItemView);
701 DropDownDataItem data = adapter.GetData(index);
704 data.IsSelected = true;
705 DropDownItemView listItemView = dropDownMenuFullList?.GetChildAt((uint)index) as DropDownItemView;
708 SetListItemToSelected(listItemView);
713 selectedItemIndex = index;
714 dropDownMenuFullList?.Layout?.RequestLayout();
717 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
720 listBackgroundImage.Show();
721 dropDownMenuFullList?.Layout?.RequestLayout();
722 listBackgroundImage.RaiseToTop();
727 #region ItemClickEventArgs
729 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
731 /// <since_tizen> 6 </since_tizen>
732 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
733 [EditorBrowsable(EditorBrowsableState.Never)]
734 public class ItemClickEventArgs : EventArgs
736 /// <summary> Clicked item index of DropDown's list </summary>
737 /// <since_tizen> 6 </since_tizen>
738 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
739 [EditorBrowsable(EditorBrowsableState.Never)]
741 /// <summary> Clicked item text string of DropDown's list </summary>
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)]
749 #region DropDownDataItem
751 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
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)]
756 public class DropDownDataItem
758 private DropDownItemStyle itemDataStyle = new DropDownItemStyle();
761 /// Creates a new instance of a DropDownItemData.
763 /// <since_tizen> 6 </since_tizen>
764 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
765 [EditorBrowsable(EditorBrowsableState.Never)]
766 public DropDownDataItem()
772 /// Creates a new instance of a DropDownItemData with style.
774 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
775 /// <since_tizen> 6 </since_tizen>
776 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
777 [EditorBrowsable(EditorBrowsableState.Never)]
778 public DropDownDataItem(string style)
782 ViewStyle attributes = StyleManager.Instance.GetAttributes(style);
783 if(attributes == null)
785 throw new InvalidOperationException($"There is no style {style}");
787 itemDataStyle = attributes as DropDownItemStyle;
793 /// Creates a new instance of a DropDownItemData with style.
795 /// <param name="style">Create DropDownItemData by style customized by user.</param>
796 /// <since_tizen> 6 </since_tizen>
797 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
798 [EditorBrowsable(EditorBrowsableState.Never)]
799 public DropDownDataItem(DropDownItemStyle style)
801 itemDataStyle.CopyFrom(style);
806 /// DropDown item size.
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)]
815 return itemDataStyle.Size;
819 itemDataStyle.Size = value;
824 /// DropDown item background color selector.
826 /// <since_tizen> 6 </since_tizen>
827 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
828 [EditorBrowsable(EditorBrowsableState.Never)]
829 public Selector<Color> BackgroundColorSelector
833 return itemDataStyle.BackgroundColor;
837 if (null == itemDataStyle.BackgroundColor)
839 itemDataStyle.BackgroundColor = new Selector<Color>();
841 if (null != itemDataStyle.BackgroundColor)
843 itemDataStyle.BackgroundColor.Clone(value);
850 /// DropDown item text string.
852 /// <since_tizen> 6 </since_tizen>
853 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
854 [EditorBrowsable(EditorBrowsableState.Never)]
859 return itemDataStyle.Text?.Text?.All;
863 if (null == itemDataStyle.Text.Text)
865 itemDataStyle.Text.Text = new Selector<string> { All = value };
869 itemDataStyle.Text.Text = value;
875 /// DropDown item text's point size.
877 /// <since_tizen> 6 </since_tizen>
878 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
879 [EditorBrowsable(EditorBrowsableState.Never)]
880 public float PointSize
884 return itemDataStyle.Text?.PointSize?.All ?? 0;
888 if (null == itemDataStyle.Text.PointSize)
890 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
894 itemDataStyle.Text.PointSize = value;
900 /// DropDown item text's font family.
902 /// <since_tizen> 6 </since_tizen>
903 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
904 [EditorBrowsable(EditorBrowsableState.Never)]
905 public string FontFamily
909 return itemDataStyle.Text.FontFamily?.All;
913 if (null == itemDataStyle.Text.FontFamily)
915 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
919 itemDataStyle.Text.FontFamily = value;
925 /// DropDown item text's position.
927 /// <since_tizen> 6 </since_tizen>
928 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
929 [EditorBrowsable(EditorBrowsableState.Never)]
930 public Position TextPosition
934 return itemDataStyle.Text?.Position;
938 itemDataStyle.Text.Position = value;
943 /// DropDown item's icon's resource url.
945 /// <since_tizen> 6 </since_tizen>
946 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
947 [EditorBrowsable(EditorBrowsableState.Never)]
948 public string IconResourceUrl
952 return itemDataStyle.Icon?.ResourceUrl?.All;
956 if (null == itemDataStyle.Icon.ResourceUrl)
958 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
962 itemDataStyle.Icon.ResourceUrl = value;
968 /// DropDown item's icon's size.
970 /// <since_tizen> 6 </since_tizen>
971 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
972 [EditorBrowsable(EditorBrowsableState.Never)]
977 return itemDataStyle.Icon?.Size;
981 itemDataStyle.Icon.Size = value;
986 /// DropDown item's icon's position.
988 /// <since_tizen> 6 </since_tizen>
989 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
990 [EditorBrowsable(EditorBrowsableState.Never)]
991 public Position IconPosition
995 return itemDataStyle.Icon.Position;
999 itemDataStyle.Icon.Position = value;
1004 /// DropDown item's check image's resource url.
1006 /// <since_tizen> 6 </since_tizen>
1007 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1008 [EditorBrowsable(EditorBrowsableState.Never)]
1009 public string CheckImageResourceUrl
1013 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1017 if (null == itemDataStyle.CheckImage.ResourceUrl)
1019 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1023 itemDataStyle.CheckImage.ResourceUrl = value;
1029 /// DropDown item's check image's size.
1031 /// <since_tizen> 6 </since_tizen>
1032 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1033 [EditorBrowsable(EditorBrowsableState.Never)]
1034 public Size CheckImageSize
1038 return itemDataStyle.CheckImage?.Size;
1042 itemDataStyle.CheckImage.Size = value;
1047 /// DropDown item's check image's right space.
1049 /// <since_tizen> 6 </since_tizen>
1050 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1051 [EditorBrowsable(EditorBrowsableState.Never)]
1052 public int CheckImageGapToBoundary
1056 return itemDataStyle.CheckImageGapToBoundary;
1060 itemDataStyle.CheckImageGapToBoundary = value;
1065 /// Flag to decide DropDown item is selected or not.
1067 /// <since_tizen> 6 </since_tizen>
1068 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1069 [EditorBrowsable(EditorBrowsableState.Never)]
1070 public bool IsSelected
1074 return itemDataStyle.IsSelected;
1078 itemDataStyle.IsSelected = value;
1082 private void Initialize()
1084 if (itemDataStyle == null)
1086 throw new Exception("DropDownDataItem style parse error.");
1092 #region DropDownItemView
1093 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1094 [EditorBrowsable(EditorBrowsableState.Never)]
1095 internal class DropDownItemView : Control
1097 private TextLabel mText = null;
1098 private ImageView mIcon = null;
1099 private ImageView mCheck = null;
1101 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1102 [EditorBrowsable(EditorBrowsableState.Never)]
1103 public DropDownItemView() : base() { }
1105 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1106 [EditorBrowsable(EditorBrowsableState.Never)]
1107 public Selector<Color> BackgroundColorSelector { get; set; }
1109 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1110 [EditorBrowsable(EditorBrowsableState.Never)]
1128 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1129 [EditorBrowsable(EditorBrowsableState.Never)]
1130 public string FontFamily
1138 return mText.FontFamily;
1143 mText.FontFamily = value;
1147 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1148 [EditorBrowsable(EditorBrowsableState.Never)]
1149 public float? PointSize
1157 return mText.PointSize;
1162 mText.PointSize = (float)value;
1166 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1167 [EditorBrowsable(EditorBrowsableState.Never)]
1168 public Color TextColor
1176 return mText.TextColor;
1181 mText.TextColor = value;
1185 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1186 [EditorBrowsable(EditorBrowsableState.Never)]
1187 public Position TextPosition
1195 return mText.Position;
1200 mText.Position = value;
1204 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1205 [EditorBrowsable(EditorBrowsableState.Never)]
1206 public string IconResourceUrl
1214 return mIcon.ResourceUrl;
1219 mIcon.ResourceUrl = 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 Size IconSize
1242 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1243 [EditorBrowsable(EditorBrowsableState.Never)]
1244 public Position IconPosition
1252 return mIcon.Position;
1257 mIcon.Position = value;
1261 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1262 [EditorBrowsable(EditorBrowsableState.Never)]
1263 public string CheckResourceUrl
1271 return mCheck.ResourceUrl;
1276 mCheck.ResourceUrl = value;
1280 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1281 [EditorBrowsable(EditorBrowsableState.Never)]
1282 public Position CheckPosition
1290 return mCheck.Position;
1295 mCheck.Position = value;
1299 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1300 [EditorBrowsable(EditorBrowsableState.Never)]
1301 public Size CheckImageSize
1314 mCheck.Size = value;
1318 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1319 [EditorBrowsable(EditorBrowsableState.Never)]
1320 public bool IsSelected
1328 return mCheck.Visibility;
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 void Dispose(DisposeTypes type)
1353 if (type == DisposeTypes.Explicit)
1379 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1380 [EditorBrowsable(EditorBrowsableState.Never)]
1381 protected override ViewStyle GetViewStyle()
1386 private void CreateIcon()
1390 mIcon = new ImageView()
1392 PositionUsesPivotPoint = true,
1393 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1394 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1400 private void CreateText()
1404 mText = new TextLabel()
1406 PositionUsesPivotPoint = true,
1407 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1408 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1409 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1410 HeightResizePolicy = ResizePolicyType.FillToParent,
1411 VerticalAlignment = VerticalAlignment.Center,
1412 HorizontalAlignment = HorizontalAlignment.Begin,
1418 private void CreateCheckImage()
1422 mCheck = new ImageView()
1424 PositionUsesPivotPoint = true,
1425 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1426 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1427 Name = "checkedImage",
1436 #region DropDownListBridge
1439 /// DropDownListBridge is bridge to connect item data and an item View.
1441 /// <since_tizen> 6 </since_tizen>
1442 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1443 [EditorBrowsable(EditorBrowsableState.Never)]
1444 public class DropDownListBridge
1446 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1448 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1451 /// Creates a new instance of a DropDownListBridge.
1453 /// <since_tizen> 6 </since_tizen>
1454 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1455 [EditorBrowsable(EditorBrowsableState.Never)]
1456 public DropDownListBridge() { }
1459 /// Insert data. The inserted data will be added to the special position by index automatically.
1461 /// <param name="position">Position index where will be inserted.</param>
1462 /// <param name="data">Item data which will apply to tab item view.</param>
1463 /// <since_tizen> 6 </since_tizen>
1464 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1465 [EditorBrowsable(EditorBrowsableState.Never)]
1466 public void InsertData(int position, DropDownDataItem data)
1470 position = itemDataList.Count;
1472 itemDataList.Insert(position, data);
1473 AdapterPurge = true;
1477 /// Remove data by position.
1479 /// <param name="position">Position index where will be removed.</param>
1480 /// <since_tizen> 6 </since_tizen>
1481 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1482 [EditorBrowsable(EditorBrowsableState.Never)]
1483 public void RemoveData(int position)
1485 itemDataList.RemoveAt(position);
1486 AdapterPurge = true;
1490 /// Get data by position.
1492 /// <param name="position">Position index where will be gotten.</param>
1493 /// <since_tizen> 6 </since_tizen>
1494 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1495 [EditorBrowsable(EditorBrowsableState.Never)]
1496 public DropDownDataItem GetData(int position)
1498 return itemDataList[position];
1502 /// Get view holder by view type.
1504 /// <since_tizen> 6 </since_tizen>
1505 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1506 [EditorBrowsable(EditorBrowsableState.Never)]
1507 public ViewHolder OnCreateViewHolder()
1509 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1515 /// Bind ViewHolder with View.
1517 /// <param name="holder">View holder.</param>
1518 /// <param name="position">Position index of source data.</param>
1519 /// <since_tizen> 6 </since_tizen>
1520 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1521 [EditorBrowsable(EditorBrowsableState.Never)]
1522 public void BindViewHolder(ViewHolder holder, int position)
1524 DropDownDataItem listItemData = itemDataList[position];
1525 if(listItemData == null)
1529 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1530 listItemView.Name = "Item" + position;
1531 if (listItemData.Size != null)
1533 if (listItemData.Size.Width > 0)
1535 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1539 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1542 if (listItemData.Size.Height > 0)
1544 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1548 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1552 if (listItemView != null)
1554 listItemView.BackgroundColorSelector = listItemData.BackgroundColorSelector;
1555 if (listItemData.Text != null)
1557 listItemView.Text = listItemData.Text;
1558 listItemView.PointSize = listItemData.PointSize;
1559 listItemView.FontFamily = listItemData.FontFamily;
1560 listItemView.TextPosition = listItemData.TextPosition;
1563 if (listItemData.IconResourceUrl != null)
1565 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1566 listItemView.IconSize = listItemData.IconSize;
1567 if (listItemView.IconSize != null)
1569 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1573 if (listItemData.CheckImageResourceUrl != null)
1575 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1576 listItemView.CheckImageSize = listItemData.CheckImageSize;
1577 if (listItemView.CheckImageSize != null)
1579 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1583 listItemView.IsSelected = listItemData.IsSelected;
1588 /// Destroy view holder, it can be override.
1590 /// <param name="holder">View holder.</param>
1591 /// <since_tizen> 6 </since_tizen>
1592 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1593 [EditorBrowsable(EditorBrowsableState.Never)]
1594 public void OnDestroyViewHolder(ViewHolder holder)
1596 if (holder.ItemView != null)
1598 holder.ItemView.Dispose();
1603 /// Get item count, it can be override.
1605 /// <since_tizen> 6 </since_tizen>
1606 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1607 [EditorBrowsable(EditorBrowsableState.Never)]
1608 public int GetItemCount()
1610 return itemDataList.Count;
1619 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1621 /// <since_tizen> 6 </since_tizen>
1622 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1623 [EditorBrowsable(EditorBrowsableState.Never)]
1624 public class ViewHolder
1627 /// ViewHolder constructor.
1629 /// <param name="itemView">View</param>
1630 /// <since_tizen> 6 </since_tizen>
1631 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1632 [EditorBrowsable(EditorBrowsableState.Never)]
1633 public ViewHolder(View itemView)
1635 if (itemView == null)
1637 throw new ArgumentNullException("itemView may not be null");
1639 this.ItemView = itemView;
1643 /// Returns the view.
1645 /// <since_tizen> 6 </since_tizen>
1646 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1647 [EditorBrowsable(EditorBrowsableState.Never)]
1648 public View ItemView { get; }
1650 internal bool IsBound { get; set; }