Revert "Revert "[NUI] Add AlertDialogStyle class with the latest AlertDialog UX""
authorhuiyu.eun <huiyu.eun@samsung.com>
Tue, 20 Apr 2021 06:01:52 +0000 (15:01 +0900)
committerhuiyueun <35286162+huiyueun@users.noreply.github.com>
Tue, 20 Apr 2021 06:13:00 +0000 (15:13 +0900)
This reverts commit 18a2050cf2890d02668449571e5950ef3c3faf42.

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI.Components/Controls/AlertDialog.cs
src/Tizen.NUI.Components/Style/AlertDialogStyle.cs [new file with mode: 0755]
src/Tizen.NUI.Components/Theme/DefaultTheme.cs
src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs

index 6e42b4c..b1b3ee5 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 using System;
 using System.ComponentModel;
+using System.Collections.Generic;
 using Tizen.NUI.BaseComponents;
 
 namespace Tizen.NUI.Components
 {
     /// <summary>
-    /// Types of the action button of AlertDialog.
-    /// </summary>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public enum AlertDialogActionButtonType
-    {
-        /// <summary>
-        /// Type of the positive action button.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        Positive,
-
-        /// <summary>
-        /// Type of the negative action button.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        Negative
-    }
-
-    /// <summary>
     /// AlertDialog class shows a dialog with title, message and action buttons.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class AlertDialog : Dialog
+    public class AlertDialog : Control
     {
         private string title = null;
         private string message = null;
 
-        private View popupTitle = null;
-        private View popupContent = null;
-        private View popupAction = null;
+        private View titleContent = null;
+        private View content = null;
+        private View actionContent = null;
+        private IEnumerable<View> actionContentViews = null;
 
         private View defaultTitleContent = null;
         private View defaultContent = null;
         private View defaultActionContent = null;
+        // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+        //        Until the bug is fixed, padding view is added after action content.
+        private View defaultActionContentPadding = null;
 
-        private Button positiveButton = null;
-        private Button negativeButton = null;
-
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="title">The title of AlertDialog.</param>
-        /// <param name="message">The message of AlertDialog.</param>
-        /// <param name="positiveButtonText">The positive button text in the action content of AlertDialog.</param>
-        /// <param name="positiveButtonClickedHandler">The clicked callback of the positive button in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonText">The negative button text in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonClickedHandler">The clicked callback of the negative button in the action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string title, string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : base()
-        {
-            //Content is initialized to add TitleContent, BodyContent and ActionContent.
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            InitContent();
-
-            //Title setter calls TitleContent setter if TitleContent is null.
-            Title = title;
+        private AlertDialogStyle alertDialogStyle => ViewStyle as AlertDialogStyle;
 
-            //Message setter calls BodyContent setter if BodyContent is null.
-            Message = message;
-
-            ActionContent = CreateActionContent(positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler);
-        }
+        private bool styleApplied = false;
 
         /// <summary>
         /// Creates a new instance of AlertDialog.
         /// </summary>
-        /// <param name="message">The message of AlertDialog.</param>
-        /// <param name="positiveButtonText">The positive button text in the action content of AlertDialog.</param>
-        /// <param name="positiveButtonClickedHandler">The clicked callback of the positive button in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonText">The negative button text in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonClickedHandler">The clicked callback of the negative button in the action content of AlertDialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : this(null, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler)
+        public AlertDialog() : base()
         {
+            Initialize();
         }
 
         /// <summary>
-        /// Creates a new instance of AlertDialog.
+        /// Dispose AlertDialog and all children on it.
         /// </summary>
-        /// <param name="title">The title of AlertDialog.</param>
-        /// <param name="message">The message of AlertDialog.</param>
+        /// <param name="type">Dispose type.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string title, string message) : this(title, message, null, null, null, null)
+        protected override void Dispose(DisposeTypes type)
         {
-        }
+            if (disposed)
+            {
+                return;
+            }
 
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="message">The message of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string message) : this(null, message)
-        {
-        }
+            if (type == DisposeTypes.Explicit)
+            {
+                if (titleContent != null)
+                {
+                    Utility.Dispose(titleContent);
+                }
 
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="titleContent">The title content of AlertDialog.</param>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
-        /// <param name="actionContent">The action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View titleContent, View bodyContent, View actionContent) : base()
-        {
-            //Content is initialized to add TitleContent, BodyContent and ActionContent.
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            InitContent();
+                if (content != null)
+                {
+                    Utility.Dispose(content);
+                }
 
-            TitleContent = titleContent;
+                if (actionContent != null)
+                {
+                    Utility.Dispose(actionContent);
+                }
 
-            BodyContent = bodyContent;
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (defaultActionContentPadding != null)
+                {
+                    Utility.Dispose(defaultActionContentPadding);
+                }
+            }
 
-            ActionContent = actionContent;
+            base.Dispose(type);
         }
 
         /// <summary>
-        /// Creates a new instance of AlertDialog.
+        /// Applies style to AlertDialog.
         /// </summary>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
-        /// <param name="actionContent">The action content of AlertDialog.</param>
+        /// <param name="viewStyle">The style to apply.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View bodyContent, View actionContent) : this(null, bodyContent, actionContent)
+        public override void ApplyStyle(ViewStyle viewStyle)
         {
-        }
+            styleApplied = false;
 
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View bodyContent = null) : this(bodyContent, null)
-        {
-        }
+            base.ApplyStyle(viewStyle);
 
