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 public class CustomNavigator : Navigator
152 // Customizes how to handle back navigation.
153 // base.OnBackNavigation() pops the peek page.
154 protected override void OnBackNavigation(BackNavigationEventArgs args)
158 // Deactivates the peek page example before page pop.
159 if (Peek() is IExample currentExample)
161 currentExample.Deactivate();
165 // Pops the peek page if navigator has more than one page.
166 // If navigator has only one page, then the program is exited.
167 base.OnBackNavigation(args);
171 class Program : NUIApplication
173 private Window window;
174 private AppBar appBar;
175 private View pageContent;
176 private Navigator navigator;
177 private CollectionView colView;
178 private ItemSelectionMode selMode;
179 private IExample currentExample = null;
180 private ContentPage page;
181 private SearchField field;
182 private List<Gallery> testSource;
184 public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
186 Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}");
188 foreach (object item in ev.CurrentSelection)
195 var selItem = item as Gallery;
196 Console.WriteLine($"@@@ selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
197 RunSample(selItem?.FullName);
198 colView.SelectedItem = null;
201 /* Use the following code when it is actually required.
202 foreach (object item in ev.PreviousSelection)
209 var unselItem = item as Gallery;
212 foreach (object item in ev.CurrentSelection)
219 var selItem = item as Gallery;
224 protected override void OnCreate()
229 pageContent.SizeHeight = Window.Instance.WindowSize.Height - appBar.SizeHeight;
231 private void Initialize()
233 window = GetDefaultWindow();
234 window.Title = "NUITizenGallery";
236 // In this example, GetDefaultNavigator() has not been called before so default navigator has not been set yet.
237 // Therefore, the following codes for unsetting and disposing the previous default navigator are not required in this example.
239 var prevDefaultNavigator = window.GetDefaultNavigator();
240 window.Remove(prevDefaultNavigator);
241 prevDefaultNavigator.Dispose();
242 prevDefaultNavigator = null;
245 // Uses customized navigator to customize how to handle back navigation.
246 navigator = new CustomNavigator()
248 WidthSpecification = LayoutParamPolicies.MatchParent,
249 HeightSpecification = LayoutParamPolicies.MatchParent,
252 // Sets the customized navigator as the default navigator of the window.
253 window.SetDefaultNavigator(navigator);
256 void OnSearchBtnClicked(object sender, ClickedEventArgs e)
258 var filteredSource = from filter in testSource
259 where filter.Name.ToLower().Contains(field.SearchTextField?.Text?.ToLower())
262 colView.Header = new DefaultTitleItem()
265 WidthSpecification = LayoutParamPolicies.MatchParent,
267 colView.ItemsSource = filteredSource;
270 private void SetMainPage()
272 appBar = new AppBar()
274 Title = "NUI Tizen Gallery",
275 AutoNavigationContent = false,
278 var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar");
279 var moreButton = new Button(((AppBarStyle)appBarStyle).BackButton);
280 moreButton.Icon.ResourceUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "menu.png";
281 appBar.NavigationContent = moreButton;
284 pageContent = new View()
286 Layout = new LinearLayout()
288 LinearOrientation = LinearLayout.Orientation.Vertical,
290 WidthSpecification = LayoutParamPolicies.MatchParent,
291 HeightSpecification = LayoutParamPolicies.MatchParent,
294 field = new SearchField()
296 WidthSpecification = LayoutParamPolicies.MatchParent,
298 field.SearchButton.Clicked += OnSearchBtnClicked;
300 testSource = new GalleryViewModel().CreateData();
301 selMode = ItemSelectionMode.SingleAlways;
302 var myTitle = new DefaultTitleItem()
305 WidthSpecification = LayoutParamPolicies.MatchParent,
308 colView = new CollectionView()
310 ItemsSource = testSource,
311 ItemsLayouter = new LinearLayouter(),
312 ItemTemplate = new DataTemplate(() =>
314 DefaultLinearItem item = new DefaultLinearItem()
316 WidthSpecification = LayoutParamPolicies.MatchParent,
318 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
319 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
323 ScrollingDirection = ScrollableBase.Direction.Vertical,
324 HideScrollbar = false,
325 WidthSpecification = LayoutParamPolicies.MatchParent,
326 HeightSpecification = LayoutParamPolicies.MatchParent,
327 SelectionMode = selMode,
329 colView.SelectionChanged += OnSelectionChanged;
331 pageContent.Add(field);
332 pageContent.Add(colView);
334 page = new ContentPage()
337 Content = pageContent,
339 navigator.Push(page);
342 private void RunSample(string name)
344 IExample example = typeof(Program).Assembly?.CreateInstance(name) as IExample;
346 Console.WriteLine($"@@@ typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
354 Console.WriteLine($"@@@ examle is null!");
356 currentExample = example;
359 private void ExitSample()
361 currentExample?.Deactivate();
362 currentExample = null;
367 private void FullGC()
369 global::System.GC.Collect();
370 global::System.GC.WaitForPendingFinalizers();
371 global::System.GC.Collect();
374 static void Main(string[] args)
376 string[] emptyArgs = new string[0];
377 foreach(string arg in args)
379 Console.WriteLine(arg);
380 if (arg.ToString() == "--implicit-scaling-factor")
382 Console.WriteLine("NOTE: Scaling Factor is implicitly declaired as 1.5");
383 System.Environment.SetEnvironmentVariable("NUI_SCALING_FACTOR","1.5");
387 var app = new Program();