Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            ContextWrapper cw       = new ContextWrapper(ApplicationContext);
            var            dbFolder = cw.GetExternalFilesDir(Android.OS.Environment.DirectoryDocuments);

            DBController.Instance.RefreshDB(dbFolder.AbsolutePath);

            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            DrawerLayout          drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            navigationView.SetNavigationItemSelectedListener(this);

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

            RegisterForContextMenu(lvTests);

            RefreshTests();
        }
Beispiel #2
0
        public LogFile(ContextWrapper ctx, string log_filename, DateTime expires)
        {
            bool append;

            using (var file = new Java.IO.File(ctx.GetExternalFilesDir(null), log_filename))
            //            using (var file = ctx.GetFileStreamPath(log_filename))
            {
                Path   = file.AbsolutePath;
                append = file != null && file.Exists()
                         // check if last modification to file was after experition
                         && Common.FromTimeStampMs(file.LastModified()) > expires;
            }
            this.writer = new StreamWriter(Path, append);
            //            this.writer = new StreamWriter(ctx.OpenFileOutput(log_filename, FileCreationMode.WorldReadable | (append ? FileCreationMode.Append : 0)));
        }
Beispiel #3
0
    public async Task onPictureTakeAsync(byte[] data, Camera camera)
    {
            /*ContextWrapper cw = new ContextWrapper(ApplicationContext);
            imageFileFolder = cw.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);

            Calendar c = Calendar.Instance;
            imageFileName = new Java.IO.File(imageFileFolder, c.Time.Seconds + ".bmp");
            imageFileName.CreateNewFile();

            using (var os = new FileStream(imageFileName.AbsolutePath, FileMode.Create))
            {
                os.Write(data, 0, data.Length);
            }
            */
            TesseractApi tesseractApi = new TesseractApi(ApplicationContext, AssetsDeployment.OncePerInitialization);
            if (!tesseractApi.Initialized)
                await tesseractApi.Init("eng");
            var tessResult = await tesseractApi.SetImage(data);
            if (tessResult)
            {
                var a = tesseractApi.Text;
                var b = a;
            }

            Bitmap cameraBitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length);
            int wid = cameraBitmap.Width;
            int hgt = cameraBitmap.Height;

            Bitmap resultImage = Bitmap.CreateBitmap(wid, hgt, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(resultImage);
            canvas.DrawBitmap(cameraBitmap, 0f, 0f, null);

            image.DrawingCacheEnabled = true;
            image.Measure(MeasureSpec.MakeMeasureSpec(300, MeasureSpecMode.Exactly),
                          MeasureSpec.MakeMeasureSpec(300, MeasureSpecMode.Exactly));
            image.Layout(0, 0, image.MeasuredWidth, image.MeasuredHeight);
            image.BuildDrawingCache(true);
            Bitmap layoutBitmap = Bitmap.CreateBitmap(image.DrawingCache);
            image.DrawingCacheEnabled = false;
            canvas.DrawBitmap(layoutBitmap, 80f, 0f, null);

            ContextWrapper cw = new ContextWrapper(ApplicationContext);
            imageFileFolder = cw.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);

            imageFileName = new Java.IO.File(imageFileFolder, DateTime.Now.Ticks.ToString() + ".jpg");
            imageFileName.CreateNewFile();

            try
            {
                using (var os = new FileStream(imageFileName.AbsolutePath, FileMode.Create))
                {
                    resultImage.Compress(Bitmap.CompressFormat.Jpeg, 95, os);
                }
            }
            catch (Exception e)
            {
                Log.Debug("In Saving File", e + "");
            }

            dialog.Dismiss();

            var activity = new Intent(this, typeof(ImageActivity));

            activity.PutExtra("AbsolutePath", imageFileName.AbsolutePath);
            StartActivity(activity);
            Finish();
            //StartActivity(typeof(ImageActivity));
        }