Exemplo n.º 1
1
 public void StrokeColorChanges()
 {
     SignaturePadView signature = new SignaturePadView ();
     signature.StrokeColor = UIColor.Green;
     Assert.That (signature.StrokeColor == UIColor.Green);
 }
Exemplo n.º 2
0
 public void NullStrokeColorDoesntChange()
 {
     SignaturePadView signature = new SignaturePadView ();
     signature.StrokeColor = UIColor.Green;
     signature.StrokeColor = null;
     Assert.That (signature.StrokeColor == UIColor.Green);
 }
        protected override void OnCreate(Bundle bundle) {
            base.OnCreate(bundle);
            this.SetContentView(Resource.Layout.SignaturePad);

            var rootView = this.FindViewById<RelativeLayout>(Resource.Id.rootView);
            this.signatureView = this.FindViewById<SignaturePadView>(Resource.Id.signatureView);
            this.btnSave = this.FindViewById<Button>(Resource.Id.btnSave);
            this.btnCancel = this.FindViewById<Button>(Resource.Id.btnCancel);

			var cfg = this.Resolve().CurrentConfig;
            rootView.SetBackgroundColor(cfg.BackgroundColor.ToAndroidColor());
            this.signatureView.BackgroundColor = cfg.SignatureBackgroundColor.ToAndroidColor();
            this.signatureView.Caption.Text = cfg.CaptionText;
            this.signatureView.Caption.SetTextColor(cfg.CaptionTextColor.ToAndroidColor());
            this.signatureView.ClearLabel.Text = cfg.ClearText;
            this.signatureView.ClearLabel.SetTextColor(cfg.ClearTextColor.ToAndroidColor());
            this.signatureView.SignatureLineColor = cfg.SignatureLineColor.ToAndroidColor(); 
            this.signatureView.SignaturePrompt.Text = cfg.PromptText;
            this.signatureView.SignaturePrompt.SetTextColor(cfg.PromptTextColor.ToAndroidColor());
            this.signatureView.StrokeColor = cfg.StrokeColor.ToAndroidColor();
            this.signatureView.StrokeWidth = cfg.StrokeWidth;

            this.btnSave.Text = cfg.SaveText;
            this.btnCancel.Text = cfg.CancelText;
        }
Exemplo n.º 4
0
		public void ValidPointsArrayDoesGetLoaded ()
		{
			SignaturePadView signature = new SignaturePadView ();
			CGPoint [] points = new CGPoint [] { new CGPoint (0, 0), new CGPoint (10, 30), new CGPoint (50, 70) };
			signature.LoadPoints (points);
			Assert.That (signature.Points.Count () > 0);
		}
 private void InitComponents()
 {
     _signaturePadView = new SignaturePadView(this);
     AddContentView(_signaturePadView,
         new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,
         ViewGroup.LayoutParams.MatchParent));
 }
Exemplo n.º 6
0
 public void NullPointsArrayDoesntChangeAnything()
 {
     SignaturePadView signature = new SignaturePadView ();
     PointF [] points = new PointF [] { new PointF (0, 0), new PointF (10, 30), new PointF (50, 70) };
     signature.LoadPoints (points);
     signature.LoadPoints (null);
     Assert.That (signature.Points.Count () > 0);
 }
Exemplo n.º 7
0
		public void EmptyPointsArrayDoesntChangeAnything ()
		{
			SignaturePadView signature = new SignaturePadView ();
			CGPoint [] points = new CGPoint [] { new CGPoint (0, 0), new CGPoint (10, 30), new CGPoint (50, 70) };
			signature.LoadPoints (points);
			signature.LoadPoints (new CGPoint [0]);
			Assert.That (signature.Points.Count () > 0);
		}
