コード例 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            viewModel = new ImageSearchViewModel();

            CollectionViewImages.WeakDataSource = this;

            ButtonSearch.TouchUpInside += async(sender, args) =>
            {
                ButtonSearch.Enabled = false;
                ActivityIsLoading.StartAnimating();

                await viewModel.SearchForImagesAsync(TextFieldQuery.Text);

                CollectionViewImages.ReloadData();

                ButtonSearch.Enabled = true;
                ActivityIsLoading.StopAnimating();
            };


            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Camera, async delegate
            {
                await viewModel.TakePhotoAndAnalyzeAsync(false);
            });
        }
コード例 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            viewModel = new ImageSearchViewModel();

            //Setup RecyclerView

            adapter = new ImageAdapter(this, viewModel);

            recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);

            recyclerView.SetAdapter(adapter);

            layoutManager = new GridLayoutManager(this, 2);

            recyclerView.SetLayoutManager(layoutManager);

            progressBar            = FindViewById <ProgressBar>(Resource.Id.my_progress);
            progressBar.Visibility = ViewStates.Gone;

            var query = FindViewById <EditText>(Resource.Id.my_query);

            // Get our button from the layout resource,
            // and attach an event to it
            var clickButton = FindViewById <Button>(Resource.Id.my_button);

            //Button Click event to get images

            //clickButton.Click += async (sender, args) =>
            //{
            //    clickButton.Enabled = false;
            //    progressBar.Visibility = ViewStates.Visible;

            //    await viewModel.SearchForImagesAsync(query.Text.Trim());


            //    progressBar.Visibility = ViewStates.Gone;
            //    clickButton.Enabled = true;
            //};

            clickButton.Click += async(sender, args) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;

                await viewModel.SearchForImagesAsync(query.Text.Trim());

                clickButton.Enabled    = true;
                progressBar.Visibility = ViewStates.Gone;
            };

            UserDialogs.Init(this);
            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
コード例 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            viewModel = new ImageSearchViewModel();

            //Setup RecyclerView
            adapter      = new ImageAdapter(this, viewModel);
            recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            recyclerView.SetAdapter(adapter);
            layoutManager = new GridLayoutManager(this, 2);
            recyclerView.SetLayoutManager(layoutManager);

            progressBar            = FindViewById <ProgressBar>(Resource.Id.my_progress);
            progressBar.Visibility = ViewStates.Gone;

            var query = FindViewById <EditText>(Resource.Id.my_query);

            var clickButton = FindViewById <Button>(Resource.Id.my_button);

            clickButton.Click += async(sender, e) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;
                await viewModel.SearchForImagesAsync(query.Text.Trim());

                clickButton.Enabled    = true;
                progressBar.Visibility = ViewStates.Gone;
            };

//DEMO: 2b - Image Analysis
            //Button Click event to get images
            adapter.ItemClick += async(object sender, ImageAdapterClickEventArgs e) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;

                var result = await viewModel.GetImageDescription(viewModel.Images[e.Position].ImageLink);

                new AlertDialog.Builder(this)
                .SetTitle("Image Analysis")
                .SetMessage(result)
                .SetNeutralButton("OK", delegate { })
                .Show();

                progressBar.Visibility = ViewStates.Gone;
                clickButton.Enabled    = true;
            };

            UserDialogs.Init(this);

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
コード例 #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            viewModel = new ImageSearchViewModel();

            CollectionViewImages.WeakDataSource  = this;
            CollectionViewImages.AllowsSelection = true;

            CollectionViewImages.Delegate = this;

            ButtonSearch.TouchUpInside += async(sender, e) =>
            {
                ButtonSearch.Enabled = false;
                ActivityIsLoading.StartAnimating();

                await viewModel.SearchForImagesAsync(TextFieldQuery.Text);

                CollectionViewImages.ReloadData();

                ButtonSearch.Enabled = true;
                ActivityIsLoading.StopAnimating();
            };

            var cameraButton = new UIBarButtonItem(UIBarButtonSystemItem.Camera,
                                                   async(sender, e) =>
            {
                ActivityIsLoading.StartAnimating();
                await viewModel.TakePhotAsync();
                ActivityIsLoading.StopAnimating();
            });

            var pickButton = new UIBarButtonItem(UIBarButtonSystemItem.Organize,
                                                 async(sender, e) =>
            {
                ActivityIsLoading.StartAnimating();
                await viewModel.TakePhotAsync(false);
                ActivityIsLoading.StopAnimating();
            });

            this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[] { cameraButton, pickButton };
        }
