From 169945ae5c06a26f69504afb3de4259f72b3b137 Mon Sep 17 00:00:00 2001 From: Xianbing Teng Date: Tue, 16 Jun 2020 14:27:38 +0800 Subject: [PATCH] [NUI.Components]Improve SAM score of NUI.Components (#1713) Co-authored-by: Xianbing Teng --- .../Controls/DropDown.DropDownDataItem.cs | 348 ++++ .../Controls/DropDown.DropDownItemView.cs | 306 ++++ .../Controls/DropDown.DropDownListBridge.cs | 193 ++ src/Tizen.NUI.Components/Controls/DropDown.cs | 830 +-------- .../Controls/FlexibleView/FlexibleView.Adapter.cs | 301 +++ .../Controls/FlexibleView/FlexibleView.Helper.cs | 363 ++++ .../FlexibleView/FlexibleView.LayoutManager.cs | 899 +++++++++ .../Controls/FlexibleView/FlexibleView.Recycler.cs | 166 ++ .../FlexibleView/FlexibleView.ViewHolder.cs | 245 +++ .../Controls/FlexibleView/FlexibleView.cs | 1932 +------------------- .../Controls/Slider.Internal.cs | 881 +++++++++ src/Tizen.NUI.Components/Controls/Slider.cs | 872 +-------- src/Tizen.NUI.Components/Tizen.NUI.Components.sln | 10 +- 13 files changed, 3713 insertions(+), 3633 deletions(-) create mode 100755 src/Tizen.NUI.Components/Controls/DropDown.DropDownDataItem.cs create mode 100755 src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs create mode 100755 src/Tizen.NUI.Components/Controls/DropDown.DropDownListBridge.cs create mode 100755 src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Adapter.cs create mode 100755 src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Helper.cs create mode 100755 src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.LayoutManager.cs create mode 100755 src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Recycler.cs create mode 100755 src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.ViewHolder.cs create mode 100755 src/Tizen.NUI.Components/Controls/Slider.Internal.cs diff --git a/src/Tizen.NUI.Components/Controls/DropDown.DropDownDataItem.cs b/src/Tizen.NUI.Components/Controls/DropDown.DropDownDataItem.cs new file mode 100755 index 0000000..eafd140 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/DropDown.DropDownDataItem.cs @@ -0,0 +1,348 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class DropDown + { + /// + /// DropDownDataItem is a class to record all data which will be applied to DropDown item. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + //[EditorBrowsable(EditorBrowsableState.Never)] + public class DropDownDataItem + { + internal DropDownItemStyle itemDataStyle = new DropDownItemStyle(); + + /// + /// Creates a new instance of a DropDownItemData. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownDataItem() + { + itemDataStyle = (DropDownItemStyle)StyleManager.Instance.GetComponentStyle(this.GetType()); + Initialize(); + } + + /// + /// Creates a new instance of a DropDownItemData with style. + /// + /// Create DropDownItemData by special style defined in UX. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownDataItem(string style) + { + if (style != null) + { + ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(style); + if (viewStyle == null) + { + throw new InvalidOperationException($"There is no style {style}"); + } + itemDataStyle = viewStyle as DropDownItemStyle; + } + Initialize(); + } + + /// + /// Creates a new instance of a DropDownItemData with style. + /// + /// Create DropDownItemData by style customized by user. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownDataItem(DropDownItemStyle style) + { + itemDataStyle.CopyFrom(style); + Initialize(); + } + + /// + /// DropDown item size. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Size Size + { + get + { + return itemDataStyle.Size; + } + set + { + itemDataStyle.Size = value; + } + } + + /// + /// DropDown item background color selector. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Selector BackgroundColor + { + get + { + return itemDataStyle.BackgroundColor; + } + set + { + if (null == itemDataStyle?.BackgroundColor) + { + itemDataStyle.BackgroundColor = new Selector(); + } + + itemDataStyle.BackgroundColor.Clone(value); + } + } + + /// + /// DropDown item text string. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Text + { + get + { + return itemDataStyle.Text?.Text?.All; + } + set + { + if (null == itemDataStyle.Text.Text) + { + itemDataStyle.Text.Text = new Selector { All = value }; + } + else + { + itemDataStyle.Text.Text = value; + } + } + } + + /// + /// DropDown item text's point size. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float PointSize + { + get + { + return itemDataStyle.Text?.PointSize?.All ?? 0; + } + set + { + if (null == itemDataStyle.Text.PointSize) + { + itemDataStyle.Text.PointSize = new Selector { All = value }; + } + else + { + itemDataStyle.Text.PointSize = value; + } + } + } + + /// + /// DropDown item text's font family. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string FontFamily + { + get + { + return itemDataStyle.Text.FontFamily?.All; + } + set + { + if (null == itemDataStyle.Text.FontFamily) + { + itemDataStyle.Text.FontFamily = new Selector { All = value }; + } + else + { + itemDataStyle.Text.FontFamily = value; + } + } + } + + /// + /// DropDown item text's position. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Position TextPosition + { + get + { + return itemDataStyle.Text?.Position; + } + set + { + itemDataStyle.Text.Position = value; + } + } + + /// + /// DropDown item's icon's resource url. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string IconResourceUrl + { + get + { + return itemDataStyle.Icon?.ResourceUrl?.All; + } + set + { + if (null == itemDataStyle.Icon.ResourceUrl) + { + itemDataStyle.Icon.ResourceUrl = new Selector { All = value }; + } + else + { + itemDataStyle.Icon.ResourceUrl = value; + } + } + } + + /// + /// DropDown item's icon's size. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Size IconSize + { + get + { + return itemDataStyle.Icon?.Size; + } + set + { + itemDataStyle.Icon.Size = value; + } + } + + /// + /// DropDown item's icon's position. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Position IconPosition + { + get + { + return itemDataStyle.Icon.Position; + } + set + { + itemDataStyle.Icon.Position = value; + } + } + + /// + /// DropDown item's check image's resource url. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string CheckImageResourceUrl + { + get + { + return itemDataStyle.CheckImage?.ResourceUrl?.All; + } + set + { + if (null == itemDataStyle.CheckImage.ResourceUrl) + { + itemDataStyle.CheckImage.ResourceUrl = new Selector { All = value }; + } + else + { + itemDataStyle.CheckImage.ResourceUrl = value; + } + } + } + + /// + /// DropDown item's check image's size. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Size CheckImageSize + { + get + { + return itemDataStyle.CheckImage?.Size; + } + set + { + itemDataStyle.CheckImage.Size = value; + } + } + + /// + /// DropDown item's check image's right space. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int CheckImageGapToBoundary + { + get + { + return itemDataStyle.CheckImageGapToBoundary; + } + set + { + itemDataStyle.CheckImageGapToBoundary = value; + } + } + + /// + /// Flag to decide DropDown item is selected or not. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsSelected + { + get + { + return itemDataStyle.IsSelected; + } + set + { + itemDataStyle.IsSelected = value; + } + } + + private void Initialize() + { + if (itemDataStyle == null) + { + throw new Exception("DropDownDataItem style parse error."); + } + } + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs b/src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs new file mode 100755 index 0000000..f580156 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs @@ -0,0 +1,306 @@ +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class DropDown + { + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + internal class DropDownItemView : Control + { + private TextLabel mText = null; + private ImageView mIcon = null; + private ImageView mCheck = null; + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownItemView() : base() { } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Selector BackgroundColorSelector { get; set; } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Text + { + get + { + return (null == mText) ? null : mText.Text; + } + set + { + CreateText(); + mText.Text = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string FontFamily + { + get + { + return (null == mText) ? null : mText.FontFamily; + } + set + { + CreateText(); + mText.FontFamily = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float? PointSize + { + get + { + return (null == mText) ? 0 : mText.PointSize; + } + set + { + CreateText(); + mText.PointSize = (float)value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Color TextColor + { + get + { + return (null == mText) ? null : mText.TextColor; + } + set + { + CreateText(); + mText.TextColor = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Position TextPosition + { + get + { + return (null == mText) ? null : mText.Position; + } + set + { + CreateText(); + mText.Position = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string IconResourceUrl + { + get + { + return (null == mIcon) ? null : mIcon.ResourceUrl; + } + set + { + CreateIcon(); + mIcon.ResourceUrl = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Size IconSize + { + get + { + return (null == mIcon) ? null : mIcon.Size; + } + set + { + CreateIcon(); + mIcon.Size = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Position IconPosition + { + get + { + return (null == mIcon) ? null : mIcon.Position; + } + set + { + CreateIcon(); + mIcon.Position = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string CheckResourceUrl + { + get + { + return (null == mCheck) ? null : mCheck.ResourceUrl; + } + set + { + CreateCheckImage(); + mCheck.ResourceUrl = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Position CheckPosition + { + get + { + return (null == mCheck) ? null : mCheck.Position; + } + set + { + CreateCheckImage(); + mCheck.Position = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Size CheckImageSize + { + get + { + return (null == mCheck) ? null : mCheck.Size; + } + set + { + CreateCheckImage(); + mCheck.Size = value; + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsSelected + { + get + { + return (null == mCheck) ? false : mCheck.Visibility; + } + set + { + CreateCheckImage(); + if (value) + { + mCheck.Show(); + } + else + { + mCheck.Hide(); + } + } + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + if (mText != null) + { + Remove(mText); + mText.Dispose(); + mText = null; + } + + if (mIcon != null) + { + Remove(mIcon); + mIcon.Dispose(); + mIcon = null; + } + + if (mCheck != null) + { + Remove(mCheck); + mCheck.Dispose(); + mCheck = null; + } + } + base.Dispose(type); + } + + /// + /// Get DropDownItemView style. + /// + /// The empty. + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override ViewStyle CreateViewStyle() + { + return new DropDownItemStyle(); + } + + private void CreateIcon() + { + if (mIcon == null) + { + mIcon = new ImageView() + { + PositionUsesPivotPoint = true, + ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, + PivotPoint = Tizen.NUI.PivotPoint.TopLeft, + }; + Add(mIcon); + } + } + + private void CreateText() + { + if (mText == null) + { + mText = new TextLabel() + { + PositionUsesPivotPoint = true, + ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, + PivotPoint = Tizen.NUI.PivotPoint.TopLeft, + WidthResizePolicy = ResizePolicyType.UseNaturalSize, + HeightResizePolicy = ResizePolicyType.FillToParent, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Begin, + }; + Add(mText); + } + } + + private void CreateCheckImage() + { + if (mCheck == null) + { + mCheck = new ImageView() + { + PositionUsesPivotPoint = true, + ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, + PivotPoint = Tizen.NUI.PivotPoint.TopLeft, + Name = "checkedImage", + }; + Add(mCheck); + } + mCheck.Hide(); + } + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/DropDown.DropDownListBridge.cs b/src/Tizen.NUI.Components/Controls/DropDown.DropDownListBridge.cs new file mode 100755 index 0000000..0899013 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/DropDown.DropDownListBridge.cs @@ -0,0 +1,193 @@ +using System.Collections.Generic; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class DropDown + { + + /// + /// DropDownListBridge is bridge to connect item data and an item View. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class DropDownListBridge + { + private List itemDataList = new List(); + + internal bool AdapterPurge { get; set; } = false; // Set to true if adapter content changed since last iteration. + + /// + /// Creates a new instance of a DropDownListBridge. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownListBridge() { } + + /// + /// Insert data. The inserted data will be added to the special position by index automatically. + /// + /// Position index where will be inserted. + /// Item data which will apply to tab item view. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void InsertData(int position, DropDownDataItem data) + { + if (position == -1) + { + position = itemDataList.Count; + } + itemDataList.Insert(position, data); + AdapterPurge = true; + } + + /// + /// Remove data by position. + /// + /// Position index where will be removed. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RemoveData(int position) + { + itemDataList.RemoveAt(position); + AdapterPurge = true; + } + + /// + /// Get data by position. + /// + /// Position index where will be gotten. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DropDownDataItem GetData(int position) + { + return itemDataList[position]; + } + + /// + /// Get view holder by view type. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder OnCreateViewHolder() + { + ViewHolder viewHolder = new ViewHolder(new DropDownItemView()); + + return viewHolder; + } + + /// + /// Bind ViewHolder with View. + /// + /// View holder. + /// Position index of source data. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void BindViewHolder(ViewHolder holder, int position) + { + if (null == holder) return; + DropDownDataItem listItemData = itemDataList[position]; + if (listItemData == null) + { + return; + } + DropDownItemView listItemView = holder.ItemView as DropDownItemView; + listItemView.Name = "Item" + position; + if (listItemData.Size != null) + { + if (listItemData.Size.Width > 0) + { + holder.ItemView.WidthSpecification = (int)listItemData.Size.Width; + } + else + { + holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent; + } + + if (listItemData.Size.Height > 0) + { + holder.ItemView.HeightSpecification = (int)listItemData.Size.Height; + } + else + { + holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent; + } + } + + if (listItemView != null) + { + listItemView.BackgroundColorSelector = listItemData.BackgroundColor; + if (listItemData.Text != null) + { + listItemView.Text = listItemData.Text; + listItemView.PointSize = listItemData.PointSize; + listItemView.FontFamily = listItemData.FontFamily; + listItemView.TextPosition = listItemData.TextPosition; + } + + if (listItemData.IconResourceUrl != null) + { + listItemView.IconResourceUrl = listItemData.IconResourceUrl; + listItemView.IconSize = listItemData.IconSize; + if (listItemView.IconSize != null) + { + listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2); + } + } + + if (listItemData.CheckImageResourceUrl != null) + { + listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl; + + if (null != listItemData.CheckImageSize) + { + listItemView.CheckImageSize = listItemData.CheckImageSize; + } + + if (listItemView.CheckImageSize != null) + { + listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2); + } + } + + listItemView.IsSelected = listItemData.IsSelected; + } + } + + /// + /// Destroy view holder, it can be override. + /// + /// View holder. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void OnDestroyViewHolder(ViewHolder holder) + { + if (null == holder) return; + if (holder.ItemView != null) + { + holder.ItemView.Dispose(); + } + } + + /// + /// Get item count, it can be override. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int GetItemCount() + { + return itemDataList.Count; + } + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/DropDown.cs b/src/Tizen.NUI.Components/Controls/DropDown.cs index 2e12a57..288a607 100755 --- a/src/Tizen.NUI.Components/Controls/DropDown.cs +++ b/src/Tizen.NUI.Components/Controls/DropDown.cs @@ -28,7 +28,7 @@ namespace Tizen.NUI.Components /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public class DropDown : Control + public partial class DropDown : Control { /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] @@ -838,834 +838,6 @@ namespace Tizen.NUI.Components } #endregion - #region DropDownDataItem - /// - /// DropDownDataItem is a class to record all data which will be applied to DropDown item. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - //[EditorBrowsable(EditorBrowsableState.Never)] - public class DropDownDataItem - { - internal DropDownItemStyle itemDataStyle = new DropDownItemStyle(); - - /// - /// Creates a new instance of a DropDownItemData. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownDataItem() - { - itemDataStyle = (DropDownItemStyle)StyleManager.Instance.GetComponentStyle(this.GetType()); - Initialize(); - } - - /// - /// Creates a new instance of a DropDownItemData with style. - /// - /// Create DropDownItemData by special style defined in UX. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownDataItem(string style) - { - if(style != null) - { - ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(style); - if(viewStyle == null) - { - throw new InvalidOperationException($"There is no style {style}"); - } - itemDataStyle = viewStyle as DropDownItemStyle; - } - Initialize(); - } - - /// - /// Creates a new instance of a DropDownItemData with style. - /// - /// Create DropDownItemData by style customized by user. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownDataItem(DropDownItemStyle style) - { - itemDataStyle.CopyFrom(style); - Initialize(); - } - - /// - /// DropDown item size. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Size Size - { - get - { - return itemDataStyle.Size; - } - set - { - itemDataStyle.Size = value; - } - } - - /// - /// DropDown item background color selector. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Selector BackgroundColor - { - get - { - return itemDataStyle.BackgroundColor; - } - set - { - if (null == itemDataStyle?.BackgroundColor) - { - itemDataStyle.BackgroundColor = new Selector(); - } - - itemDataStyle.BackgroundColor.Clone(value); - } - } - - /// - /// DropDown item text string. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string Text - { - get - { - return itemDataStyle.Text?.Text?.All; - } - set - { - if (null == itemDataStyle.Text.Text) - { - itemDataStyle.Text.Text = new Selector { All = value }; - } - else - { - itemDataStyle.Text.Text = value; - } - } - } - - /// - /// DropDown item text's point size. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float PointSize - { - get - { - return itemDataStyle.Text?.PointSize?.All ?? 0; - } - set - { - if (null == itemDataStyle.Text.PointSize) - { - itemDataStyle.Text.PointSize = new Selector { All = value }; - } - else - { - itemDataStyle.Text.PointSize = value; - } - } - } - - /// - /// DropDown item text's font family. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string FontFamily - { - get - { - return itemDataStyle.Text.FontFamily?.All; - } - set - { - if (null == itemDataStyle.Text.FontFamily) - { - itemDataStyle.Text.FontFamily = new Selector { All = value }; - } - else - { - itemDataStyle.Text.FontFamily = value; - } - } - } - - /// - /// DropDown item text's position. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Position TextPosition - { - get - { - return itemDataStyle.Text?.Position; - } - set - { - itemDataStyle.Text.Position = value; - } - } - - /// - /// DropDown item's icon's resource url. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string IconResourceUrl - { - get - { - return itemDataStyle.Icon?.ResourceUrl?.All; - } - set - { - if (null == itemDataStyle.Icon.ResourceUrl) - { - itemDataStyle.Icon.ResourceUrl = new Selector { All = value }; - } - else - { - itemDataStyle.Icon.ResourceUrl = value; - } - } - } - - /// - /// DropDown item's icon's size. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Size IconSize - { - get - { - return itemDataStyle.Icon?.Size; - } - set - { - itemDataStyle.Icon.Size = value; - } - } - - /// - /// DropDown item's icon's position. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Position IconPosition - { - get - { - return itemDataStyle.Icon.Position; - } - set - { - itemDataStyle.Icon.Position = value; - } - } - - /// - /// DropDown item's check image's resource url. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string CheckImageResourceUrl - { - get - { - return itemDataStyle.CheckImage?.ResourceUrl?.All; - } - set - { - if (null == itemDataStyle.CheckImage.ResourceUrl) - { - itemDataStyle.CheckImage.ResourceUrl = new Selector { All = value }; - } - else - { - itemDataStyle.CheckImage.ResourceUrl = value; - } - } - } - - /// - /// DropDown item's check image's size. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Size CheckImageSize - { - get - { - return itemDataStyle.CheckImage?.Size; - } - set - { - itemDataStyle.CheckImage.Size = value; - } - } - - /// - /// DropDown item's check image's right space. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int CheckImageGapToBoundary - { - get - { - return itemDataStyle.CheckImageGapToBoundary; - } - set - { - itemDataStyle.CheckImageGapToBoundary = value; - } - } - - /// - /// Flag to decide DropDown item is selected or not. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsSelected - { - get - { - return itemDataStyle.IsSelected; - } - set - { - itemDataStyle.IsSelected = value; - } - } - - private void Initialize() - { - if (itemDataStyle == null) - { - throw new Exception("DropDownDataItem style parse error."); - } - } - } - #endregion - - #region DropDownItemView - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - internal class DropDownItemView : Control - { - private TextLabel mText = null; - private ImageView mIcon = null; - private ImageView mCheck = null; - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownItemView() : base() { } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Selector BackgroundColorSelector { get; set; } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string Text - { - get - { - return (null == mText) ? null : mText.Text; - } - set - { - CreateText(); - mText.Text = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string FontFamily - { - get - { - return (null == mText) ? null : mText.FontFamily; - } - set - { - CreateText(); - mText.FontFamily = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float? PointSize - { - get - { - return (null == mText) ? 0 : mText.PointSize; - } - set - { - CreateText(); - mText.PointSize = (float)value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Color TextColor - { - get - { - return (null == mText) ? null : mText.TextColor; - } - set - { - CreateText(); - mText.TextColor = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Position TextPosition - { - get - { - return (null == mText) ? null : mText.Position; - } - set - { - CreateText(); - mText.Position = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string IconResourceUrl - { - get - { - return (null == mIcon) ? null : mIcon.ResourceUrl; - } - set - { - CreateIcon(); - mIcon.ResourceUrl = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Size IconSize - { - get - { - return (null == mIcon) ? null : mIcon.Size; - } - set - { - CreateIcon(); - mIcon.Size = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Position IconPosition - { - get - { - return (null == mIcon) ? null : mIcon.Position; - } - set - { - CreateIcon(); - mIcon.Position = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string CheckResourceUrl - { - get - { - return (null == mCheck) ? null : mCheck.ResourceUrl; - } - set - { - CreateCheckImage(); - mCheck.ResourceUrl = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Position CheckPosition - { - get - { - return (null == mCheck) ? null : mCheck.Position; - } - set - { - CreateCheckImage(); - mCheck.Position = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Size CheckImageSize - { - get - { - return (null == mCheck) ? null : mCheck.Size; - } - set - { - CreateCheckImage(); - mCheck.Size = value; - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsSelected - { - get - { - return (null == mCheck) ? false : mCheck.Visibility; - } - set - { - CreateCheckImage(); - if(value) - { - mCheck.Show(); - } - else - { - mCheck.Hide(); - } - } - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override void Dispose(DisposeTypes type) - { - if (disposed) - { - return; - } - - if (type == DisposeTypes.Explicit) - { - if (mText != null) - { - Remove(mText); - mText.Dispose(); - mText = null; - } - - if (mIcon != null) - { - Remove(mIcon); - mIcon.Dispose(); - mIcon = null; - } - - if (mCheck != null) - { - Remove(mCheck); - mCheck.Dispose(); - mCheck = null; - } - } - base.Dispose(type); - } - - /// - /// Get DropDownItemView style. - /// - /// The empty. - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override ViewStyle CreateViewStyle() - { - return new DropDownItemStyle(); - } - - private void CreateIcon() - { - if(mIcon == null) - { - mIcon = new ImageView() - { - PositionUsesPivotPoint = true, - ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, - PivotPoint = Tizen.NUI.PivotPoint.TopLeft, - }; - Add(mIcon); - } - } - - private void CreateText() - { - if (mText == null) - { - mText = new TextLabel() - { - PositionUsesPivotPoint = true, - ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, - PivotPoint = Tizen.NUI.PivotPoint.TopLeft, - WidthResizePolicy = ResizePolicyType.UseNaturalSize, - HeightResizePolicy = ResizePolicyType.FillToParent, - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Begin, - }; - Add(mText); - } - } - - private void CreateCheckImage() - { - if (mCheck == null) - { - mCheck = new ImageView() - { - PositionUsesPivotPoint = true, - ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, - PivotPoint = Tizen.NUI.PivotPoint.TopLeft, - Name = "checkedImage", - }; - Add(mCheck); - } - mCheck.Hide(); - } - } - #endregion - - #region DropDownListBridge - - /// - /// DropDownListBridge is bridge to connect item data and an item View. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public class DropDownListBridge - { - private List itemDataList = new List(); - - internal bool AdapterPurge {get;set;} = false; // Set to true if adapter content changed since last iteration. - - /// - /// Creates a new instance of a DropDownListBridge. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownListBridge() { } - - /// - /// Insert data. The inserted data will be added to the special position by index automatically. - /// - /// Position index where will be inserted. - /// Item data which will apply to tab item view. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void InsertData(int position, DropDownDataItem data) - { - if(position == -1) - { - position = itemDataList.Count; - } - itemDataList.Insert(position, data); - AdapterPurge = true; - } - - /// - /// Remove data by position. - /// - /// Position index where will be removed. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void RemoveData(int position) - { - itemDataList.RemoveAt(position); - AdapterPurge = true; - } - - /// - /// Get data by position. - /// - /// Position index where will be gotten. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public DropDownDataItem GetData(int position) - { - return itemDataList[position]; - } - - /// - /// Get view holder by view type. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder OnCreateViewHolder() - { - ViewHolder viewHolder = new ViewHolder(new DropDownItemView()); - - return viewHolder; - } - - /// - /// Bind ViewHolder with View. - /// - /// View holder. - /// Position index of source data. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void BindViewHolder(ViewHolder holder, int position) - { - if (null == holder) return; - DropDownDataItem listItemData = itemDataList[position]; - if(listItemData == null) - { - return; - } - DropDownItemView listItemView = holder.ItemView as DropDownItemView; - listItemView.Name = "Item" + position; - if (listItemData.Size != null) - { - if (listItemData.Size.Width > 0) - { - holder.ItemView.WidthSpecification = (int)listItemData.Size.Width; - } - else - { - holder.ItemView.WidthSpecification = LayoutParamPolicies.MatchParent; - } - - if (listItemData.Size.Height > 0) - { - holder.ItemView.HeightSpecification = (int)listItemData.Size.Height; - } - else - { - holder.ItemView.HeightSpecification = LayoutParamPolicies.MatchParent; - } - } - - if (listItemView != null) - { - listItemView.BackgroundColorSelector = listItemData.BackgroundColor; - if (listItemData.Text != null) - { - listItemView.Text = listItemData.Text; - listItemView.PointSize = listItemData.PointSize; - listItemView.FontFamily = listItemData.FontFamily; - listItemView.TextPosition = listItemData.TextPosition; - } - - if (listItemData.IconResourceUrl != null) - { - listItemView.IconResourceUrl = listItemData.IconResourceUrl; - listItemView.IconSize = listItemData.IconSize; - if (listItemView.IconSize != null) - { - listItemView.IconPosition = new Position(listItemData.IconPosition.X, (listItemView.Size2D.Height - listItemView.IconSize.Height) / 2); - } - } - - if (listItemData.CheckImageResourceUrl != null) - { - listItemView.CheckResourceUrl = listItemData.CheckImageResourceUrl; - - if (null != listItemData.CheckImageSize) - { - listItemView.CheckImageSize = listItemData.CheckImageSize; - } - - if (listItemView.CheckImageSize != null) - { - listItemView.CheckPosition = new Position(listItemView.Size2D.Width - listItemData.CheckImageGapToBoundary - listItemView.CheckImageSize.Width, (listItemView.Size2D.Height - listItemView.CheckImageSize.Height) / 2); - } - } - - listItemView.IsSelected = listItemData.IsSelected; - } - } - - /// - /// Destroy view holder, it can be override. - /// - /// View holder. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void OnDestroyViewHolder(ViewHolder holder) - { - if (null == holder) return; - if (holder.ItemView != null) - { - holder.ItemView.Dispose(); - } - } - - /// - /// Get item count, it can be override. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int GetItemCount() - { - return itemDataList.Count; - } - } - - #endregion - #region ViewHolder /// diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Adapter.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Adapter.cs new file mode 100755 index 0000000..75234b0 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Adapter.cs @@ -0,0 +1,301 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Components +{ + public partial class FlexibleView + { + /// + /// Adapters provide a binding from an app-specific data set to views that are displayed within a FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class Adapter + { + private EventHandler itemEventHandlers; + + internal event EventHandler ItemEvent + { + add + { + itemEventHandlers += value; + } + + remove + { + itemEventHandlers -= value; + } + } + + internal enum ItemEventType + { + Insert = 0, + Remove, + Move, + Change + } + + /// + /// Called when FlexibleView needs a new FlexibleView.ViewHolder of the given type to represent an item. + /// + /// The view type of the new View + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract ViewHolder OnCreateViewHolder(int viewType); + + /// + /// Called by FlexibleView to display the data at the specified position. + /// + /// The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. + /// The position of the item within the adapter's data set. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract void OnBindViewHolder(ViewHolder holder, int position); + + /// + /// Called when a ViewHolder is never used. + /// + /// The ViewHolder which need to be disposed + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract void OnDestroyViewHolder(ViewHolder holder); + + /// + /// Returns the total number of items in the data set held by the adapter. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract int GetItemCount(); + + /// + /// Return the view type of the item at position for the purposes of view recycling. + /// + /// The position of the item within the adapter's data set. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual int GetItemViewType(int position) + { + return 0; + } + + /// + /// Called by FlexibleView when it starts observing this Adapter. + /// Keep in mind that same adapter may be observed by multiple FlexibleView. + /// + /// The FlexibleView instance which started observing this adapter. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnAttachedToRecyclerView(FlexibleView flexibleView) + { + } + + /// + /// Called by FlexibleView when it stops observing this Adapter. + /// + /// The FlexibleView instance which stopped observing this adapter. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnDetachedFromRecyclerView(FlexibleView flexibleView) + { + } + + /// + /// Called when FlexibleView focus changed. + /// + /// The FlexibleView into which the focus ViewHolder changed. + /// The position of previous focus + /// The position of current focus + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnFocusChange(FlexibleView flexibleView, int previousFocus, int currentFocus) + { + } + + /// + /// Called when a view created by this adapter has been recycled. + /// If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources + /// + /// The ViewHolder will be recycled. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnViewRecycled(ViewHolder holder) + { + } + + /// + /// Called when a view created by this adapter has been attached to a window. + /// This can be used as a reasonable signal that the view is about to be seen by the user. + /// + /// Holder of the view being attached. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnViewAttachedToWindow(ViewHolder holder) + { + } + + /// + /// Called when a view created by this adapter has been detached from its window. + /// + /// Holder of the view being detached. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnViewDetachedFromWindow(ViewHolder holder) + { + } + + /// + /// Notify any registered observers that the data set has changed. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyDataSetChanged() + { + } + + /// + /// Notify any registered observers that the data set has changed. + /// It indicates that any reflection of the data at position is out of date and should be updated. + /// + /// Position of the item that has changed + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemChanged(int position) + { + ItemEventArgs args = new ItemEventArgs + { + EventType = ItemEventType.Change, + }; + args.param[0] = position; + args.param[1] = 1; + OnItemEvent(this, args); + } + + /// + /// Notify any registered observers that the itemCount items starting at position positionStart have changed. + /// An optional payload can be passed to each changed item. + /// + /// Position of the first item that has changed + /// Number of items that have changed + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemRangeChanged(int positionStart, int itemCount) + { + } + + /// + /// Notify any registered observers that the data set has been newly inserted. + /// It indicates that any reflection of the data at position is out of date and should be updated. + /// + /// Position of the item that has been newly inserted + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemInserted(int position) + { + NotifyItemRangeInserted(position, 1); + } + + /// + /// Notify any registered observers that the itemCount items starting at position positionStart have been newly inserted. + /// + /// Position of the first item that was inserted + /// Number of items inserted + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemRangeInserted(int positionStart, int itemCount) + { + ItemEventArgs args = new ItemEventArgs + { + EventType = ItemEventType.Insert, + }; + args.param[0] = positionStart; + args.param[1] = itemCount; + OnItemEvent(this, args); + } + + /// + /// Notify any registered observers that the item previously located at position has been removed from the data set. + /// + /// Previous position of the first item that was removed + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemRemoved(int position) + { + NotifyItemRangeRemoved(position, 1); + } + + /// + /// Notify any registered observers that the itemCount items previously located at positionStart have been removed from the data set. + /// + /// Previous position of the first item that was removed + /// Number of items removed from the data set + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemRangeRemoved(int positionStart, int itemCount) + { + ItemEventArgs args = new ItemEventArgs + { + EventType = ItemEventType.Remove, + }; + args.param[0] = positionStart; + args.param[1] = itemCount; + OnItemEvent(this, args); + } + + /// + /// Notify any registered observers that the item reflected at fromPosition has been moved to toPosition. + /// + /// Previous position of the item + /// New position of the item. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void NotifyItemMoved(int fromPosition, int toPosition) + { + + } + + private void OnItemEvent(object sender, ItemEventArgs e) + { + itemEventHandlers?.Invoke(sender, e); + } + + internal class ItemEventArgs : EventArgs + { + + /// + /// Data change event parameters. + /// + public int[] param = new int[4]; + + /// + /// Data changed event type. + /// + public ItemEventType EventType + { + get; + set; + } + } + } + + } +} diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Helper.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Helper.cs new file mode 100755 index 0000000..a69dbb0 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Helper.cs @@ -0,0 +1,363 @@ +using System; +using System.Collections.Generic; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class FlexibleView + { + internal class RecycledViewPool + { + private FlexibleView mFlexibleView; + + private int mMaxTypeCount = 10; + private List[] mScrap; + + public RecycledViewPool(FlexibleView flexibleView) + { + mFlexibleView = flexibleView; + mScrap = new List[mMaxTypeCount]; + } + + //public void SetViewTypeCount(int typeCount) + //{ + //} + + public ViewHolder GetRecycledView(int viewType) + { + if (viewType >= mMaxTypeCount || mScrap[viewType] == null) + { + return null; + } + + int index = mScrap[viewType].Count - 1; + if (index < 0) + { + return null; + } + ViewHolder recycledView = mScrap[viewType][index]; + mScrap[viewType].RemoveAt(index); + + return recycledView; + } + + public void PutRecycledView(ViewHolder view) + { + int viewType = view.ItemViewType; + if (viewType >= mMaxTypeCount) + { + return; + } + if (mScrap[viewType] == null) + { + mScrap[viewType] = new List(); + } + view.IsBound = false; + mScrap[viewType].Add(view); + } + + public void Clear() + { + for (int i = 0; i < mMaxTypeCount; i++) + { + if (mScrap[i] == null) + { + continue; + } + for (int j = 0; j < mScrap[i].Count; j++) + { + mFlexibleView.DispatchChildDestroyed(mScrap[i][j]); + } + mScrap[i].Clear(); + } + } + } + + private class ChildHelper + { + private FlexibleView mFlexibleView; + + private List mViewList = new List(); + + //private List mRemovePendingViews; + + private Dictionary itemViewTable = new Dictionary(); + private TapGestureDetector mTapGestureDetector; + + public ChildHelper(FlexibleView owner) + { + mFlexibleView = owner; + + mTapGestureDetector = new TapGestureDetector(); + mTapGestureDetector.Detected += OnTapGestureDetected; + } + + public void Clear() + { + foreach (ViewHolder holder in mViewList) + { + mFlexibleView.Remove(holder.ItemView); + + mFlexibleView.DispatchChildDestroyed(holder); + } + mViewList.Clear(); + } + + public void ScrapViews(Recycler recycler) + { + recycler.Clear(); + foreach (ViewHolder itemView in mViewList) + { + recycler.ScrapView(itemView); + } + + mViewList.Clear(); + } + + public void AttachView(ViewHolder holder, int index) + { + if (index == -1) + { + index = mViewList.Count; + } + + mViewList.Insert(index, holder); + + if (!itemViewTable.ContainsKey(holder.ItemView.ID)) + { + mTapGestureDetector.Attach(holder.ItemView); + holder.ItemView.TouchEvent += OnTouchEvent; + } + + itemViewTable[holder.ItemView.ID] = holder; + } + + public void AddView(ViewHolder holder, int index) + { + mFlexibleView.Add(holder.ItemView); + + mFlexibleView.DispatchChildAttached(holder); + + AttachView(holder, index); + } + + public bool RemoveView(ViewHolder holder) + { + mFlexibleView.Remove(holder.ItemView); + + mFlexibleView.DispatchChildDetached(holder); + + return mViewList.Remove(holder); + } + + public bool RemoveViewAt(int index) + { + ViewHolder itemView = mViewList[index]; + return RemoveView(itemView); + } + + public bool RemoveViewsRange(int index, int count) + { + for (int i = index; i < index + count; i++) + { + ViewHolder holder = mViewList[i]; + mFlexibleView.Remove(holder.ItemView); + } + mViewList.RemoveRange(index, count); + return false; + } + + public int GetChildCount() + { + return mViewList.Count; + } + + public ViewHolder GetChildAt(int index) + { + if (index < 0 || index >= mViewList.Count) + { + return null; + } + return mViewList[index]; + } + + private void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e) + { + View itemView = e.View as View; + if (itemView == null) + { + return; + } + if (itemViewTable.ContainsKey(itemView.ID)) + { + ViewHolder holder = itemViewTable[itemView.ID]; + mFlexibleView.FocusedItemIndex = holder.AdapterPosition; + + mFlexibleView.DispatchItemClicked(holder); + } + } + + private bool OnTouchEvent(object source, TouchEventArgs e) + { + View itemView = source as View; + if (itemView != null && itemViewTable.ContainsKey(itemView.ID)) + { + ViewHolder holder = itemViewTable[itemView.ID]; + + mFlexibleView.DispatchItemTouched(holder, e.Touch); + return true; + } + return false; + } + } + + private class AdapterHelper + { + private FlexibleView mFlexibleView; + + private List mPendingUpdates = new List(); + + private int mExistingUpdateTypes = 0; + + public AdapterHelper(FlexibleView flexibleView) + { + mFlexibleView = flexibleView; + } + + /** + * @return True if updates should be processed. + */ + public bool OnItemRangeInserted(int positionStart, int itemCount) + { + if (itemCount < 1) + { + return false; + } + mPendingUpdates.Add(new UpdateOp(UpdateOp.ADD, positionStart, itemCount)); + mExistingUpdateTypes |= UpdateOp.ADD; + return mPendingUpdates.Count == 1; + } + + /** + * @return True if updates should be processed. + */ + public bool OnItemRangeRemoved(int positionStart, int itemCount) + { + if (itemCount < 1) + { + return false; + } + mPendingUpdates.Add(new UpdateOp(UpdateOp.REMOVE, positionStart, itemCount)); + mExistingUpdateTypes |= UpdateOp.REMOVE; + return mPendingUpdates.Count == 1; + } + + public void PreProcess() + { + int count = mPendingUpdates.Count; + for (int i = 0; i < count; i++) + { + UpdateOp op = mPendingUpdates[i]; + switch (op.cmd) + { + case UpdateOp.ADD: + mFlexibleView.OffsetPositionRecordsForInsert(op.positionStart, op.itemCount); + break; + case UpdateOp.REMOVE: + mFlexibleView.OffsetPositionRecordsForRemove(op.positionStart, op.itemCount, false); + break; + case UpdateOp.UPDATE: + break; + case UpdateOp.MOVE: + break; + } + } + mPendingUpdates.Clear(); + } + + } + + /** + * Queued operation to happen when child views are updated. + */ + private class UpdateOp + { + + public const int ADD = 1; + + public const int REMOVE = 1 << 1; + + public const int UPDATE = 1 << 2; + + public const int MOVE = 1 << 3; + + public const int POOL_SIZE = 30; + + public int cmd; + + public int positionStart; + + // holds the target position if this is a MOVE + public int itemCount; + + public UpdateOp(int cmd, int positionStart, int itemCount) + { + this.cmd = cmd; + this.positionStart = positionStart; + this.itemCount = itemCount; + } + + public bool Equals(UpdateOp op) + { + if (cmd != op.cmd) + { + return false; + } + if (cmd == MOVE && Math.Abs(itemCount - positionStart) == 1) + { + // reverse of this is also true + if (itemCount == op.positionStart && positionStart == op.itemCount) + { + return true; + } + } + if (itemCount != op.itemCount) + { + return false; + } + if (positionStart != op.positionStart) + { + return false; + } + + return true; + } + + } + + private class ItemViewInfo + { + public float Left + { + get; + set; + } + public float Top + { + get; + set; + } + public float Right + { + get; + set; + } + public float Bottom + { + get; + set; + } + } + + } +} diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.LayoutManager.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.LayoutManager.cs new file mode 100755 index 0000000..8122078 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.LayoutManager.cs @@ -0,0 +1,899 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class FlexibleView + { + /// + /// A LayoutManager is responsible for measuring and positioning item views within a FlexibleView + /// as well as determining the policy for when to recycle item views that are no longer visible to the user. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class LayoutManager + { + /// + /// Direction + /// + public enum Direction + { + /// + /// Left + /// + Left, + + /// + /// Right + /// + Right, + + /// + /// Up + /// + Up, + + /// + /// Down + /// + Down + } + + private readonly int SCROLL_ANIMATION_DURATION = 500; + + private FlexibleView mFlexibleView; + private ChildHelper mChildHelper; + + private List mPendingRecycleViews = new List(); + + private Animation mScrollAni; + + /// + /// Layout all relevant child views from the given adapter. + /// + /// Recycler to use for fetching potentially cached views for a position + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract void OnLayoutChildren(Recycler recycler); + + /// + /// Called after a full layout calculation is finished. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void OnLayoutCompleted() + { + } + + /// + /// Gets the current focus position in adapter. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int FocusPosition + { + get + { + return mFlexibleView.mFocusedItemIndex; + } + } + + /// + /// Gets the datas count in data sets. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int ItemCount + { + get + { + Adapter b = mFlexibleView != null ? mFlexibleView.mAdapter : null; + + return b != null ? b.GetItemCount() : 0; + } + } + + /// + /// Query if horizontal scrolling is currently supported. The default implementation returns false. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool CanScrollHorizontally() + { + return false; + } + + /// + /// Query if vertical scrolling is currently supported. The default implementation returns false. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool CanScrollVertically() + { + return false; + } + + /// + /// Scroll horizontally by dy pixels in screen coordinates. + /// + /// distance to scroll in pixels. Y increases as scroll position approaches the top. + /// Recycler to use for fetching potentially cached views for a position + /// Specify if the scroll need animation + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual float ScrollHorizontallyBy(float dy, Recycler recycler, bool immediate) + { + return 0; + } + + /// + /// Scroll vertically by dy pixels in screen coordinates. + /// + /// distance to scroll in pixels. Y increases as scroll position approaches the top. + /// Recycler to use for fetching potentially cached views for a position + /// Specify if the scroll need animation + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual float ScrollVerticallyBy(float dy, Recycler recycler, bool immediate) + { + return 0; + } + + /// + /// Compute the extent of the scrollbar's thumb within the range. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual float ComputeScrollExtent() + { + return 0; + } + + /// + /// Compute the offset of the scrollbar's thumb within the range. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual float ComputeScrollOffset() + { + return 0; + } + + /// + /// Compute the range that the scrollbar represents. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual float ComputeScrollRange() + { + return 0; + } + + /// + /// Scroll the FlexibleView to make the position visible. + /// + /// Scroll to this adapter position + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void ScrollToPosition(int position) + { + + } + + /// + /// Scroll to the specified adapter position with the given offset from resolved layout start. + /// + /// Scroll to this adapter position + /// The distance (in pixels) between the start edge of the item view and start edge of the FlexibleView. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void ScrollToPositionWithOffset(int position, int offset) + { + + } + + internal void MoveFocus(FlexibleView.LayoutManager.Direction direction, Recycler recycler) + { + int prevFocusPosition = FocusPosition; + int nextFocusPosition = GetNextPosition(FocusPosition, direction); + if (nextFocusPosition == NO_POSITION) + { + return; + } + + FlexibleView.ViewHolder nextFocusChild = FindItemViewByPosition(nextFocusPosition); + if (nextFocusChild == null) + { + nextFocusChild = OnFocusSearchFailed(null, direction, recycler); + } + + if (nextFocusChild != null) + { + RequestChildRectangleOnScreen(mFlexibleView, nextFocusChild, recycler, false); + + ChangeFocus(nextFocusPosition); + } + } + + /** + * Requests that the given child of the RecyclerView be positioned onto the screen. This + * method can be called for both unfocusable and focusable child views. For unfocusable + * child views, focusedChildVisible is typically true in which case, layout manager + * makes the child view visible only if the currently focused child stays in-bounds of RV. + * @param parent The parent RecyclerView. + * @param child The direct child making the request. + * @param rect The rectangle in the child's coordinates the child + * wishes to be on the screen. + * @param immediate True to forbid animated or delayed scrolling, + * false otherwise + * @param focusedChildVisible Whether the currently focused view must stay visible. + * @return Whether the group scrolled to handle the operation + */ + internal bool RequestChildRectangleOnScreen(FlexibleView parent, FlexibleView.ViewHolder child, Recycler recycler, bool immediate) + { + Vector2 scrollAmount = GetChildRectangleOnScreenScrollAmount(parent, child); + float dx = scrollAmount[0]; + float dy = scrollAmount[1]; + if (dx != 0 || dy != 0) + { + if (dx != 0 && CanScrollHorizontally()) + { + ScrollHorizontallyBy(dx, recycler, immediate); + } + else if (dy != 0 && CanScrollVertically()) + { + ScrollVerticallyBy(dy, recycler, immediate); + } + return true; + } + return false; + } + + /// + /// Calls {@code FlexibleView#RelayoutRequest} on the underlying FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RelayoutRequest() + { + if (mFlexibleView != null) + { + mFlexibleView.RelayoutRequest(); + } + } + + /// + /// Lay out the given child view within the FlexibleView using coordinates that include view margins. + /// + /// Child to lay out + /// Left edge, with item view left margin included + /// Top edge, with item view top margin included + /// Width, with item view left and right margin included + /// Height, with item view top and bottom margin included + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void LayoutChild(ViewHolder child, float left, float top, float width, float height) + { + if (null == child) return; + View itemView = child.ItemView; + itemView.SizeWidth = width - itemView.Margin.Start - itemView.Margin.End; + itemView.SizeHeight = height - itemView.Margin.Top - itemView.Margin.Bottom; + itemView.PositionX = left + itemView.Margin.Start; + itemView.PositionY = top + itemView.Margin.Top; + } + + /// + /// Change the ViewHolder with focusPosition to focus. + /// + /// the newly focus position + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void ChangeFocus(int focusPosition) + { + if (mFlexibleView != null) + { + mFlexibleView.DispatchFocusChanged(focusPosition); + } + } + + /// + /// Return the current number of child views attached to the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int ChildCount + { + get + { + return mChildHelper != null ? mChildHelper.GetChildCount() : 0; + } + } + + /// + /// Return the child view at the given index. + /// + /// child index + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder GetChildAt(int index) + { + return mChildHelper != null ? mChildHelper.GetChildAt(index) : null; + } + + /// + /// Finds the view which represents the given adapter position. + /// + /// adapter position + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder FindItemViewByPosition(int position) + { + return mFlexibleView.FindViewHolderForLayoutPosition(position); + } + + /// + /// Offset all child views attached to the parent FlexibleView by dx pixels along the horizontal axis. + /// + /// Pixels to offset by + /// specify if the offset need animation + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void OffsetChildrenHorizontal(float dx, bool immediate) + { + if (mChildHelper == null) + { + return; + } + + if (dx == 0) + { + return; + } + + int childCount = mChildHelper.GetChildCount(); + if (immediate == true) + { + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + v.ItemView.PositionX += dx; + } + } + else + { + if (mScrollAni == null) + { + mScrollAni = new Animation(); + mScrollAni.Duration = SCROLL_ANIMATION_DURATION; + mScrollAni.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare); + } + + // avoid out of boundary of flexibleview. delta value might be used for shadow. + // this must be done before animation clear. + if (childCount > 0) + { + ViewHolder vh = mChildHelper.GetChildAt(0); + if (vh.LayoutPosition == 0) + { + if ((int)(vh.Left + dx) > 0) + { + dx = 0 - vh.Left; + } + } + + vh = mChildHelper.GetChildAt(childCount - 1); + if (vh.LayoutPosition == ItemCount - 1) + { + if ((int)(vh.Right + dx) < (int)Width + PaddingRight) + { + dx = Width + PaddingRight - vh.Right; + } + } + } + + // save position before animation clear. + float[] childrenPositon = new float[childCount]; + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + childrenPositon[i] = v.ItemView.PositionX; + } + + mScrollAni.Clear(); + mScrollAni.Finished += OnScrollAnimationFinished; + + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + // set position again because position might be changed after animation clear. + v.ItemView.PositionX = childrenPositon[i]; + mScrollAni.AnimateTo(v.ItemView, "PositionX", v.ItemView.PositionX + dx); + } + mScrollAni.Play(); + } + } + + /// + /// Offset all child views attached to the parent FlexibleView by dy pixels along the vertical axis. + /// + /// Pixels to offset by + /// specify if the offset need animation + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void OffsetChildrenVertical(float dy, bool immediate) + { + if (mChildHelper == null) + { + return; + } + + if (dy == 0) + { + return; + } + + int childCount = mChildHelper.GetChildCount(); + if (immediate == true) + { + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + v.ItemView.PositionY += dy; + } + } + else + { + if (mScrollAni == null) + { + mScrollAni = new Animation(); + mScrollAni.Duration = SCROLL_ANIMATION_DURATION; + mScrollAni.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare); + } + + // avoid out of boundary of flexibleview. delta value might be used for shadow. + // this must be done before animation clear. + if (childCount > 0) + { + ViewHolder vh = mChildHelper.GetChildAt(0); + if (vh.LayoutPosition == 0) + { + if ((int)(vh.Top + dy) > 0) + { + dy = 0 - vh.Top; + } + } + + vh = mChildHelper.GetChildAt(childCount - 1); + if (vh.LayoutPosition == ItemCount - 1) + { + if ((int)(vh.Bottom + dy) < (int)Height + PaddingBottom) + { + dy = Height + PaddingBottom - vh.Bottom; + } + } + } + + // save position before animation clear. + float[] childPositon = new float[childCount]; + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + childPositon[i] = v.ItemView.PositionY; + } + + mScrollAni.Clear(); + mScrollAni.Finished += OnScrollAnimationFinished; + + for (int i = childCount - 1; i >= 0; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + // set position again because position might be changed after animation clear. + v.ItemView.PositionY = childPositon[i]; + mScrollAni.AnimateTo(v.ItemView, "PositionY", v.ItemView.PositionY + dy); + } + mScrollAni.Play(); + } + } + + /// + /// Return the width of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Width + { + get + { + return mFlexibleView != null ? mFlexibleView.SizeWidth : 0; + } + } + + /// + /// Return the height of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Height + { + get + { + return mFlexibleView != null ? mFlexibleView.SizeHeight : 0; + } + } + + /// + /// Return the left padding of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int PaddingLeft + { + get + { + return mFlexibleView?.Padding?.Start ?? 0; + } + } + + /// + /// Return the top padding of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int PaddingTop + { + get + { + return mFlexibleView?.Padding?.Top ?? 0; + } + } + + /// + /// Return the right padding of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int PaddingRight + { + get + { + return mFlexibleView?.Padding?.End ?? 0; + } + } + + /// + /// Return the bottom padding of the parent FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int PaddingBottom + { + get + { + return mFlexibleView?.Padding?.Bottom ?? 0; + } + } + + /// + /// Add a view to the currently attached FlexibleView if needed.
+ /// LayoutManagers should use this method to add views obtained from a FlexibleView.Recycler using getViewForPosition(int).
+ ///
+ /// view to add + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void AddView(ViewHolder holder) + { + AddView(holder, -1); + } + + /// + /// Add a view to the currently attached FlexibleView if needed.
+ /// LayoutManagers should use this method to add views obtained from a FlexibleView.Recycler using getViewForPosition(int).
+ ///
+ /// view to add + /// index to add child at + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void AddView(ViewHolder holder, int index) + { + AddViewInternal(holder, index, false); + } + + /// + /// Temporarily detach and scrap all currently attached child views. + /// Views will be scrapped into the given Recycler. + /// The Recycler may prefer to reuse scrap views before other views that were previously recycled. + /// + /// Recycler to scrap views into + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void ScrapAttachedViews(Recycler recycler) + { + if (null == mChildHelper || null == recycler) + { + return; + } + + recycler.Clear(); + + mChildHelper.ScrapViews(recycler); + } + + /** + * Remove a child view and recycle it using the given Recycler. + * + * @param index Index of child to remove and recycle + * @param recycler Recycler to use to recycle child + */ + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RemoveAndRecycleViewAt(int index, Recycler recycler) + { + if (null == recycler) return; + ViewHolder v = mChildHelper.GetChildAt(index); + mChildHelper.RemoveViewAt(index); + recycler.RecycleView(v); + } + + /// + /// ecycles children between given indices.. + /// + /// Recycler to recycle views into + /// inclusive + /// exclusive + /// recycle immediately or add to pending list and recycle later. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RecycleChildren(FlexibleView.Recycler recycler, int startIndex, int endIndex, bool immediate) + { + if (startIndex == endIndex) + { + return; + } + if (endIndex > startIndex) + { + for (int i = startIndex; i < endIndex; i++) + { + ViewHolder v = mChildHelper.GetChildAt(i); + if (v.PendingRecycle == false) + { + v.PendingRecycle = true; + mPendingRecycleViews.Add(v); + } + } + } + else + { + for (int i = startIndex; i > endIndex; i--) + { + ViewHolder v = mChildHelper.GetChildAt(i); + if (v.PendingRecycle == false) + { + v.PendingRecycle = true; + mPendingRecycleViews.Add(v); + } + } + } + if (immediate == true) + { + RecycleChildrenInt(recycler); + } + } + + /// + /// Retrieves a position that neighbor to current position by direction. + /// + /// The anchor adapter position + /// The direction. + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected abstract int GetNextPosition(int position, FlexibleView.LayoutManager.Direction direction); + + /// + /// Retrieves the first visible item view. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual ViewHolder FindFirstVisibleItemView() + { + return null; + } + + /// + /// Retrieves the last visible item view. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual ViewHolder FindLastVisibleItemView() + { + return null; + } + + internal virtual ViewHolder OnFocusSearchFailed(FlexibleView.ViewHolder focused, LayoutManager.Direction direction, Recycler recycler) + { + return null; + } + + internal void SetRecyclerView(FlexibleView recyclerView) + { + mFlexibleView = recyclerView; + mChildHelper = recyclerView.mChildHelper; + } + + internal void StopScroll(bool doSomethingAfterAnimationStopped) + { + if (mScrollAni != null && mScrollAni.State == Animation.States.Playing) + { + mScrollAni.Finished -= OnScrollAnimationFinished; + mScrollAni.Stop(); + + if (doSomethingAfterAnimationStopped) + { + OnScrollAnimationFinished(mScrollAni, null); + } + } + } + + /** + * Returns the scroll amount that brings the given rect in child's coordinate system within + * the padded area of RecyclerView. + * @param parent The parent RecyclerView. + * @param child The direct child making the request. + * @param rect The rectangle in the child's coordinates the child + * wishes to be on the screen. + * @param immediate True to forbid animated or delayed scrolling, + * false otherwise + * @return The array containing the scroll amount in x and y directions that brings the + * given rect into RV's padded area. + */ + private Vector2 GetChildRectangleOnScreenScrollAmount(FlexibleView parent, FlexibleView.ViewHolder child) + { + Vector2 ret = new Vector2(0, 0); + int parentLeft = PaddingLeft; + int parentTop = PaddingTop; + int parentRight = (int)Width - PaddingRight; + int parentBottom = (int)Height - PaddingBottom; + int childLeft = (int)child.Left; + int childTop = (int)child.Top; + int childRight = (int)child.Right; + int childBottom = (int)child.Bottom; + + int offScreenLeft = Math.Min(0, childLeft - parentLeft); + int offScreenTop = Math.Min(0, childTop - parentTop); + int offScreenRight = Math.Max(0, childRight - parentRight); + int offScreenBottom = Math.Max(0, childBottom - parentBottom); + + // Favor the "start" layout direction over the end when bringing one side or the other + // of a large rect into view. If we decide to bring in end because start is already + // visible, limit the scroll such that start won't go out of bounds. + int dx = offScreenLeft != 0 ? offScreenLeft + : Math.Min(childLeft - parentLeft, offScreenRight); + + // Favor bringing the top into view over the bottom. If top is already visible and + // we should scroll to make bottom visible, make sure top does not go out of bounds. + int dy = offScreenTop != 0 ? offScreenTop + : Math.Min(childTop - parentTop, offScreenBottom); + + ret.X = -dx; + ret.Y = -dy; + + return ret; + } + + private void OnScrollAnimationFinished(object sender, EventArgs e) + { + foreach (ViewHolder holder in mPendingRecycleViews) + { + holder.PendingRecycle = false; + } + mPendingRecycleViews.Clear(); + + int start = NO_POSITION; + ViewHolder firstItemView = FindFirstVisibleItemView(); + if (firstItemView != null) + start = firstItemView.LayoutPosition; + else + start = 0; + + int itemCount = ChildCount; + + int end = NO_POSITION; + ViewHolder lastItemView = FindLastVisibleItemView(); + if (lastItemView != null) + end = lastItemView.LayoutPosition; + else + end = itemCount - 1; + + List removedViewList = new List(); + for (int i = 0; i < itemCount; i++) + { + ViewHolder v = GetChildAt(i); + + //if item view of holder is visible, it should not be recycled. + if (v.LayoutPosition >= start && v.LayoutPosition <= end) + continue; + + removedViewList.Add(v); + } + + for (int i = 0; i < removedViewList.Count; i++) + { + ViewHolder v = removedViewList[i]; + v.PendingRecycle = false; + mFlexibleView.mRecycler.RecycleView(v); + mChildHelper.RemoveView(v); + } + + // relayout + } + + private void AddViewInternal(ViewHolder holder, int index, bool disappearing) + { + if (null == holder) return; + if (holder.IsScrap()) + { + holder.Unscrap(); + mChildHelper.AttachView(holder, index); + } + else + { + mChildHelper.AddView(holder, index); + } + } + + private void RecycleChildrenInt(FlexibleView.Recycler recycler) + { + if (null == recycler) return; + foreach (ViewHolder holder in mPendingRecycleViews) + { + holder.PendingRecycle = false; + recycler.RecycleView(holder); + mChildHelper.RemoveView(holder); + } + mPendingRecycleViews.Clear(); + } + + private void ScrapOrRecycleView(Recycler recycler, ViewHolder itemView) + { + recycler.ScrapView(itemView); + } + + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Recycler.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Recycler.cs new file mode 100755 index 0000000..c23e5e2 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.Recycler.cs @@ -0,0 +1,166 @@ +using System.Collections.Generic; +using System.ComponentModel; + +namespace Tizen.NUI.Components +{ + public partial class FlexibleView + { + /// + /// A Recycler is responsible for managing scrapped or detached item views for reuse. + /// A "scrapped" view is a view that is still attached to its parent FlexibleView but that has been marked for removal or reuse. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class Recycler + { + private FlexibleView mFlexibleView; + private RecycledViewPool mRecyclerPool; + + private List mAttachedScrap = new List(); + private List mChangedScrap = null; + //private List mCachedViews = new List(); + + //private List mUnmodifiableAttachedScrap; + + private int mCacheSizeMax = 2; + + /// + /// Recycler constructor. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Recycler(FlexibleView recyclerView) + { + mFlexibleView = recyclerView; + } + + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetViewCacheSize(int viewCount) + { + mCacheSizeMax = viewCount; + } + + /// + /// Obtain a view initialized for the given position. + /// + /// Position to obtain a view for + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder GetViewForPosition(int position) + { + Adapter b = mFlexibleView != null ? mFlexibleView.mAdapter : null; + if (b == null) + { + return null; + } + if (position < 0 || position >= b.GetItemCount()) + { + return null; + } + + int type = b.GetItemViewType(position); + ViewHolder itemView = null; + for (int i = 0; i < mAttachedScrap.Count; i++) + { + if (mAttachedScrap[i].LayoutPosition == position && mAttachedScrap[i].ItemViewType == type) + { + itemView = mAttachedScrap[i]; + break; + } + } + if (itemView == null) + { + itemView = mRecyclerPool.GetRecycledView(type); + if (itemView == null) + { + itemView = b.OnCreateViewHolder(type); + } + + if (!itemView.IsBound) + { + b.OnBindViewHolder(itemView, position); + itemView.IsBound = true; + } + + itemView.AdapterPosition = position; + itemView.ItemViewType = type; + } + + return itemView; + } + + /// + /// Recycle a detached view. + /// + /// Removed holder for recycling + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RecycleView(ViewHolder itemView) + { + if (null == itemView) return; + itemView.ScrapContainer = null; + mRecyclerPool.PutRecycledView(itemView); + } + + /// + /// Returns the count in scrap list. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int GetScrapCount() + { + return mAttachedScrap.Count; + } + + /// + /// Gets the scrap view at index. + /// + /// index + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder GetScrapViewAt(int index) + { + return mAttachedScrap[index]; + } + + /// + /// Clear scrap views out of this recycler. Detached views contained within a recycled view pool will remain. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void Clear() + { + mAttachedScrap.Clear(); + if (mChangedScrap != null) + { + mChangedScrap.Clear(); + } + } + + internal void ScrapView(ViewHolder itemView) + { + mAttachedScrap.Add(itemView); + itemView.ScrapContainer = this; + } + + internal void UnscrapView(ViewHolder itemView) + { + mAttachedScrap.Remove(itemView); + itemView.ScrapContainer = null; + } + + internal void SetRecycledViewPool(RecycledViewPool pool) + { + mRecyclerPool = pool; + } + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.ViewHolder.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.ViewHolder.cs new file mode 100755 index 0000000..bf37ef1 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.ViewHolder.cs @@ -0,0 +1,245 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class FlexibleView + { + /// + /// A ViewHolder describes an item view and metadata about its place within the FlexibleView. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class ViewHolder + { + // This ViewHolder has been bound to a position; AdapterPosition, mItemId and mItemViewType + // are all valid. + //static readonly int FLAG_BOUND = 1 << 0; + + // The data this ViewHolder's view reflects is stale and needs to be rebound + // by the adapter. AdapterPosition and mItemId are consistent. + //static readonly int FLAG_UPDATE = 1 << 1; + + // This ViewHolder's data is invalid. The identity implied by AdapterPosition and mItemId + // are not to be trusted and may no longer match the item view type. + // This ViewHolder must be fully rebound to different data. + //static readonly int FLAG_INVALID = 1 << 2; + + // This ViewHolder points at data that represents an item previously removed from the + // data set. Its view may still be used for things like outgoing animations. + //static readonly int FLAG_REMOVED = 1 << 3; + + // This ViewHolder should not be recycled. This flag is set via setIsRecyclable() + // and is intended to keep views around during animations. + //static readonly int FLAG_NOT_RECYCLABLE = 1 << 4; + + // This ViewHolder is returned from scrap which means we are expecting an addView call + // for this itemView. When returned from scrap, ViewHolder stays in the scrap list until + // the end of the layout pass and then recycled by RecyclerView if it is not added back to + // the RecyclerView. + //static readonly int FLAG_RETURNED_FROM_SCRAP = 1 << 5; + + // This ViewHolder is fully managed by the LayoutManager. We do not scrap, recycle or remove + // it unless LayoutManager is replaced. + // It is still fully visible to the LayoutManager. + //static readonly int FLAG_IGNORE = 1 << 7; + + private int mFlags; + private int mPreLayoutPosition = NO_POSITION; + + /// + /// ViewHolder constructor. + /// + /// View + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewHolder(View itemView) + { + if (itemView == null) + { + throw new ArgumentNullException("itemView may not be null"); + } + this.ItemView = itemView; + } + + /// + /// Returns the view. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public View ItemView { get; } + + /// + /// Returns the left edge includes the view left margin. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Left + { + get + { + return ItemView.PositionX - ItemView.Margin.Start; + } + } + + /// + /// Returns the right edge includes the view right margin. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Right + { + get + { + return ItemView.PositionX + ItemView.SizeWidth + ItemView.Margin.End; + } + } + + /// + /// Returns the top edge includes the view top margin. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Top + { + get + { + return ItemView.PositionY - ItemView.Margin.Top; + } + } + + /// + /// Returns the bottom edge includes the view bottom margin. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public float Bottom + { + get + { + return ItemView.PositionY + ItemView.SizeHeight + ItemView.Margin.Bottom; + } + } + + /// + /// Returns the position of the ViewHolder in terms of the latest layout pass. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int LayoutPosition + { + get + { + return mPreLayoutPosition == NO_POSITION ? AdapterPosition : mPreLayoutPosition; + } + } + + /// + /// Returns the Adapter position of the item represented by this ViewHolder. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int AdapterPosition { get; internal set; } = NO_POSITION; + + /// + /// Get old position of item view. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int OldPosition { get; private set; } = NO_POSITION; + + /// + /// Gets or sets item view type. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int ItemViewType { get; set; } = INVALID_TYPE; + + internal bool IsBound + { + get; + set; + } + + internal Recycler ScrapContainer { get; set; } + + internal bool PendingRecycle + { + get; + set; + } = false; + + + internal bool IsScrap() + { + return ScrapContainer != null; + } + + internal void Unscrap() + { + ScrapContainer.UnscrapView(this); + } + + + internal void FlagRemovedAndOffsetPosition(int mNewPosition, int offset, bool applyToPreLayout) + { + //AddFlags(ViewHolder.FLAG_REMOVED); + OffsetPosition(offset, applyToPreLayout); + AdapterPosition = mNewPosition; + } + + internal void OffsetPosition(int offset, bool applyToPreLayout) + { + if (OldPosition == NO_POSITION) + { + OldPosition = AdapterPosition; + } + if (mPreLayoutPosition == NO_POSITION) + { + mPreLayoutPosition = AdapterPosition; + } + if (applyToPreLayout) + { + mPreLayoutPosition += offset; + } + AdapterPosition += offset; + } + + internal void ClearOldPosition() + { + OldPosition = NO_POSITION; + mPreLayoutPosition = NO_POSITION; + } + + internal void SaveOldPosition() + { + if (OldPosition == NO_POSITION) + { + OldPosition = AdapterPosition; + } + } + + private void SetFlags(int flags, int mask) + { + mFlags = (mFlags & ~mask) | (flags & mask); + } + + private void AddFlags(int flags) + { + mFlags |= flags; + } + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs index c8fdac0..c0062c1 100755 --- a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs @@ -27,7 +27,7 @@ namespace Tizen.NUI.Components /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public class FlexibleView : Control + public partial class FlexibleView : Control { /// /// Constant value: -1. @@ -833,1935 +833,5 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public ViewHolder TouchedView { get; set; } } - - /// - /// Adapters provide a binding from an app-specific data set to views that are displayed within a FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class Adapter - { - private EventHandler itemEventHandlers; - - internal event EventHandler ItemEvent - { - add - { - itemEventHandlers += value; - } - - remove - { - itemEventHandlers -= value; - } - } - - internal enum ItemEventType - { - Insert = 0, - Remove, - Move, - Change - } - - /// - /// Called when FlexibleView needs a new FlexibleView.ViewHolder of the given type to represent an item. - /// - /// The view type of the new View - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract ViewHolder OnCreateViewHolder(int viewType); - - /// - /// Called by FlexibleView to display the data at the specified position. - /// - /// The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. - /// The position of the item within the adapter's data set. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract void OnBindViewHolder(ViewHolder holder, int position); - - /// - /// Called when a ViewHolder is never used. - /// - /// The ViewHolder which need to be disposed - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract void OnDestroyViewHolder(ViewHolder holder); - - /// - /// Returns the total number of items in the data set held by the adapter. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract int GetItemCount(); - - /// - /// Return the view type of the item at position for the purposes of view recycling. - /// - /// The position of the item within the adapter's data set. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual int GetItemViewType(int position) - { - return 0; - } - - /// - /// Called by FlexibleView when it starts observing this Adapter. - /// Keep in mind that same adapter may be observed by multiple FlexibleView. - /// - /// The FlexibleView instance which started observing this adapter. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnAttachedToRecyclerView(FlexibleView flexibleView) - { - } - - /// - /// Called by FlexibleView when it stops observing this Adapter. - /// - /// The FlexibleView instance which stopped observing this adapter. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnDetachedFromRecyclerView(FlexibleView flexibleView) - { - } - - /// - /// Called when FlexibleView focus changed. - /// - /// The FlexibleView into which the focus ViewHolder changed. - /// The position of previous focus - /// The position of current focus - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnFocusChange(FlexibleView flexibleView, int previousFocus, int currentFocus) - { - } - - /// - /// Called when a view created by this adapter has been recycled. - /// If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources - /// - /// The ViewHolder will be recycled. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnViewRecycled(ViewHolder holder) - { - } - - /// - /// Called when a view created by this adapter has been attached to a window. - /// This can be used as a reasonable signal that the view is about to be seen by the user. - /// - /// Holder of the view being attached. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnViewAttachedToWindow(ViewHolder holder) - { - } - - /// - /// Called when a view created by this adapter has been detached from its window. - /// - /// Holder of the view being detached. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnViewDetachedFromWindow(ViewHolder holder) - { - } - - /// - /// Notify any registered observers that the data set has changed. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyDataSetChanged() - { - } - - /// - /// Notify any registered observers that the data set has changed. - /// It indicates that any reflection of the data at position is out of date and should be updated. - /// - /// Position of the item that has changed - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemChanged(int position) - { - ItemEventArgs args = new ItemEventArgs - { - EventType = ItemEventType.Change, - }; - args.param[0] = position; - args.param[1] = 1; - OnItemEvent(this, args); - } - - /// - /// Notify any registered observers that the itemCount items starting at position positionStart have changed. - /// An optional payload can be passed to each changed item. - /// - /// Position of the first item that has changed - /// Number of items that have changed - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemRangeChanged(int positionStart, int itemCount) - { - } - - /// - /// Notify any registered observers that the data set has been newly inserted. - /// It indicates that any reflection of the data at position is out of date and should be updated. - /// - /// Position of the item that has been newly inserted - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemInserted(int position) - { - NotifyItemRangeInserted(position, 1); - } - - /// - /// Notify any registered observers that the itemCount items starting at position positionStart have been newly inserted. - /// - /// Position of the first item that was inserted - /// Number of items inserted - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemRangeInserted(int positionStart, int itemCount) - { - ItemEventArgs args = new ItemEventArgs - { - EventType = ItemEventType.Insert, - }; - args.param[0] = positionStart; - args.param[1] = itemCount; - OnItemEvent(this, args); - } - - /// - /// Notify any registered observers that the item previously located at position has been removed from the data set. - /// - /// Previous position of the first item that was removed - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemRemoved(int position) - { - NotifyItemRangeRemoved(position, 1); - } - - /// - /// Notify any registered observers that the itemCount items previously located at positionStart have been removed from the data set. - /// - /// Previous position of the first item that was removed - /// Number of items removed from the data set - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemRangeRemoved(int positionStart, int itemCount) - { - ItemEventArgs args = new ItemEventArgs - { - EventType = ItemEventType.Remove, - }; - args.param[0] = positionStart; - args.param[1] = itemCount; - OnItemEvent(this, args); - } - - /// - /// Notify any registered observers that the item reflected at fromPosition has been moved to toPosition. - /// - /// Previous position of the item - /// New position of the item. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void NotifyItemMoved(int fromPosition, int toPosition) - { - - } - - private void OnItemEvent(object sender, ItemEventArgs e) - { - itemEventHandlers?.Invoke(sender, e); - } - - internal class ItemEventArgs : EventArgs - { - - /// - /// Data change event parameters. - /// - public int[] param = new int[4]; - - /// - /// Data changed event type. - /// - public ItemEventType EventType - { - get; - set; - } - } - } - - /// - /// A LayoutManager is responsible for measuring and positioning item views within a FlexibleView - /// as well as determining the policy for when to recycle item views that are no longer visible to the user. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class LayoutManager - { - /// - /// Direction - /// - public enum Direction - { - /// - /// Left - /// - Left, - - /// - /// Right - /// - Right, - - /// - /// Up - /// - Up, - - /// - /// Down - /// - Down - } - - private readonly int SCROLL_ANIMATION_DURATION = 500; - - private FlexibleView mFlexibleView; - private ChildHelper mChildHelper; - - private List mPendingRecycleViews = new List(); - - private Animation mScrollAni; - - /// - /// Layout all relevant child views from the given adapter. - /// - /// Recycler to use for fetching potentially cached views for a position - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract void OnLayoutChildren(Recycler recycler); - - /// - /// Called after a full layout calculation is finished. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void OnLayoutCompleted() - { - } - - /// - /// Gets the current focus position in adapter. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int FocusPosition - { - get - { - return mFlexibleView.mFocusedItemIndex; - } - } - - /// - /// Gets the datas count in data sets. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int ItemCount - { - get - { - Adapter b = mFlexibleView != null ? mFlexibleView.mAdapter : null; - - return b != null ? b.GetItemCount() : 0; - } - } - - /// - /// Query if horizontal scrolling is currently supported. The default implementation returns false. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual bool CanScrollHorizontally() - { - return false; - } - - /// - /// Query if vertical scrolling is currently supported. The default implementation returns false. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual bool CanScrollVertically() - { - return false; - } - - /// - /// Scroll horizontally by dy pixels in screen coordinates. - /// - /// distance to scroll in pixels. Y increases as scroll position approaches the top. - /// Recycler to use for fetching potentially cached views for a position - /// Specify if the scroll need animation - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual float ScrollHorizontallyBy(float dy, Recycler recycler, bool immediate) - { - return 0; - } - - /// - /// Scroll vertically by dy pixels in screen coordinates. - /// - /// distance to scroll in pixels. Y increases as scroll position approaches the top. - /// Recycler to use for fetching potentially cached views for a position - /// Specify if the scroll need animation - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual float ScrollVerticallyBy(float dy, Recycler recycler, bool immediate) - { - return 0; - } - - /// - /// Compute the extent of the scrollbar's thumb within the range. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual float ComputeScrollExtent() - { - return 0; - } - - /// - /// Compute the offset of the scrollbar's thumb within the range. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual float ComputeScrollOffset() - { - return 0; - } - - /// - /// Compute the range that the scrollbar represents. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual float ComputeScrollRange() - { - return 0; - } - - /// - /// Scroll the FlexibleView to make the position visible. - /// - /// Scroll to this adapter position - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void ScrollToPosition(int position) - { - - } - - /// - /// Scroll to the specified adapter position with the given offset from resolved layout start. - /// - /// Scroll to this adapter position - /// The distance (in pixels) between the start edge of the item view and start edge of the FlexibleView. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void ScrollToPositionWithOffset(int position, int offset) - { - - } - - internal void MoveFocus(FlexibleView.LayoutManager.Direction direction, Recycler recycler) - { - int prevFocusPosition = FocusPosition; - int nextFocusPosition = GetNextPosition(FocusPosition, direction); - if (nextFocusPosition == NO_POSITION) - { - return; - } - - FlexibleView.ViewHolder nextFocusChild = FindItemViewByPosition(nextFocusPosition); - if (nextFocusChild == null) - { - nextFocusChild = OnFocusSearchFailed(null, direction, recycler); - } - - if (nextFocusChild != null) - { - RequestChildRectangleOnScreen(mFlexibleView, nextFocusChild, recycler, false); - - ChangeFocus(nextFocusPosition); - } - } - - /** - * Requests that the given child of the RecyclerView be positioned onto the screen. This - * method can be called for both unfocusable and focusable child views. For unfocusable - * child views, focusedChildVisible is typically true in which case, layout manager - * makes the child view visible only if the currently focused child stays in-bounds of RV. - * @param parent The parent RecyclerView. - * @param child The direct child making the request. - * @param rect The rectangle in the child's coordinates the child - * wishes to be on the screen. - * @param immediate True to forbid animated or delayed scrolling, - * false otherwise - * @param focusedChildVisible Whether the currently focused view must stay visible. - * @return Whether the group scrolled to handle the operation - */ - internal bool RequestChildRectangleOnScreen(FlexibleView parent, FlexibleView.ViewHolder child, Recycler recycler, bool immediate) - { - Vector2 scrollAmount = GetChildRectangleOnScreenScrollAmount(parent, child); - float dx = scrollAmount[0]; - float dy = scrollAmount[1]; - if (dx != 0 || dy != 0) - { - if (dx != 0 && CanScrollHorizontally()) - { - ScrollHorizontallyBy(dx, recycler, immediate); - } - else if (dy != 0 && CanScrollVertically()) - { - ScrollVerticallyBy(dy, recycler, immediate); - } - return true; - } - return false; - } - - /// - /// Calls {@code FlexibleView#RelayoutRequest} on the underlying FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void RelayoutRequest() - { - if (mFlexibleView != null) - { - mFlexibleView.RelayoutRequest(); - } - } - - /// - /// Lay out the given child view within the FlexibleView using coordinates that include view margins. - /// - /// Child to lay out - /// Left edge, with item view left margin included - /// Top edge, with item view top margin included - /// Width, with item view left and right margin included - /// Height, with item view top and bottom margin included - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void LayoutChild(ViewHolder child, float left, float top, float width, float height) - { - if (null == child) return; - View itemView = child.ItemView; - itemView.SizeWidth = width - itemView.Margin.Start - itemView.Margin.End; - itemView.SizeHeight = height - itemView.Margin.Top - itemView.Margin.Bottom; - itemView.PositionX = left + itemView.Margin.Start; - itemView.PositionY = top + itemView.Margin.Top; - } - - /// - /// Change the ViewHolder with focusPosition to focus. - /// - /// the newly focus position - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void ChangeFocus(int focusPosition) - { - if (mFlexibleView != null) - { - mFlexibleView.DispatchFocusChanged(focusPosition); - } - } - - /// - /// Return the current number of child views attached to the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int ChildCount - { - get - { - return mChildHelper != null ? mChildHelper.GetChildCount() : 0; - } - } - - /// - /// Return the child view at the given index. - /// - /// child index - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder GetChildAt(int index) - { - return mChildHelper != null ? mChildHelper.GetChildAt(index) : null; - } - - /// - /// Finds the view which represents the given adapter position. - /// - /// adapter position - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder FindItemViewByPosition(int position) - { - return mFlexibleView.FindViewHolderForLayoutPosition(position); - } - - /// - /// Offset all child views attached to the parent FlexibleView by dx pixels along the horizontal axis. - /// - /// Pixels to offset by - /// specify if the offset need animation - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void OffsetChildrenHorizontal(float dx, bool immediate) - { - if (mChildHelper == null) - { - return; - } - - if (dx == 0) - { - return; - } - - int childCount = mChildHelper.GetChildCount(); - if (immediate == true) - { - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - v.ItemView.PositionX += dx; - } - } - else - { - if (mScrollAni == null) - { - mScrollAni = new Animation(); - mScrollAni.Duration = SCROLL_ANIMATION_DURATION; - mScrollAni.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare); - } - - // avoid out of boundary of flexibleview. delta value might be used for shadow. - // this must be done before animation clear. - if (childCount > 0) - { - ViewHolder vh = mChildHelper.GetChildAt(0); - if (vh.LayoutPosition == 0) - { - if ((int)(vh.Left + dx) > 0) - { - dx = 0 - vh.Left; - } - } - - vh = mChildHelper.GetChildAt(childCount - 1); - if (vh.LayoutPosition == ItemCount - 1) - { - if ((int)(vh.Right + dx) < (int)Width + PaddingRight) - { - dx = Width + PaddingRight - vh.Right; - } - } - } - - // save position before animation clear. - float[] childrenPositon = new float[childCount]; - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - childrenPositon[i] = v.ItemView.PositionX; - } - - mScrollAni.Clear(); - mScrollAni.Finished += OnScrollAnimationFinished; - - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - // set position again because position might be changed after animation clear. - v.ItemView.PositionX = childrenPositon[i]; - mScrollAni.AnimateTo(v.ItemView, "PositionX", v.ItemView.PositionX + dx); - } - mScrollAni.Play(); - } - } - - /// - /// Offset all child views attached to the parent FlexibleView by dy pixels along the vertical axis. - /// - /// Pixels to offset by - /// specify if the offset need animation - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void OffsetChildrenVertical(float dy, bool immediate) - { - if (mChildHelper == null) - { - return; - } - - if (dy == 0) - { - return; - } - - int childCount = mChildHelper.GetChildCount(); - if (immediate == true) - { - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - v.ItemView.PositionY += dy; - } - } - else - { - if (mScrollAni == null) - { - mScrollAni = new Animation(); - mScrollAni.Duration = SCROLL_ANIMATION_DURATION; - mScrollAni.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare); - } - - // avoid out of boundary of flexibleview. delta value might be used for shadow. - // this must be done before animation clear. - if (childCount > 0) - { - ViewHolder vh = mChildHelper.GetChildAt(0); - if (vh.LayoutPosition == 0) - { - if ((int)(vh.Top + dy) > 0) - { - dy = 0 - vh.Top; - } - } - - vh = mChildHelper.GetChildAt(childCount - 1); - if (vh.LayoutPosition == ItemCount - 1) - { - if ((int)(vh.Bottom + dy) < (int)Height + PaddingBottom) - { - dy = Height + PaddingBottom - vh.Bottom; - } - } - } - - // save position before animation clear. - float[] childPositon = new float[childCount]; - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - childPositon[i] = v.ItemView.PositionY; - } - - mScrollAni.Clear(); - mScrollAni.Finished += OnScrollAnimationFinished; - - for (int i = childCount - 1; i >= 0; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - // set position again because position might be changed after animation clear. - v.ItemView.PositionY = childPositon[i]; - mScrollAni.AnimateTo(v.ItemView, "PositionY", v.ItemView.PositionY + dy); - } - mScrollAni.Play(); - } - } - - /// - /// Return the width of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Width - { - get - { - return mFlexibleView != null ? mFlexibleView.SizeWidth : 0; - } - } - - /// - /// Return the height of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Height - { - get - { - return mFlexibleView != null ? mFlexibleView.SizeHeight : 0; - } - } - - /// - /// Return the left padding of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int PaddingLeft - { - get - { - return mFlexibleView?.Padding?.Start ?? 0; - } - } - - /// - /// Return the top padding of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int PaddingTop - { - get - { - return mFlexibleView?.Padding?.Top ?? 0; - } - } - - /// - /// Return the right padding of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int PaddingRight - { - get - { - return mFlexibleView?.Padding?.End ?? 0; - } - } - - /// - /// Return the bottom padding of the parent FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int PaddingBottom - { - get - { - return mFlexibleView?.Padding?.Bottom ?? 0; - } - } - - /// - /// Add a view to the currently attached FlexibleView if needed.
- /// LayoutManagers should use this method to add views obtained from a FlexibleView.Recycler using getViewForPosition(int).
- ///
- /// view to add - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void AddView(ViewHolder holder) - { - AddView(holder, -1); - } - - /// - /// Add a view to the currently attached FlexibleView if needed.
- /// LayoutManagers should use this method to add views obtained from a FlexibleView.Recycler using getViewForPosition(int).
- ///
- /// view to add - /// index to add child at - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void AddView(ViewHolder holder, int index) - { - AddViewInternal(holder, index, false); - } - - /// - /// Temporarily detach and scrap all currently attached child views. - /// Views will be scrapped into the given Recycler. - /// The Recycler may prefer to reuse scrap views before other views that were previously recycled. - /// - /// Recycler to scrap views into - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void ScrapAttachedViews(Recycler recycler) - { - if (null == mChildHelper || null == recycler) - { - return; - } - - recycler.Clear(); - - mChildHelper.ScrapViews(recycler); - } - - /** - * Remove a child view and recycle it using the given Recycler. - * - * @param index Index of child to remove and recycle - * @param recycler Recycler to use to recycle child - */ - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void RemoveAndRecycleViewAt(int index, Recycler recycler) - { - if (null == recycler) return; - ViewHolder v = mChildHelper.GetChildAt(index); - mChildHelper.RemoveViewAt(index); - recycler.RecycleView(v); - } - - /// - /// ecycles children between given indices.. - /// - /// Recycler to recycle views into - /// inclusive - /// exclusive - /// recycle immediately or add to pending list and recycle later. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void RecycleChildren(FlexibleView.Recycler recycler, int startIndex, int endIndex, bool immediate) - { - if (startIndex == endIndex) - { - return; - } - if (endIndex > startIndex) - { - for (int i = startIndex; i < endIndex; i++) - { - ViewHolder v = mChildHelper.GetChildAt(i); - if (v.PendingRecycle == false) - { - v.PendingRecycle = true; - mPendingRecycleViews.Add(v); - } - } - } - else - { - for (int i = startIndex; i > endIndex; i--) - { - ViewHolder v = mChildHelper.GetChildAt(i); - if (v.PendingRecycle == false) - { - v.PendingRecycle = true; - mPendingRecycleViews.Add(v); - } - } - } - if (immediate == true) - { - RecycleChildrenInt(recycler); - } - } - - /// - /// Retrieves a position that neighbor to current position by direction. - /// - /// The anchor adapter position - /// The direction. - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected abstract int GetNextPosition(int position, FlexibleView.LayoutManager.Direction direction); - - /// - /// Retrieves the first visible item view. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected virtual ViewHolder FindFirstVisibleItemView() - { - return null; - } - - /// - /// Retrieves the last visible item view. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected virtual ViewHolder FindLastVisibleItemView() - { - return null; - } - - internal virtual ViewHolder OnFocusSearchFailed(FlexibleView.ViewHolder focused, LayoutManager.Direction direction, Recycler recycler) - { - return null; - } - - internal void SetRecyclerView(FlexibleView recyclerView) - { - mFlexibleView = recyclerView; - mChildHelper = recyclerView.mChildHelper; - } - - internal void StopScroll(bool doSomethingAfterAnimationStopped) - { - if (mScrollAni != null && mScrollAni.State == Animation.States.Playing) - { - mScrollAni.Finished -= OnScrollAnimationFinished; - mScrollAni.Stop(); - - if (doSomethingAfterAnimationStopped) - { - OnScrollAnimationFinished(mScrollAni, null); - } - } - } - - /** - * Returns the scroll amount that brings the given rect in child's coordinate system within - * the padded area of RecyclerView. - * @param parent The parent RecyclerView. - * @param child The direct child making the request. - * @param rect The rectangle in the child's coordinates the child - * wishes to be on the screen. - * @param immediate True to forbid animated or delayed scrolling, - * false otherwise - * @return The array containing the scroll amount in x and y directions that brings the - * given rect into RV's padded area. - */ - private Vector2 GetChildRectangleOnScreenScrollAmount(FlexibleView parent, FlexibleView.ViewHolder child) - { - Vector2 ret = new Vector2(0, 0); - int parentLeft = PaddingLeft; - int parentTop = PaddingTop; - int parentRight = (int)Width - PaddingRight; - int parentBottom = (int)Height - PaddingBottom; - int childLeft = (int)child.Left; - int childTop = (int)child.Top; - int childRight = (int)child.Right; - int childBottom = (int)child.Bottom; - - int offScreenLeft = Math.Min(0, childLeft - parentLeft); - int offScreenTop = Math.Min(0, childTop - parentTop); - int offScreenRight = Math.Max(0, childRight - parentRight); - int offScreenBottom = Math.Max(0, childBottom - parentBottom); - - // Favor the "start" layout direction over the end when bringing one side or the other - // of a large rect into view. If we decide to bring in end because start is already - // visible, limit the scroll such that start won't go out of bounds. - int dx = offScreenLeft != 0 ? offScreenLeft - : Math.Min(childLeft - parentLeft, offScreenRight); - - // Favor bringing the top into view over the bottom. If top is already visible and - // we should scroll to make bottom visible, make sure top does not go out of bounds. - int dy = offScreenTop != 0 ? offScreenTop - : Math.Min(childTop - parentTop, offScreenBottom); - - ret.X = -dx; - ret.Y = -dy; - - return ret; - } - - private void OnScrollAnimationFinished(object sender, EventArgs e) - { - foreach (ViewHolder holder in mPendingRecycleViews) - { - holder.PendingRecycle = false; - } - mPendingRecycleViews.Clear(); - - int start = NO_POSITION; - ViewHolder firstItemView = FindFirstVisibleItemView(); - if (firstItemView != null) - start = firstItemView.LayoutPosition; - else - start = 0; - - int itemCount = ChildCount; - - int end = NO_POSITION; - ViewHolder lastItemView = FindLastVisibleItemView(); - if (lastItemView != null) - end = lastItemView.LayoutPosition; - else - end = itemCount - 1; - - List removedViewList = new List(); - for (int i = 0; i < itemCount; i++) - { - ViewHolder v = GetChildAt(i); - - //if item view of holder is visible, it should not be recycled. - if (v.LayoutPosition >= start && v.LayoutPosition <= end) - continue; - - removedViewList.Add(v); - } - - for (int i = 0; i < removedViewList.Count; i++) - { - ViewHolder v = removedViewList[i]; - v.PendingRecycle = false; - mFlexibleView.mRecycler.RecycleView(v); - mChildHelper.RemoveView(v); - } - - // relayout - } - - private void AddViewInternal(ViewHolder holder, int index, bool disappearing) - { - if (null == holder) return; - if (holder.IsScrap()) - { - holder.Unscrap(); - mChildHelper.AttachView(holder, index); - } - else - { - mChildHelper.AddView(holder, index); - } - } - - private void RecycleChildrenInt(FlexibleView.Recycler recycler) - { - if (null == recycler) return; - foreach (ViewHolder holder in mPendingRecycleViews) - { - holder.PendingRecycle = false; - recycler.RecycleView(holder); - mChildHelper.RemoveView(holder); - } - mPendingRecycleViews.Clear(); - } - - private void ScrapOrRecycleView(Recycler recycler, ViewHolder itemView) - { - recycler.ScrapView(itemView); - } - - } - - /// - /// A ViewHolder describes an item view and metadata about its place within the FlexibleView. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public class ViewHolder - { - // This ViewHolder has been bound to a position; AdapterPosition, mItemId and mItemViewType - // are all valid. - //static readonly int FLAG_BOUND = 1 << 0; - - // The data this ViewHolder's view reflects is stale and needs to be rebound - // by the adapter. AdapterPosition and mItemId are consistent. - //static readonly int FLAG_UPDATE = 1 << 1; - - // This ViewHolder's data is invalid. The identity implied by AdapterPosition and mItemId - // are not to be trusted and may no longer match the item view type. - // This ViewHolder must be fully rebound to different data. - //static readonly int FLAG_INVALID = 1 << 2; - - // This ViewHolder points at data that represents an item previously removed from the - // data set. Its view may still be used for things like outgoing animations. - //static readonly int FLAG_REMOVED = 1 << 3; - - // This ViewHolder should not be recycled. This flag is set via setIsRecyclable() - // and is intended to keep views around during animations. - //static readonly int FLAG_NOT_RECYCLABLE = 1 << 4; - - // This ViewHolder is returned from scrap which means we are expecting an addView call - // for this itemView. When returned from scrap, ViewHolder stays in the scrap list until - // the end of the layout pass and then recycled by RecyclerView if it is not added back to - // the RecyclerView. - //static readonly int FLAG_RETURNED_FROM_SCRAP = 1 << 5; - - // This ViewHolder is fully managed by the LayoutManager. We do not scrap, recycle or remove - // it unless LayoutManager is replaced. - // It is still fully visible to the LayoutManager. - //static readonly int FLAG_IGNORE = 1 << 7; - - private int mFlags; - private int mPreLayoutPosition = NO_POSITION; - - /// - /// ViewHolder constructor. - /// - /// View - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder(View itemView) - { - if (itemView == null) - { - throw new ArgumentNullException("itemView may not be null"); - } - this.ItemView = itemView; - } - - /// - /// Returns the view. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public View ItemView { get; } - - /// - /// Returns the left edge includes the view left margin. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Left - { - get - { - return ItemView.PositionX - ItemView.Margin.Start; - } - } - - /// - /// Returns the right edge includes the view right margin. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Right - { - get - { - return ItemView.PositionX + ItemView.SizeWidth + ItemView.Margin.End; - } - } - - /// - /// Returns the top edge includes the view top margin. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Top - { - get - { - return ItemView.PositionY - ItemView.Margin.Top; - } - } - - /// - /// Returns the bottom edge includes the view bottom margin. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public float Bottom - { - get - { - return ItemView.PositionY + ItemView.SizeHeight + ItemView.Margin.Bottom; - } - } - - /// - /// Returns the position of the ViewHolder in terms of the latest layout pass. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int LayoutPosition - { - get - { - return mPreLayoutPosition == NO_POSITION ? AdapterPosition : mPreLayoutPosition; - } - } - - /// - /// Returns the Adapter position of the item represented by this ViewHolder. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int AdapterPosition { get; internal set; } = NO_POSITION; - - /// - /// Get old position of item view. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int OldPosition { get; private set; } = NO_POSITION; - - /// - /// Gets or sets item view type. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int ItemViewType { get; set; } = INVALID_TYPE; - - internal bool IsBound - { - get; - set; - } - - internal Recycler ScrapContainer { get; set; } - - internal bool PendingRecycle - { - get; - set; - } = false; - - - internal bool IsScrap() - { - return ScrapContainer != null; - } - - internal void Unscrap() - { - ScrapContainer.UnscrapView(this); - } - - - internal void FlagRemovedAndOffsetPosition(int mNewPosition, int offset, bool applyToPreLayout) - { - //AddFlags(ViewHolder.FLAG_REMOVED); - OffsetPosition(offset, applyToPreLayout); - AdapterPosition = mNewPosition; - } - - internal void OffsetPosition(int offset, bool applyToPreLayout) - { - if (OldPosition == NO_POSITION) - { - OldPosition = AdapterPosition; - } - if (mPreLayoutPosition == NO_POSITION) - { - mPreLayoutPosition = AdapterPosition; - } - if (applyToPreLayout) - { - mPreLayoutPosition += offset; - } - AdapterPosition += offset; - } - - internal void ClearOldPosition() - { - OldPosition = NO_POSITION; - mPreLayoutPosition = NO_POSITION; - } - - internal void SaveOldPosition() - { - if (OldPosition == NO_POSITION) - { - OldPosition = AdapterPosition; - } - } - - private void SetFlags(int flags, int mask) - { - mFlags = (mFlags & ~mask) | (flags & mask); - } - - private void AddFlags(int flags) - { - mFlags |= flags; - } - - } - - /// - /// A Recycler is responsible for managing scrapped or detached item views for reuse. - /// A "scrapped" view is a view that is still attached to its parent FlexibleView but that has been marked for removal or reuse. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public class Recycler - { - private FlexibleView mFlexibleView; - private RecycledViewPool mRecyclerPool; - - private List mAttachedScrap = new List(); - private List mChangedScrap = null; - //private List mCachedViews = new List(); - - //private List mUnmodifiableAttachedScrap; - - private int mCacheSizeMax = 2; - - /// - /// Recycler constructor. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public Recycler(FlexibleView recyclerView) - { - mFlexibleView = recyclerView; - } - - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void SetViewCacheSize(int viewCount) - { - mCacheSizeMax = viewCount; - } - - /// - /// Obtain a view initialized for the given position. - /// - /// Position to obtain a view for - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder GetViewForPosition(int position) - { - Adapter b = mFlexibleView != null ? mFlexibleView.mAdapter : null; - if (b == null) - { - return null; - } - if (position < 0 || position >= b.GetItemCount()) - { - return null; - } - - int type = b.GetItemViewType(position); - ViewHolder itemView = null; - for (int i = 0; i < mAttachedScrap.Count; i++) - { - if (mAttachedScrap[i].LayoutPosition == position && mAttachedScrap[i].ItemViewType == type) - { - itemView = mAttachedScrap[i]; - break; - } - } - if (itemView == null) - { - itemView = mRecyclerPool.GetRecycledView(type); - if (itemView == null) - { - itemView = b.OnCreateViewHolder(type); - } - - if (!itemView.IsBound) - { - b.OnBindViewHolder(itemView, position); - itemView.IsBound = true; - } - - itemView.AdapterPosition = position; - itemView.ItemViewType = type; - } - - return itemView; - } - - /// - /// Recycle a detached view. - /// - /// Removed holder for recycling - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void RecycleView(ViewHolder itemView) - { - if (null == itemView) return; - itemView.ScrapContainer = null; - mRecyclerPool.PutRecycledView(itemView); - } - - /// - /// Returns the count in scrap list. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public int GetScrapCount() - { - return mAttachedScrap.Count; - } - - /// - /// Gets the scrap view at index. - /// - /// index - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public ViewHolder GetScrapViewAt(int index) - { - return mAttachedScrap[index]; - } - - /// - /// Clear scrap views out of this recycler. Detached views contained within a recycled view pool will remain. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public void Clear() - { - mAttachedScrap.Clear(); - if (mChangedScrap != null) - { - mChangedScrap.Clear(); - } - } - - internal void ScrapView(ViewHolder itemView) - { - mAttachedScrap.Add(itemView); - itemView.ScrapContainer = this; - } - - internal void UnscrapView(ViewHolder itemView) - { - mAttachedScrap.Remove(itemView); - itemView.ScrapContainer = null; - } - - internal void SetRecycledViewPool(RecycledViewPool pool) - { - mRecyclerPool = pool; - } - } - - internal class RecycledViewPool - { - private FlexibleView mFlexibleView; - - private int mMaxTypeCount = 10; - private List[] mScrap; - - public RecycledViewPool(FlexibleView flexibleView) - { - mFlexibleView = flexibleView; - mScrap = new List[mMaxTypeCount]; - } - - //public void SetViewTypeCount(int typeCount) - //{ - //} - - public ViewHolder GetRecycledView(int viewType) - { - if (viewType >= mMaxTypeCount || mScrap[viewType] == null) - { - return null; - } - - int index = mScrap[viewType].Count - 1; - if (index < 0) - { - return null; - } - ViewHolder recycledView = mScrap[viewType][index]; - mScrap[viewType].RemoveAt(index); - - return recycledView; - } - - public void PutRecycledView(ViewHolder view) - { - int viewType = view.ItemViewType; - if (viewType >= mMaxTypeCount) - { - return; - } - if (mScrap[viewType] == null) - { - mScrap[viewType] = new List(); - } - view.IsBound = false; - mScrap[viewType].Add(view); - } - - public void Clear() - { - for (int i = 0; i < mMaxTypeCount; i++) - { - if (mScrap[i] == null) - { - continue; - } - for (int j = 0; j < mScrap[i].Count; j++) - { - mFlexibleView.DispatchChildDestroyed(mScrap[i][j]); - } - mScrap[i].Clear(); - } - } - } - - private class ChildHelper - { - private FlexibleView mFlexibleView; - - private List mViewList = new List(); - - //private List mRemovePendingViews; - - private Dictionary itemViewTable = new Dictionary(); - private TapGestureDetector mTapGestureDetector; - - public ChildHelper(FlexibleView owner) - { - mFlexibleView = owner; - - mTapGestureDetector = new TapGestureDetector(); - mTapGestureDetector.Detected += OnTapGestureDetected; - } - - public void Clear() - { - foreach (ViewHolder holder in mViewList) - { - mFlexibleView.Remove(holder.ItemView); - - mFlexibleView.DispatchChildDestroyed(holder); - } - mViewList.Clear(); - } - - public void ScrapViews(Recycler recycler) - { - recycler.Clear(); - foreach (ViewHolder itemView in mViewList) - { - recycler.ScrapView(itemView); - } - - mViewList.Clear(); - } - - public void AttachView(ViewHolder holder, int index) - { - if (index == -1) - { - index = mViewList.Count; - } - - mViewList.Insert(index, holder); - - if (!itemViewTable.ContainsKey(holder.ItemView.ID)) - { - mTapGestureDetector.Attach(holder.ItemView); - holder.ItemView.TouchEvent += OnTouchEvent; - } - - itemViewTable[holder.ItemView.ID] = holder; - } - - public void AddView(ViewHolder holder, int index) - { - mFlexibleView.Add(holder.ItemView); - - mFlexibleView.DispatchChildAttached(holder); - - AttachView(holder, index); - } - - public bool RemoveView(ViewHolder holder) - { - mFlexibleView.Remove(holder.ItemView); - - mFlexibleView.DispatchChildDetached(holder); - - return mViewList.Remove(holder); - } - - public bool RemoveViewAt(int index) - { - ViewHolder itemView = mViewList[index]; - return RemoveView(itemView); - } - - public bool RemoveViewsRange(int index, int count) - { - for (int i = index; i < index + count; i++) - { - ViewHolder holder = mViewList[i]; - mFlexibleView.Remove(holder.ItemView); - } - mViewList.RemoveRange(index, count); - return false; - } - - public int GetChildCount() - { - return mViewList.Count; - } - - public ViewHolder GetChildAt(int index) - { - if (index < 0 || index >= mViewList.Count) - { - return null; - } - return mViewList[index]; - } - - private void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e) - { - View itemView = e.View as View; - if (itemView == null) - { - return; - } - if (itemViewTable.ContainsKey(itemView.ID)) - { - ViewHolder holder = itemViewTable[itemView.ID]; - mFlexibleView.FocusedItemIndex = holder.AdapterPosition; - - mFlexibleView.DispatchItemClicked(holder); - } - } - - private bool OnTouchEvent(object source, TouchEventArgs e) - { - View itemView = source as View; - if (itemView != null && itemViewTable.ContainsKey(itemView.ID)) - { - ViewHolder holder = itemViewTable[itemView.ID]; - - mFlexibleView.DispatchItemTouched(holder, e.Touch); - return true; - } - return false; - } - } - - private class AdapterHelper - { - private FlexibleView mFlexibleView; - - private List mPendingUpdates = new List(); - - private int mExistingUpdateTypes = 0; - - public AdapterHelper(FlexibleView flexibleView) - { - mFlexibleView = flexibleView; - } - - /** - * @return True if updates should be processed. - */ - public bool OnItemRangeInserted(int positionStart, int itemCount) - { - if (itemCount < 1) - { - return false; - } - mPendingUpdates.Add(new UpdateOp(UpdateOp.ADD, positionStart, itemCount)); - mExistingUpdateTypes |= UpdateOp.ADD; - return mPendingUpdates.Count == 1; - } - - /** - * @return True if updates should be processed. - */ - public bool OnItemRangeRemoved(int positionStart, int itemCount) - { - if (itemCount < 1) - { - return false; - } - mPendingUpdates.Add(new UpdateOp(UpdateOp.REMOVE, positionStart, itemCount)); - mExistingUpdateTypes |= UpdateOp.REMOVE; - return mPendingUpdates.Count == 1; - } - - public void PreProcess() - { - int count = mPendingUpdates.Count; - for (int i = 0; i < count; i++) - { - UpdateOp op = mPendingUpdates[i]; - switch (op.cmd) - { - case UpdateOp.ADD: - mFlexibleView.OffsetPositionRecordsForInsert(op.positionStart, op.itemCount); - break; - case UpdateOp.REMOVE: - mFlexibleView.OffsetPositionRecordsForRemove(op.positionStart, op.itemCount, false); - break; - case UpdateOp.UPDATE: - break; - case UpdateOp.MOVE: - break; - } - } - mPendingUpdates.Clear(); - } - - } - - /** - * Queued operation to happen when child views are updated. - */ - private class UpdateOp - { - - public const int ADD = 1; - - public const int REMOVE = 1 << 1; - - public const int UPDATE = 1 << 2; - - public const int MOVE = 1 << 3; - - public const int POOL_SIZE = 30; - - public int cmd; - - public int positionStart; - - // holds the target position if this is a MOVE - public int itemCount; - - public UpdateOp(int cmd, int positionStart, int itemCount) - { - this.cmd = cmd; - this.positionStart = positionStart; - this.itemCount = itemCount; - } - - public bool Equals(UpdateOp op) - { - if (cmd != op.cmd) - { - return false; - } - if (cmd == MOVE && Math.Abs(itemCount - positionStart) == 1) - { - // reverse of this is also true - if (itemCount == op.positionStart && positionStart == op.itemCount) - { - return true; - } - } - if (itemCount != op.itemCount) - { - return false; - } - if (positionStart != op.positionStart) - { - return false; - } - - return true; - } - - } - - private class ItemViewInfo - { - public float Left - { - get; - set; - } - public float Top - { - get; - set; - } - public float Right - { - get; - set; - } - public float Bottom - { - get; - set; - } - } - } } diff --git a/src/Tizen.NUI.Components/Controls/Slider.Internal.cs b/src/Tizen.NUI.Components/Controls/Slider.Internal.cs new file mode 100755 index 0000000..7cbe003 --- /dev/null +++ b/src/Tizen.NUI.Components/Controls/Slider.Internal.cs @@ -0,0 +1,881 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + public partial class Slider + { + + /// + /// Get Slider style. + /// + /// The default slider style. + /// 8 + protected override ViewStyle CreateViewStyle() + { + return new SliderStyle(); + } + + /// + /// Dispose Slider. + /// + /// Dispose type. + /// 6 + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + if (null != panGestureDetector) + { + if (null != thumbImage) + { + panGestureDetector.Detach(thumbImage); + } + panGestureDetector.Detected -= OnPanGestureDetected; + panGestureDetector.Dispose(); + panGestureDetector = null; + } + + if (null != thumbImage) + { + thumbImage.TouchEvent -= OnTouchEventForThumb; + Utility.Dispose(thumbImage); + } + Utility.Dispose(slidedTrackImage); + if (null != bgTrackImage) + { + bgTrackImage.TouchEvent -= OnTouchEventForBgTrack; + Utility.Dispose(bgTrackImage); + } + Utility.Dispose(lowIndicatorImage); + Utility.Dispose(highIndicatorImage); + Utility.Dispose(lowIndicatorText); + Utility.Dispose(highIndicatorText); + } + + base.Dispose(type); + } + + /// + /// Update Slider by style. + /// + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void OnUpdate() + { + RelayoutBaseComponent(); + + UpdateComponentByIndicatorTypeChanged(); + UpdateBgTrackSize(); + UpdateBgTrackPosition(); + UpdateLowIndicatorSize(); + UpdateValue(); + } + + /// + /// Theme change callback when theme is changed, this callback will be trigger. + /// + /// The sender + /// The event data + /// 8 + protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e) + { + SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(StyleName) as SliderStyle; + if (sliderStyle != null) + { + Style?.CopyFrom(sliderStyle); + RelayoutRequest(); + } + } + + + private void Initialize() + { + currentSlidedOffset = 0; + isFocused = false; + isPressed = false; + LayoutDirectionChanged += OnLayoutDirectionChanged; + } + + private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e) + { + RelayoutRequest(); + } + + private ImageView CreateSlidedTrack() + { + if (null == slidedTrackImage) + { + slidedTrackImage = new ImageView() + { + WidthResizePolicy = ResizePolicyType.Fixed, + HeightResizePolicy = ResizePolicyType.Fixed + }; + + if (bgTrackImage != null) + { + bgTrackImage.Add(slidedTrackImage); + } + + if (null != thumbImage) + { + slidedTrackImage.Add(thumbImage); + } + } + + return slidedTrackImage; + } + + private TextLabel CreateLowIndicatorText() + { + if (null == lowIndicatorText) + { + lowIndicatorText = new TextLabel() + { + WidthResizePolicy = ResizePolicyType.Fixed, + HeightResizePolicy = ResizePolicyType.Fixed + }; + this.Add(lowIndicatorText); + } + + return lowIndicatorText; + } + + private TextLabel CreateHighIndicatorText() + { + if (null == highIndicatorText) + { + highIndicatorText = new TextLabel() + { + WidthResizePolicy = ResizePolicyType.Fixed, + HeightResizePolicy = ResizePolicyType.Fixed + }; + this.Add(highIndicatorText); + } + + return highIndicatorText; + } + + private ImageView CreateBackgroundTrack() + { + if (null == bgTrackImage) + { + bgTrackImage = new ImageView() + { + WidthResizePolicy = ResizePolicyType.Fixed, + HeightResizePolicy = ResizePolicyType.Fixed, + ParentOrigin = Tizen.NUI.ParentOrigin.Center, + PivotPoint = Tizen.NUI.PivotPoint.Center, + PositionUsesPivotPoint = true + }; + this.Add(bgTrackImage); + + if (null != slidedTrackImage) + { + bgTrackImage.Add(slidedTrackImage); + } + + bgTrackImage.TouchEvent += OnTouchEventForBgTrack; + } + + return bgTrackImage; + } + + private ImageView CreateThumb() + { + if (null == thumbImage) + { + thumbImage = new ImageView() + { + WidthResizePolicy = ResizePolicyType.Fixed, + HeightResizePolicy = ResizePolicyType.Fixed, + ParentOrigin = NUI.ParentOrigin.Center, + PivotPoint = NUI.PivotPoint.Center, + PositionUsesPivotPoint = true + }; + if (slidedTrackImage != null) + { + slidedTrackImage.Add(thumbImage); + } + thumbImage.TouchEvent += OnTouchEventForThumb; + + panGestureDetector = new PanGestureDetector(); + panGestureDetector.Attach(thumbImage); + panGestureDetector.Detected += OnPanGestureDetected; + } + + return thumbImage; + } + + private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e) + { + if (e.PanGesture.State == Gesture.StateType.Started) + { + if (direction == DirectionType.Horizontal) + { + currentSlidedOffset = slidedTrackImage.SizeWidth; + } + else if (direction == DirectionType.Vertical) + { + currentSlidedOffset = slidedTrackImage.SizeHeight; + } + UpdateState(isFocused, true); + } + + if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started) + { + if (direction == DirectionType.Horizontal) + { + CalculateCurrentValueByGesture(e.PanGesture.Displacement.X); + } + else if (direction == DirectionType.Vertical) + { + CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y); + } + UpdateValue(); + } + + if (e.PanGesture.State == Gesture.StateType.Finished) + { + if (null != slidingFinishedHandler) + { + SlidingFinishedArgs args = new SlidingFinishedArgs(); + args.CurrentValue = curValue; + slidingFinishedHandler(this, args); + } + + UpdateState(isFocused, false); + } + } + + // Relayout basic component: track, thumb and indicator + private void RelayoutBaseComponent(bool isInitial = true) + { + if (direction == DirectionType.Horizontal) + { + if (slidedTrackImage != null) + { + slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft; + slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft; + slidedTrackImage.PositionUsesPivotPoint = true; + } + if (thumbImage != null) + { + thumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight; + thumbImage.PivotPoint = NUI.PivotPoint.Center; + thumbImage.PositionUsesPivotPoint = true; + } + if (lowIndicatorImage != null) + { + lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft; + lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft; + lowIndicatorImage.PositionUsesPivotPoint = true; + } + if (highIndicatorImage != null) + { + highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight; + highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight; + highIndicatorImage.PositionUsesPivotPoint = true; + } + if (lowIndicatorText != null) + { + lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft; + lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft; + lowIndicatorText.PositionUsesPivotPoint = true; + } + if (highIndicatorText != null) + { + highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight; + highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight; + highIndicatorText.PositionUsesPivotPoint = true; + } + if (panGestureDetector != null) + { + if (!isInitial) + { + panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical); + } + panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal); + } + } + else if (direction == DirectionType.Vertical) + { + if (slidedTrackImage != null) + { + slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter; + slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter; + slidedTrackImage.PositionUsesPivotPoint = true; + } + if (thumbImage != null) + { + thumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter; + thumbImage.PivotPoint = NUI.PivotPoint.Center; + thumbImage.PositionUsesPivotPoint = true; + } + if (lowIndicatorImage != null) + { + lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter; + lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter; + lowIndicatorImage.PositionUsesPivotPoint = true; + } + if (highIndicatorImage != null) + { + highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter; + highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter; + highIndicatorImage.PositionUsesPivotPoint = true; + } + if (lowIndicatorText != null) + { + lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter; + lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter; + lowIndicatorText.PositionUsesPivotPoint = true; + } + if (highIndicatorText != null) + { + highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter; + highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter; + highIndicatorText.PositionUsesPivotPoint = true; + } + if (panGestureDetector != null) + { + if (!isInitial) + { + panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal); + } + panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical); + } + } + } + + private int BgTrackLength() + { + int bgTrackLength = 0; + IndicatorType type = CurrentIndicatorType(); + + if (type == IndicatorType.None) + { + if (direction == DirectionType.Horizontal) + { + bgTrackLength = this.Size2D.Width; + } + else if (direction == DirectionType.Vertical) + { + bgTrackLength = this.Size2D.Height; + } + } + else if (type == IndicatorType.Image) + {// + Size lowIndicatorImageSize = LowIndicatorImageSize(); + Size highIndicatorImageSize = HighIndicatorImageSize(); + int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); + if (direction == DirectionType.Horizontal) + { + int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width))); + int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width))); + bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace; + } + else if (direction == DirectionType.Vertical) + { + int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height))); + int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height))); + bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace; + } + } + else if (type == IndicatorType.Text) + {// + Size lowIndicatorTextSize = LowIndicatorTextSize(); + Size highIndicatorTextSize = HighIndicatorTextSize(); + int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); + if (direction == DirectionType.Horizontal) + { + int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width))); + int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width))); + bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace; + } + else if (direction == DirectionType.Vertical) + { + int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height))); + int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height))); + bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace; + } + } + return bgTrackLength; + } + + private void UpdateLowIndicatorSize() + { + if (lowIndicatorSize != null) + { + if (lowIndicatorImage != null) + { + lowIndicatorImage.Size = lowIndicatorSize; + } + if (lowIndicatorText != null) + { + lowIndicatorText.Size = lowIndicatorSize; + } + } + else + { + if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage != null && Style.LowIndicatorImage.Size != null) + { + lowIndicatorImage.Size = Style.LowIndicatorImage.Size; + } + if (lowIndicatorText != null && Style != null && Style.LowIndicator != null && Style.LowIndicator.Size != null) + { + lowIndicatorText.Size = Style.LowIndicator.Size; + } + } + } + + private void UpdateBgTrackSize() + { + if (bgTrackImage == null) + { + return; + } + int curTrackThickness = (int)CurrentTrackThickness(); + int bgTrackLength = BgTrackLength(); + if (direction == DirectionType.Horizontal) + { + bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness); + } + else if (direction == DirectionType.Vertical) + { + bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength); + } + } + + private void UpdateBgTrackPosition() + { + if (bgTrackImage == null) + { + return; + } + IndicatorType type = CurrentIndicatorType(); + + if (type == IndicatorType.None) + { + bgTrackImage.Position2D = new Position2D(0, 0); + } + else if (type == IndicatorType.Image) + { + Size lowIndicatorImageSize = LowIndicatorImageSize(); + Size highIndicatorImageSize = HighIndicatorImageSize(); + int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); + if (direction == DirectionType.Horizontal) + { + int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width))); + int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width))); + bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0); + } + else if (direction == DirectionType.Vertical) + { + int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height))); + int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height))); + bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2); + } + } + else if (type == IndicatorType.Text) + { + Size lowIndicatorTextSize = LowIndicatorTextSize(); + Size highIndicatorTextSize = HighIndicatorTextSize(); + int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); + if (direction == DirectionType.Horizontal) + { + int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width))); + int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width))); + bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0); + } + else if (direction == DirectionType.Vertical) + { + int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height))); + int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height))); + bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2)); + } + } + } + + private void UpdateValue() + { + if (slidedTrackImage == null) + { + return; + } + if (curValue < minValue || curValue > maxValue || minValue >= maxValue) + { + return; + } + + float ratio = 0; + ratio = (float)(curValue - minValue) / (float)(maxValue - minValue); + + uint curTrackThickness = CurrentTrackThickness(); + + if (direction == DirectionType.Horizontal) + { + if (LayoutDirection == ViewLayoutDirectionType.RTL) + { + ratio = 1.0f - ratio; + } + float slidedTrackLength = (float)BgTrackLength() * ratio; + slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function. + } + else if (direction == DirectionType.Vertical) + { + float slidedTrackLength = (float)BgTrackLength() * ratio; + slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function. + } + } + + private uint CurrentTrackThickness() + { + uint curTrackThickness = 0; + if (trackThickness != null) + { + curTrackThickness = trackThickness.Value; + } + else + { + if (Style != null && Style.TrackThickness != null) + { + curTrackThickness = Style.TrackThickness.Value; + } + } + return curTrackThickness; + } + + private uint CurrentSpaceBetweenTrackAndIndicator() + { + uint curSpace = 0; + if (spaceBetweenTrackAndIndicator != null) + { + curSpace = spaceBetweenTrackAndIndicator.Start; + } + else + { + if (Style != null && Style.TrackPadding != null) + { + curSpace = Style.TrackPadding.Start; + } + } + return curSpace; + } + + private IndicatorType CurrentIndicatorType() + { + IndicatorType type = IndicatorType.None; + if (Style != null) + { + type = (IndicatorType)Style.IndicatorType; + } + return type; + } + + private Size LowIndicatorImageSize() + { + Size size = new Size(0, 0); + if (lowIndicatorSize != null) + { + size = lowIndicatorSize; + } + else + { + if (Style != null && Style.LowIndicatorImage != null && Style.LowIndicatorImage.Size != null) + { + size = Style.LowIndicatorImage.Size; + } + } + return size; + } + + private Size HighIndicatorImageSize() + { + Size size = new Size(0, 0); + if (highIndicatorSize != null) + { + size = highIndicatorSize; + } + else + { + if (Style != null && Style.HighIndicatorImage != null && Style.HighIndicatorImage.Size != null) + { + size = Style.HighIndicatorImage.Size; + } + } + return size; + } + + private Size LowIndicatorTextSize() + { + Size size = new Size(0, 0); + if (lowIndicatorSize != null) + { + size = lowIndicatorSize; + } + else + { + if (Style != null && Style.LowIndicator != null && Style.LowIndicator.Size != null) + { + size = Style.LowIndicator.Size; + } + } + return size; + } + + private Size HighIndicatorTextSize() + { + Size size = new Size(0, 0); + if (highIndicatorSize != null) + { + size = highIndicatorSize; + } + else + { + if (Style != null && Style.HighIndicator != null && Style.HighIndicator.Size != null) + { + size = Style.HighIndicator.Size; + } + } + return size; + } + + private void CalculateCurrentValueByGesture(float offset) + { + currentSlidedOffset += offset; + + if (currentSlidedOffset <= 0) + { + curValue = minValue; + } + else if (currentSlidedOffset >= BgTrackLength()) + { + curValue = maxValue; + } + else + { + int bgTrackLength = BgTrackLength(); + if (bgTrackLength != 0) + { + curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue; + } + } + if (valueChangedHandler != null) + { + ValueChangedArgs args = new ValueChangedArgs(); + args.CurrentValue = curValue; + valueChangedHandler(this, args); + } + } + + private bool OnTouchEventForBgTrack(object source, TouchEventArgs e) + { + PointStateType state = e.Touch.GetState(0); + if (state == PointStateType.Down) + { + Vector2 pos = e.Touch.GetLocalPosition(0); + CalculateCurrentValueByTouch(pos); + UpdateValue(); + if (null != slidingFinishedHandler) + { + SlidingFinishedArgs args = new SlidingFinishedArgs(); + args.CurrentValue = curValue; + slidingFinishedHandler(this, args); + } + } + return false; + } + + private bool OnTouchEventForThumb(object source, TouchEventArgs e) + { + PointStateType state = e.Touch.GetState(0); + if (state == PointStateType.Down) + { + UpdateState(isFocused, true); + } + else if (state == PointStateType.Up) + { + UpdateState(isFocused, false); + } + return true; + } + + private void CalculateCurrentValueByTouch(Vector2 pos) + { + int bgTrackLength = BgTrackLength(); + if (direction == DirectionType.Horizontal) + { + currentSlidedOffset = pos.X; + } + else if (direction == DirectionType.Vertical) + { + currentSlidedOffset = bgTrackLength - pos.Y; + } + if (bgTrackLength != 0) + { + curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue; + if (null != valueChangedHandler) + { + ValueChangedArgs args = new ValueChangedArgs(); + args.CurrentValue = curValue; + valueChangedHandler(this, args); + } + } + } + + private void UpdateState(bool isFocusedNew, bool isPressedNew) + { + if (isFocused == isFocusedNew && isPressed == isPressedNew) + { + return; + } + if (thumbImage == null || Style == null) + { + return; + } + isFocused = isFocusedNew; + isPressed = isPressedNew; + + if (!isFocused && !isPressed) + { + ControlState = ControlStates.Normal; + if (stateChangedHandler != null) + { + StateChangedArgs args = new StateChangedArgs(); + args.CurrentState = (ControlStates)ControlStates.Normal; + stateChangedHandler(this, args); + } + } + else if (isPressed) + { + ControlState = ControlStates.Pressed; + + if (stateChangedHandler != null) + { + StateChangedArgs args = new StateChangedArgs(); + args.CurrentState = (ControlStates)ControlStates.Pressed; + stateChangedHandler(this, args); + } + } + else if (!isPressed && isFocused) + { + ControlState = ControlStates.Focused; + + if (stateChangedHandler != null) + { + StateChangedArgs args = new StateChangedArgs(); + args.CurrentState = (ControlStates)ControlStates.Focused; + stateChangedHandler(this, args); + } + } + } + + private void UpdateComponentByIndicatorTypeChanged() + { + IndicatorType type = CurrentIndicatorType(); + if (type == IndicatorType.None) + { + if (lowIndicatorImage != null) + { + lowIndicatorImage.Hide(); + } + if (highIndicatorImage != null) + { + highIndicatorImage.Hide(); + } + if (lowIndicatorText != null) + { + lowIndicatorText.Hide(); + } + if (highIndicatorText != null) + { + highIndicatorText.Hide(); + } + } + else if (type == IndicatorType.Image) + { + if (lowIndicatorImage != null) + { + lowIndicatorImage.Show(); + } + if (highIndicatorImage != null) + { + highIndicatorImage.Show(); + } + if (lowIndicatorText != null) + { + lowIndicatorText.Hide(); + } + if (highIndicatorText != null) + { + highIndicatorText.Hide(); + } + } + else if (type == IndicatorType.Text) + { + if (lowIndicatorText != null) + { + lowIndicatorText.Show(); + } + if (highIndicatorText != null) + { + highIndicatorText.Show(); + } + if (lowIndicatorImage != null) + { + lowIndicatorImage.Hide(); + } + if (highIndicatorImage != null) + { + highIndicatorImage.Hide(); + } + } + } + + /// + /// Value Changed event data. + /// + /// 6 + public class ValueChangedArgs : EventArgs + { + /// + /// Curren value + /// + /// 6 + public float CurrentValue; + } + + /// + /// Value Changed event data. + /// + /// 6 + public class SlidingFinishedArgs : EventArgs + { + /// + /// Curren value + /// + /// 6 + public float CurrentValue; + } + + /// + /// State Changed event data. + /// + /// 6 + public class StateChangedArgs : EventArgs + { + /// + /// Curent state + /// + /// 6 + public ControlStates CurrentState; + } + } +} diff --git a/src/Tizen.NUI.Components/Controls/Slider.cs b/src/Tizen.NUI.Components/Controls/Slider.cs index f69a8e0..2ead05f 100755 --- a/src/Tizen.NUI.Components/Controls/Slider.cs +++ b/src/Tizen.NUI.Components/Controls/Slider.cs @@ -25,7 +25,7 @@ namespace Tizen.NUI.Components /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb. ///
/// 6 - public class Slider : Control + public partial class Slider : Control { // the background track image object private ImageView bgTrackImage = null; @@ -759,94 +759,6 @@ namespace Tizen.NUI.Components } /// - /// Get Slider style. - /// - /// The default slider style. - /// 8 - protected override ViewStyle CreateViewStyle() - { - return new SliderStyle(); - } - - /// - /// Dispose Slider. - /// - /// Dispose type. - /// 6 - protected override void Dispose(DisposeTypes type) - { - if (disposed) - { - return; - } - - if (type == DisposeTypes.Explicit) - { - if (null != panGestureDetector) - { - if (null != thumbImage) - { - panGestureDetector.Detach(thumbImage); - } - panGestureDetector.Detected -= OnPanGestureDetected; - panGestureDetector.Dispose(); - panGestureDetector = null; - } - - if (null != thumbImage) - { - thumbImage.TouchEvent -= OnTouchEventForThumb; - Utility.Dispose(thumbImage); - } - Utility.Dispose(slidedTrackImage); - if (null != bgTrackImage) - { - bgTrackImage.TouchEvent -= OnTouchEventForBgTrack; - Utility.Dispose(bgTrackImage); - } - Utility.Dispose(lowIndicatorImage); - Utility.Dispose(highIndicatorImage); - Utility.Dispose(lowIndicatorText); - Utility.Dispose(highIndicatorText); - } - - base.Dispose(type); - } - - /// - /// Update Slider by style. - /// - /// 6 - /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override void OnUpdate() - { - RelayoutBaseComponent(); - - UpdateComponentByIndicatorTypeChanged(); - UpdateBgTrackSize(); - UpdateBgTrackPosition(); - UpdateLowIndicatorSize(); - UpdateValue(); - } - - /// - /// Theme change callback when theme is changed, this callback will be trigger. - /// - /// The sender - /// The event data - /// 8 - protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e) - { - SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(StyleName) as SliderStyle; - if (sliderStyle != null) - { - Style?.CopyFrom(sliderStyle); - RelayoutRequest(); - } - } - - /// /// Apply style to scrollbar. /// /// The style to apply. @@ -884,787 +796,5 @@ namespace Tizen.NUI.Components EnableControlStatePropagation = true; } - - private void Initialize() - { - currentSlidedOffset = 0; - isFocused = false; - isPressed = false; - LayoutDirectionChanged += OnLayoutDirectionChanged; - } - - private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e) - { - RelayoutRequest(); - } - - private ImageView CreateSlidedTrack() - { - if (null == slidedTrackImage) - { - slidedTrackImage = new ImageView() - { - WidthResizePolicy = ResizePolicyType.Fixed, - HeightResizePolicy = ResizePolicyType.Fixed - }; - - if (bgTrackImage != null) - { - bgTrackImage.Add(slidedTrackImage); - } - - if (null != thumbImage) - { - slidedTrackImage.Add(thumbImage); - } - } - - return slidedTrackImage; - } - - private TextLabel CreateLowIndicatorText() - { - if (null == lowIndicatorText) - { - lowIndicatorText = new TextLabel() - { - WidthResizePolicy = ResizePolicyType.Fixed, - HeightResizePolicy = ResizePolicyType.Fixed - }; - this.Add(lowIndicatorText); - } - - return lowIndicatorText; - } - - private TextLabel CreateHighIndicatorText() - { - if (null == highIndicatorText) - { - highIndicatorText = new TextLabel() - { - WidthResizePolicy = ResizePolicyType.Fixed, - HeightResizePolicy = ResizePolicyType.Fixed - }; - this.Add(highIndicatorText); - } - - return highIndicatorText; - } - - private ImageView CreateBackgroundTrack() - { - if (null == bgTrackImage) - { - bgTrackImage = new ImageView() - { - WidthResizePolicy = ResizePolicyType.Fixed, - HeightResizePolicy = ResizePolicyType.Fixed, - ParentOrigin = Tizen.NUI.ParentOrigin.Center, - PivotPoint = Tizen.NUI.PivotPoint.Center, - PositionUsesPivotPoint = true - }; - this.Add(bgTrackImage); - - if (null != slidedTrackImage) - { - bgTrackImage.Add(slidedTrackImage); - } - - bgTrackImage.TouchEvent += OnTouchEventForBgTrack; - } - - return bgTrackImage; - } - - private ImageView CreateThumb() - { - if (null == thumbImage) - { - thumbImage = new ImageView() - { - WidthResizePolicy = ResizePolicyType.Fixed, - HeightResizePolicy = ResizePolicyType.Fixed, - ParentOrigin = NUI.ParentOrigin.Center, - PivotPoint = NUI.PivotPoint.Center, - PositionUsesPivotPoint = true - }; - if (slidedTrackImage != null) - { - slidedTrackImage.Add(thumbImage); - } - thumbImage.TouchEvent += OnTouchEventForThumb; - - panGestureDetector = new PanGestureDetector(); - panGestureDetector.Attach(thumbImage); - panGestureDetector.Detected += OnPanGestureDetected; - } - - return thumbImage; - } - - private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e) - { - if (e.PanGesture.State == Gesture.StateType.Started) - { - if (direction == DirectionType.Horizontal) - { - currentSlidedOffset = slidedTrackImage.SizeWidth; - } - else if (direction == DirectionType.Vertical) - { - currentSlidedOffset = slidedTrackImage.SizeHeight; - } - UpdateState(isFocused, true); - } - - if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started) - { - if (direction == DirectionType.Horizontal) - { - CalculateCurrentValueByGesture(e.PanGesture.Displacement.X); - } - else if (direction == DirectionType.Vertical) - { - CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y); - } - UpdateValue(); - } - - if (e.PanGesture.State == Gesture.StateType.Finished) - { - if (null != slidingFinishedHandler) - { - SlidingFinishedArgs args = new SlidingFinishedArgs(); - args.CurrentValue = curValue; - slidingFinishedHandler(this, args); - } - - UpdateState(isFocused, false); - } - } - - // Relayout basic component: track, thumb and indicator - private void RelayoutBaseComponent(bool isInitial = true) - { - if (direction == DirectionType.Horizontal) - { - if (slidedTrackImage != null) - { - slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft; - slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft; - slidedTrackImage.PositionUsesPivotPoint = true; - } - if (thumbImage != null) - { - thumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight; - thumbImage.PivotPoint = NUI.PivotPoint.Center; - thumbImage.PositionUsesPivotPoint = true; - } - if (lowIndicatorImage != null) - { - lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft; - lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft; - lowIndicatorImage.PositionUsesPivotPoint = true; - } - if (highIndicatorImage != null) - { - highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight; - highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight; - highIndicatorImage.PositionUsesPivotPoint = true; - } - if (lowIndicatorText != null) - { - lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft; - lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft; - lowIndicatorText.PositionUsesPivotPoint = true; - } - if (highIndicatorText != null) - { - highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight; - highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight; - highIndicatorText.PositionUsesPivotPoint = true; - } - if (panGestureDetector != null) - { - if (!isInitial) - { - panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical); - } - panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal); - } - } - else if (direction == DirectionType.Vertical) - { - if (slidedTrackImage != null) - { - slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter; - slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter; - slidedTrackImage.PositionUsesPivotPoint = true; - } - if (thumbImage != null) - { - thumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter; - thumbImage.PivotPoint = NUI.PivotPoint.Center; - thumbImage.PositionUsesPivotPoint = true; - } - if (lowIndicatorImage != null) - { - lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter; - lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter; - lowIndicatorImage.PositionUsesPivotPoint = true; - } - if (highIndicatorImage != null) - { - highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter; - highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter; - highIndicatorImage.PositionUsesPivotPoint = true; - } - if (lowIndicatorText != null) - { - lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter; - lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter; - lowIndicatorText.PositionUsesPivotPoint = true; - } - if (highIndicatorText != null) - { - highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter; - highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter; - highIndicatorText.PositionUsesPivotPoint = true; - } - if (panGestureDetector != null) - { - if (!isInitial) - { - panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal); - } - panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical); - } - } - } - - private int BgTrackLength() - { - int bgTrackLength = 0; - IndicatorType type = CurrentIndicatorType(); - - if (type == IndicatorType.None) - { - if (direction == DirectionType.Horizontal) - { - bgTrackLength = this.Size2D.Width; - } - else if (direction == DirectionType.Vertical) - { - bgTrackLength = this.Size2D.Height; - } - } - else if (type == IndicatorType.Image) - {// - Size lowIndicatorImageSize = LowIndicatorImageSize(); - Size highIndicatorImageSize = HighIndicatorImageSize(); - int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); - if (direction == DirectionType.Horizontal) - { - int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width))); - int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width))); - bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace; - } - else if (direction == DirectionType.Vertical) - { - int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height))); - int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height))); - bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace; - } - } - else if (type == IndicatorType.Text) - {// - Size lowIndicatorTextSize = LowIndicatorTextSize(); - Size highIndicatorTextSize = HighIndicatorTextSize(); - int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); - if (direction == DirectionType.Horizontal) - { - int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width))); - int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width))); - bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace; - } - else if (direction == DirectionType.Vertical) - { - int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height))); - int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height))); - bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace; - } - } - return bgTrackLength; - } - - private void UpdateLowIndicatorSize() - { - if (lowIndicatorSize != null) - { - if (lowIndicatorImage != null) - { - lowIndicatorImage.Size = lowIndicatorSize; - } - if (lowIndicatorText != null) - { - lowIndicatorText.Size = lowIndicatorSize; - } - } - else - { - if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null) - { - lowIndicatorImage.Size = Style.LowIndicatorImage.Size; - } - if (lowIndicatorText != null && Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null) - { - lowIndicatorText.Size = Style.LowIndicator.Size; - } - } - } - - private void UpdateBgTrackSize() - { - if(bgTrackImage == null) - { - return; - } - int curTrackThickness = (int)CurrentTrackThickness(); - int bgTrackLength = BgTrackLength(); - if (direction == DirectionType.Horizontal) - { - bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness); - } - else if (direction == DirectionType.Vertical) - { - bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength); - } - } - - private void UpdateBgTrackPosition() - { - if (bgTrackImage == null) - { - return; - } - IndicatorType type = CurrentIndicatorType(); - - if (type == IndicatorType.None) - { - bgTrackImage.Position2D = new Position2D(0, 0); - } - else if (type == IndicatorType.Image) - { - Size lowIndicatorImageSize = LowIndicatorImageSize(); - Size highIndicatorImageSize = HighIndicatorImageSize(); - int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); - if (direction == DirectionType.Horizontal) - { - int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width))); - int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width))); - bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0); - } - else if (direction == DirectionType.Vertical) - { - int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height))); - int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height))); - bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2); - } - } - else if (type == IndicatorType.Text) - { - Size lowIndicatorTextSize = LowIndicatorTextSize(); - Size highIndicatorTextSize = HighIndicatorTextSize(); - int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator(); - if (direction == DirectionType.Horizontal) - { - int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width))); - int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width))); - bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0); - } - else if (direction == DirectionType.Vertical) - { - int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height))); - int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height))); - bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2)); - } - } - } - - private void UpdateValue() - { - if (slidedTrackImage == null) - { - return; - } - if (curValue < minValue || curValue > maxValue || minValue >= maxValue) - { - return; - } - - float ratio = 0; - ratio = (float)(curValue - minValue) / (float)(maxValue - minValue); - - uint curTrackThickness = CurrentTrackThickness(); - - if (direction == DirectionType.Horizontal) - { - if (LayoutDirection == ViewLayoutDirectionType.RTL) - { - ratio = 1.0f - ratio; - } - float slidedTrackLength = (float)BgTrackLength() * ratio; - slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function. - } - else if (direction == DirectionType.Vertical) - { - float slidedTrackLength = (float)BgTrackLength() * ratio; - slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function. - } - } - - private uint CurrentTrackThickness() - { - uint curTrackThickness = 0; - if (trackThickness != null) - { - curTrackThickness = trackThickness.Value; - } - else - { - if (Style != null && Style.TrackThickness != null) - { - curTrackThickness = Style.TrackThickness.Value; - } - } - return curTrackThickness; - } - - private uint CurrentSpaceBetweenTrackAndIndicator() - { - uint curSpace = 0; - if (spaceBetweenTrackAndIndicator != null) - { - curSpace = spaceBetweenTrackAndIndicator.Start; - } - else - { - if (Style != null && Style.TrackPadding != null) - { - curSpace = Style.TrackPadding.Start; - } - } - return curSpace; - } - - private IndicatorType CurrentIndicatorType() - { - IndicatorType type = IndicatorType.None; - if (Style != null) - { - type = (IndicatorType)Style.IndicatorType; - } - return type; - } - - private Size LowIndicatorImageSize() - { - Size size = new Size(0, 0); - if (lowIndicatorSize != null) - { - size = lowIndicatorSize; - } - else - { - if (Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null) - { - size = Style.LowIndicatorImage.Size; - } - } - return size; - } - - private Size HighIndicatorImageSize() - { - Size size = new Size(0, 0); - if (highIndicatorSize != null) - { - size = highIndicatorSize; - } - else - { - if (Style != null && Style.HighIndicatorImage!= null && Style.HighIndicatorImage.Size != null) - { - size = Style.HighIndicatorImage.Size; - } - } - return size; - } - - private Size LowIndicatorTextSize() - { - Size size = new Size(0, 0); - if (lowIndicatorSize != null) - { - size = lowIndicatorSize; - } - else - { - if (Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null) - { - size = Style.LowIndicator.Size; - } - } - return size; - } - - private Size HighIndicatorTextSize() - { - Size size = new Size(0, 0); - if (highIndicatorSize != null) - { - size = highIndicatorSize; - } - else - { - if (Style != null && Style.HighIndicator!= null && Style.HighIndicator.Size != null) - { - size = Style.HighIndicator.Size; - } - } - return size; - } - - private void CalculateCurrentValueByGesture(float offset) - { - currentSlidedOffset += offset; - - if (currentSlidedOffset <= 0) - { - curValue = minValue; - } - else if (currentSlidedOffset >= BgTrackLength()) - { - curValue = maxValue; - } - else - { - int bgTrackLength = BgTrackLength(); - if (bgTrackLength != 0) - { - curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue; - } - } - if (valueChangedHandler != null) - { - ValueChangedArgs args = new ValueChangedArgs(); - args.CurrentValue = curValue; - valueChangedHandler(this, args); - } - } - - private bool OnTouchEventForBgTrack(object source, TouchEventArgs e) - { - PointStateType state = e.Touch.GetState(0); - if (state == PointStateType.Down) - { - Vector2 pos = e.Touch.GetLocalPosition(0); - CalculateCurrentValueByTouch(pos); - UpdateValue(); - if (null != slidingFinishedHandler) - { - SlidingFinishedArgs args = new SlidingFinishedArgs(); - args.CurrentValue = curValue; - slidingFinishedHandler(this, args); - } - } - return false; - } - - private bool OnTouchEventForThumb(object source, TouchEventArgs e) - { - PointStateType state = e.Touch.GetState(0); - if (state == PointStateType.Down) - { - UpdateState(isFocused, true); - } - else if (state == PointStateType.Up) - { - UpdateState(isFocused, false); - } - return true; - } - - private void CalculateCurrentValueByTouch(Vector2 pos) - { - int bgTrackLength = BgTrackLength(); - if (direction == DirectionType.Horizontal) - { - currentSlidedOffset = pos.X; - } - else if (direction == DirectionType.Vertical) - { - currentSlidedOffset = bgTrackLength - pos.Y; - } - if (bgTrackLength != 0) - { - curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue; - if (null != valueChangedHandler) - { - ValueChangedArgs args = new ValueChangedArgs(); - args.CurrentValue = curValue; - valueChangedHandler(this, args); - } - } - } - - private void UpdateState(bool isFocusedNew, bool isPressedNew) - { - if (isFocused == isFocusedNew && isPressed == isPressedNew) - { - return; - } - if (thumbImage == null || Style == null) - { - return; - } - isFocused = isFocusedNew; - isPressed = isPressedNew; - - if (!isFocused && !isPressed) - { - ControlState = ControlStates.Normal; - if (stateChangedHandler != null) - { - StateChangedArgs args = new StateChangedArgs(); - args.CurrentState = (ControlStates)ControlStates.Normal; - stateChangedHandler(this, args); - } - } - else if (isPressed) - { - ControlState = ControlStates.Pressed; - - if (stateChangedHandler != null) - { - StateChangedArgs args = new StateChangedArgs(); - args.CurrentState = (ControlStates)ControlStates.Pressed; - stateChangedHandler(this, args); - } - } - else if (!isPressed && isFocused) - { - ControlState = ControlStates.Focused; - - if (stateChangedHandler != null) - { - StateChangedArgs args = new StateChangedArgs(); - args.CurrentState = (ControlStates)ControlStates.Focused; - stateChangedHandler(this, args); - } - } - } - - private void UpdateComponentByIndicatorTypeChanged() - { - IndicatorType type = CurrentIndicatorType(); - if (type == IndicatorType.None) - { - if (lowIndicatorImage != null) - { - lowIndicatorImage.Hide(); - } - if (highIndicatorImage != null) - { - highIndicatorImage.Hide(); - } - if (lowIndicatorText != null) - { - lowIndicatorText.Hide(); - } - if (highIndicatorText != null) - { - highIndicatorText.Hide(); - } - } - else if (type == IndicatorType.Image) - { - if (lowIndicatorImage != null) - { - lowIndicatorImage.Show(); - } - if (highIndicatorImage != null) - { - highIndicatorImage.Show(); - } - if (lowIndicatorText != null) - { - lowIndicatorText.Hide(); - } - if (highIndicatorText != null) - { - highIndicatorText.Hide(); - } - } - else if (type == IndicatorType.Text) - { - if (lowIndicatorText != null) - { - lowIndicatorText.Show(); - } - if (highIndicatorText != null) - { - highIndicatorText.Show(); - } - if (lowIndicatorImage != null) - { - lowIndicatorImage.Hide(); - } - if (highIndicatorImage != null) - { - highIndicatorImage.Hide(); - } - } - } - - /// - /// Value Changed event data. - /// - /// 6 - public class ValueChangedArgs : EventArgs - { - /// - /// Curren value - /// - /// 6 - public float CurrentValue; - } - - /// - /// Value Changed event data. - /// - /// 6 - public class SlidingFinishedArgs : EventArgs - { - /// - /// Curren value - /// - /// 6 - public float CurrentValue; - } - - /// - /// State Changed event data. - /// - /// 6 - public class StateChangedArgs : EventArgs - { - /// - /// Curent state - /// - /// 6 - public ControlStates CurrentState; - } } } diff --git a/src/Tizen.NUI.Components/Tizen.NUI.Components.sln b/src/Tizen.NUI.Components/Tizen.NUI.Components.sln index fccddc6..f3d1317 100755 --- a/src/Tizen.NUI.Components/Tizen.NUI.Components.sln +++ b/src/Tizen.NUI.Components/Tizen.NUI.Components.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.779 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI.Components", "Tizen.NUI.Components.csproj", "{0E7470D1-2A0F-4DDB-A259-2A35F6D5B64B}" EndProject @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI", "..\Tizen.NUI\T EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.SystemSettings", "..\Tizen.System.SystemSettings\Tizen.System.SystemSettings.csproj", "{572188E5-797A-485E-B00E-59C88077E611}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Information", "..\Tizen.System.Information\Tizen.System.Information.csproj", "{11CACB07-AF47-480E-AB25-88E3C3297631}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {572188E5-797A-485E-B00E-59C88077E611}.Debug|Any CPU.Build.0 = Debug|Any CPU {572188E5-797A-485E-B00E-59C88077E611}.Release|Any CPU.ActiveCfg = Release|Any CPU {572188E5-797A-485E-B00E-59C88077E611}.Release|Any CPU.Build.0 = Release|Any CPU + {11CACB07-AF47-480E-AB25-88E3C3297631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11CACB07-AF47-480E-AB25-88E3C3297631}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11CACB07-AF47-480E-AB25-88E3C3297631}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11CACB07-AF47-480E-AB25-88E3C3297631}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.7.4