Exemplo n.º 8
0
		public SampleView ()
		{
			BackgroundColor = UIColor.White;

			//Create the save button
			btnSave = UIButton.FromType (UIButtonType.RoundedRect);
			btnSave.SetTitle ("Save", UIControlState.Normal);

			//Create the load button
			btnLoad = UIButton.FromType (UIButtonType.RoundedRect);
			btnLoad.SetTitle ("Load Last", UIControlState.Normal);
			btnLoad.TouchUpInside += (sender, e) => {
				if (points != null)
					signature.LoadPoints (points);
			};

			signature = new SignaturePadView ();

			//Using different layouts for the iPhone and iPad, so setup device specific requirements here.
			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {
				//iPhone uses Landscape, but ApplicationFrame still returns Portrait values, so 
				//reverse them for creating the view's frame.
				Frame = new RectangleF (0, 20, UIScreen.MainScreen.ApplicationFrame.Height, 
				                        UIScreen.MainScreen.ApplicationFrame.Width);

				//iPhone version simply saves the vector of points in an instance variable.
				btnSave.TouchUpInside += (sender, e) => {
					if (signature.IsBlank)
						new UIAlertView ("", "No signature to save.", null, "Okay", null).Show ();
					else {
						points = signature.Points;
						new UIAlertView ("", "Vector Saved.", null, "Okay", null).Show ();
					}
				};
			} else {
				Frame = UIScreen.MainScreen.ApplicationFrame;

				//iPad version saves the vector of points as well as retrieving the UIImage to display
				//in a UIImageView.
				btnSave.TouchUpInside += (sender, e) => {
					//if (signature.IsBlank)
					//	new UIAlertView ("", "No signature to save.", null, "Okay", null).Show ();
					imageView.Image = signature.GetImage ();
					points = signature.Points;
				};

				//Create the UIImageView to display a saved signature.
				imageView = new UIImageView();
				AddSubview(imageView);
			}

			//Add the subviews.
			AddSubview (signature);
			AddSubview (btnSave);
			AddSubview (btnLoad);
		}
Exemplo n.º 9
0
			public SigView ()
			{
				BackgroundColor = Color.DarkGray;
				Add(Label = new UILabel{
					Font = UIFont.BoldSystemFontOfSize(60),
					TextAlignment = UITextAlignment.Center,
					TextColor = UIColor.White,
					Text = "$100",
				});
				Label.SizeToFit();
				Add(SignaturePadView = new SignaturePadView());
			}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            // the Signature Pad
            signaturepad = new SignaturePadView();
            signaturepad.Caption.Font = UIFont.FromName("Marker Felt", 16f);
            signaturepad.CaptionText = "Authorization Signature";
            signaturepad.SignaturePromptText = "☛";
            signaturepad.SignaturePrompt.Font = UIFont.FromName("Helvetica", 32f);
            signaturepad.BackgroundColor = UIColor.FromRGB(255, 255, 200); // a light yellow.
            signaturepad.BackgroundImageView.Image = UIImage.FromBundle("logo-galaxy-black-64.png");
            signaturepad.BackgroundImageView.Alpha = 0.0625f;
            signaturepad.BackgroundImageView.ContentMode = UIViewContentMode.ScaleToFill;
            signaturepad.BackgroundImageView.Frame = new System.Drawing.RectangleF(20, 20, 256, 256);
            signaturepad.Layer.ShadowOffset = new System.Drawing.SizeF(0, 0);
            signaturepad.Layer.ShadowOpacity = 1f;
            View.AddSubviews(signaturepad);

            // the buttons
            btnSave = UIButton.FromType(UIButtonType.RoundedRect);
            btnSave.SetTitle("Save", UIControlState.Normal);
            btnSave.TouchUpInside += (sender, e) =>
            {
                if (signaturepad.IsBlank)
                {
                    new UIAlertView("", "No signature to save.", null, "OK", null).Show();
                }
                else
                {
                    points = signaturepad.Points;
                    new UIAlertView("", "Vector Saved.", null, "OK", null).Show();
                }
            };
            btnLoad = UIButton.FromType(UIButtonType.RoundedRect);
            btnLoad.SetTitle("Load Last", UIControlState.Normal);
            btnLoad.TouchUpInside += (sender, e) =>
            {
                if (points != null)
                {
                    signaturepad.LoadPoints(points);
                }
            };
            View.AddSubviews(btnSave, btnLoad);
        }
Exemplo n.º 11
0
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.AddSignatureLayout);

            var save = (Button)FindViewById (Resource.Id.signatureSaveButton);
            save.Click += (sender, e) => {
                if (signatureView.IsBlank) {
                    AlertDialog.Builder builder = new AlertDialog.Builder (Activity);
                    builder
                        .SetTitle (string.Empty)
                        .SetMessage ("No signature!")
                        .SetPositiveButton ("Ok", (innerSender, innere) => { })
                        .Show ();
                    return;
                }
                if (assignmentViewModel.Signature == null)
                {
                    assignmentViewModel.Signature = new Signature
                    {
                        AssignmentId = Assignment.Id
                    };
                }

                assignmentViewModel.Signature.Image = signatureView.GetImage(Color.Black, Color.White).ToByteArray();
                assignmentViewModel.SaveSignatureAsync ()
                    .ContinueWith (_ => {
                        activity.RunOnUiThread (() => {
                            var fragment = Activity.FragmentManager.FindFragmentById<ConfirmationFragment> (Resource.Id.contentFrame);
                            fragment.ReloadConfirmation ();
                            Dismiss ();
                        });
                    });
            };

            var cancel = (Button)FindViewById (Resource.Id.signatureCancelButton);
            cancel.Click += (sender, e) => {
                Dismiss ();
            };

            signatureView = (SignaturePadView)FindViewById (Resource.Id.signatureImage);
            signatureView.BackgroundColor = Color.White;
            signatureView.StrokeColor = Color.Black;
        }
