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();
            }
        }
示例#2
0
        private void initProgressCircles()
        {
            animatedCircleLoadingViewIndeterminate.StartIndeterminate();
            animatedCircleLoadingView.StartDeterminate();

            Task.Run(async() => {
                await Task.Delay(1000);
                for (int i = 1; i < 100; i++)
                {
                    await Task.Delay(100);
                    RunOnUiThread(() => {
                        animatedCircleLoadingView.SetPercent(i);
                    });
                }
            });
        }