-        private void InitContent()
-        {
-            var content = new Control();
+            // Apply Title style.
+            if ((alertDialogStyle?.TitleTextLabel != null) && (DefaultTitleContent is TextLabel))
+            {
+                ((TextLabel)DefaultTitleContent)?.ApplyStyle(alertDialogStyle.TitleTextLabel);
+            }
+
+            // Apply Message style.
+            if ((alertDialogStyle?.MessageTextLabel != null) && (DefaultContent is TextLabel))
+            {
+                ((TextLabel)DefaultContent)?.ApplyStyle(alertDialogStyle.MessageTextLabel);
+            }
+
+            // Apply ActionContent style.
+            if (alertDialogStyle?.ActionContent != null)
+            {
+                DefaultActionContent?.ApplyStyle(alertDialogStyle.ActionContent);
+            }
 
-            var linearLayout = new LinearLayout();
-            linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
-            content.Layout = linearLayout;
+            styleApplied = true;
 
-            Content = content;
+            // Calculate dialog position and children's positions based on padding sizes.
+            CalculatePosition();
         }
 
         /// <summary>
-        /// Title content of AlertDialog. TitleContent is added to Children automatically.
+        /// Title text of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View TitleContent
+        public string Title
         {
             get
             {
-                return popupTitle;
+                return title;
             }
             set
             {
-                if (popupTitle == value)
+                if (title == value)
                 {
                     return;
                 }
 
-                if (popupTitle != null)
-                {
-                    Remove(popupTitle);
-                }
+                title = value;
 
-                popupTitle = value;
-                if (popupTitle == null)
+                if (TitleContent is TextLabel textLabel)
                 {
-                    return;
+                    textLabel.Text = title;
                 }
-
-                ResetContent();
             }
         }
 
         /// <summary>
-        /// BodyContent of AlertDialog. BodyContent is added to Children automatically.
+        /// Title content of AlertDialog. TitleContent is added to Children automatically.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View BodyContent
+        public View TitleContent
         {
             get
             {
-                return popupContent;
+                return titleContent;
             }
             set
             {
-                if (popupContent == value)
+                if (titleContent == value)
                 {
                     return;
                 }
 
-                if (popupContent != null)
+                if (titleContent != null)
                 {
-                    Remove(popupContent);
+                    Remove(titleContent);
                 }
 
-                popupContent = value;
-                if (popupContent == null)
+                titleContent = value;
+                if (titleContent == null)
                 {
                     return;
                 }
 
+                if (titleContent is TextLabel textLabel)
+                {
+                    textLabel.Text = Title;
+                }
+
                 ResetContent();
             }
         }
 
         /// <summary>
-        /// Action content of AlertDialog. ActionContent is added to Children automatically.
+        /// Message text of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View ActionContent
+        public string Message
         {
             get
             {
-                return popupAction;
+                return message;
             }
             set
             {
-                if (popupAction == value)
+                if (message == value)
                 {
                     return;
                 }
 
-                if (popupAction != null)
-                {
-                    Remove(popupAction);
-                }
+                message = value;
 
-                popupAction = value;
-                if (popupAction == null)
+                if (Content is TextLabel textLabel)
                 {
-                    return;
+                    textLabel.Text = message;
                 }
-
-                ResetContent();
             }
         }
 
