Add a main page 49/282249/1
authorchaehee-hong <chaehee.hong@samsung.com>
Thu, 29 Sep 2022 06:21:37 +0000 (15:21 +0900)
committerchaehee-hong <chaehee.hong@samsung.com>
Thu, 29 Sep 2022 06:22:19 +0000 (15:22 +0900)
Change-Id: Id7422f7e3bd6d7d12a5957f0d2c86f3293afb576

SettingWiFi/SettingWiFi/Device.cs [new file with mode: 0755]
SettingWiFi/SettingWiFi/WidgetSettingWiFi.cs

diff --git a/SettingWiFi/SettingWiFi/Device.cs b/SettingWiFi/SettingWiFi/Device.cs
new file mode 100755 (executable)
index 0000000..7862484
--- /dev/null
@@ -0,0 +1,150 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Collections.ObjectModel;\r
+using System.ComponentModel;\r
+using Tizen.NUI.BaseComponents;\r
+using Tizen.NUI.Binding;\r
+using Tizen.NUI.Components;\r
+\r
+namespace SettingWiFi\r
+{\r
+    public class Device : INotifyPropertyChanged\r
+    {\r
+        string iconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png";\r
+        private string name;\r
+        private bool connected;\r
+        private bool registered;\r
+        public event PropertyChangedEventHandler PropertyChanged;\r
+\r
+        private void OnPropertyChanged(string propertyName)\r
+        {\r
+\r
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\r
+        }\r
+\r
+        public Device(string deviceName, bool con, bool reg)\r
+        {\r
+            name = deviceName;\r
+            connected = con;\r
+            registered = reg;\r
+        }\r
+\r
+        public string Name\r
+        {\r
+            get\r
+            {\r
+                return name;\r
+            }\r
+            set\r
+            {\r
+                name = value;\r
+                OnPropertyChanged("Name");\r
+            }\r
+        }\r
+\r
+        public string ImageUrl\r
+        {\r
+            get\r
+            {\r
+                return iconDir;\r
+            }\r
+        }\r
+\r
+        public bool Connected\r
+        {\r
+            get\r
+            {\r
+                return connected;\r
+            }\r
+            set\r
+            {\r
+                connected = value;\r
+                OnPropertyChanged("Connected");\r
+            }\r
+        }\r
+        public bool Registered\r
+        {\r
+            get\r
+            {\r
+                return registered;\r
+            }\r
+            set\r
+            {\r
+                registered = value;\r
+                OnPropertyChanged("Registered");\r
+            }\r
+        }\r
+    };\r
+\r
+    public class DeviceCollection : ObservableCollection<Device>\r
+    {\r
+        string[] devicePool = {\r
+           "Galaxy Buds2 Pro",\r
+           "Galaxy Fold 4",\r
+           "Galaxy Tab S8+",\r
+           "Galaxy Buds2",\r
+           "Galaxy Watch 5",\r
+           "[TV] Samsung 65",\r
+           "Galaxy Fit2",\r
+           "Sony WH-100XM5",\r
+           "Logitech MX Vertical",\r
+           "Ioniq 5",\r
+           "Galaxy Home Mini",\r
+           "Samsung Family Hub",\r
+           "Galaxy Book Pro2",\r
+        };\r
+\r
+        private string title;\r
+\r
+        public DeviceCollection(string groupTitle)\r
+        {\r
+            title = groupTitle;\r
+            UpdateDevices();\r
+        }\r
+\r
+        public string Title\r
+        {\r
+            get\r
+            {\r
+                return title;\r
+            }\r
+            set\r
+            {\r
+                title = value;\r
+                OnPropertyChanged(new PropertyChangedEventArgs("Title"));\r
+            }\r
+        }\r
+\r
+        public void UpdateDevices()\r
+        {\r
+            // Clear method have some issue about asynchronous actions,\r
+            // so call Remove for all item is recommanded.\r
+            while (this.Count > 0)\r
+            {\r
+                this.RemoveAt(this.Count - 1);\r
+            }\r
+            Random rand = new Random();\r
+            int count = rand.Next(13);\r
+\r
+            for (int i = 0; i < count; i++)\r
+            {\r
+                this.Add(new Device(devicePool[rand.Next(13)], false, false));\r
+            }\r
+        }\r
+    }\r
+\r
+    public class DeviceSource : ObservableCollection<DeviceCollection>\r
+    {\r
+        private DeviceCollection available;\r
+        public DeviceSource()\r
+        {\r
+            available = new DeviceCollection("Available networks");\r
+            this.Add(available);\r
+        }\r
+\r
+        public void UpdateDevices()\r
+        {\r
+            available.UpdateDevices();\r
+        }\r
+    }\r
+}
\ No newline at end of file
index e06975b44fd83a6609cd3f4c951f79db3e149324..2e3a29494e2c32cb29a983cc7fbd0d46cb974ba9 100755 (executable)
 using System;
