Buttons customization
authorKamil Stepaniuk/IoT K.stepaniuk UI Sample (PLT) /SRPOL/Designer/Samsung Electronics <k.stepaniuk@samsung.com>
Thu, 19 Mar 2020 15:54:28 +0000 (16:54 +0100)
committerLukasz Stanislawski/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <l.stanislaws@samsung.com>
Fri, 20 Mar 2020 12:29:56 +0000 (13:29 +0100)
Handling TurnOn/Off button with screen replacement

Signed-off-by: Kamil Stepaniuk/IoT K.stepaniuk UI Sample (PLT) /SRPOL/Designer/Samsung Electronics <k.stepaniuk@samsung.com>
Oobe/OobeCommon/Styles/ButtonStyles.cs
Oobe/OobeWifi/Controls/Wifi/WifiState.cs [new file with mode: 0644]
Oobe/OobeWifi/Controls/Wifi/WifiView.cs [new file with mode: 0644]
Oobe/OobeWifi/Controls/WifiView.cs [deleted file]
Oobe/OobeWifi/WifiStep.cs
Oobe/OobeWifi/res/12_icon_scan.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_scan.svg [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_wifioff.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_wifioff.svg [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_wifion.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_wifion.svg [new file with mode: 0644]

index 4c77f7c465f9f1492e649b144134c163145549e1..1f0f19d27046f69955219701e2703fd929fdd0f0 100644 (file)
@@ -7,15 +7,19 @@ namespace Oobe.Common.Styles
     public class ButtonStyles
     {
         public static ButtonStyle Next = GetNextButtonStyle();
-        public static ButtonStyle Previous = new ButtonStyle {
-            Text = new TextLabelStyle {
-                PointSize = new Selector<float?> {
+        public static ButtonStyle Previous = new ButtonStyle
+        {
+            Text = new TextLabelStyle
+            {
+                PointSize = new Selector<float?>
+                {
                     Normal = 22.0f,
                     Pressed = 24.0f
                 },
                 EnableMarkup = true,
                 Text = "PREVIOUS",
-                TextColor = new Selector<Color> {
+                TextColor = new Selector<Color>
+                {
                     Normal = new Color(0.0f, 20.0f / 255.0f, 71 / 255.0f, 1.0f),
                     Pressed = new Color(41.0f / 255.0f, 91.0f / 255.0f, 178 / 255.0f, 1.0f),
                 }
@@ -23,6 +27,22 @@ namespace Oobe.Common.Styles
             Size2D = new Size2D(240, 72),
         };
         public static ButtonStyle Skip = GetSkipButtonStyle();
+        public static ButtonStyle Scan = new ButtonStyle
+        {
+            BackgroundImage = new Selector<string>
+            {
+                Normal = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_scan.png",
+            },
+            Size2D = new Size2D(72, 32),
+        };
+        public static ButtonStyle AddNetwork = new ButtonStyle
+        {
+            BackgroundImage = new Selector<string>
+            {
+                Normal = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_addnetwork.png",
+            },
+            Size2D = new Size2D(42, 42),
+        };
 
         private static ButtonStyle GetSkipButtonStyle()
         {
@@ -31,7 +51,8 @@ namespace Oobe.Common.Styles
             return style;
         }
 
-        private static ButtonStyle GetNextButtonStyle() => new ButtonStyle {
+        private static ButtonStyle GetNextButtonStyle() => new ButtonStyle
+        {
             BackgroundImage = new Selector<string>
             {
                 Normal = NUIApplication.Current.DirectoryInfo.Resource + "button/02_CTA_empty_active.svg",
diff --git a/Oobe/OobeWifi/Controls/Wifi/WifiState.cs b/Oobe/OobeWifi/Controls/Wifi/WifiState.cs
new file mode 100644 (file)
index 0000000..410257d
--- /dev/null
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Oobe.Wifi.Controls.Wifi
+{
+    struct WifiInfo
+    {
+    }
+
+    internal class WifiState
+    {
+        public event Action OnTurningOnFailed;
+        public event Action OnTurnedOn;
+        public event Action OnTurnedOff;
+        public bool IsTurnedOn { get; private set; } = true;
+
+        private int counter = 1; //for verify
+        public void TurnWifi()
+        {
+            if (IsTurnedOn)
+            {
+                //turn off wifi
+                IsTurnedOn = false;
+                OnTurnedOff?.Invoke();
+
+            }
+            else
+            {
+                //for verify
+                counter++;
+                if (counter % 3 == 0)
+                {
+                    OnTurningOnFailed?.Invoke();
+                    return;
+                }
+                //turn on wifi
+                //if succesful
+                IsTurnedOn = true;
+                OnTurnedOn?.Invoke();
+            }
+        }
+
+        async Task<IEnumerable<WifiInfo>> Scan()
+        {
+            return await Task.FromResult<IEnumerable<WifiInfo>>(null);
+        }
+    }
+}
diff --git a/Oobe/OobeWifi/Controls/Wifi/WifiView.cs b/Oobe/OobeWifi/Controls/Wifi/WifiView.cs
new file mode 100644 (file)
index 0000000..5cc176b
--- /dev/null
@@ -0,0 +1,230 @@
+using Oobe.Common.Styles;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Threading.Tasks;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Oobe.Wifi.Controls.Wifi
+{
+    public class WifiView : IDisposable
+    {
+        private View view = null;
+        private ObservableCollection<View> items;
+        private int counter = 0;
+
+        private WifiState State { get; set; } = new WifiState();
+
+        private static IEnumerable<View> CreateViews(string pattern)
+        {
+            yield return CreateManualWifiView(460, 89);
+            foreach (var item in Enumerable.Range(1, 10))
+            {
+                yield return CreateWifiView(460, 89, $"Wi-Fi_{item}");
+            }
+        }
+
+        public View View
+        {
+            get
+            {
+                if (view == null)
+                {
+                    view = new View()
+                    {
+                        Layout = new LinearLayout()
+                        {
+                            LinearOrientation = LinearLayout.Orientation.Vertical,
+                        },
+                        BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "Rectangle_918.png"),
+                        //Size = new Size(480, 401),
+                    };
+                    view.Add(CreateHeader(480, 80));
+
+                    view.Add(new View()
+                    {
+                        Size2D = new Size(400, 1),
+                        BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "Line_94.png"),
+                        Margin = new Extents(40, 0, 0, 0),
+                    });
+
+                    view.Add(CreateListViewPlaceHolder());
+
+                    ForVerify();
+                }
+                return view;
+            }
+        }
+
+        private async void ForVerify()
+        {
+            counter++;
+            if (counter > 4)
+                return;
+            if (view != null)
+            {
+                await Task.Delay(2000);
+                items.RemoveAt(1);
+                //items.Insert(1, CreateViewAbsolute($"s{counter}"));
+                ForVerify();
+            }
+        }
+
+        private static View CreateManualWifiView(int width, int height)
+        {
+            var manualWifi = new View()
+            {
+                Size = new Size(width, height),
+                Layout = new AbsoluteLayout(),
+            };
+
+            manualWifi.Add(new Button(ButtonStyles.AddNetwork)
+            {
+                Position = new Position(29, 20),
+                Size = new Size(42, 42),
+            });
+
+            manualWifi.Add(new TextLabel("Add new...")
+            {
+                Position = new Position(87, 29),
+                PixelSize = 20f,
+                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            });
+            return manualWifi;
+        }
+
+        private static View CreateWifiView(int width, int height, string name)
+        {
+            var wifi = new View()
+            {
+                Size = new Size(width, height),
+                Layout = new AbsoluteLayout(),
+            };
+
+            wifi.Add(new View()
+            {
+                //Size = new Size(21, 15),
+                Position = new Position(39, 32),
+                BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_wifi.svg"),
+            });
+
+            wifi.Add(new TextLabel(name)
+            {
+                Position = new Position(78, 28),
+                PixelSize = 20f,
+                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Light(),
+            });
+
+            wifi.Add(new TextLabel("detail")
+            {
+                Position = new Position(79, 56),
+                PixelSize = 14f,
+                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            });
+            return wifi;
+        }
+
+        private View CreateHeader(int width, int height)
+        {
+            var header = new View()
+            {
+                Size = new Size(width, height),
+                Layout = new AbsoluteLayout(),
+            };
+
+            header.Add(new TextLabel("Wi-Fi")
+            {
+                Size = new Size(49, 24),
+                Position = new Position(40, 43),
+                PixelSize = 19f,
+                TextColor = new Color(0, 14.0f / 255.0f, 47.0f / 255.0f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            });
+
+            header.Add(new Button(ButtonStyles.Scan)
+            {
+                Size = new Size(72, 32),
+                Position = new Position(276, 39),
+            });
+
+            header.Add(CreateTurnOnButton());
+            return header;
+        }
+
+        private Button CreateTurnOnButton()
+        {
+            var button = new Button(new ButtonStyle())
+            {
+                Size = new Size(72, 32),
+                Position = new Position(369, 39),
+            };
+            button.Style.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource +
+                (State.IsTurnedOn ? "12_icon_wifion.png" : "12_icon_wifioff.png");
+
+            State.OnTurnedOff += () =>
+                button.Style.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_wifioff.png";
+            State.OnTurnedOn += () =>
+                button.Style.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_wifion.png";
+
+            button.ClickEvent += (s, e) => State.TurnWifi();
+            return button;
+        }
+
+        private View CreateListViewPlaceHolder()
+        {
+            var view = new View();
+            items = new ObservableCollection<View>(CreateViews($"{counter} "));
+            var listView = new ListView(480, 328)//480, 335
+            {
+                Items = items
+            }.View;
+            listView.Hide();
+            view.Add(listView);
+
+            var prompt = new TextLabel()
+            {
+                Position = new Position(42, 32),
+                PixelSize = 20,
+                TextColor = new Color(0, 0x14 / 255f, 0x47 / 255f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            };
+            view.Add(prompt);
+
+            void turnOn()
+            {
+                prompt.Hide();
+                listView.Show();
+            }
+            void turnOff(string message)
+            {
+                listView.Hide();
+                prompt.Text = message;
+                prompt.Show();
+            }
+            if (State.IsTurnedOn)
+                turnOn();
+            else
+                turnOff("To see available networks, turn on Wi - Fi.");
+            State.OnTurnedOff += () => turnOff("To see available networks, turn on Wi - Fi.");
+            State.OnTurnedOn += () => turnOn();
+            State.OnTurningOnFailed += () => turnOff("Connection failed.");
+            return view;
+        }
+
+        public void Dispose()
+        {
+            view = null;
+        }
+    }
+}
diff --git a/Oobe/OobeWifi/Controls/WifiView.cs b/Oobe/OobeWifi/Controls/WifiView.cs
deleted file mode 100644 (file)
index 09ebdd7..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-using Oobe.Common.Styles;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Threading.Tasks;
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
-using Tizen.NUI.Components;
-
-namespace Oobe.Wifi.Controls
-{
-    public class WifiView : IDisposable
-    {
-        private View view = null;
-        private ObservableCollection<View> items;
-        private int counter = 0;
-
-        private static IEnumerable<View> CreateViews(string pattern)
-        {
-            yield return CreateManualWifiView(460, 89);
-            foreach (var item in Enumerable.Range(1, 10))
-            {
-                yield return CreateWifiView(460, 89, $"Wi-Fi_{item}");
-            }
-        }
-
-        public View View
-        {
-            get
-            {
-                if (view == null)
-                {
-                    view = new View()
-                    {
-                        Layout = new LinearLayout()
-                        {
-                            LinearOrientation = LinearLayout.Orientation.Vertical,
-                        },
-                        BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "Rectangle_918.png"),
-                        //Size = new Size(480, 401),
-                    };
-                    view.Add(CreateHeader(480, 80));
-
-                    view.Add(new View() // separator doesn't display
-                    {
-                        Size2D = new Size(400, 1),
-                        BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "Line_94.png"),
-                        Margin = new Extents(40, 0, 0, 0),
-                    });
-
-                    items = new ObservableCollection<View>(CreateViews($"{counter} "));
-                    view.Add(new ListView(480, 328)//480, 335
-                    {
-                        Items = items
-                    }.View);
-
-                    ForVerify();
-                }
-                return view;
-            }
-        }
-
-        private async void ForVerify()
-        {
-            counter++;
-            if (counter > 4)
-                return;
-            if (view != null)
-            {
-                await Task.Delay(2000);
-                items.RemoveAt(1);
-                //items.Insert(1, CreateViewAbsolute($"s{counter}"));
-                ForVerify();
-            }
-        }
-
-        private static View CreateManualWifiView(int width, int height)
-        {
-            var manualWifi = new View()
-            {
-                Size = new Size(width, height),
-                Layout = new AbsoluteLayout(),
-            };
-
-            manualWifi.Add(new View()
-            {
-                Position = new Position(29, 20),
-                BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_addnetwork.png"),
-            });
-
-            manualWifi.Add(new TextLabel("Add new...")
-            {
-                Position = new Position(87, 29),
-                PixelSize = 20f,
-                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
-                FontFamily = "BreezeSans",
-                FontStyle = FontsStyles.Regular(),
-            });
-            return manualWifi;
-        }
-
-        private static View CreateWifiView(int width, int height, string name)
-        {
-            var wifi = new View()
-            {
-                Size = new Size(width, height),
-                Layout = new AbsoluteLayout(),
-            };
-
-            wifi.Add(new View()
-            {
-                //Size = new Size(21, 15),
-                Position = new Position(39, 32),
-                BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_wifi.svg"),
-            });
-
-            wifi.Add(new TextLabel(name)
-            {
-                Position = new Position(78, 28),
-                PixelSize = 20f,
-                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
-                FontFamily = "BreezeSans",
-                FontStyle = FontsStyles.Light(),
-            });
-
-            wifi.Add(new TextLabel("detail")
-            {
-                Position = new Position(79, 56),
-                PixelSize = 14f,
-                TextColor = new Color(0, 0x0C / 255f, 0x2B / 255f, 1.0f),
-                FontFamily = "BreezeSans",
-                FontStyle = FontsStyles.Regular(),
-            });
-            return wifi;
-        }
-
-        private static View CreateHeader(int width, int height)
-        {
-            var header = new View()
-            {
-                Size = new Size(width, height),
-                Layout = new AbsoluteLayout(),
-            };
-
-            header.Add(new TextLabel("Wi-Fi")
-            {
-                Size = new Size(49, 24),
-                Position = new Position(40, 43),
-                PixelSize = 19f,
-                TextColor = new Color(0, 14.0f / 255.0f, 47.0f / 255.0f, 1.0f),
-                FontFamily = "BreezeSans",
-                FontStyle = FontsStyles.Regular(),
-            });
-
-            header.Add(new Button()
-            {
-                Text = "Scan",
-                Size = new Size(72, 32),
-                Position = new Position(276, 39),
-            });
-
-            header.Add(new Button()
-            {
-                Text = "Off",
-                Size = new Size(72, 32),
-                Position = new Position(369, 39),
-            });
-            return header;
-        }
-
-        public void Dispose()
-        {
-            view = null;
-        }
-    }
-}
index 03f97736091a177a250f75001ce0c467d3dd9135..07fb085016fa29c062e3c13063b58d1629206366 100644 (file)
@@ -1,9 +1,9 @@
 using Oobe.Common.Interfaces;
 using Oobe.Common.Styles;
-using Oobe.Wifi.Controls;
 using Tizen.NUI.Components;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
+using Oobe.Wifi.Controls.Wifi;
 
 namespace Oobe.Wifi
 {
diff --git a/Oobe/OobeWifi/res/12_icon_scan.png b/Oobe/OobeWifi/res/12_icon_scan.png
new file mode 100644 (file)
index 0000000..3c87e08
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_scan.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_scan.svg b/Oobe/OobeWifi/res/12_icon_scan.svg
new file mode 100644 (file)
index 0000000..74eb1a3
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="72" height="32" viewBox="0 0 72 32"><defs><style>.a,.d{fill:none;}.a{stroke:#205247;}.b{fill:#205247;font-size:18px;font-family:BreezeSans;}.c{stroke:none;}</style></defs><g class="a"><rect class="c" width="72" height="32" rx="16"/><rect class="d" x="0.5" y="0.5" width="71" height="31" rx="15.5"/></g><text class="b" transform="translate(17 22)"><tspan x="0" y="0">Scan</tspan></text></svg>
\ No newline at end of file
diff --git a/Oobe/OobeWifi/res/12_icon_wifioff.png b/Oobe/OobeWifi/res/12_icon_wifioff.png
new file mode 100644 (file)
index 0000000..5120fd2
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_wifioff.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_wifioff.svg b/Oobe/OobeWifi/res/12_icon_wifioff.svg
new file mode 100644 (file)
index 0000000..413a46d
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="72" height="32" viewBox="0 0 72 32"><defs><style>.a{fill:#dfeae4;}.b,.c{fill:#205247;}.b{font-size:18px;font-family:BreezeSans;}</style></defs><rect class="a" width="72" height="32" rx="16"/><text class="b" transform="translate(29 22)"><tspan x="0" y="0">OFF</tspan></text><circle class="c" cx="6" cy="6" r="6" transform="translate(11 10)"/></svg>
\ No newline at end of file
diff --git a/Oobe/OobeWifi/res/12_icon_wifion.png b/Oobe/OobeWifi/res/12_icon_wifion.png
new file mode 100644 (file)
index 0000000..d4603d6
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_wifion.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_wifion.svg b/Oobe/OobeWifi/res/12_icon_wifion.svg
new file mode 100644 (file)
index 0000000..9bd94f6
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="72" height="32" viewBox="0 0 72 32"><defs><style>.a{fill:#205247;}.b,.c{fill:#fff;}.b{font-size:18px;font-family:BreezeSans;}</style></defs><rect class="a" width="72" height="32" rx="16"/><text class="b" transform="translate(14 22)"><tspan x="0" y="0">ON</tspan></text><circle class="c" cx="6" cy="6" r="6" transform="translate(47 9)"/></svg>
\ No newline at end of file