-        private void ResetContent()
+        /// <summary>
+        /// Content of AlertDialog. Content is added to Children automatically.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View Content
         {
-            if (Content == null)
-            {
-                return;
-            }
-
-            //To keep the order of TitleContent, BodyContent and ActionContent,
-            //the existing contents are removed and added again.
-            if (popupTitle != null)
+            get
             {
-                Content.Remove(popupTitle);
+                return content;
             }
-
-            if (popupContent != null)
+            set
             {
-                Content.Remove(popupContent);
-            }
+                if (content == value)
+                {
+                    return;
+                }
 
-            if (popupAction != null)
-            {
-                Content.Remove(popupAction);
-            }
+                if (content != null)
+                {
+                    Remove(content);
+                }
 
-            if (popupTitle != null)
-            {
-                Content.Add(popupTitle);
-            }
+                content = value;
+                if (content == null)
+                {
+                    return;
+                }
 
-            if (popupContent != null)
-            {
-                Content.Add(popupContent);
-            }
+                if (content is TextLabel textLabel)
+                {
+                    textLabel.Text = message;
+                }
 
-            if (popupAction != null)
-            {
-                Content.Add(popupAction);
+                ResetContent();
             }
         }
 
         /// <summary>
-        /// Title text of AlertDialog.
+        /// Action views of AlertDialog.
+        /// Action views are added to ActionContent of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public string Title
+        public IEnumerable<View> Actions
         {
             get
             {
-                return title;
+                return actionContentViews;
             }
             set
             {
-                if (title == value)
+                if (ActionContent == null)
                 {
+                    actionContentViews = value;
                     return;
                 }
 
-                title = value;
-                if (title == null)
+                if (actionContentViews != null)
                 {
-                    if (TitleContent != null)
+                    foreach (var oldAction in actionContentViews)
                     {
-                        //TitleContent setter calls Remove(popupTitle).
-                        TitleContent = null;
+                        if (ActionContent.Children?.Contains(oldAction) == true)
+                        {
+                            ActionContent.Children.Remove(oldAction);
+                        }
                     }
                 }
-                else
+
+                actionContentViews = value;
+
+                if (actionContentViews == null)
                 {
-                    if (TitleContent == null)
-                    {
-                        TitleContent = CreateTitleContent(title);
-                    }
-                    else if (TitleContent == defaultTitleContent)
-                    {
-                        //Sets text if TitleContent is not set by user.
-                        ((TextLabel)TitleContent).Text = title;
-                    }
+                    return;
+                }
+
+                foreach (var action in actionContentViews)
+                {
+                    ActionContent.Add(action);
                 }
             }
         }
 
         /// <summary>