Exemplo n.º 12
0
		public void NullStrokeColorReturnsNullImage ()
		{
			SignaturePadView signature = new SignaturePadView (new RectangleF (0, 0, 50, 100));
			UIImage image = signature.GetImage (null);
			Assert.That (image == null);
		}
Exemplo n.º 13
0
		public void ReturnsFalseIfPointsExist ()
		{
			SignaturePadView signature = new SignaturePadView ();
			signature.LoadPoints (new CGPoint [] { new CGPoint (0, 30) });
			Assert.That (!signature.IsBlank);
		}
Exemplo n.º 14
0
		public void NegativeHeightReturnsNullImage ()
		{
			SignaturePadView signature = new SignaturePadView (new RectangleF (0, 0, 50, 100));
			UIImage image = signature.GetImage (new SizeF (25, -50));
			Assert.That (image == null);
		}
Exemplo n.º 15
0
		public void PositiveScaleReturnsImage ()
		{
			SignaturePadView signature = new SignaturePadView (new RectangleF (0, 0, 50, 100));
			UIImage image = signature.GetImage (2f);
			Assert.That (image != null);
		}
Exemplo n.º 16
0
		public void UnboundSignaturePadViewReturnsNullImage ()
		{
			SignaturePadView signature = new SignaturePadView ();
			UIImage image = signature.GetImage ();
			Assert.That (image == null);
		}
Exemplo n.º 17
0
		public void ZeroWidthReturnsNullImage ()
		{
			SignaturePadView signature = new SignaturePadView (new RectangleF (0, 0, 50, 100));
			UIImage image = signature.GetImage (new SizeF (0, 50));
			Assert.That (image == null);
		}
Exemplo n.º 18
0
		public void ValidFillColorReturnsImage ()
		{
			SignaturePadView signature = new SignaturePadView (new RectangleF (0, 0, 50, 100));
			UIImage image = signature.GetImage (UIColor.Black, UIColor.White);
			Assert.That (image != null);
		}
