2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// DropDown is one kind of common component, a dropdown allows the user click dropdown button to choose one value from a list.
28 /// <since_tizen> 6 </since_tizen>
29 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class DropDown : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ListPaddingProperty = BindableProperty.Create(nameof(ListPadding), typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (DropDown)bindable;
40 instance.listPadding.CopyFrom((Extents)newValue);
41 instance.UpdateDropDown();
44 defaultValueCreator: (bindable) =>
46 var instance = (DropDown)bindable;
47 return instance.listPadding;
49 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public static readonly BindableProperty SelectedItemIndexProperty = BindableProperty.Create(nameof(SelectedItemIndex), typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
53 var instance = (DropDown)bindable;
56 int selectedItemIndex = (int)newValue;
57 if (selectedItemIndex == instance.selectedItemIndex || instance.adapter == null || selectedItemIndex < 0 || selectedItemIndex >= instance.adapter.GetItemCount())
61 instance.SetListItemToSelected((uint)selectedItemIndex);
64 defaultValueCreator: (bindable) =>
66 var instance = (DropDown)bindable;
67 return instance.selectedItemIndex;
69 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static readonly BindableProperty ListMarginProperty = BindableProperty.Create(nameof(ListMargin), typeof(Extents), typeof(DropDown), null, propertyChanged: (bindable, oldValue, newValue) =>
73 var instance = (DropDown)bindable;
76 instance.listMargin.CopyFrom((Extents)newValue);
77 instance.UpdateDropDown();
80 defaultValueCreator: (bindable) =>
82 var instance = (DropDown)bindable;
83 return instance.listMargin;
85 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty ListRelativeOrientationProperty = BindableProperty.Create(nameof(ListRelativeOrientation), typeof(ListOrientation), typeof(DropDown), ListOrientation.Left, propertyChanged: (bindable, oldValue, newValue) =>
89 var instance = (DropDown)bindable;
92 instance.listRelativeOrientation = (ListOrientation)newValue;
93 instance.UpdateDropDown();
96 defaultValueCreator: (bindable) =>
98 var instance = (DropDown)bindable;
99 return instance.listRelativeOrientation;
101 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public static readonly BindableProperty SpaceBetweenButtonTextAndIconProperty = BindableProperty.Create(nameof(SpaceBetweenButtonTextAndIcon), typeof(int), typeof(DropDown), 0, propertyChanged: (bindable, oldValue, newValue) =>
105 var instance = (DropDown)bindable;
106 if (newValue != null)
108 instance.spaceBetweenButtonTextAndIcon = (int)newValue;
111 defaultValueCreator: (bindable) =>
113 var instance = (DropDown)bindable;
114 return instance.spaceBetweenButtonTextAndIcon;
118 private Button button = null;
119 private TextLabel headerText = null;
120 private TextLabel buttonText = null;
121 private ImageView listBackgroundImage = null;
122 // Component that scrolls the child added to it.
123 private ScrollableBase scrollableBase = null;
125 // The LinearLayout container to house the items in the drop down list.
126 private View dropDownMenuFullList = null;
127 private DropDownListBridge adapter = new DropDownListBridge();
128 private DropDownItemView selectedItemView = null;
129 private TapGestureDetector tapGestureDetector = null;
131 private Extents listMargin = new Extents(0, 0, 0, 0);
132 private Extents listPadding = new Extents(0, 0, 0, 0);
133 private ListOrientation listRelativeOrientation = ListOrientation.Left;
134 private int selectedItemIndex = -1;
135 private int spaceBetweenButtonTextAndIcon = 0;
136 private bool itemPressed = false;
138 static DropDown() { }
141 /// Creates a new instance of a DropDown.
143 /// <since_tizen> 6 </since_tizen>
144 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public DropDown() : base() { }
149 /// Creates a new instance of a DropDown with style.
151 /// <param name="style">Create DropDown by special style defined in UX.</param>
152 /// <since_tizen> 6 </since_tizen>
153 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public DropDown(string style) : base(style) { }
158 /// Creates a new instance of a DropDown with style.
160 /// <param name="dropDownStyle">Create DropDown by style customized by user.</param>
161 /// <since_tizen> 6 </since_tizen>
162 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public DropDown(DropDownStyle dropDownStyle) : base(dropDownStyle)
169 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
171 /// <since_tizen> 6 </since_tizen>
172 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public delegate void ClickEventHandler<ClickEventArgs>(object sender, ClickEventArgs e);
177 /// An event for the item clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
179 /// <since_tizen> 6 </since_tizen>
180 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public event ClickEventHandler<ItemClickEventArgs> ItemClickEvent;
185 /// List position in relation to the main button.
187 /// <since_tizen> 6 </since_tizen>
188 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public enum ListOrientation
195 /// <since_tizen> 6 </since_tizen>
196 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
197 [EditorBrowsable(EditorBrowsableState.Never)]
202 /// <since_tizen> 6 </since_tizen>
203 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
204 [EditorBrowsable(EditorBrowsableState.Never)]
209 /// Get or set header text.
211 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
212 [EditorBrowsable(EditorBrowsableState.Never)]
213 public TextLabel HeaderText
217 if (null == headerText)
219 headerText = new TextLabel()
221 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
222 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
223 HorizontalAlignment = HorizontalAlignment.Center,
224 VerticalAlignment = VerticalAlignment.Center,
225 ParentOrigin = NUI.ParentOrigin.Center,
226 PivotPoint = NUI.ParentOrigin.Center,
227 PositionUsesPivotPoint = true,
228 Name = "DropDownHeaderText"
241 /// Get or set button.
243 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
244 [EditorBrowsable(EditorBrowsableState.Never)]
251 button = new Button()
253 ParentOrigin = NUI.ParentOrigin.CenterLeft,
254 PivotPoint = NUI.PivotPoint.CenterLeft,
255 PositionUsesPivotPoint = true,
256 HeightResizePolicy = ResizePolicyType.FitToChildren,
257 IconRelativeOrientation = Button.IconOrientation.Right,
258 Name = "DropDownButton"
260 button.ClickEvent += ButtonClickEvent;
263 if (null == buttonText)
265 buttonText = new TextLabel();
277 /// Get or set the background image of list.
279 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public ImageView ListBackgroundImage
285 if (null == listBackgroundImage)
287 listBackgroundImage = new ImageView()
289 Name = "ListBackgroundImage",
290 PositionUsesPivotPoint = true,
291 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
292 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
293 WidthResizePolicy = ResizePolicyType.FitToChildren,
294 HeightResizePolicy = ResizePolicyType.FitToChildren,
296 Add(listBackgroundImage);
298 if (null == scrollableBase) // scrollableBase used to test of ListContainer Setup invoked already
300 SetUpListContainer();
303 return listBackgroundImage;
307 listBackgroundImage = value;
312 /// Return a copied Style instance of DropDown
315 /// It returns copied Style instance and changing it does not effect to the DropDown.
316 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
318 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 //public new DropDownStyle Style
324 // return new DropDownStyle(ViewStyle as DropDownStyle);
327 public new DropDownStyle Style => ViewStyle as DropDownStyle;
330 /// Space between button text and button icon in DropDown.
332 /// <since_tizen> 6 </since_tizen>
333 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
334 public int SpaceBetweenButtonTextAndIcon
336 get => (int)GetValue(SpaceBetweenButtonTextAndIconProperty);
337 set => SetValue(SpaceBetweenButtonTextAndIconProperty, value);
341 /// List relative orientation in DropDown.
343 /// <since_tizen> 6 </since_tizen>
344 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
345 public ListOrientation ListRelativeOrientation
347 get => (ListOrientation)GetValue(ListRelativeOrientationProperty);
348 set => SetValue(ListRelativeOrientationProperty, value);
354 /// <since_tizen> 6 </since_tizen>
355 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
356 public Extents ListMargin
360 Extents tmp = (Extents)GetValue(ListMarginProperty);
361 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);
363 set => SetValue(ListMarginProperty, value);
367 /// Selected item index in list.
369 /// <since_tizen> 6 </since_tizen>
370 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
371 public int SelectedItemIndex
373 get => (int)GetValue(SelectedItemIndexProperty);
374 set => SetValue(SelectedItemIndexProperty, value);
378 /// List padding in DropDown.
380 /// <since_tizen> 6 </since_tizen>
381 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
382 public Extents ListPadding
386 Extents tmp = (Extents)GetValue(ListPaddingProperty);
387 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);
389 set => SetValue(ListPaddingProperty, value);
393 /// Add list item by item data. The added item will be added to end of all items automatically.
395 /// <param name="itemData">Item data which will apply to tab item view.</param>
396 /// <since_tizen> 6 </since_tizen>
397 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
398 [EditorBrowsable(EditorBrowsableState.Never)]
399 public void AddItem(DropDownDataItem itemData)
401 // Add item to adaptor, will be added to list via AddItemAt during OnUpdate()
402 int insertionPosition = adapter.GetItemCount();
403 adapter.InsertData(insertionPosition, itemData);
407 /// Delete list item by index.
409 /// <param name="index">Position index where will be deleted.</param>
410 /// <since_tizen> 6 </since_tizen>
411 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
412 [EditorBrowsable(EditorBrowsableState.Never)]
413 public void DeleteItem(int index)
415 if (index < 0 || index >= adapter?.GetItemCount()) return;
416 if (null == dropDownMenuFullList) return;
418 if (selectedItemIndex == index)
420 selectedItemIndex = -1;
422 else if(selectedItemIndex > index)
427 adapter?.RemoveData(index);
429 if(index < dropDownMenuFullList.ChildCount)
431 View childToRemove = dropDownMenuFullList.GetChildAt((uint)index);
434 childToRemove.TouchEvent -= ListItemTouchEvent;
435 dropDownMenuFullList.Remove(childToRemove);
436 dropDownMenuFullList?.Layout?.RequestLayout();
442 /// Insert list item by item data. The inserted item will be added to the special position by index automatically.
444 /// <param name="item">Item data which will apply to tab item view.</param>
445 /// <param name="index">Position index where will be inserted.</param>
446 /// <since_tizen> 6 </since_tizen>
447 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
448 [EditorBrowsable(EditorBrowsableState.Never)]
449 public void InsertItem(DropDownDataItem item, int index)
451 if (index < 0 || index >= adapter.GetItemCount())
456 if (selectedItemIndex >= index)
461 adapter.InsertData(index, item);
465 /// Add scroll bar to list.
467 /// <param name="scrollBar">Scroll bar defined by user which will be added to list.</param>
468 /// <since_tizen> 6 </since_tizen>
469 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
470 [EditorBrowsable(EditorBrowsableState.Never)]
471 public void AttachScrollBar(ScrollBar scrollBar)
473 if (scrollableBase == null)
477 Tizen.Log.Error("DropDown","Feature unsupported");
481 /// Detach scroll bar to list.
483 /// <since_tizen> 6 </since_tizen>
484 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
485 [EditorBrowsable(EditorBrowsableState.Never)]
486 public void DetachScrollBar()
488 if (scrollableBase == null)
492 Tizen.Log.Error("DropDown","Feature unsupported");
495 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 public override void ApplyStyle(ViewStyle viewStyle)
499 base.ApplyStyle(viewStyle);
501 DropDownStyle dropDownStyle = viewStyle as DropDownStyle;
502 if (null != dropDownStyle)
504 if (null != dropDownStyle.Button)
506 Button.ApplyStyle(dropDownStyle.Button);
508 if (null != dropDownStyle.HeaderText)
510 HeaderText.ApplyStyle(dropDownStyle.HeaderText);
512 if (null != dropDownStyle.ListBackgroundImage)
514 ListBackgroundImage.ApplyStyle(dropDownStyle.ListBackgroundImage);
521 /// Update DropDown by style.
523 /// <since_tizen> 6 </since_tizen>
524 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
525 [EditorBrowsable(EditorBrowsableState.Never)]
526 protected void UpdateDropDown()
528 if (null == scrollableBase || null == listBackgroundImage || null == dropDownMenuFullList) return;
529 if (null == Style.ListBackgroundImage.Size) return;
530 // Resize and position scrolling list within the drop down list container. Can be used to position list in relation to the background image.
531 scrollableBase.Size = Style.ListBackgroundImage.Size - new Size((listPadding.Start + listPadding.End), (listPadding.Top + listPadding.Bottom), 0);
532 scrollableBase.Position2D = new Position2D(listPadding.Start, listPadding.Top);
534 int listBackgroundImageX = 0;
535 int listBackgroundImageY = 0;
536 if (listRelativeOrientation == ListOrientation.Left)
538 listBackgroundImageX = (int)listMargin.Start;
539 listBackgroundImageY = (int)listMargin.Top;
541 else if (listRelativeOrientation == ListOrientation.Right)
543 listBackgroundImageX = -(int)listMargin.End;
544 listBackgroundImageY = (int)listMargin.Top;
546 listBackgroundImage.Position2D = new Position2D(listBackgroundImageX, listBackgroundImageY);
547 dropDownMenuFullList?.Layout?.RequestLayout();
553 protected override void OnUpdate()
555 float buttonTextWidth = 0;
556 if (null != buttonText)
558 buttonText.Text = Style.Button.Text.Text.All;
559 buttonText.PointSize = Style.Button.Text.PointSize?.GetValue(ControlState) ?? StyleManager.PointSizeNormal;
560 buttonTextWidth = buttonText.NaturalSize.Width;
562 float fitWidth = (Style.Button.Icon.Size?.Width ?? 48) + Style.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
563 fitWidth += (button.IconPadding.Start + button.IconPadding.End);
564 button.Size.Width = Math.Max(button.Size.Width, fitWidth);
567 int numberOfItemsToAdd = adapter.GetItemCount();
569 if (adapter.AdapterPurge == true)
571 adapter.AdapterPurge = false;
572 for (int i = 0; i < numberOfItemsToAdd; i++)
574 AddItemAt(adapter.GetData(i), i);
577 // Set selection icon on View
578 if (selectedItemIndex > 0)
580 SetListItemToSelected((uint)selectedItemIndex, selectedItemView);
585 /// Dispose DropDown and all children on it.
587 /// <param name="type">Dispose type.</param>
588 /// <since_tizen> 6 </since_tizen>
589 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
590 [EditorBrowsable(EditorBrowsableState.Never)]
591 protected override void Dispose(DisposeTypes type)
598 if (type == DisposeTypes.Explicit)
600 Utility.Dispose(headerText);
601 Utility.Dispose(buttonText);
602 Utility.Dispose(button);
603 Utility.Dispose(scrollableBase);
604 Utility.Dispose(dropDownMenuFullList);
605 Utility.Dispose(listBackgroundImage);
612 /// Get DropDown style.
614 /// <returns>The default dropdown style.</returns>
615 /// <since_tizen> 6 </since_tizen>
616 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
617 [EditorBrowsable(EditorBrowsableState.Never)]
618 protected override ViewStyle CreateViewStyle()
620 return new DropDownStyle();
623 private void AddItemAt(DropDownDataItem itemData,int index)
625 ViewHolder viewHolder = adapter.OnCreateViewHolder();
626 if (!viewHolder.IsBound)
628 adapter.BindViewHolder(viewHolder, index);
629 viewHolder.IsBound = true;
632 if (tapGestureDetector == null)
634 tapGestureDetector = new TapGestureDetector();
636 View view = viewHolder.ItemView;
637 view.ApplyStyle(itemData.itemDataStyle);
638 view.TouchEvent += ListItemTouchEvent;
639 dropDownMenuFullList.Add(view);
642 private void OnClickEvent(object sender, ItemClickEventArgs e)
644 ItemClickEvent?.Invoke(sender, e);
647 private void CreateButtonText()
649 if (null == buttonText)
651 buttonText = new TextLabel();
655 private void CreateButton()
659 button = new Button()
661 ParentOrigin = NUI.ParentOrigin.CenterLeft,
662 PivotPoint = NUI.PivotPoint.CenterLeft,
663 PositionUsesPivotPoint = true,
664 HeightResizePolicy = ResizePolicyType.FitToChildren,
665 IconRelativeOrientation = Button.IconOrientation.Right,
667 button.Name = "DropDownButton";
668 button.ClickEvent += ButtonClickEvent;
673 private void SetUpListContainer()
675 LinearLayout linear = new LinearLayout()
677 LinearOrientation = LinearLayout.Orientation.Vertical,
680 dropDownMenuFullList = new View()
683 Name = "DropDownMenuList",
684 WidthSpecification = LayoutParamPolicies.MatchParent,
685 HeightSpecification = LayoutParamPolicies.WrapContent,
689 scrollableBase = new ScrollableBase()
693 scrollableBase.Add(dropDownMenuFullList);
695 listBackgroundImage.Add(scrollableBase);
696 listBackgroundImage.Hide();
699 private View GetViewFromIndex(uint index)
701 if ((index < dropDownMenuFullList.ChildCount) && (index >=0) )
703 return dropDownMenuFullList.GetChildAt(index);
711 private void SetListItemToSelected(DropDownItemView view)
713 if (dropDownMenuFullList == null || view == null || view == selectedItemView)
718 uint newSelectedIndex = 0;
719 for (; newSelectedIndex < dropDownMenuFullList.ChildCount; newSelectedIndex++)
721 var itemView = dropDownMenuFullList.GetChildAt(newSelectedIndex) as DropDownItemView;
722 if (itemView == view)
724 SetListItemToSelected(newSelectedIndex, view);
730 private void SetListItemToSelected(uint index)
732 if (dropDownMenuFullList == null || index == selectedItemIndex)
737 SetListItemToSelected(index, GetViewFromIndex(index) as DropDownItemView);
740 private void SetListItemToSelected(uint index, DropDownItemView view)
747 if (selectedItemView != null)
749 selectedItemView.IsSelected = false;
750 selectedItemView.ControlState = ControlStates.Normal;
751 adapter.GetData(selectedItemIndex).IsSelected = false;
754 if (view == null || index >= dropDownMenuFullList.ChildCount)
756 selectedItemIndex = -1;
757 selectedItemView = null;
761 selectedItemIndex = (int)index;
762 selectedItemView = view;
763 selectedItemView.ControlState = ControlStates.Selected;
764 selectedItemView.IsSelected = true;
765 adapter.GetData(selectedItemIndex).IsSelected = true;
766 dropDownMenuFullList.Layout?.RequestLayout();
769 private bool ListItemTouchEvent(object sender, TouchEventArgs e)
771 PointStateType state = e.Touch.GetState(0);
772 DropDownItemView touchedView = sender as DropDownItemView;;
775 case PointStateType.Down:
776 if (touchedView != null)
778 touchedView.ControlState = ControlStates.Pressed;
780 itemPressed = true; // if matched with a Up then a click event.
782 case PointStateType.Motion:
783 if (touchedView != null)
785 touchedView.ControlState = ControlStates.Normal;
789 case PointStateType.Up:
790 if (touchedView != null)
792 if (itemPressed) // if Down was previously sent without motion (Scrolling) in-between then a clicked event occurred.
795 Console.WriteLine("Tapped{0}", touchedView.Name);
796 SetListItemToSelected(touchedView);
797 button.Text = touchedView.Text;
799 listBackgroundImage.Hide();
809 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
812 listBackgroundImage.Show();
813 dropDownMenuFullList?.Layout?.RequestLayout();
814 listBackgroundImage.RaiseToTop();
819 #region ItemClickEventArgs
821 /// ItemClickEventArgs is a class to record item click event arguments which will sent to user.
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 class ItemClickEventArgs : EventArgs
828 /// <summary> Clicked item index of DropDown's list </summary>
829 /// <since_tizen> 6 </since_tizen>
830 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
831 [EditorBrowsable(EditorBrowsableState.Never)]
832 public int Index { get; set; }
833 /// <summary> Clicked item text string of DropDown's list </summary>
834 /// <since_tizen> 6 </since_tizen>
835 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
836 [EditorBrowsable(EditorBrowsableState.Never)]
837 public string Text { get; set; }
841 #region DropDownDataItem
843 /// DropDownDataItem is a class to record all data which will be applied to DropDown item.
845 /// <since_tizen> 6 </since_tizen>
846 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
847 //[EditorBrowsable(EditorBrowsableState.Never)]
848 public class DropDownDataItem
850 internal DropDownItemStyle itemDataStyle = new DropDownItemStyle();
853 /// Creates a new instance of a DropDownItemData.
855 /// <since_tizen> 6 </since_tizen>
856 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
857 [EditorBrowsable(EditorBrowsableState.Never)]
858 public DropDownDataItem()
860 itemDataStyle = (DropDownItemStyle)StyleManager.Instance.GetComponentStyle(this.GetType());
865 /// Creates a new instance of a DropDownItemData with style.
867 /// <param name="style">Create DropDownItemData by special style defined in UX.</param>
868 /// <since_tizen> 6 </since_tizen>
869 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
870 [EditorBrowsable(EditorBrowsableState.Never)]
871 public DropDownDataItem(string style)
875 ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(style);
876 if(viewStyle == null)
878 throw new InvalidOperationException($"There is no style {style}");
880 itemDataStyle = viewStyle as DropDownItemStyle;
886 /// Creates a new instance of a DropDownItemData with style.
888 /// <param name="style">Create DropDownItemData by style customized by user.</param>
889 /// <since_tizen> 6 </since_tizen>
890 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
891 [EditorBrowsable(EditorBrowsableState.Never)]
892 public DropDownDataItem(DropDownItemStyle style)
894 itemDataStyle.CopyFrom(style);
899 /// DropDown item size.
901 /// <since_tizen> 6 </since_tizen>
902 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
903 [EditorBrowsable(EditorBrowsableState.Never)]
908 return itemDataStyle.Size;
912 itemDataStyle.Size = value;
917 /// DropDown item background color selector.
919 /// <since_tizen> 6 </since_tizen>
920 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
921 [EditorBrowsable(EditorBrowsableState.Never)]
922 public Selector<Color> BackgroundColor
926 return itemDataStyle.BackgroundColor;
930 if (null == itemDataStyle?.BackgroundColor)
932 itemDataStyle.BackgroundColor = new Selector<Color>();
935 itemDataStyle.BackgroundColor.Clone(value);
940 /// DropDown item text string.
942 /// <since_tizen> 6 </since_tizen>
943 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
944 [EditorBrowsable(EditorBrowsableState.Never)]
949 return itemDataStyle.Text?.Text?.All;
953 if (null == itemDataStyle.Text.Text)
955 itemDataStyle.Text.Text = new Selector<string> { All = value };
959 itemDataStyle.Text.Text = value;
965 /// DropDown item text's point size.
967 /// <since_tizen> 6 </since_tizen>
968 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
969 [EditorBrowsable(EditorBrowsableState.Never)]
970 public float PointSize
974 return itemDataStyle.Text?.PointSize?.All ?? 0;
978 if (null == itemDataStyle.Text.PointSize)
980 itemDataStyle.Text.PointSize = new Selector<float?> { All = value };
984 itemDataStyle.Text.PointSize = value;
990 /// DropDown item text's font family.
992 /// <since_tizen> 6 </since_tizen>
993 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
994 [EditorBrowsable(EditorBrowsableState.Never)]
995 public string FontFamily
999 return itemDataStyle.Text.FontFamily?.All;
1003 if (null == itemDataStyle.Text.FontFamily)
1005 itemDataStyle.Text.FontFamily = new Selector<string> { All = value };
1009 itemDataStyle.Text.FontFamily = value;
1015 /// DropDown item text's position.
1017 /// <since_tizen> 6 </since_tizen>
1018 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1019 [EditorBrowsable(EditorBrowsableState.Never)]
1020 public Position TextPosition
1024 return itemDataStyle.Text?.Position;
1028 itemDataStyle.Text.Position = value;
1033 /// DropDown item's icon's resource url.
1035 /// <since_tizen> 6 </since_tizen>
1036 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1037 [EditorBrowsable(EditorBrowsableState.Never)]
1038 public string IconResourceUrl
1042 return itemDataStyle.Icon?.ResourceUrl?.All;
1046 if (null == itemDataStyle.Icon.ResourceUrl)
1048 itemDataStyle.Icon.ResourceUrl = new Selector<string> { All = value };
1052 itemDataStyle.Icon.ResourceUrl = value;
1058 /// DropDown item's icon's size.
1060 /// <since_tizen> 6 </since_tizen>
1061 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1062 [EditorBrowsable(EditorBrowsableState.Never)]
1063 public Size IconSize
1067 return itemDataStyle.Icon?.Size;
1071 itemDataStyle.Icon.Size = value;
1076 /// DropDown item's icon's position.
1078 /// <since_tizen> 6 </since_tizen>
1079 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1080 [EditorBrowsable(EditorBrowsableState.Never)]
1081 public Position IconPosition
1085 return itemDataStyle.Icon.Position;
1089 itemDataStyle.Icon.Position = value;
1094 /// DropDown item's check image's resource url.
1096 /// <since_tizen> 6 </since_tizen>
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 string CheckImageResourceUrl
1103 return itemDataStyle.CheckImage?.ResourceUrl?.All;
1107 if (null == itemDataStyle.CheckImage.ResourceUrl)
1109 itemDataStyle.CheckImage.ResourceUrl = new Selector<string> { All = value };
1113 itemDataStyle.CheckImage.ResourceUrl = value;
1119 /// DropDown item's check image's size.
1121 /// <since_tizen> 6 </since_tizen>
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 Size CheckImageSize
1128 return itemDataStyle.CheckImage?.Size;
1132 itemDataStyle.CheckImage.Size = value;
1137 /// DropDown item's check image's right space.
1139 /// <since_tizen> 6 </since_tizen>
1140 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1141 [EditorBrowsable(EditorBrowsableState.Never)]
1142 public int CheckImageGapToBoundary
1146 return itemDataStyle.CheckImageGapToBoundary;
1150 itemDataStyle.CheckImageGapToBoundary = value;
1155 /// Flag to decide DropDown item is selected or not.
1157 /// <since_tizen> 6 </since_tizen>
1158 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1159 [EditorBrowsable(EditorBrowsableState.Never)]
1160 public bool IsSelected
1164 return itemDataStyle.IsSelected;
1168 itemDataStyle.IsSelected = value;
1172 private void Initialize()
1174 if (itemDataStyle == null)
1176 throw new Exception("DropDownDataItem style parse error.");
1182 #region DropDownItemView
1183 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1184 [EditorBrowsable(EditorBrowsableState.Never)]
1185 internal class DropDownItemView : Control
1187 private TextLabel mText = null;
1188 private ImageView mIcon = null;
1189 private ImageView mCheck = null;
1191 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1192 [EditorBrowsable(EditorBrowsableState.Never)]
1193 public DropDownItemView() : base() { }
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 Selector<Color> BackgroundColorSelector { get; set; }
1199 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1200 [EditorBrowsable(EditorBrowsableState.Never)]
1205 return (null == mText) ? null : mText.Text;
1214 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1215 [EditorBrowsable(EditorBrowsableState.Never)]
1216 public string FontFamily
1220 return (null == mText) ? null : mText.FontFamily;
1225 mText.FontFamily = value;
1229 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1230 [EditorBrowsable(EditorBrowsableState.Never)]
1231 public float? PointSize
1235 return (null == mText) ? 0 : mText.PointSize;
1240 mText.PointSize = (float)value;
1244 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1245 [EditorBrowsable(EditorBrowsableState.Never)]
1246 public Color TextColor
1250 return (null == mText) ? null : mText.TextColor;
1255 mText.TextColor = value;
1259 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1260 [EditorBrowsable(EditorBrowsableState.Never)]
1261 public Position TextPosition
1265 return (null == mText) ? null : mText.Position;
1270 mText.Position = 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 string IconResourceUrl
1280 return (null == mIcon) ? null : mIcon.ResourceUrl;
1285 mIcon.ResourceUrl = value;
1289 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1290 [EditorBrowsable(EditorBrowsableState.Never)]
1291 public Size IconSize
1295 return (null == mIcon) ? null : mIcon.Size;
1304 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1305 [EditorBrowsable(EditorBrowsableState.Never)]
1306 public Position IconPosition
1310 return (null == mIcon) ? null : mIcon.Position;
1315 mIcon.Position = value;
1319 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1320 [EditorBrowsable(EditorBrowsableState.Never)]
1321 public string CheckResourceUrl
1325 return (null == mCheck) ? null : mCheck.ResourceUrl;
1330 mCheck.ResourceUrl = value;
1334 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1335 [EditorBrowsable(EditorBrowsableState.Never)]
1336 public Position CheckPosition
1340 return (null == mCheck) ? null : mCheck.Position;
1345 mCheck.Position = value;
1349 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1350 [EditorBrowsable(EditorBrowsableState.Never)]
1351 public Size CheckImageSize
1355 return (null == mCheck) ? null : mCheck.Size;
1360 mCheck.Size = value;
1364 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1365 [EditorBrowsable(EditorBrowsableState.Never)]
1366 public bool IsSelected
1370 return (null == mCheck) ? false : mCheck.Visibility;
1386 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1387 [EditorBrowsable(EditorBrowsableState.Never)]
1388 protected override void Dispose(DisposeTypes type)
1395 if (type == DisposeTypes.Explicit)
1422 /// Get DropDownItemView style.
1424 /// <returns>The empty.</returns>
1425 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1426 [EditorBrowsable(EditorBrowsableState.Never)]
1427 protected override ViewStyle CreateViewStyle()
1429 return new DropDownItemStyle();
1432 private void CreateIcon()
1436 mIcon = new ImageView()
1438 PositionUsesPivotPoint = true,
1439 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1440 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1446 private void CreateText()
1450 mText = new TextLabel()
1452 PositionUsesPivotPoint = true,
1453 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1454 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1455 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1456 HeightResizePolicy = ResizePolicyType.FillToParent,
1457 VerticalAlignment = VerticalAlignment.Center,
1458 HorizontalAlignment = HorizontalAlignment.Begin,
1464 private void CreateCheckImage()
1468 mCheck = new ImageView()
1470 PositionUsesPivotPoint = true,
1471 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
1472 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
1473 Name = "checkedImage",
1482 #region DropDownListBridge
1485 /// DropDownListBridge is bridge to connect item data and an item View.
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 class DropDownListBridge
1492 private List<DropDownDataItem> itemDataList = new List<DropDownDataItem>();
1494 internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration.
1497 /// Creates a new instance of a DropDownListBridge.
1499 /// <since_tizen> 6 </since_tizen>
1500 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1501 [EditorBrowsable(EditorBrowsableState.Never)]
1502 public DropDownListBridge() { }
1505 /// Insert data. The inserted data will be added to the special position by index automatically.
1507 /// <param name="position">Position index where will be inserted.</param>
1508 /// <param name="data">Item data which will apply to tab item view.</param>
1509 /// <since_tizen> 6 </since_tizen>
1510 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1511 [EditorBrowsable(EditorBrowsableState.Never)]
1512 public void InsertData(int position, DropDownDataItem data)
1516 position = itemDataList.Count;
1518 itemDataList.Insert(position, data);
1519 AdapterPurge = true;
1523 /// Remove data by position.
1525 /// <param name="position">Position index where will be removed.</param>
1526 /// <since_tizen> 6 </since_tizen>
1527 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1528 [EditorBrowsable(EditorBrowsableState.Never)]
1529 public void RemoveData(int position)
1531 itemDataList.RemoveAt(position);
1532 AdapterPurge = true;
1536 /// Get data by position.
1538 /// <param name="position">Position index where will be gotten.</param>
1539 /// <since_tizen> 6 </since_tizen>
1540 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1541 [EditorBrowsable(EditorBrowsableState.Never)]
1542 public DropDownDataItem GetData(int position)
1544 return itemDataList[position];
1548 /// Get view holder by view type.
1550 /// <since_tizen> 6 </since_tizen>
1551 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1552 [EditorBrowsable(EditorBrowsableState.Never)]
1553 public ViewHolder OnCreateViewHolder()
1555 ViewHolder viewHolder = new ViewHolder(new DropDownItemView());
1561 /// Bind ViewHolder with View.
1563 /// <param name="holder">View holder.</param>
1564 /// <param name="position">Position index of source data.</param>
1565 /// <since_tizen> 6 </since_tizen>
1566 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1567 [EditorBrowsable(EditorBrowsableState.Never)]
1568 public void BindViewHolder(ViewHolder holder, int position)
1570 if (null == holder) return;
1571 DropDownDataItem listItemData = itemDataList[position];
1572 if(listItemData == null)
1576 DropDownItemView listItemView = holder.ItemView as DropDownItemView;
1577 listItemView.Name = "Item" + position;
1578 if (listItemData.Size != null)
1580 if (listItemData.Size.Width > 0)
1582 holder.ItemView.WidthSpecification = (int)listItemData.Size.Width;
1586 holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent;
1589 if (listItemData.Size.Height > 0)
1591 holder.ItemView.HeightSpecification = (int)listItemData.Size.Height;
1595 holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent;
1599 if (listItemView != null)
1601 listItemView.BackgroundColorSelector = listItemData.BackgroundColor;
1602 if (listItemData.Text != null)
1604 listItemView.Text = listItemData.Text;
1605 listItemView.PointSize = listItemData.PointSize;
1606 listItemView.FontFamily = listItemData.FontFamily;
1607 listItemView.TextPosition = listItemData.TextPosition;
1610 if (listItemData.IconResourceUrl != null)
1612 listItemView.IconResourceUrl = listItemData.IconResourceUrl;
1613 listItemView.IconSize = listItemData.IconSize;
1614 if (listItemView.IconSize != null)
1616 listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2);
1620 if (listItemData.CheckImageResourceUrl != null)
1622 listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl;
1624 if (null != listItemData.CheckImageSize)
1626 listItemView.CheckImageSize = listItemData.CheckImageSize;
1629 if (listItemView.CheckImageSize != null)
1631 listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2);
1635 listItemView.IsSelected = listItemData.IsSelected;
1640 /// Destroy view holder, it can be override.
1642 /// <param name="holder">View holder.</param>
1643 /// <since_tizen> 6 </since_tizen>
1644 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1645 [EditorBrowsable(EditorBrowsableState.Never)]
1646 public void OnDestroyViewHolder(ViewHolder holder)
1648 if (null == holder) return;
1649 if (holder.ItemView != null)
1651 holder.ItemView.Dispose();
1656 /// Get item count, it can be override.
1658 /// <since_tizen> 6 </since_tizen>
1659 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1660 [EditorBrowsable(EditorBrowsableState.Never)]
1661 public int GetItemCount()
1663 return itemDataList.Count;
1672 /// A ViewHolder is a class that holds a View created from DropDownListBridge data.
1674 /// <since_tizen> 6 </since_tizen>
1675 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1676 [EditorBrowsable(EditorBrowsableState.Never)]
1677 public class ViewHolder
1680 /// ViewHolder constructor.
1682 /// <param name="itemView">View</param>
1683 /// <since_tizen> 6 </since_tizen>
1684 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1685 [EditorBrowsable(EditorBrowsableState.Never)]
1686 public ViewHolder(View itemView)
1688 if (itemView == null)
1690 throw new ArgumentNullException("itemView may not be null");
1692 this.ItemView = itemView;
1696 /// Returns the view.
1698 /// <since_tizen> 6 </since_tizen>
1699 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1700 [EditorBrowsable(EditorBrowsableState.Never)]
1701 public View ItemView { get; }
1703 internal bool IsBound { get; set; }