-        /// Message text of AlertDialog.
+        /// Action content of AlertDialog. ActionContent is added to Children automatically.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public string Message
+        public View ActionContent
         {
-            get
-            {
-                return message;
-            }
-            set
-            {
-                if (message == value)
+             get
+             {
+                return actionContent;
+             }
+             set
+             {
+                if (actionContent == value)
+                 {
+                     return;
+                 }
+
+                var oldActionContent = actionContent;
+                actionContent = value;
+
+                // Add views first before remove previous action content
+                // not to cause Garbage Collector collects views.
+                if ((actionContent != null) && (Actions != null))
                 {
-                    return;
+                    foreach (var action in Actions)
+                    {
+                        actionContent.Add(action);
+                    }
                 }
 
-                message = value;
-                if (message == null)
+                if (oldActionContent != null)
                 {
-                    if (BodyContent != null)
-                    {
-                        //BodyContent setter calls Remove(popupContent).
-                        BodyContent = null;
-                    }
+                    Remove(oldActionContent);
                 }
-                else
+
+                if (actionContent == null)
                 {
-                    if (BodyContent == null)
-                    {
-                        BodyContent = CreateContent(message);
-                    }
-                    else if (BodyContent == defaultContent)
-                    {
-                        //Sets text if BodyContent is not set by user.
-                        ((TextLabel)BodyContent).Text = message;
-                    }
+                    return;
                 }
+
+                ResetContent();
             }
         }
 
         /// <summary>
-        /// Sets action button in the action content of AlertDialog.
+        /// AccessibilityGetName.
         /// </summary>
-        /// <param name="type">The type of action button.</param>
-        /// <param name="text">The text of action button in the action content of AlertDialog.</param>
-        /// <param name="clickedHandler">The clicked callback of the action button in the action content of AlertDialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void SetActionButton(AlertDialogActionButtonType type, string text, EventHandler<ClickedEventArgs> clickedHandler)
+        protected override string AccessibilityGetName()
         {
-            if (ActionContent == null)
+            if (!String.IsNullOrEmpty(Title))
             {
-                if (type == AlertDialogActionButtonType.Positive)
-                {
-                    ActionContent = CreateActionContent(text, clickedHandler, null, null);
-                }
-                else
-                {
-                    ActionContent = CreateActionContent(null, null, text, clickedHandler);
-                }
+                return Title;
             }
-            else if (ActionContent == defaultActionContent)
+            else
+            {
+                return Message;
+            }
+        }
+
+        /// <summary>
+        /// Default title content of AlertDialog.
+        /// If Title is set, then default title content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultTitleContent
+        {
+            get
             {
-                //To keep the order of negativeButton and positiveButton,
-                //positiveButton is always removed.
-                if (positiveButton != null)
+                if (defaultTitleContent == null)
                 {
-                    ActionContent.Remove(positiveButton);
+                    defaultTitleContent = CreateDefaultTitleContent();
                 }
 
-                if (type == AlertDialogActionButtonType.Negative)
+                return defaultTitleContent;
+            }
+        }
+
+        /// <summary>
+        /// Default content of AlertDialog.
+        /// If Message is set, then default content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultContent
+        {
+            get
+            {
+                if (defaultContent == null)
                 {
-                    if (negativeButton != null)
-                    {
-                        ActionContent.Remove(negativeButton);
-                    }
+                    defaultContent = CreateDefaultContent();
+                }
 
-                    negativeButton = CreateActionButton(text, clickedHandler);
-                    if (negativeButton != null)
-                    {
-                        ActionContent.Add(negativeButton);
+                return defaultContent;
+            }
+        }
 
-                        if (positiveButton != null)
-                        {
-                            ActionContent.Add(positiveButton);
-                        }
-                    }
+        /// <summary>
+        /// Default action content of AlertDialog.
+        /// If Actions are set, then default action content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultActionContent
+        {
+            get
+            {
+                if (defaultActionContent == null)
+                {
+                    defaultActionContent = CreateDefaultActionContent();
                 }
-                else
+
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (defaultActionContentPadding == null)
                 {
-                    positiveButton = CreateActionButton(text, clickedHandler);
-                    if (positiveButton != null)
-                    {
-                        ActionContent.Add(positiveButton);
-                    }
+                    defaultActionContentPadding = CreateDefaultActionContentPadding();
                 }
+
+                return defaultActionContent;
             }
         }
 
-        private TextLabel CreateTitleContent(string text)
+        private void Initialize()
         {
-            if (text == null)
+            Layout = new LinearLayout()
             {
-                return null;
-            }
+                LinearOrientation = LinearLayout.Orientation.Vertical,
+            };
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var titleContent = new TextLabel(text);
-            titleContent.HorizontalAlignment = HorizontalAlignment.Center;
-            titleContent.VerticalAlignment = VerticalAlignment.Center;
-            titleContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            titleContent.Size = new Size(360, 80);
+            this.Relayout += OnRelayout;
 
-            defaultTitleContent = titleContent;
+            TitleContent = DefaultTitleContent;
 
-            return titleContent;
+            Content = DefaultContent;
+
+            ActionContent = DefaultActionContent;
         }
 