-using System.Collections.Generic;
-using System.Linq;
+using Tizen;
 using Tizen.Applications;
 using Tizen.NUI;
+using Tizen.NUI.Accessibility;
 using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
 using Tizen.NUI.Components;
 using Tizen.Network.WiFi;
-using Tizen;
+
 
 namespace SettingWiFi
 {
     internal class WidgetSettingWiFi : Widget
     {
         internal static readonly string LogTag = "SettingWiFi";
-        protected View mRootView;
-
-        public WidgetSettingWiFi() : base()
-        {
+        Navigator navigator;
+        ContentPage page;
+        View rootView;
+        CollectionView deviceView;
+        DeviceSource deviceSource;\r
+\r
+        private RecyclerViewItem GetHeader()\r
+        {\r
+            var header = new RecyclerViewItem()\r
+            {\r
+                Layout = new LinearLayout()\r
+                {\r
+                    LinearOrientation = LinearLayout.Orientation.Vertical,\r
+                },\r
+                WidthSpecification = LayoutParamPolicies.MatchParent,\r
+                HeightSpecification = LayoutParamPolicies.WrapContent,\r
+            };\r
+\r
+            var wifiOnOff = new DefaultLinearItem()\r
+            {\r
+                WidthSpecification = LayoutParamPolicies.MatchParent,\r
+                Text = "Wi-Fi",\r
+            };\r
+            wifiOnOff.Label.HorizontalAlignment = HorizontalAlignment.Begin;\r
+            var wifiOnOffSwith = new Switch();\r
+            wifiOnOffSwith.SelectedChanged += (object obj, SelectedChangedEventArgs ev) =>\r
+            {\r
+                Tizen.Log.Debug("NUI", "Wi-Fi On&Off Switch changed");\r
+                if (obj != null && obj is Switch switchButton)\r
+                {\r
+                    var parent = switchButton.GetParent();\r
+                    if (parent is DefaultLinearItem item)\r
+                    {\r
+                        item.IsSelected = switchButton.IsSelected;\r
+                    }\r
+                }\r
+            };\r
+            wifiOnOff.Extra = wifiOnOffSwith;\r
+            /*\r
+            var myDeviceName = new DefaultLinearItem()\r
+            {\r
+                WidthSpecification = LayoutParamPolicies.MatchParent,\r
+                Text = "Tizen",\r
+            };\r
+            myDeviceName.Label.HorizontalAlignment = HorizontalAlignment.Begin;\r
+            */\r
+            header.Add(wifiOnOff);\r
+            //header.Add(myDeviceName);\r
+\r
+            return header;\r
         }
 
-        DefaultLinearItem CreateItem(string text, string subText = null, bool icon = false, bool extra = false)
-        {
-            var item = new DefaultLinearItem()
-            {
-                WidthSpecification = LayoutParamPolicies.MatchParent,
-                Text = text,
-            };
-
-
-            if (subText != null) item.SubText = subText;
-            if (icon) item.Icon = new CheckBox();
-            //if (extra) item.Extra = new RadioButton();
-            var onoffSwitch = new Switch();
-            if (extra) item.Extra = onoffSwitch;
-            onoffSwitch.SelectedChanged += (object obj, SelectedChangedEventArgs ev) =>
-            {
-                Log.Info(LogTag, "onoffSwitch clicked. isSelected: " + ev.IsSelected);
-            };
-
-            item.IsSelectable = true;
-            return item;
-        }
-
-
-        void CreateItems(View parent, string text, string subText = null, bool icon = false, bool extra = false)
-        {
-            var newItem = CreateItem(text, subText, icon, extra);
-            newItem.Clicked += (object obj, ClickedEventArgs ev) =>
-            {
-                Log.Info(LogTag, "newItem clicked");
-            };
-            parent.Add(newItem);
-        }
-
-
         protected override void OnCreate(string contentInfo, Window window)
         {
             Bundle bundle = Bundle.Decode(contentInfo);
+            navigator = window.GetDefaultNavigator();
 
-            mRootView = new View();
-            mRootView.BackgroundColor = Color.White;
-            mRootView.Size2D = window.Size;
-            mRootView.PivotPoint = PivotPoint.Center;
-            window.GetDefaultLayer().Add(mRootView);
+            var appBar = new AppBar()\r
+            {\r
+                Title = "Wi-Fi",\r
+            };
 
-            // Example root content view.
-            // you can decorate, add children on this view.
-            View rootContent = new ScrollableBase()
-            {
-                WidthSpecification = LayoutParamPolicies.MatchParent,
-                HeightSpecification = LayoutParamPolicies.MatchParent,
-                ScrollingDirection = ScrollableBase.Direction.Vertical,
-                HideScrollbar = false,
-                Layout = new LinearLayout()
-                {
-                    LinearOrientation = LinearLayout.Orientation.Vertical,
-                    HorizontalAlignment = HorizontalAlignment.Center,
-                    VerticalAlignment = VerticalAlignment.Center,
-                    CellPadding = new Size2D(10, 20),
-                },
+            rootView = new View()\r
+            {\r
+                Layout = new LinearLayout()\r
+                {\r
+                    LinearOrientation = LinearLayout.Orientation.Vertical,\r
+                    HorizontalAlignment = HorizontalAlignment.Center,\r
+                },\r
+                WidthSpecification = LayoutParamPolicies.MatchParent,\r
+                HeightSpecification = LayoutParamPolicies.MatchParent,\r
             };
 
-            CreateItems(rootContent, "Wifi", null, false, true);
+            deviceSource = new DeviceSource();\r
+\r
+            deviceView = new CollectionView()\r
+            {\r
+                ItemsSource = deviceSource,\r
+                ItemsLayouter = new LinearLayouter(),\r
+                ItemTemplate = new DataTemplate(() =>\r
+                {\r
+                    DefaultLinearItem item = new DefaultLinearItem();\r
+                    //Set Width Specification as MatchParent to fit the Item width with parent View.\r
+                    item.WidthSpecification = LayoutParamPolicies.MatchParent;\r
+                    //Decorate Label\r
+                    item.Label.SetBinding(TextLabel.TextProperty, "Name");\r
+                    item.Label.HorizontalAlignment = HorizontalAlignment.Begin;\r
+                    //Decorate Icon\r
+                    item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");\r
+                    item.Icon.WidthSpecification = 40;\r
+                    item.Icon.HeightSpecification = 40;\r
+\r
+                    return item;\r
+                }),\r
+                GroupHeaderTemplate = new DataTemplate(() =>\r
+                {\r
+                    DefaultTitleItem group = new DefaultTitleItem();\r
+                    //Set Width Specification as MatchParent to fit the Item width with parent View.\r
+                    group.WidthSpecification = LayoutParamPolicies.MatchParent;\r
+\r
+                    group.Label.SetBinding(TextLabel.TextProperty, "Title");\r
+                    group.Label.HorizontalAlignment = HorizontalAlignment.Begin;\r
+\r
+                    return group;\r
+                }),\r
+                Header = GetHeader(),\r
+                IsGrouped = true,\r
+                ScrollingDirection = ScrollableBase.Direction.Vertical,\r
+                WidthSpecification = LayoutParamPolicies.MatchParent,\r
+                HeightSpecification = LayoutParamPolicies.MatchParent,\r
+                SelectionMode = ItemSelectionMode.Single,\r
+            };\r
+            deviceView.SelectionChanged += DeviceConnectedEvent;
+
+            deviceSource.UpdateDevices();
+            rootView.Add(deviceView);
 
-            window.GetDefaultLayer().Add(rootContent);
+            page = new ContentPage()\r
+            {\r
+                AppBar = appBar,\r
+                Content = rootView,\r
+            };\r
+\r
+            navigator.Push(page);
+        }\r
+        public void DeviceConnectedEvent(object sender, SelectionChangedEventArgs ev)\r
+        {\r
+            Tizen.Log.Debug("NUI", "DeviceConnectedEvent called");\r
+\r
+            //SingleSelection Only have 1 or nil object in the list.\r
+            foreach (object item in ev.PreviousSelection)\r
+            {\r
+                if (item == null) break;\r
+                if (item is Device device)\r
+                {\r
+                    device.Connected = false;\r
+                }\r
+            }\r
+            foreach (object item in ev.CurrentSelection)\r
+            {\r
+                if (item == null) break;\r
+                if (item is Device device)\r
+                {\r
+                    device.Connected = true;\r
+                    device.Registered = true;\r
+                }\r
+            }\r
         }
     }
 }