private void SearchBoxOnQueryTextChange(object sender, SearchView.QueryTextChangeEventArgs queryTextChangeEventArgs)
        {
            SearchableTreeNode stnResult = SampleManager.Current.FullTree.Search(sample => SampleManager.Current.SampleSearchFunc(sample, queryTextChangeEventArgs.NewText));

            if (stnResult != null)
            {
                _filteredSampleCategories = stnResult.Items.OfType <SearchableTreeNode>().ToList();
                if (!_arCompatible)
                {
                    _filteredSampleCategories.RemoveAll(category => category.Name == "Augmented reality");
                }
            }
            else
            {
                _filteredSampleCategories = new List <SearchableTreeNode>();
            }

            _categoriesListView.SetAdapter(new CategoriesAdapter(this, _filteredSampleCategories));

            // Expand all entries; makes it easier to see search results.
            for (int index = 0; index < _filteredSampleCategories.Count; index++)
            {
                _categoriesListView.ExpandGroup(index);
            }
        }
        /// <summary>
        /// Creates a usable list of <c>TreeViewItem</c>.
        /// from the tree of samples and categories.
        /// This function assumes that there is only one level of categories.
        /// </summary>
        public static List <TreeViewItem> ToTreeViewItem(SearchableTreeNode fullTree)
        {
            // Create the list of tree view items.
            List <TreeViewItem> categories = new List <TreeViewItem>();

            // This happens when there are no search results.
            if (fullTree == null)
            {
                return(categories);
            }

            // For each category in the tree, create a category item.
            foreach (SearchableTreeNode category in fullTree.Items)
            {
                // Create the category item.
                var categoryItem = new TreeViewItem
                {
                    Header      = category.Name,
                    DataContext = category
                };

                // Add items for each sample.
                foreach (SampleInfo sampleInfo in category.Items)
                {
                    categoryItem.Items.Add(new TreeViewItem {
                        Header = sampleInfo.SampleName, DataContext = sampleInfo
                    });
                }

                categories.Add(categoryItem);
            }
            return(categories);
        }
예제 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set the ContentView to the SamplesList (a ListView).
            SetContentView(Resource.Layout.SamplesList);

            // Retrieve the selected category from the Categories List.
            var selectedCategory = Intent.GetIntExtra("SelectedCategory", 0);

            // Get the listing of categories; Would be good to eventually be able to pass
            // this info, but Android doesn't allow passing Complex types.
            List <object>      sampleCategories = SampleManager.Current.FullTree.Items; // TODO: Cache this in the SampleManager
            SearchableTreeNode category         = (SearchableTreeNode)sampleCategories[selectedCategory];

            // Loop through the categories and create a list of samples.
            _listSampleItems = category.Items.OfType <SampleInfo>().ToList();

            var samplesAdapter = new SamplesListAdapter(this, _listSampleItems);

            ListView samplesListView = FindViewById <ListView>(Resource.Id.samplesListView);

            samplesListView.Adapter    = samplesAdapter;
            samplesListView.ItemClick += SamplesListView_ItemClick;
        }
        private void LoadTreeView(SearchableTreeNode fullTree)
        {
            // This happens when there are no search results.
            if (fullTree == null)
            {
                return;
            }
            CategoriesTree.RootNodes.Clear();

            muxc.TreeViewNode rootNode;

            foreach (SearchableTreeNode category in fullTree.Items)
            {
                rootNode = new muxc.TreeViewNode()
                {
                    Content = category
                };
                category.Items.ForEach(info => rootNode.Children.Add(new muxc.TreeViewNode()
                {
                    Content = info
                }));

                CategoriesTree.RootNodes.Add(rootNode);
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes the sample manager by loading all of the samples in the app.
        /// </summary>
        public void Initialize()
        {
            // Get the currently-executing assembly.
            Assembly samplesAssembly = GetType().GetTypeInfo().Assembly;

            // Get the list of all samples in the assembly.
            AllSamples = CreateSampleInfos(samplesAssembly).OrderBy(info => info.Category)
                         .ThenBy(info => info.SampleName.ToLowerInvariant())
                         .ToList();

            // Create a tree from the list of all samples.
            FullTree = BuildFullTree(AllSamples);

            // Add a special category for featured samples.
            SearchableTreeNode featured = new SearchableTreeNode("Featured", AllSamples.Where(sample => sample.Tags.Contains("Featured")));

            FullTree.Items.Insert(0, featured);
        }
        private async void OnSearchQuerySubmitted(AutoSuggestBox searchBox, AutoSuggestBoxTextChangedEventArgs searchBoxQueryChangedEventArgs)
        {
            // Dont search again until wait from previous search expires.
            if (_waitFlag)
            {
                return;
            }

            _waitFlag = true;
            await Task.Delay(200);

            _waitFlag = false;

            // Search using the sample manager
            var categoriesList = SampleManager.Current.FullTree.Search(SampleSearchFunc);

            if (categoriesList == null)
            {
                categoriesList = new SearchableTreeNode("Search", new[] { new SearchableTreeNode("No results", new List <object>()) });
            }

            // Load the tree of the current categories.
            LoadTreeView(categoriesList);

            // Check if there are search results.
            if (CategoriesTree.RootNodes.Any())
            {
                // Set the items source of the grid to the first category from the search.
                SamplesGridView.ItemsSource = CategoriesTree.RootNodes[0].Children.ToList().Select(x => (SampleInfo)x.Content).ToList();

                if (!String.IsNullOrWhiteSpace(searchBox.Text))
                {
                    foreach (muxc.TreeViewNode node in CategoriesTree.RootNodes)
                    {
                        node.IsExpanded = true;
                    }
                }
            }

            // Switch to the sample selection grid.
            SamplePageContainer.Visibility = Visibility.Collapsed;
            SamplePageContainer.Content    = null;
            SampleSelectionGrid.Visibility = Visibility.Visible;
        }
        private void OnSearchQuerySubmitted(AutoSuggestBox searchBox, AutoSuggestBoxTextChangedEventArgs searchBoxQueryChangedEventArgs)
        {
            if (SearchToggleButton.IsChecked == true)
            {
                SearchBox.Visibility          = Visibility.Collapsed;
                SearchToggleButton.Visibility = Visibility.Visible;
                SearchToggleButton.IsChecked  = false;
            }
            var categoriesList = SampleManager.Current.FullTree.Search(SampleSearchFunc);

            if (categoriesList == null)
            {
                categoriesList = new SearchableTreeNode("Search", new[] { new SearchableTreeNode("No results", new List <object>()) });
            }
            Categories.ItemsSource = categoriesList.Items;

            if (categoriesList.Items.Any())
            {
                Categories.SelectedIndex = 0;
            }
        }
 public SamplesViewController(SearchableTreeNode category)
 {
     _category = category;
 }