-        private TextLabel CreateContent(string message)
+        private void ResetContent()
         {
-            if (message == null)
+            //To keep the order of TitleContent, Content and ActionContent,
+            //the existing contents are removed and added again.
+            if (titleContent != null)
             {
-                return null;
+                Remove(titleContent);
+            }
+
+            if (content != null)
+            {
+                Remove(content);
+            }
+
+            if (actionContent != null)
+            {
+                Remove(actionContent);
+            }
+
+            if (titleContent != null)
+            {
+                Add(titleContent);
+            }
+
+            if (content != null)
+            {
+                Add(content);
+            }
+
+            if (actionContent != null)
+            {
+                Add(actionContent);
+
+                // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+                //        Until the bug is fixed, padding view is added after action content.
+                if (actionContent == defaultActionContent)
+                {
+                    if (defaultActionContentPadding != null)
+                    {
+                        Add(defaultActionContentPadding);
+                    }
+                }
             }
+        }
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var messageContent = new TextLabel(message);
-            messageContent.HorizontalAlignment = HorizontalAlignment.Center;
-            messageContent.VerticalAlignment = VerticalAlignment.Center;
-            messageContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            messageContent.Size = new Size(360, 200);
+        private TextLabel CreateDefaultTitleContent()
+        {
+            return new TextLabel();
+        }
 
-            defaultContent = messageContent;
+        private TextLabel CreateDefaultContent()
+        {
+            return new TextLabel();
+        }
 
-            return messageContent;
+        private View CreateDefaultActionContent()
+        {
+            return new View()
+            {
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                },
+            };
         }
 
-        private Button CreateActionButton(string text, EventHandler<ClickedEventArgs> clickedHandler)
+        // FIXME: Now AlertDialog.Padding Top and Bottom increases AlertDialog size incorrectly.
+        //        Until the bug is fixed, padding view is added after action content.
+        private View CreateDefaultActionContentPadding()
         {
-            if (text == null)
+            var layout = Layout as LinearLayout;
+
+            if ((layout == null) || (defaultActionContent == null))
             {
                 return null;
             }
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionButton = new Button();
-            actionButton.Text = text;
-            actionButton.Size = new Size(120, 80);
+            View paddingView = null;
 
-            if (clickedHandler != null)
+            using (Size2D size = new Size2D(defaultActionContent.Size2D.Width, defaultActionContent.Size2D.Height))
             {
-                actionButton.Clicked += clickedHandler;
+                if (layout.LinearOrientation == LinearLayout.Orientation.Horizontal)
+                {
+                    size.Width = 40;
+                }
+                else
+                {
+                    size.Height = 40;
+                }
+
+                paddingView = new View()
+                {
+                    Size2D = new Size2D(size.Width, size.Height),
+                };
             }
 
-            return actionButton;
+            return paddingView;
+        }
+
+        private void OnRelayout(object sender, EventArgs e)
+        {
+            // Calculate dialog position and children's positions based on padding sizes.
+            CalculatePosition();
         }
 
-        private View CreateActionContent(string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText, EventHandler<ClickedEventArgs> negativeButtonClickedHandler)
+        // Calculate dialog position and children's positions based on padding sizes.
+        private void CalculatePosition()
         {
-            if ((negativeButtonText == null) && (positiveButtonText == null))
+            if (styleApplied == false)
             {
-                return null;
+                return;
             }
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionContent = new Control();
-            actionContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            actionContent.Size = new Size(360, 80);
+            CalculateActionsCellPadding();
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionLayout = new LinearLayout();
-            actionLayout.LinearOrientation = LinearLayout.Orientation.Horizontal;
-            actionLayout.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;
-            actionLayout.CellPadding = new Size2D(10, 0);
-            actionContent.Layout = actionLayout;
+            var size = Size2D;
+            var parent = GetParent();
+            Size2D parentSize;
 
-            negativeButton = CreateActionButton(negativeButtonText, negativeButtonClickedHandler);
-            if (negativeButton != null)
+            if ((parent != null) && (parent is View))
             {
-                actionContent.Add(negativeButton);
+                parentSize = ((View)parent).Size;
             }
-
-            positiveButton = CreateActionButton(positiveButtonText, positiveButtonClickedHandler);
-            if (positiveButton != null)
+            else
             {
-                actionContent.Add(positiveButton);
+                parentSize = NUIApplication.GetDefaultWindow().Size;
             }
 
-            defaultActionContent = actionContent;
-
-            return actionContent;
+            Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
         }
 
