protected async override void OnResume()
        {
            base.OnResume();

            _errorView.Visibility   = ViewStates.Gone;
            _textZone.Visibility    = ViewStates.Gone;
            _loadingView.Visibility = ViewStates.Visible;
            _loadingView.StartIndeterminate();

            if (!string.IsNullOrEmpty(_picturePath))
            {
                new Thread(new ThreadStart(async() =>
                {
                    _pictureBytes = System.IO.File.ReadAllBytes(_picturePath);

                    Bitmap bitmap = await BitmapFactory.DecodeByteArrayAsync(
                        _pictureBytes, 0, _pictureBytes.Length);

                    Bitmap cropped = Bitmap.CreateScaledBitmap(bitmap, 1920, 1080, false);
                    byte[] byteArray;
                    using (var stream = new MemoryStream())
                    {
                        await cropped.CompressAsync(Bitmap.CompressFormat.Jpeg, 100, stream);
                        byteArray = stream.ToArray();
                    }

                    try
                    {
                        var result = await _visionService.RecognizeTextService(byteArray);

                        RunOnUiThread(() =>
                        {
                            _loadingView.StopOk();
                            _loadingView.Visibility = ViewStates.Gone;

                            if (result == null)
                            {
                                throw new Exception("");
                            }

                            PrintText(result.Lines);
                        });
                    }
                    catch (Exception e)
                    {
                        if (!string.IsNullOrEmpty(e.Message))
                        {
                            _errorView.Text = e.Message;
                        }

                        RunOnUiThread(() =>
                        {
                            _loadingView.StopOk();
                            _loadingView.Visibility = ViewStates.Gone;
                            _errorView.Visibility   = ViewStates.Visible;
                        });
                    }
                })).Start();
            }
        }
Esempio n. 2
0
        private void FabOnClick(object sender, EventArgs eventArgs)
        {
            animatedCircleLoadingViewIndeterminate.StopOk();
            animatedCircleLoadingView.StopOk();
            View view = (View)sender;

            Snackbar.Make(view, "Stopped Progress with OK status.", Snackbar.LengthLong).SetAction("Action", (Android.Views.View.IOnClickListener)null).Show();
        }
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            loading = FindViewById <AnimatedCircleLoadingView> (Resource.Id.circle_loading_view);

            // prepare for the work
            loading.StartDeterminate();

            // do the work
            await Task.Delay(1500);

            for (int i = 0; i <= 100; i++)
            {
                await Task.Delay(65);

                loading.SetPercent(i);
            }
            loading.StopOk();
        }