3 using System.Collections.Generic;
5 using Tizen.NUI.Components;
6 using Tizen.NUI.BaseComponents;
7 using Tizen.NUI.Binding;
8 using System.Reflection;
10 namespace NUITizenGallery
12 public class SearchField : View
14 public TextField SearchTextField;
15 public Button SearchButton;
16 public SearchField() : base()
18 Layout = new LinearLayout()
20 LinearOrientation = LinearLayout.Orientation.Horizontal,
21 LinearAlignment = LinearLayout.Alignment.CenterVertical,
22 CellPadding = new Size2D(40, 0),
25 BackgroundColor = Color.White;
27 WidthSpecification = LayoutParamPolicies.MatchParent;
28 HeightSpecification = LayoutParamPolicies.WrapContent;
29 Padding = new Extents(64, 64, 0, 0);
31 var searchTextBox = CreateSearchText();
32 SearchTextField = CreateTextField();
33 var underline = CreateUnderline();
35 searchTextBox.Add(SearchTextField);
36 searchTextBox.Add(underline);
38 SearchButton = CreateSearchButton();
44 private View CreateSearchText()
48 Layout = new LinearLayout()
50 LinearOrientation = LinearLayout.Orientation.Vertical,
51 CellPadding = new Size2D(0, 20),
53 WidthSpecification = LayoutParamPolicies.MatchParent,
54 HeightSpecification = LayoutParamPolicies.WrapContent,
58 private TextField CreateTextField()
60 return new TextField()
62 PlaceholderText = "Search",
63 WidthSpecification = LayoutParamPolicies.MatchParent,
64 HeightSpecification = LayoutParamPolicies.WrapContent,
65 MinimumSize = new Size2D(0, 40),
69 private View CreateUnderline()
73 BackgroundColor = new Color("#0A0E4AFF"),
74 WidthSpecification = LayoutParamPolicies.MatchParent,
75 HeightSpecification = 2,
79 private Button CreateSearchButton()
84 WidthSpecification = 120,
85 HeightSpecification = LayoutParamPolicies.WrapContent,
92 public Gallery(string name, string fullName = null)
98 public string Name { get; set; }
100 public string ViewLabel
108 public bool Selected { get; set; }
110 internal string FullName { get; set; }
113 public class GalleryViewModel
115 public List<Tuple<string, string>> NamePool = new List<Tuple<string, string>>();
117 public GalleryViewModel()
122 public List<Gallery> CreateData()
126 List<Gallery> result = new List<Gallery>();
127 foreach (var name in NamePool)
129 result.Add(new Gallery(name.Item1, name.Item2));
134 private void GetXamlPages()
136 Assembly assembly = this.GetType().Assembly;
137 Type exampleType = assembly.GetType("NUITizenGallery.IExample");
139 foreach (Type type in assembly.GetTypes())
141 Console.WriteLine($"@@@ type.Name={type.Name}, type.FullName={type.FullName}");
142 if (exampleType.IsAssignableFrom(type) && type.Name != "SampleMain" && this.GetType() != type && type.IsClass)
144 NamePool.Add(new Tuple<string, string>(type.Name, type.FullName));
150 class Program : NUIApplication
152 private Window window;
153 private Navigator navigator;
154 private CollectionView colView;
155 private ItemSelectionMode selMode;
156 private IExample currentExample = null;
157 private ContentPage page;
158 private SearchField field;
159 private List<Gallery> testSource;
161 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
163 if (e.Key.State == Key.StateType.Up)
165 if (e.Key.KeyPressedName == "Escape" || e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "BackSpace")
167 if (null != currentExample)
179 public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
181 Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}");
183 foreach (object item in ev.CurrentSelection)
190 var selItem = item as Gallery;
191 Console.WriteLine($"@@@ selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
192 RunSample(selItem?.FullName);
193 colView.SelectedItem = null;
196 /* Use the following code when it is actually required.
197 foreach (object item in ev.PreviousSelection)
204 var unselItem = item as Gallery;
207 foreach (object item in ev.CurrentSelection)
214 var selItem = item as Gallery;
219 protected override void OnCreate()
225 private void Initialize()
227 window = GetDefaultWindow();
228 window.Title = "NUITizenGallery";
229 window.KeyEvent += OnKeyEvent;
231 navigator = window.GetDefaultNavigator();
234 void OnSearchBtnClicked(object sender, ClickedEventArgs e)
236 var filteredSource = from filter in testSource
237 where filter.Name.ToLower().Contains(field.SearchTextField?.Text?.ToLower())
240 colView.Header = new DefaultTitleItem()
243 WidthSpecification = LayoutParamPolicies.MatchParent,
245 colView.ItemsSource = filteredSource;
248 private void SetMainPage()
250 var appBar = new AppBar()
252 Title = "NUI Tizen Gallery",
253 AutoNavigationContent = false,
256 var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar");
257 var moreButton = new Button(((AppBarStyle)appBarStyle).BackButton);
258 moreButton.Icon.ResourceUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "menu.png";
259 appBar.NavigationContent = moreButton;
262 var pageContent = new View()
264 Layout = new LinearLayout()
266 LinearOrientation = LinearLayout.Orientation.Vertical,
268 WidthSpecification = LayoutParamPolicies.MatchParent,
269 HeightSpecification = LayoutParamPolicies.MatchParent,
272 field = new SearchField()
274 WidthSpecification = LayoutParamPolicies.MatchParent,
276 field.SearchButton.Clicked += OnSearchBtnClicked;
278 testSource = new GalleryViewModel().CreateData();
279 selMode = ItemSelectionMode.SingleAlways;
280 var myTitle = new DefaultTitleItem()
283 WidthSpecification = LayoutParamPolicies.MatchParent,
286 colView = new CollectionView()
288 ItemsSource = testSource,
289 ItemsLayouter = new LinearLayouter(),
290 ItemTemplate = new DataTemplate(() =>
292 DefaultLinearItem item = new DefaultLinearItem()
294 WidthSpecification = LayoutParamPolicies.MatchParent,
296 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
297 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
301 ScrollingDirection = ScrollableBase.Direction.Vertical,
302 WidthSpecification = LayoutParamPolicies.MatchParent,
303 HeightSpecification = LayoutParamPolicies.MatchParent,
304 SelectionMode = selMode,
306 colView.SelectionChanged += OnSelectionChanged;
308 pageContent.Add(field);
309 pageContent.Add(colView);
311 page = new ContentPage()
314 Content = pageContent,
316 navigator.Push(page);
319 private void RunSample(string name)
321 IExample example = typeof(Program).Assembly?.CreateInstance(name) as IExample;
323 Console.WriteLine($"@@@ typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
331 Console.WriteLine($"@@@ examle is null!");
333 currentExample = example;
336 private void ExitSample()
338 currentExample?.Deactivate();
339 currentExample = null;
344 private void FullGC()
346 global::System.GC.Collect();
347 global::System.GC.WaitForPendingFinalizers();
348 global::System.GC.Collect();
351 static void Main(string[] args)
353 var app = new Program();