-        /// <summary>
-        /// Dispose AlertDialog and all children on it.
-        /// </summary>
-        /// <param name="type">Dispose type.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        // Calculate CellPadding among Actions if ActionContent is LinearLayout.
+        private void CalculateActionsCellPadding()
         {
-            if (disposed)
+            if ((ActionContent != DefaultActionContent) || (ActionContent.Layout is LinearLayout == false))
             {
                 return;
             }
 
-            if (type == DisposeTypes.Explicit)
+            if (Actions == null)
             {
-                if (popupTitle != null)
-                {
-                    Utility.Dispose(popupTitle);
-                }
+                return;
+            }
+
+            var size = Size2D;
+            var layout = ActionContent.Layout as LinearLayout;
+            int count = 0;
 
-                if (popupContent != null)
+            if (layout.LinearOrientation == LinearLayout.Orientation.Horizontal)
+            {
+                int actionsWidth = 0;
+
+                foreach (var action in Actions)
                 {
-                    Utility.Dispose(popupContent);
+                    actionsWidth += ((View)action).Size2D.Width + ((((View)action).Margin?.Start + ((View)action).Margin?.End) ?? 0);
+                    count++;
                 }
 
-                if (popupAction != null)
+                if (count > 1)
                 {
-                    if (positiveButton != null)
-                    {
-                        Utility.Dispose(positiveButton);
-                    }
-
-                    if (negativeButton != null)
-                    {
-                        Utility.Dispose(negativeButton);
-                    }
-
-                    Utility.Dispose(popupAction);
+                    actionsWidth += (Padding?.Start + Padding?.End) ?? 0;
+                    var cellPaddingWidth = (size.Width - actionsWidth) / (count - 1);
+                    layout.CellPadding = new Size2D(cellPaddingWidth , 0);
                 }
             }
-
-            base.Dispose(type);
-        }
-
-        /// <summary>
-        /// AccessibilityGetName.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override string AccessibilityGetName()
-        {
-            if (!String.IsNullOrEmpty(Title))
-            {
-                return Title;
-            }
             else
             {
-                return Message;
+                int actionsHeight = 0;
+
+                foreach (var action in Actions)
+                {
+                    actionsHeight += ((View)action).Size2D.Height + ((((View)action).Margin?.Top + ((View)action).Margin?.Bottom) ?? 0);
+                    count++;
+                }
+
+                if (count > 1)
+                {
+                    actionsHeight += (Padding?.Top + Padding?.Bottom) ?? 0;
+                    var cellPaddingHeight = (size.Height - actionsHeight) / (count - 1);
+                    layout.CellPadding = new Size2D(0, cellPaddingHeight);
+                }
             }
         }
     }
diff --git a/src/Tizen.NUI.Components/Style/AlertDialogStyle.cs b/src/Tizen.NUI.Components/Style/AlertDialogStyle.cs
new file mode 100755 (executable)
index 0000000..0cc8ed8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using System.ComponentModel;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.Components
+{
+    /// <summary>
+    /// AlertDialogStyle is a class which saves AlertDialog's ux data.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AlertDialogStyle : ButtonStyle
+    {
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static AlertDialogStyle() { }
+
+        /// <summary>
+        /// Creates a new instance of a AlertDialogStyle.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AlertDialogStyle() : base()
+        {
+        }
+
+        /// <summary>
+        /// Creates a new instance of a AlertDialogStyle with style.
+        /// </summary>
+        /// <param name="style">Create AlertDialogStyle by style customized by user.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AlertDialogStyle(AlertDialogStyle style) : base(style)
+        {
+        }
+
+        /// <summary>
+        /// Gets or sets the AlertDialog Title TextLabel style.
+        /// This style is applied if AlertDialog TitleContent is a TextLabel.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextLabelStyle TitleTextLabel { get; set; } = new TextLabelStyle();
+
+        /// <summary>
+        /// Gets or sets the AlertDialog Message TextLabel style.
+        /// This style is applied if AlertDialog Content is a TextLabel.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TextLabelStyle MessageTextLabel { get; set; } = new TextLabelStyle();
+
+        /// <summary>
+        /// Gets or sets the AlertDialog ActionContent style.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ViewStyle ActionContent { get; set; } = new ViewStyle();
+
+        /// <summary>
+        /// Style's clone function.
+        /// </summary>
+        /// <param name="bindableObject">The style that need to copy.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void CopyFrom(BindableObject bindableObject)
+        {
+            base.CopyFrom(bindableObject);
+
+            if (bindableObject is AlertDialogStyle alertDialogStyle)
+            {
+                TitleTextLabel.CopyFrom(alertDialogStyle.TitleTextLabel);
+                MessageTextLabel.CopyFrom(alertDialogStyle.MessageTextLabel);
+                ActionContent.CopyFrom(alertDialogStyle.ActionContent);
+            }
+        }
+    }
+}
index 84323f2..cdfd732 100755 (executable)
@@ -180,6 +180,26 @@ namespace Tizen.NUI.Components
                     .Add<Position>("/Pickers/Divider/Position", (ViewStyle style, Position value) => ((DatePickerStyle)style).Pickers.Divider.Position = value)
                     .AddSelector("/Pickers/Divider/BackgroundColor", (ViewStyle style, Selector<Color> value) => ((DatePickerStyle)style).Pickers.Divider.BackgroundColor = value, ControlState.Selected)
                     .Add<Size>("/Pickers/StartScrollOffset", (ViewStyle style, Size value) => ((DatePickerStyle)style).Pickers.StartScrollOffset = value),