コード例 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var viewModel = new ImageSearchViewModel();

            var adapter = new ImageAdapter(this, viewModel);

            var recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);

            recyclerView.SetAdapter(adapter);

            var layoutManager = new GridLayoutManager(this, 2);

            recyclerView.SetLayoutManager(layoutManager);

            var progressBar = FindViewById <ProgressBar>(Resource.Id.my_progress);

            progressBar.Visibility = ViewStates.Gone;

            var query = FindViewById <EditText>(Resource.Id.my_query);

            var clickButton = FindViewById <Button>(Resource.Id.my_button);

            clickButton.Click += async(sender, args) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;

                await viewModel.SearchForImagesAsync(query.Text.Trim());

                progressBar.Visibility = ViewStates.Gone;
                clickButton.Enabled    = true;
            };

            UserDialogs.Init(this);

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
コード例 #6
0
        private async void SelectedIndexChanged(object sender, EventArgs e)
        {
            Picker pk = (Picker)sender;

            if (string.Compare(pk.Title, "Years") == 0)
            {
                Picker        makes = Content.FindByName <Picker>("pickerMakes");
                List <string> mks   = await svcCar.GetMakes(pk.Items[pk.SelectedIndex]);

                foreach (string m in mks)
                {
                    if (m != null)
                    {
                        makes.Items.Add(m);
                    }
                }
            }
            else if (string.Compare(pk.Title, "Makes") == 0)
            {
                Picker years  = Content.FindByName <Picker>("pickerYears");
                Picker models = Content.FindByName <Picker>("pickerModels");

                List <string> mdl = await svcCar.GetModels(years.Items[years.SelectedIndex], pk.Items[pk.SelectedIndex]);

                var ic = models.Items.Count;
                if (ic > 0)
                {
                    for (int i = 0; i < ic; i++)
                    {
                        models.Items.RemoveAt(0);
                    }
                }

                if (mdl.Count == 1)
                {
                    models.Items.Add("");
                }
                else
                {
                    foreach (string m in mdl)
                    {
                        if (m != null)
                        {
                            models.Items.Add(m);
                        }
                    }
                }
            }

            else if (string.Compare(pk.Title, "Models") == 0)
            {
                Picker            years  = Content.FindByName <Picker>("pickerYears");
                Picker            makes  = Content.FindByName <Picker>("pickerMakes");
                Picker            models = Content.FindByName <Picker>("pickerModels");
                ActivityIndicator busy   = Content.FindByName <ActivityIndicator>("busyIndicator");

                yrSelected = years.Items[years.SelectedIndex];
                mkSelected = makes.Items[makes.SelectedIndex];
                mdSelected = models.Items[models.SelectedIndex];

                _searchForCar = "new" + yrSelected + " " + mkSelected + " " + mdSelected;

                busy.IsRunning = true;
                busy.IsVisible = true;

                List <ImageResult> result = await imgCar.SearchForImagesAsync(_searchForCar);

                _carList = result;
                car      = result.FirstOrDefault();

                carLabel.Text   = car.Title;
                carImage.Source = car.ImageLink;

                busy.IsRunning = false;
                busy.IsVisible = false;
            }

            pk.IsEnabled = false; /*grays out field once selected*/
        }