Exemple #1
0
        protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (requestCode == 102 && resultCode == Result.Ok)
            {
                if (_file == null)
                {
                    _file = new File(GetPathToImage(data.Data));
                }
                // make it available in the gallery
                Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                Uri    contentUri      = Uri.FromFile(_file);

                mediaScanIntent.SetData(contentUri);
                SendBroadcast(mediaScanIntent);
                //Converstion Image Size
                //int height = ImgView.Height;
                int width = Resources.DisplayMetrics.WidthPixels;
                using (Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, 600))
                {
                    progress = new ProgressDialog(this);
                    progress.Indeterminate = true;
                    progress.SetProgressStyle(Android.App.ProgressDialogStyle.Spinner);
                    progress.SetMessage("Chargement...");
                    progress.SetCancelable(false);
                    progress.Show();

                    var closest = await ClarifaiCaller.CallApi(bitmap);

                    //View ImageView
                    //ImgView.RecycleBitmap();
                    //ImgView.SetImageBitmap(bitmap);
                    //Upload Image in Database

                    Intent res = new Intent(this, typeof(ResultActivity));
                    if (closest.Count != 0)
                    {
                        res.PutExtra("name", closest.First().name);
                        res.PutExtra("value", $"{(int)Math.Round(closest.First().value * 100)}%");
                        await DatabaseCaller.AddBuilding(FakeDatabase.Buildings[closest.First().name], (int)Math.Round(closest.First().value * 100), _file.AbsolutePath);
                    }
                    else
                    {
                        res.PutExtra("name", "Aucun monument reconnu");
                        res.PutExtra("value", "");
                        await DatabaseCaller.AddBuilding(FakeDatabase.Buildings["Aucun monument reconnu"], 0, _file.AbsolutePath);
                    }

                    StartActivity(res);
                }
            }
        }
Exemple #2
0
        private async void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var ls      = sender as ListView;
            var myAdaps = ls.Adapter as MyListViewAdapter;
            var buid    = myAdaps[e.Position];

            Intent intent = new Intent();

            intent.SetAction(Intent.ActionView);
            var rep = await DatabaseCaller.GetFromId(buid.Id);

            intent.SetDataAndType(Uri.Parse("file://" + rep.ImgPath), "image/*");
            StartActivity(intent);
        }
Exemple #3
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Recognition);
            if (IsThereAnAppToTakePictures())
            {
                _file = null;
                CreateDirectoryForPictures();
                BtnTakeImg   = FindViewById <Button>(Resource.Id.btntakepicture);
                BtnSelectImg = FindViewById <Button>(Resource.Id.btnselectpicture);
                //ImgView = FindViewById<ImageView>(Resource.Id.ImgTakeimg);
                BtnTakeImg.Click   += TakeAPicture;
                BtnSelectImg.Click += BtnSelectImg_Click;
            }

            var listView = FindViewById <ListView>(Resource.Id.listView);

            listView.Adapter    = new MyListViewAdapter(this, await DatabaseCaller.GetLatest());
            listView.ItemClick += ListView_ItemClick;
        }