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 [moved from Oobe/OobeWifi/Controls/WifiView.cs with 65% similarity]
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 4c77f7c..1f0f19d 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);
+        }
+    }
+}
similarity index 65%
rename from Oobe/OobeWifi/Controls/WifiView.cs
rename to Oobe/OobeWifi/Controls/Wifi/WifiView.cs
index 09ebdd7..5cc176b 100644 (file)
@@ -8,7 +8,7 @@ using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
 
-namespace Oobe.Wifi.Controls
+namespace Oobe.Wifi.Controls.Wifi
 {
     public class WifiView : IDisposable
     {
@@ -16,6 +16,8 @@ namespace Oobe.Wifi.Controls
         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);
@@ -42,18 +44,14 @@ namespace Oobe.Wifi.Controls
                     };
                     view.Add(CreateHeader(480, 80));
 
-                    view.Add(new View() // separator doesn't display
+                    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),
                     });
 
-                    items = new ObservableCollection<View>(CreateViews($"{counter} "));
-                    view.Add(new ListView(480, 328)//480, 335
-                    {
-                        Items = items
-                    }.View);
+                    view.Add(CreateListViewPlaceHolder());
 
                     ForVerify();
                 }
@@ -83,10 +81,10 @@ namespace Oobe.Wifi.Controls
                 Layout = new AbsoluteLayout(),
             };
 
-            manualWifi.Add(new View()
+            manualWifi.Add(new Button(ButtonStyles.AddNetwork)
             {
                 Position = new Position(29, 20),
-                BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_addnetwork.png"),
+                Size = new Size(42, 42),
             });
 
             manualWifi.Add(new TextLabel("Add new...")
@@ -135,7 +133,7 @@ namespace Oobe.Wifi.Controls
             return wifi;
         }
 
-        private static View CreateHeader(int width, int height)
+        private View CreateHeader(int width, int height)
         {
             var header = new View()
             {
@@ -153,20 +151,75 @@ namespace Oobe.Wifi.Controls
                 FontStyle = FontsStyles.Regular(),
             });
 
-            header.Add(new Button()
+            header.Add(new Button(ButtonStyles.Scan)
             {
-                Text = "Scan",
                 Size = new Size(72, 32),
                 Position = new Position(276, 39),
             });
 
-            header.Add(new Button()
+            header.Add(CreateTurnOnButton());
+            return header;
+        }
+
+        private Button CreateTurnOnButton()
+        {
+            var button = new Button(new ButtonStyle())
             {
-                Text = "Off",
                 Size = new Size(72, 32),
                 Position = new Position(369, 39),
-            });
-            return header;
+            };
+            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()
index 03f9773..07fb085 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