+
+                // AlertDialog
+                (new ExternalThemeKeyList(typeof(AlertDialog), typeof(AlertDialogStyle)))
+                    .Add<Size>("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value)
+                    .Add<Extents>("/Padding", (ViewStyle style, Extents value) => ((ViewStyle)style).Padding = value)
+                    .Add<string>("/BackgroundImage", (ViewStyle style, string value) => ((ViewStyle)style).BackgroundImage = value)
+                    .Add<Size>("/TitleTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).TitleTextLabel.Size = value)
+                    .Add<Extents>("/TitleTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).TitleTextLabel.Margin = value)
+                    .Add<float?>("/TitleTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).TitleTextLabel.PixelSize = value)
+                    .Add<HorizontalAlignment?>("/TitleTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.HorizontalAlignment = value)
+                    .Add<VerticalAlignment?>("/TitleTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.VerticalAlignment = value)
+                    .AddSelector<Color>("/TitleTextLabel/TextColor", (ViewStyle style, Selector<Color> value) => ((AlertDialogStyle)style).TitleTextLabel.TextColor = value)
+                    .Add<Size>("/MessageTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).MessageTextLabel.Size = value)
+                    .Add<Extents>("/MessageTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).MessageTextLabel.Margin = value)
+                    .Add<float?>("/MessageTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).MessageTextLabel.PixelSize = value)
+                    .Add<bool?>("/MessageTextLabel/MultiLine", (ViewStyle style, bool? value) => ((AlertDialogStyle)style).MessageTextLabel.MultiLine = value)
+                    .Add<HorizontalAlignment?>("/MessageTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.HorizontalAlignment = value)
+                    .Add<VerticalAlignment?>("/MessageTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.VerticalAlignment = value)
+                    .AddSelector<Color>("/MessageTextLabel/TextColor", (ViewStyle style, Selector<Color> value) => ((AlertDialogStyle)style).MessageTextLabel.TextColor = value)
+                    .Add<Size>("/ActionContent/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).ActionContent.Size = value),
             };
 
             return actionSet;
index d9ebcc7..0e79362 100755 (executable)
@@ -626,6 +626,42 @@ namespace Tizen.NUI.Components
                 }
             });
 
+            theme.AddStyleWithoutClone("Tizen.NUI.Components.AlertDialog", new AlertDialogStyle()
+            {
+                Size = new Size(-2, -2),
+                Padding = new Extents(80, 80, 0, 0),
+                BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_dialog_bg.#.png",
+                TitleTextLabel = new TextLabelStyle()
+                {
+                    Size = new Size(1024, -2),
+                    Margin = new Extents(0, 0, 40, 40),
+                    PixelSize = 40,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    TextColor = new Selector<Color>()
+                    {
+                        Normal = new Color("#000C2BFF"),
+                    },
+                },
+                MessageTextLabel = new TextLabelStyle()
+                {
+                    Size = new Size(1024, -2),
+                    Margin = new Extents(0, 0, 0, 64),
+                    PixelSize = 32,
+                    MultiLine = true,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    TextColor = new Selector<Color>()
+                    {
+                        Normal = new Color("#000C2BFF"),
+                    },
+                },
+                ActionContent = new ViewStyle()
+                {
+                    Size = new Size(1024, -2),
+                },
+            });
+
             return theme;
         }
     }