2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// DropDown is one kind of common component, a dropdown allows the user click dropdown button to choose one value from a list.
28 /// <since_tizen> 6 </since_tizen>
29 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class DropDown : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ListPaddingProperty = BindableProperty.Create(nameof(ListPadding), typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (DropDown)bindable;
40 instance.listPadding.CopyFrom((Extents)newValue);
41 instance.UpdateDropDown();
44 defaultValueCreator: (bindable) =>
46 var instance = (DropDown)bindable;
47 return instance.listPadding;
49 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public static readonly BindableProperty SelectedItemIndexProperty = BindableProperty.Create(nameof(SelectedItemIndex), typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
53 var instance = (DropDown)bindable;
56 int selectedItemIndex = (int)newValue;
57 if (selectedItemIndex == instance.selectedItemIndex || instance.adapter == null || selectedItemIndex >= instance.adapter.GetItemCount())
61 instance.UpdateSelectedItem(selectedItemIndex);
64 defaultValueCreator: (bindable) =>
66 var instance = (DropDown)bindable;
67 return instance.selectedItemIndex;
69 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static readonly BindableProperty ListMarginProperty = BindableProperty.Create(nameof(ListMargin), typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
73 var instance = (DropDown)bindable;
76 instance.listMargin.CopyFrom((Extents)newValue);
77 instance.UpdateDropDown();
80 defaultValueCreator: (bindable) =>
82 var instance = (DropDown)bindable;
83 return instance.listMargin;
85 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty ListRelativeOrientationProperty = BindableProperty.Create(nameof(ListRelativeOrientation), typeof(ListOrientation), typeof(DropDown), ListOrientation.Left, propertyChanged: (bindable, oldValue, newValue) =>
89 var instance = (DropDown)bindable;
92 instance.listRelativeOrientation = (ListOrientation)newValue;
93 instance.UpdateDropDown();
96 defaultValueCreator: (bindable) =>
98 var instance = (DropDown)bindable;
99 return instance.listRelativeOrientation;
101 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public static readonly BindableProperty SpaceBetweenButtonTextAndIconProperty = BindableProperty.Create(nameof(SpaceBetweenButtonTextAndIcon), typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
105 var instance = (DropDown)bindable;
106 if (newValue != null)
108 instance.spaceBetweenButtonTextAndIcon = (int)newValue;
111 defaultValueCreator: (bindable) =>
113 var instance = (DropDown)bindable;
114 return instance.spaceBetweenButtonTextAndIcon;
118 private Button button = null;
119 private TextLabel headerText = null;
120 private TextLabel buttonText = null;
121 private ImageView listBackgroundImage = null;
122 // Component that scrolls the child added to it.
123 private ScrollableBase scrollableBase = null;
125 // The LinearLayout container to house the items in the drop down list.
126 private View dropDownMenuFullList = null;
127 private DropDownListBridge adapter = new DropDownListBridge();
128 private DropDownItemView selectedItemView = null;
129 private TapGestureDetector tapGestureDetector = null;
131 private Extents listMargin = new Extents(0, 0, 0, 0);
132 private Extents listPadding = new Extents(0, 0, 0, 0);
133 private ListOrientation listRelativeOrientation = ListOrientation.Left;
134 private int selectedItemIndex = -1;
135 private int spaceBetweenButtonTextAndIcon = 0;
136 private bool itemPressed = false;
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 attributes.
160 /// <param name="attributes">Create DropDown by attributes 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 attributes) : base(attributes)
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 attributes.
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()
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(scrollableBase);
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 scrollableBase = new ScrollableBase()
606 scrollableBase.Add(dropDownMenuFullList);
608 listBackgroundImage.Add(scrollableBase);
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 (null == adapter) return;
685 if (null == dropDownMenuFullList) return;
686 if (selectedItemIndex != -1)
688 DropDownDataItem data = adapter.GetData(selectedItemIndex);
691 data.IsSelected = false;
693 DropDownItemView listItemView = dropDownMenuFullList.GetChildAt((uint)selectedItemIndex) as DropDownItemView;
695 SetListItemToSelected(listItemView);
700 DropDownDataItem data = adapter.GetData(index);
703 data.IsSelected = true;
704 DropDownItemView listItemView = dropDownMenuFullList?.GetChildAt((uint)index) as DropDownItemView;
707 SetListItemToSelected(listItemView);
712 selectedItemIndex = index;
713 dropDownMenuFullList?.Layout?.RequestLayout();
716 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
719 listBackgroundImage.Show();
720 dropDownMenuFullList?.Layout?.RequestLayout();
721 listBackgroundImage.RaiseToTop();
726 #region ItemClickEventArgs
728 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
730 /// <since_tizen> 6 </since_tizen>
731 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
732 [EditorBrowsable(EditorBrowsableState.Never)]
733 public class ItemClickEventArgs : EventArgs
735 /// <summary> Clicked item index of DropDown's list </summary>
736 /// <since_tizen> 6 </since_tizen>
737 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
738 [EditorBrowsable(EditorBrowsableState.Never)]
740 /// <summary> Clicked item text string of DropDown's list </summary>
741 /// <since_tizen> 6 </since_tizen>
742 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
743 [EditorBrowsable(EditorBrowsableState.Never)]
748 #region DropDownDataItem
750 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
752 /// <since_tizen> 6 </since_tizen>
753 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
754 //[EditorBrowsable(EditorBrowsableState.Never)]
755 public class DropDownDataItem
757 private DropDownItemStyle itemDataStyle = new DropDownItemStyle();
760 /// Creates a new instance of a DropDownItemData.
762 /// <since_tizen> 6 </since_tizen>
763 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
764 [EditorBrowsable(EditorBrowsableState.Never)]
765 public DropDownDataItem()
771 /// Creates a new instance of a DropDownItemData with style.
773 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
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(string style)
781 ViewStyle attributes = StyleManager.Instance.GetViewStyle(style);
782 if(attributes == null)
784 throw new InvalidOperationException($"There is no style {style}");
786 itemDataStyle = attributes as DropDownItemStyle;
792 /// Creates a new instance of a DropDownItemData with style.
794 /// <param name="style">Create DropDownItemData by style customized by user.</param>
795 /// <since_tizen> 6 </since_tizen>
796 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
797 [EditorBrowsable(EditorBrowsableState.Never)]
798 public DropDownDataItem(DropDownItemStyle style)
800 itemDataStyle.CopyFrom(style);
805 /// DropDown item size.
807 /// <since_tizen> 6 </since_tizen>
808 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
809 [EditorBrowsable(EditorBrowsableState.Never)]
814 return itemDataStyle.Size;
818 itemDataStyle.Size = value;
823 /// DropDown item background color selector.
825 /// <since_tizen> 6 </since_tizen>
826 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
827 [EditorBrowsable(EditorBrowsableState.Never)]
828 public Selector<Color> BackgroundColor
832 return itemDataStyle.BackgroundColor;
836 if (null == itemDataStyle?.BackgroundColor)
838 itemDataStyle.BackgroundColor = new Selector<Color>();
841 itemDataStyle.BackgroundColor.Clone(value);
846 /// DropDown item text string.
848 /// <since_tizen> 6 </since_tizen>
849 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
850 [EditorBrowsable(EditorBrowsableState.Never)]
855 return itemDataStyle.Text?.Text?.All;
859 if (null == itemDataStyle.Text.Text)
861 itemDataStyle.Text.Text = new Selector<string> { All = value };
865 itemDataStyle.Text.Text = value;
871 /// DropDown item text's point size.
873 /// <since_tizen> 6 </since_tizen>
874 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
875 [EditorBrowsable(EditorBrowsableState.Never)]
876 public float PointSize
880 return itemDataStyle.Text?.PointSize?.All ?? 0;
884 if (null == itemDataStyle.Text.PointSize)
886 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
890 itemDataStyle.Text.PointSize = value;
896 /// DropDown item text's font family.
898 /// <since_tizen> 6 </since_tizen>
899 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
900 [EditorBrowsable(EditorBrowsableState.Never)]
901 public string FontFamily
905 return itemDataStyle.Text.FontFamily?.All;
909 if (null == itemDataStyle.Text.FontFamily)
911 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
915 itemDataStyle.Text.FontFamily = value;
921 /// DropDown item text's position.
923 /// <since_tizen> 6 </since_tizen>
924 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
925 [EditorBrowsable(EditorBrowsableState.Never)]
926 public Position TextPosition
930 return itemDataStyle.Text?.Position;
934 itemDataStyle.Text.Position = value;
939 /// DropDown item's icon's resource url.
941 /// <since_tizen> 6 </since_tizen>
942 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
943 [EditorBrowsable(EditorBrowsableState.Never)]
944 public string IconResourceUrl
948 return itemDataStyle.Icon?.ResourceUrl?.All;
952 if (null == itemDataStyle.Icon.ResourceUrl)
954 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
958 itemDataStyle.Icon.ResourceUrl = value;
964 /// DropDown item's icon's size.
966 /// <since_tizen> 6 </since_tizen>
967 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
968 [EditorBrowsable(EditorBrowsableState.Never)]
973 return itemDataStyle.Icon?.Size;
977 itemDataStyle.Icon.Size = value;
982 /// DropDown item's icon's position.
984 /// <since_tizen> 6 </since_tizen>
985 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
986 [EditorBrowsable(EditorBrowsableState.Never)]
987 public Position IconPosition
991 return itemDataStyle.Icon.Position;
995 itemDataStyle.Icon.Position = value;
1000 /// DropDown item's check image's resource url.
1002 /// <since_tizen> 6 </since_tizen>
1003 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1004 [EditorBrowsable(EditorBrowsableState.Never)]
1005 public string CheckImageResourceUrl
1009 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1013 if (null == itemDataStyle.CheckImage.ResourceUrl)
1015 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1019 itemDataStyle.CheckImage.ResourceUrl = value;
1025 /// DropDown item's check image's size.
1027 /// <since_tizen> 6 </since_tizen>
1028 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1029 [EditorBrowsable(EditorBrowsableState.Never)]
1030 public Size CheckImageSize
1034 return itemDataStyle.CheckImage?.Size;
1038 itemDataStyle.CheckImage.Size = value;
1043 /// DropDown item's check image's right space.
1045 /// <since_tizen> 6 </since_tizen>
1046 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1047 [EditorBrowsable(EditorBrowsableState.Never)]
1048 public int CheckImageGapToBoundary
1052 return itemDataStyle.CheckImageGapToBoundary;
1056 itemDataStyle.CheckImageGapToBoundary = value;
1061 /// Flag to decide DropDown item is selected or not.
1063 /// <since_tizen> 6 </since_tizen>
1064 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1065 [EditorBrowsable(EditorBrowsableState.Never)]
1066 public bool IsSelected
1070 return itemDataStyle.IsSelected;
1074 itemDataStyle.IsSelected = value;
1078 private void Initialize()
1080 if (itemDataStyle == null)
1082 throw new Exception("DropDownDataItem style parse error.");
1088 #region DropDownItemView
1089 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1090 [EditorBrowsable(EditorBrowsableState.Never)]
1091 internal class DropDownItemView : Control
1093 private TextLabel mText = null;
1094 private ImageView mIcon = null;
1095 private ImageView mCheck = null;
1097 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1098 [EditorBrowsable(EditorBrowsableState.Never)]
1099 public DropDownItemView() : base() { }
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 Selector<Color> BackgroundColorSelector { get; set; }
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)]
1111 return (null == mText) ? null : mText.Text;
1120 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1121 [EditorBrowsable(EditorBrowsableState.Never)]
1122 public string FontFamily
1126 return (null == mText) ? null : mText.FontFamily;
1131 mText.FontFamily = value;
1135 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1136 [EditorBrowsable(EditorBrowsableState.Never)]
1137 public float? PointSize
1141 return (null == mText) ? 0 : mText.PointSize;
1146 mText.PointSize = (float)value;
1150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1151 [EditorBrowsable(EditorBrowsableState.Never)]
1152 public Color TextColor
1156 return (null == mText) ? null : mText.TextColor;
1161 mText.TextColor = value;
1165 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1166 [EditorBrowsable(EditorBrowsableState.Never)]
1167 public Position TextPosition
1171 return (null == mText) ? null : mText.Position;
1176 mText.Position = value;
1180 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1181 [EditorBrowsable(EditorBrowsableState.Never)]
1182 public string IconResourceUrl
1186 return (null == mIcon) ? null : mIcon.ResourceUrl;
1191 mIcon.ResourceUrl = value;
1195 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1196 [EditorBrowsable(EditorBrowsableState.Never)]
1197 public Size IconSize
1201 return (null == mIcon) ? null : mIcon.Size;
1210 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1211 [EditorBrowsable(EditorBrowsableState.Never)]
1212 public Position IconPosition
1216 return (null == mIcon) ? null : mIcon.Position;
1221 mIcon.Position = value;
1225 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1226 [EditorBrowsable(EditorBrowsableState.Never)]
1227 public string CheckResourceUrl
1231 return (null == mCheck) ? null : mCheck.ResourceUrl;
1236 mCheck.ResourceUrl = value;
1240 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1241 [EditorBrowsable(EditorBrowsableState.Never)]
1242 public Position CheckPosition
1246 return (null == mCheck) ? null : mCheck.Position;
1251 mCheck.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 Size CheckImageSize
1261 return (null == mCheck) ? null : mCheck.Size;
1266 mCheck.Size = value;
1270 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1271 [EditorBrowsable(EditorBrowsableState.Never)]
1272 public bool IsSelected
1276 return (null == mCheck) ? false : mCheck.Visibility;
1292 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1293 [EditorBrowsable(EditorBrowsableState.Never)]
1294 protected override void Dispose(DisposeTypes type)
1301 if (type == DisposeTypes.Explicit)
1327 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1328 [EditorBrowsable(EditorBrowsableState.Never)]
1329 protected override ViewStyle GetViewStyle()
1334 private void CreateIcon()
1338 mIcon = new ImageView()
1340 PositionUsesPivotPoint = true,
1341 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1342 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1348 private void CreateText()
1352 mText = new TextLabel()
1354 PositionUsesPivotPoint = true,
1355 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1356 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1357 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1358 HeightResizePolicy = ResizePolicyType.FillToParent,
1359 VerticalAlignment = VerticalAlignment.Center,
1360 HorizontalAlignment = HorizontalAlignment.Begin,
1366 private void CreateCheckImage()
1370 mCheck = new ImageView()
1372 PositionUsesPivotPoint = true,
1373 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1374 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1375 Name = "checkedImage",
1384 #region DropDownListBridge
1387 /// DropDownListBridge is bridge to connect item data and an item View.
1389 /// <since_tizen> 6 </since_tizen>
1390 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1391 [EditorBrowsable(EditorBrowsableState.Never)]
1392 public class DropDownListBridge
1394 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1396 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1399 /// Creates a new instance of a DropDownListBridge.
1401 /// <since_tizen> 6 </since_tizen>
1402 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1403 [EditorBrowsable(EditorBrowsableState.Never)]
1404 public DropDownListBridge() { }
1407 /// Insert data. The inserted data will be added to the special position by index automatically.
1409 /// <param name="position">Position index where will be inserted.</param>
1410 /// <param name="data">Item data which will apply to tab item view.</param>
1411 /// <since_tizen> 6 </since_tizen>
1412 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1413 [EditorBrowsable(EditorBrowsableState.Never)]
1414 public void InsertData(int position, DropDownDataItem data)
1418 position = itemDataList.Count;
1420 itemDataList.Insert(position, data);
1421 AdapterPurge = true;
1425 /// Remove data by position.
1427 /// <param name="position">Position index where will be removed.</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 RemoveData(int position)
1433 itemDataList.RemoveAt(position);
1434 AdapterPurge = true;
1438 /// Get data by position.
1440 /// <param name="position">Position index where will be gotten.</param>
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 DropDownDataItem GetData(int position)
1446 return itemDataList[position];
1450 /// Get view holder by view type.
1452 /// <since_tizen> 6 </since_tizen>
1453 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1454 [EditorBrowsable(EditorBrowsableState.Never)]
1455 public ViewHolder OnCreateViewHolder()
1457 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1463 /// Bind ViewHolder with View.
1465 /// <param name="holder">View holder.</param>
1466 /// <param name="position">Position index of source data.</param>
1467 /// <since_tizen> 6 </since_tizen>
1468 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1469 [EditorBrowsable(EditorBrowsableState.Never)]
1470 public void BindViewHolder(ViewHolder holder, int position)
1472 if (null == holder) return;
1473 DropDownDataItem listItemData = itemDataList[position];
1474 if(listItemData == null)
1478 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1479 listItemView.Name = "Item" + position;
1480 if (listItemData.Size != null)
1482 if (listItemData.Size.Width > 0)
1484 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1488 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1491 if (listItemData.Size.Height > 0)
1493 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1497 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1501 if (listItemView != null)
1503 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1504 if (listItemData.Text != null)
1506 listItemView.Text = listItemData.Text;
1507 listItemView.PointSize = listItemData.PointSize;
1508 listItemView.FontFamily = listItemData.FontFamily;
1509 listItemView.TextPosition = listItemData.TextPosition;
1512 if (listItemData.IconResourceUrl != null)
1514 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1515 listItemView.IconSize = listItemData.IconSize;
1516 if (listItemView.IconSize != null)
1518 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1522 if (listItemData.CheckImageResourceUrl != null)
1524 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1526 if (null != listItemData.CheckImageSize)
1528 listItemView.CheckImageSize = listItemData.CheckImageSize;
1531 if (listItemView.CheckImageSize != null)
1533 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1537 listItemView.IsSelected = listItemData.IsSelected;
1542 /// Destroy view holder, it can be override.
1544 /// <param name="holder">View holder.</param>
1545 /// <since_tizen> 6 </since_tizen>
1546 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1547 [EditorBrowsable(EditorBrowsableState.Never)]
1548 public void OnDestroyViewHolder(ViewHolder holder)
1550 if (null == holder) return;
1551 if (holder.ItemView != null)
1553 holder.ItemView.Dispose();
1558 /// Get item count, it can be override.
1560 /// <since_tizen> 6 </since_tizen>
1561 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1562 [EditorBrowsable(EditorBrowsableState.Never)]
1563 public int GetItemCount()
1565 return itemDataList.Count;
1574 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1576 /// <since_tizen> 6 </since_tizen>
1577 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1578 [EditorBrowsable(EditorBrowsableState.Never)]
1579 public class ViewHolder
1582 /// ViewHolder constructor.
1584 /// <param name="itemView">View</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 ViewHolder(View itemView)
1590 if (itemView == null)
1592 throw new ArgumentNullException("itemView may not be null");
1594 this.ItemView = itemView;
1598 /// Returns the view.
1600 /// <since_tizen> 6 </since_tizen>
1601 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1602 [EditorBrowsable(EditorBrowsableState.Never)]
1603 public View ItemView { get; }
1605 internal bool IsBound { get; set; }