From: chaehee-hong Date: Thu, 29 Sep 2022 06:21:37 +0000 (+0900) Subject: Add a main page X-Git-Tag: accepted/tizen/unified/20221216.024031~39 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=039382fa8bc59cff81ac258b4e8ed490761b876f;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-wifi.git Add a main page Change-Id: Id7422f7e3bd6d7d12a5957f0d2c86f3293afb576 --- diff --git a/SettingWiFi/SettingWiFi/Device.cs b/SettingWiFi/SettingWiFi/Device.cs new file mode 100755 index 0000000..7862484 --- /dev/null +++ b/SettingWiFi/SettingWiFi/Device.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Binding; +using Tizen.NUI.Components; + +namespace SettingWiFi +{ + public class Device : INotifyPropertyChanged + { + string iconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png"; + private string name; + private bool connected; + private bool registered; + public event PropertyChangedEventHandler PropertyChanged; + + private void OnPropertyChanged(string propertyName) + { + + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public Device(string deviceName, bool con, bool reg) + { + name = deviceName; + connected = con; + registered = reg; + } + + public string Name + { + get + { + return name; + } + set + { + name = value; + OnPropertyChanged("Name"); + } + } + + public string ImageUrl + { + get + { + return iconDir; + } + } + + public bool Connected + { + get + { + return connected; + } + set + { + connected = value; + OnPropertyChanged("Connected"); + } + } + public bool Registered + { + get + { + return registered; + } + set + { + registered = value; + OnPropertyChanged("Registered"); + } + } + }; + + public class DeviceCollection : ObservableCollection + { + string[] devicePool = { + "Galaxy Buds2 Pro", + "Galaxy Fold 4", + "Galaxy Tab S8+", + "Galaxy Buds2", + "Galaxy Watch 5", + "[TV] Samsung 65", + "Galaxy Fit2", + "Sony WH-100XM5", + "Logitech MX Vertical", + "Ioniq 5", + "Galaxy Home Mini", + "Samsung Family Hub", + "Galaxy Book Pro2", + }; + + private string title; + + public DeviceCollection(string groupTitle) + { + title = groupTitle; + UpdateDevices(); + } + + public string Title + { + get + { + return title; + } + set + { + title = value; + OnPropertyChanged(new PropertyChangedEventArgs("Title")); + } + } + + public void UpdateDevices() + { + // Clear method have some issue about asynchronous actions, + // so call Remove for all item is recommanded. + while (this.Count > 0) + { + this.RemoveAt(this.Count - 1); + } + Random rand = new Random(); + int count = rand.Next(13); + + for (int i = 0; i < count; i++) + { + this.Add(new Device(devicePool[rand.Next(13)], false, false)); + } + } + } + + public class DeviceSource : ObservableCollection + { + private DeviceCollection available; + public DeviceSource() + { + available = new DeviceCollection("Available networks"); + this.Add(available); + } + + public void UpdateDevices() + { + available.UpdateDevices(); + } + } +} \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/WidgetSettingWiFi.cs b/SettingWiFi/SettingWiFi/WidgetSettingWiFi.cs index e06975b..2e3a294 100755 --- a/SettingWiFi/SettingWiFi/WidgetSettingWiFi.cs +++ b/SettingWiFi/SettingWiFi/WidgetSettingWiFi.cs @@ -1,89 +1,166 @@ 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; + + private RecyclerViewItem GetHeader() + { + var header = new RecyclerViewItem() + { + Layout = new LinearLayout() + { + LinearOrientation = LinearLayout.Orientation.Vertical, + }, + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = LayoutParamPolicies.WrapContent, + }; + + var wifiOnOff = new DefaultLinearItem() + { + WidthSpecification = LayoutParamPolicies.MatchParent, + Text = "Wi-Fi", + }; + wifiOnOff.Label.HorizontalAlignment = HorizontalAlignment.Begin; + var wifiOnOffSwith = new Switch(); + wifiOnOffSwith.SelectedChanged += (object obj, SelectedChangedEventArgs ev) => + { + Tizen.Log.Debug("NUI", "Wi-Fi On&Off Switch changed"); + if (obj != null && obj is Switch switchButton) + { + var parent = switchButton.GetParent(); + if (parent is DefaultLinearItem item) + { + item.IsSelected = switchButton.IsSelected; + } + } + }; + wifiOnOff.Extra = wifiOnOffSwith; + /* + var myDeviceName = new DefaultLinearItem() + { + WidthSpecification = LayoutParamPolicies.MatchParent, + Text = "Tizen", + }; + myDeviceName.Label.HorizontalAlignment = HorizontalAlignment.Begin; + */ + header.Add(wifiOnOff); + //header.Add(myDeviceName); + + return header; } - 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() + { + Title = "Wi-Fi", + }; - // 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() + { + Layout = new LinearLayout() + { + LinearOrientation = LinearLayout.Orientation.Vertical, + HorizontalAlignment = HorizontalAlignment.Center, + }, + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = LayoutParamPolicies.MatchParent, }; - CreateItems(rootContent, "Wifi", null, false, true); + deviceSource = new DeviceSource(); + + deviceView = new CollectionView() + { + ItemsSource = deviceSource, + ItemsLayouter = new LinearLayouter(), + ItemTemplate = new DataTemplate(() => + { + DefaultLinearItem item = new DefaultLinearItem(); + //Set Width Specification as MatchParent to fit the Item width with parent View. + item.WidthSpecification = LayoutParamPolicies.MatchParent; + //Decorate Label + item.Label.SetBinding(TextLabel.TextProperty, "Name"); + item.Label.HorizontalAlignment = HorizontalAlignment.Begin; + //Decorate Icon + item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl"); + item.Icon.WidthSpecification = 40; + item.Icon.HeightSpecification = 40; + + return item; + }), + GroupHeaderTemplate = new DataTemplate(() => + { + DefaultTitleItem group = new DefaultTitleItem(); + //Set Width Specification as MatchParent to fit the Item width with parent View. + group.WidthSpecification = LayoutParamPolicies.MatchParent; + + group.Label.SetBinding(TextLabel.TextProperty, "Title"); + group.Label.HorizontalAlignment = HorizontalAlignment.Begin; + + return group; + }), + Header = GetHeader(), + IsGrouped = true, + ScrollingDirection = ScrollableBase.Direction.Vertical, + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = LayoutParamPolicies.MatchParent, + SelectionMode = ItemSelectionMode.Single, + }; + deviceView.SelectionChanged += DeviceConnectedEvent; + + deviceSource.UpdateDevices(); + rootView.Add(deviceView); - window.GetDefaultLayer().Add(rootContent); + page = new ContentPage() + { + AppBar = appBar, + Content = rootView, + }; + + navigator.Push(page); + } + public void DeviceConnectedEvent(object sender, SelectionChangedEventArgs ev) + { + Tizen.Log.Debug("NUI", "DeviceConnectedEvent called"); + + //SingleSelection Only have 1 or nil object in the list. + foreach (object item in ev.PreviousSelection) + { + if (item == null) break; + if (item is Device device) + { + device.Connected = false; + } + } + foreach (object item in ev.CurrentSelection) + { + if (item == null) break; + if (item is Device device) + { + device.Connected = true; + device.Registered = true; + } + } } } }