[NUI] Add Progress Indeterminate mode (#2733)
authorSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Tue, 23 Mar 2021 05:28:08 +0000 (14:28 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 30 Mar 2021 06:51:02 +0000 (15:51 +0900)
* [NUI] Add Progress Indeterminate mode

- Indeterminate type means an unspecified amount of wait time.
 If `ProgressState` property sets `ProgressStatusType.Indeterminate` mode,
 then progress is continually repeating until the process in complete.

Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
* Fix build warning

Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
* Update Progress based on review

Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
Co-authored-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/Progress.cs
src/Tizen.NUI.Components/res/nui_component_default_progress_indeterminate.png [new file with mode: 0755]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/images/progress-bar-skin-indeterminate.png [new file with mode: 0755]

index 8c044b2..75018c4 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  *
  */
+using System;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
 using System.ComponentModel;
@@ -127,10 +128,12 @@ namespace Tizen.NUI.Components
         private ImageView trackImage = null;
         private ImageView progressImage = null;
         private ImageView bufferImage = null;
+        private ImageVisual indeterminateImage = null;
         private float maxValue = 100;
         private float minValue = 0;
         private float currentValue = 0;
         private float bufferValue = 0;
+        private Animation indeterminateAnimation = null;
 
         static Progress() { }
         /// <summary>
@@ -224,6 +227,38 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// The property to get/set the indeterminate image.
+        /// </summary>
+        /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
+        /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string IndeterminateImageUrl
+        {
+            get
+            {
+                if (indeterminateImage == null)
+                {
+                    return null;
+                }
+                else
+                {
+                    return indeterminateImage?.URL;
+                }
+            }
+            set
+            {
+                if (value == null || indeterminateImage == null)
+                {
+                    throw new NullReferenceException("Progress.IndeterminateImage is null");
+                }
+                else
+                {
+                    indeterminateImage.URL = value;
+                }
+            }
+        }
+
+        /// <summary>
         /// The property to get/set Track object color of the Progress.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
@@ -382,6 +417,7 @@ namespace Tizen.NUI.Components
                 Utility.Dispose(trackImage);
                 Utility.Dispose(progressImage);
                 Utility.Dispose(bufferImage);
+                indeterminateImage = null;
             }
 
             //You must call base.Dispose(type) just before exit.
@@ -435,6 +471,23 @@ namespace Tizen.NUI.Components
             }
         }
 
+        private Vector4 destinationValue = new Vector4(-1.0f, 0.0f, 10.0f, 1.0f);
+        private Vector4 initialValue = new Vector4(0.0f, 0.0f, 10.0f, 1.0f);
+
+        /// <summary>
+        /// Update Animation for Indeterminate mode.
+        /// </summary>
+        /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        private void UpdateIndeterminateAnimation()
+        {
+            indeterminateAnimation?.Stop();
+
+            indeterminateAnimation = AnimateVisual(indeterminateImage, "pixelArea", destinationValue, 0, 1000,  AlphaFunction.BuiltinFunctions.Default, initialValue);
+            indeterminateAnimation.Looping = true;
+            indeterminateAnimation.Play();
+        }
+
         /// <summary>
         /// Get Progress style.
         /// </summary>
@@ -452,24 +505,48 @@ namespace Tizen.NUI.Components
         /// <param name="statusType">New status type</param>
         protected void ChangeImageState(ProgressStatusType statusType)
         {
-            if (state == ProgressStatusType.Buffering)
+            if (statusType == ProgressStatusType.Buffering)
             {
-                bufferImage.Show();
+                indeterminateAnimation?.Stop();
+                indeterminateAnimation = null;
+
+                indeterminateImage.Opacity = 0.0f;
                 progressImage.Hide();
+                bufferImage.Show();
             }
-            else if (state == ProgressStatusType.Determinate)
+            else if (statusType == ProgressStatusType.Determinate)
             {
+                indeterminateAnimation?.Stop();
+                indeterminateAnimation = null;
+
+                indeterminateImage.Opacity = 0.0f;
                 bufferImage.Show();
                 progressImage.Show();
+
                 UpdateValue();
             }
-            else
+            else if (statusType == ProgressStatusType.Indeterminate)
             {
                 bufferImage.Hide();
                 progressImage.Hide();
+                indeterminateImage.Opacity = 1.0f;
+
+                UpdateIndeterminateAnimation();
             }
         }
 
+        private void Initialize()
+        {
+            // create necessary components
+            InitializeTrack();
+            InitializeBuffer();
+            InitializeProgress();
+            InitializeIndeterminate();
+
+            indeterminateAnimation?.Stop();
+            indeterminateAnimation = null;
+        }
+
         private void InitializeTrack()
         {
             if (null == trackImage)
@@ -517,5 +594,23 @@ namespace Tizen.NUI.Components
                 Add(bufferImage);
             }
         }
+
+        private void InitializeIndeterminate()
+        {
+            indeterminateImage = new ImageVisual
+            {
+                PixelArea = new Vector4(0.0f, 0.0f, 10.0f, 1.0f),
+                WrapModeU = WrapModeType.Repeat,
+                SizePolicy = VisualTransformPolicyType.Relative,
+                Origin = Visual.AlignType.Center,
+                AnchorPoint = Visual.AlignType.Center,
+                Opacity = 1.0f,
+                Size = new Size2D(1, 1),
+                URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "nui_component_default_progress_indeterminate.png"
+            };
+            AddVisual("Indeterminate", indeterminateImage);
+
+            // TODO : Need to update Style for indeterminate state.
+        }
     }
 }
diff --git a/src/Tizen.NUI.Components/res/nui_component_default_progress_indeterminate.png b/src/Tizen.NUI.Components/res/nui_component_default_progress_indeterminate.png
new file mode 100755 (executable)
index 0000000..f5a6ff0
Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_progress_indeterminate.png differ
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/images/progress-bar-skin-indeterminate.png b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/images/progress-bar-skin-indeterminate.png
new file mode 100755 (executable)
index 0000000..df99c15
Binary files /dev/null and b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/images/progress-bar-skin-indeterminate.png differ