Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Console.WriteLine("Creating!!!!!!!!!!!!!!!..................");
            Title = Intent.GetStringExtra("title");
            base.OnCreate(savedInstanceState);

            progress = new ProgressDialog(this);
            progress.SetMessage("Loading...");
            progress.SetCancelable(false);
            progress.Indeterminate = true;
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.Show();

            SetContentView(Resource.Layout.CanvasFullScreen);

            ColorLayout     = FindViewById <LinearLayout>(Resource.Id.colourLayout);
            WidthLayout     = FindViewById <LinearLayout>(Resource.Id.widthLayout);
            EditExif        = FindViewById <EditText>(Resource.Id.editExifText);
            MainCanvas      = FindViewById <RelativeLayout>(Resource.Id.mainCanvas);
            BackgroundImage = FindViewById <ImageView>(Resource.Id.backgroundImage);

            Highlight = FindViewById <Switch>(Resource.Id.switchHighlight);
            BrushSize = FindViewById <SeekBar>(Resource.Id.widthSeek);
            WidthText = FindViewById <TextView>(Resource.Id.widthText);

            MainCanvas.ViewTreeObserver.GlobalLayout += ViewTreeObserver_GlobalLayout;

            //obtaining the items
            Binding = JsonConvert.DeserializeObject <Bindings>(Intent.GetStringExtra("binding"));
            Control = JsonConvert.DeserializeObject <Controls>(Intent.GetStringExtra("control"));
            v       = WidgetHelper.viewToPass;


            if (Control.appearance.ToLower() == "signature")
            {
                ColorLayout.Visibility    = ViewStates.Gone;
                WidgetHelper.mPaint.Color = Color.Black;
            }

            bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                Window.SetSoftInputMode(SoftInput.StateHidden);


                if (Binding != null && Control != null)
                {
                    path = XForm.GetValue(Binding.nodeset);


                    //if path is null, popup dialog for camera or gallery
                    if (string.IsNullOrEmpty(path))
                    {
                        RunOnUiThread(() => { MainCanvas.Background = new ColorDrawable(Color.White); });
                        newPhoto = true;
                        if (Control.appearance.ToLower() == "annotate" || Control.appearance.ToLower() == "textannotate")
                        {
                            TakePhoto("drawing", Binding, v, WidgetHelper.activity, false);
                        }
                    }


                    RunOnUiThread(() =>
                    {
                        BrushSize.Progress = strokeWidth;
                        WidthText.Text     = $"Width: {strokeWidth.ToString()}";

                        //we don't need colours, text box or the highlight switch if signature
                        if (Control.appearance == "signature")
                        {
                            WidgetHelper.mPaint.Color = Color.Black;
                            ColorLayout.Visibility    = ViewStates.Gone;
                            EditExif.Visibility       = ViewStates.Gone;
                            Highlight.Visibility      = ViewStates.Gone;
                        }
                        //setup events to change paint colour
                        else
                        {
                            ApplyButtonEvents(ColorLayout, WidgetHelper.mPaint);
                        }

                        /*
                         * if (Control.appearance.ToLower() == "signature" || Control.appearance.ToLower() == "draw")
                         *  SetupDrawingCanvas();
                         */
                    });
                }

                //I have no binding reference, cannot do much here lol
                else
                {
                    Finish();
                }
            };

            bw.RunWorkerCompleted += delegate
            {
                progress.Dismiss();
            };

            bw.RunWorkerAsync();
        }
Example #2
0
        private void SetupDrawingCanvas()
        {
            path = XForm.GetValue(Binding.nodeset);
            if (!string.IsNullOrEmpty(path))
            {
                Bitmap bitmap = BitmapFactory.DecodeFile(path);

                //grab the exif note if there is one
                ExifInterface exifData = new ExifInterface(path);
                string        note     = exifData.GetAttribute(ExifInterface.TagImageDescription);
                if (note != null)
                {
                    EditExif.Text = note;
                }

                //grab orientation if there is one, some images from the net may not even have it
                int orientation = exifData.GetAttributeInt(Android.Media.ExifInterface.TagOrientation, 1);
                switch (orientation)
                {
                case 6:
                    bitmap = BitmapHelpers.RotateBitmap(bitmap, 90f);
                    break;

                case 3:
                    bitmap = BitmapHelpers.RotateBitmap(bitmap, 180f);
                    break;

                case 8:
                    bitmap = BitmapHelpers.RotateBitmap(bitmap, 270f);
                    break;
                }

                Dims = new int[] { bitmap.Width, bitmap.Height };

                //this one liner does all, gets the lower of the two to determine what to scale it by
                decimal scale = Math.Min(Decimal.Divide(MainCanvas.Width, Dims[0]), Decimal.Divide(MainCanvas.Height, Dims[1]));

                int width  = (int)(Dims[0] * scale);
                int height = (int)(Dims[1] * scale);

                //background image

                if (Control.appearance.ToLower() == "annotate" || Control.appearance.ToLower() == "textannotate")
                {
                    bitmap = Bitmap.CreateScaledBitmap(bitmap, width, height, true);
                    BackgroundImage.SetImageBitmap(bitmap);
                }

                //canvas image
                if (TempBitmap != null)
                {
                    canvasBitmap = Bitmap.CreateScaledBitmap(TempBitmap, width, height, true);
                }
                else
                {
                    canvasBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                }


                if (dv == null)
                {
                    dv = new DrawingView(this, canvasBitmap, 10, BackgroundImage);
                }
                if (Control.appearance.ToLower() != "signature")
                {
                    SetupEvents();
                }

                var layoutParams = new RelativeLayout.LayoutParams(width, height);
                layoutParams.AddRule(LayoutRules.CenterInParent);
                dv.LayoutParameters = layoutParams;
                MainCanvas.AddView(dv);
                GC.Collect();
            }
            else if (Control.appearance.ToLower() == "signature" || Control.appearance.ToLower() == "draw")

            {
                int width  = MainCanvas.Width;
                int height = MainCanvas.Height;

                //canvas image
                if (TempBitmap != null)
                {
                    canvasBitmap = Bitmap.CreateScaledBitmap(TempBitmap, width, height, true);
                }
                else
                {
                    canvasBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                }

                if (dv == null)
                {
                    dv = new DrawingView(this, canvasBitmap, 10, BackgroundImage);
                }
                if (Control.appearance.ToLower() != "signature")
                {
                    SetupEvents();
                }

                var layoutParams = new RelativeLayout.LayoutParams(width, height);
                layoutParams.AddRule(LayoutRules.CenterInParent);
                dv.LayoutParameters = layoutParams;
                MainCanvas.AddView(dv);
                GC.Collect();
            }
        }