Exemplo n.º 19
0
		public void ReturnsTrueIfNoPoints ()
		{
			SignaturePadView signature = new SignaturePadView ();
			Assert.That (signature.IsBlank);
		}
			public override void ViewDidLoad ()
			{
				base.ViewDidLoad ();

				cancel = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered, (sender, e) => {
					controller.Dismiss (true);
				});
				cancel.SetTitleTextAttributes (new UITextAttributes { TextColor = UIColor.White }, UIControlState.Normal);
				cancel.SetBackgroundImage (Theme.DarkBarButtonItem, UIControlState.Normal, UIBarMetrics.Default);

				save = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, (sender, e) => {

					//If blank, return
					if (signatureView.IsBlank) {
						new UIAlertView(string.Empty, "No signature!", null, "Ok").Show ();
						return;
					}

					if (assignmentViewModel.Signature == null) {
						assignmentViewModel.Signature = new Data.Signature { AssignmentId = assignmentViewModel.SelectedAssignment.Id };
					}
					assignmentViewModel.Signature.Image = signatureView.GetImage ().ToByteArray ();

					assignmentViewModel.SaveSignatureAsync ()
						.ContinueWith (_ => {
							BeginInvokeOnMainThread (() => controller.Dismiss (true));
						});
				});

				save.SetTitleTextAttributes (new UITextAttributes { TextColor = UIColor.White }, UIControlState.Normal);
				save.SetBackgroundImage (Theme.DarkBarButtonItem, UIControlState.Normal, UIBarMetrics.Default);

				NavigationItem.LeftBarButtonItem = cancel;
				NavigationItem.RightBarButtonItem = save;
				NavigationController.NavigationBar.SetBackgroundImage (null, UIBarMetrics.Default);

				signatureView = new SignaturePadView(View.Frame)
				{
					AutoresizingMask = UIViewAutoresizing.All,
				};
				View.AddSubview (signatureView);
			}
        protected override void OnCreate(Bundle bundle) {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate(bundle);
            this.SetContentView(Resource.Layout.SignaturePad);

            SignaturePadOrientation actualOrientation = SignaturePadOrientation.Automatic;

            this.currentConfig = new SignaturePadConfiguration();
            this.currentConfig.LoadFromIntent(this.Intent);

            var rootView = this.FindViewById<RelativeLayout>(Resource.Id.rootView);
            this.signatureView = this.FindViewById<SignaturePadView>(Resource.Id.signatureView);
            this.btnSave = this.FindViewById<Button>(Resource.Id.btnSave);
            this.btnCancel = this.FindViewById<Button>(Resource.Id.btnCancel);

            var cfg = currentConfig;
            rootView.SetBackgroundColor(cfg.BackgroundColor.ToAndroidColor());
            this.signatureView.BackgroundColor = cfg.SignatureBackgroundColor.ToAndroidColor();


            this.signatureView.Caption.Text = cfg.CaptionText;
            this.signatureView.Caption.SetTextColor(cfg.CaptionTextColor.ToAndroidColor());
            this.signatureView.ClearLabel.Text = cfg.ClearText;
            this.signatureView.ClearLabel.SetTextColor(cfg.ClearTextColor.ToAndroidColor());
            this.signatureView.SignatureLineColor = cfg.SignatureLineColor.ToAndroidColor();
            this.signatureView.SignaturePrompt.Text = cfg.PromptText;
            this.signatureView.SignaturePrompt.SetTextColor(cfg.PromptTextColor.ToAndroidColor());
            this.signatureView.StrokeColor = cfg.StrokeColor.ToAndroidColor();
            this.signatureView.StrokeWidth = cfg.StrokeWidth;


            this.btnSave.Text = cfg.SaveText;
            this.btnCancel.Text = cfg.CancelText;
            if (string.IsNullOrWhiteSpace(cfg.CancelText)) {
                this.btnCancel.Visibility = ViewStates.Invisible;
            }

            var exif = new ExifInterface(cfg.BackgroundImage);
            var orientation = exif.GetAttribute(ExifInterface.TagOrientation);
            var width = exif.GetAttributeInt(ExifInterface.TagImageWidth, 100);
            var height = exif.GetAttributeInt(ExifInterface.TagImageLength, 80);            
            switch (orientation) {
                case "1": // landscape
                case "3": // landscape
                    actualOrientation = SignaturePadOrientation.Landscape;
                    break;

                case "8":
                case "4":
                case "6": // portrait
                    actualOrientation = SignaturePadOrientation.Portrait;
                    break;

                case "0": //undefined
                default:
                    if (width > height)
                        actualOrientation = SignaturePadOrientation.Landscape;
                    else
                        actualOrientation = SignaturePadOrientation.Portrait;
                    break;
            }

            switch (actualOrientation) {
                case SignaturePadOrientation.Landscape:
                    this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
                    break;
                case SignaturePadOrientation.Portrait:
                    this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
                    break;

            }


            this.signatureView.BackgroundImageView.LayoutParameters.Height = ViewGroup.LayoutParams.FillParent;
            this.signatureView.BackgroundImageView.LayoutParameters.Width = ViewGroup.LayoutParams.FillParent;


            this.signatureView.BackgroundImageView.ViewTreeObserver.GlobalLayout += (sender, e) =>  //also tried with _View
            {

                var newSize = new Size(this.signatureView.Width, this.signatureView.Height);
                if (newSize.Width > 0 && !hasBackground) {
                    if (cfg.Points != null && cfg.Points.Count() > 0) {

                        var points = cfg.Points.Select(i => i.GetPointF()).ToArray();
                        this.signatureView.LoadPoints(points);
                    } else {
                    }
                    //Get a smaller image if needed (memory optimization)
                    var bm = LoadAndResizeBitmap(cfg.BackgroundImage, newSize);
                    if (bm != null) {
                        hasBackground = true;
                        switch (cfg.BackgroundImageSize) {
                            case SignaturePadBackgroundSize.Fill:
                                this.signatureView.BackgroundImageView.SetScaleType(ImageView.ScaleType.FitXy);
                                this.signatureView.BackgroundImageView.SetAdjustViewBounds(true);
                                break;
                            case SignaturePadBackgroundSize.Stretch:
                                this.signatureView.BackgroundImageView.SetScaleType(ImageView.ScaleType.FitXy);
                                break;

                        }
                        this.signatureView.BackgroundImageView.SetImageBitmap(bm);
                    }
                }
            };


        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// Perform any additional setup after loading the view, typically from a nib.
			var signature = new SignaturePadView (View.Frame) {
				StrokeWidth = 3f
			};
			View.AddSubview (signature);

			Database db = new Database ();
			db.Save ();
		}