Applying 9Patch to ExercisingView
authork.stepaniuk <k.stepaniuk@samsung.com>
Thu, 3 Dec 2020 12:03:56 +0000 (13:03 +0100)
committerPiotr Czaja <p.czaja@samsung.com>
Tue, 14 Sep 2021 11:01:34 +0000 (13:01 +0200)
Signed-off-by: k.stepaniuk <k.stepaniuk@samsung.com>
Fitness/Controls/NinePatchButton.cs [new file with mode: 0644]
Fitness/FitnessApp.cs
Fitness/Views/Styles/Buttons.cs
Fitness/Views/Styles/NinePatchButtonStyle.cs [new file with mode: 0644]
Fitness/res/styles/button/button_outline_28px.png [new file with mode: 0644]

diff --git a/Fitness/Controls/NinePatchButton.cs b/Fitness/Controls/NinePatchButton.cs
new file mode 100644 (file)
index 0000000..a078ab8
--- /dev/null
@@ -0,0 +1,80 @@
+using System;
+using Fitness.Views.Styles;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Fitness.Controls
+{
+    public class NinePatchButton : Button
+    {
+        public NinePatchButton()
+        {
+            this.Relayout += NinePatchButton_Relayout;
+        }
+
+        protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
+        {
+            UpdateButton();
+        }
+
+        private void NinePatchButton_Relayout(object sender, EventArgs e)
+        {
+            this.Relayout -= NinePatchButton_Relayout;
+            UpdateButton();
+        }
+
+        private static string AsPath(string url)
+        {
+            if (!String.IsNullOrEmpty(url) && url.Contains("*Resource*"))
+            {
+                string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
+                url = url.Replace("*Resource*", resource);
+            }
+
+            return url;
+        }
+
+        private void UpdateButton(Color color, string url)
+        {
+            PropertyMap outputVisualMap = null;
+            if (color != null)
+            {
+                outputVisualMap = new Tizen.NUI.NPatchVisual()
+                {
+                    URL = url,
+                    MixColor = color,
+                }.OutputVisualMap;
+            }
+            else
+            {
+                outputVisualMap = new Tizen.NUI.NPatchVisual()
+                {
+                    URL = url,
+                }.OutputVisualMap;
+            }
+
+            this.Background = outputVisualMap;
+            this.OverlayImage.Background = outputVisualMap;
+        }
+
+        private void UpdateButton()
+        {
+            if (ViewStyle is NinePatchButtonStyle style && !String.IsNullOrEmpty(style.NormalImageUrl))
+            {
+                if (ControlState == ControlState.Normal)
+                {
+                    UpdateButton(style.NormalColor, AsPath(style.NormalImageUrl));
+                }
+                else if (ControlState == ControlState.Pressed)
+                {
+                    UpdateButton(style.PressedColor, AsPath(style.PressedImageUrl ?? style.NormalImageUrl));
+                }
+                else if (ControlState == ControlState.Disabled)
+                {
+                    UpdateButton(style.DisabledColor, AsPath(style.DisabledImageUrl ?? style.NormalImageUrl));
+                }
+            }
+        }
+    }
+}
index 80a889c..a1508f1 100644 (file)
@@ -15,8 +15,7 @@ namespace Fitness
 
         public void Initialize()
         {
-            //NavigationService.Instance.NavigateToMainView();
-            NavigationService.Instance.NavigateToExercisingView();
+            NavigationService.Instance.NavigateToMainView();
         }
 
         protected override void OnCreate()
index 99d740a..97e262b 100644 (file)
@@ -6,15 +6,10 @@ namespace Fitness.Views.Styles
 {
     public static class Buttons
     {
-        public static ButtonStyle Regular => new ButtonStyle
+        public static NinePatchButtonStyle Regular => new NinePatchButtonStyle
         {
             BackgroundColor = Color.Transparent,
-            //BackgroundImage = new Selector<string>
-            //{
-            //    Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_full_28px.png",
-            //    Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
-            //    Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
-            //},
+            NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
             Text = new TextLabelStyle
             {
                 PixelSize = 32.0f,
@@ -28,14 +23,12 @@ namespace Fitness.Views.Styles
             },
         };
 
-        public static ButtonStyle Inverse => new ButtonStyle
+        public static NinePatchButtonStyle Inverse => new NinePatchButtonStyle
         {
-            BackgroundImage = new Selector<string>
-            {
-                Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_inverse.png",
-                Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
-                Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
-            },
+            BackgroundColor = Color.Transparent,
+            NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
+            NormalColor = new Color(10f/255f, 14f/255f , 74f/255f, 1),
+            PressedColor = new Color(43f / 255f, 95f / 255f, 185f / 255f, 1),
             Text = new TextLabelStyle
             {
                 PixelSize = 32.0f,
@@ -44,14 +37,10 @@ namespace Fitness.Views.Styles
             },
         };
 
-        public static ButtonStyle Previous => new ButtonStyle
+        public static NinePatchButtonStyle Previous => new NinePatchButtonStyle
         {
-            BackgroundImage = new Selector<string>
-            {
-                Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_regular.png",
-                Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
-                Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
-            },
+            BackgroundColor = Color.Transparent,
+            NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
             Text = new TextLabelStyle
             {
                 PixelSize = 24.0f,
@@ -72,14 +61,10 @@ namespace Fitness.Views.Styles
             IconRelativeOrientation = Button.IconOrientation.Left,
         };
 
-        public static ButtonStyle Next => new ButtonStyle
+        public static NinePatchButtonStyle Next => new NinePatchButtonStyle
         {
-            BackgroundImage = new Selector<string>
-            {
-                Normal = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_regular.png",
-                Pressed = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_pressed.png",
-                Disabled = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/button_disabled.png",
-            },
+            BackgroundColor = Color.Transparent,
+            NormalImageUrl = "*Resource*/styles/button/button_full_28px.png",
             Text = new TextLabelStyle
             {
                 PixelSize = 24.0f,
diff --git a/Fitness/Views/Styles/NinePatchButtonStyle.cs b/Fitness/Views/Styles/NinePatchButtonStyle.cs
new file mode 100644 (file)
index 0000000..9ba6bb4
--- /dev/null
@@ -0,0 +1,14 @@
+using Tizen.NUI.Components;
+
+namespace Fitness.Views.Styles
+{
+    public class NinePatchButtonStyle : ButtonStyle
+    {
+        public string NormalImageUrl { get; set; }
+        public string PressedImageUrl { get; set; }
+        public string DisabledImageUrl { get; set; }
+        public Tizen.NUI.Color NormalColor { get; set; }
+        public Tizen.NUI.Color PressedColor { get; set; }
+        public Tizen.NUI.Color DisabledColor { get; set; }
+    }
+}
diff --git a/Fitness/res/styles/button/button_outline_28px.png b/Fitness/res/styles/button/button_outline_28px.png
new file mode 100644 (file)
index 0000000..a638f6e
Binary files /dev/null and b/Fitness/res/styles/button/button_outline_28px.png differ