public void UnboundSignaturePadViewReturnsNullImage() { SignaturePadView signature = new SignaturePadView(); UIImage image = signature.GetImage(); Assert.That(image == null); }
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); }
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); }
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); }
public void PositiveScaleReturnsImage() { SignaturePadView signature = new SignaturePadView(new RectangleF(0, 0, 50, 100)); UIImage image = signature.GetImage(2f); Assert.That(image != null); }
public void NullFillColorReturnsNullImage() { SignaturePadView signature = new SignaturePadView(new RectangleF(0, 0, 50, 100)); UIImage image = signature.GetImage(UIColor.Black, null); Assert.That(image == null); }
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); } }; Frame = UIScreen.MainScreen.ApplicationFrame; Signature = new SignaturePadView(); //Using different layouts for the iPhone and iPad, so setup device specific requirements here. if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { //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 { //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); } TranslatesAutoresizingMaskIntoConstraints = false; //Add the subviews. AddSubview(Signature); AddSubview(btnSave); AddSubview(btnLoad); }
public void HandlePositiveButtonClick(object sender, DialogClickEventArgs e) { try { //signature = Activity.FindViewById<SignaturePadView>(Resource.Id.signatureFrame); Bitmap imagen = signature.GetImage(); MemoryStream ms = new MemoryStream(); //ByteArrayOutputStream bos = new ByteArrayOutputStream(); imagen.Compress(Bitmap.CompressFormat.Png, 100, ms); byte[] bArray = ms.ToArray(); //string id = Guid.NewGuid().ToString(); System.Console.WriteLine("GUID: " + guid); loadConnection(); db.BeginTransaction(); //Se almacena en base de datos el BLOB con su respectivo GUID try { string sql = "INSERT INTO IMAGENES (Nombre,Imagen) VALUES(?,?)"; SQLiteStatement insertStmt = db.CompileStatement(sql); insertStmt.ClearBindings(); insertStmt.BindString(1, guid); insertStmt.BindBlob(2, bArray); insertStmt.ExecuteInsert(); db.SetTransactionSuccessful(); db.EndTransaction(); db.Close(); try { if (actor.Equals("notificando", StringComparison.Ordinal)) { ManejoBaseDatos.Abrir(); ManejoBaseDatos.Actualizar("Notificaciones", "ValidacionNotificando", "S", "CodigoNotificacion=" + codigo + ""); ManejoBaseDatos.Cerrar(); } if (actor.Equals("testigo", StringComparison.Ordinal)) { ManejoBaseDatos.Abrir(); ManejoBaseDatos.Actualizar("Notificaciones", "ValidacionTestigo", "S", "CodigoNotificacion=" + codigo + ""); ManejoBaseDatos.Cerrar(); } } catch (Exception ex) { System.Console.WriteLine("Error almacenando confirmacion de firma: " + ex.ToString()); Toast.MakeText(this.Activity, "Error guardando confirmacion", ToastLength.Short).Show(); } } catch (Exception ex) { System.Console.WriteLine("Error guardando imagen en db: " + ex.ToString()); } Toast.MakeText(this.Activity, "Firma capturada de forma exitosa", ToastLength.Short).Show(); } catch (Exception ex) { System.Console.WriteLine("ERROR guardando la imagen: " + ex.ToString()); } }
async void CompleteButton_OnClicked(Object sender, EventArgs e) { if (!SignaturePadView.GetDrawPoints().Any()) { await this.SignOrderPageViewModel.NoSignatureFound(); } else { var result = ImageStreamToBytes(SignaturePadView.GetImage(ImageFormatType.Png)); await this.SignOrderPageViewModel.SignatureComplete(result); } }
/// <summary> /// Se guarda la firma /// Se devuelve a la vista de donde fue llamada la pantalla de firmas /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Guardar_Click(object sender, EventArgs e) { if (fragmentoRetornar != null) { //fzeledon SignaturePadView signature = Activity.FindViewById <SignaturePadView>(Resource.Id.signatureFrame); Bitmap imagen = signature.GetImage(); var t = signature.BackgroundImageView; //guardarFirma(imagen);//Se guarda la firma //Se retorna a la pantalla anterior ((Activities.MainActivity)Activity).navegacionFragment(fragmentoRetornar); } }
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) { 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; }
/// <summary> /// Save the docket /// </summary> bool UpdateDocketDetails(bool confirm) { _confirm = confirm; // set the signature var customerName = _customerNameEditText.Text; // validate signature if (_signatureView.IsBlank) { var messageSignature = Resources.GetString(Resource.String.message_missing_signature); Activity.RunOnUiThread(() => { UserDialogs.Instance.Alert(messageSignature); }); return(false); } byte[] signature; using (var stream = new MemoryStream()) { var image = _signatureView.GetImage(true, true); image.Compress(Bitmap.CompressFormat.Png, 50, stream); signature = stream.ToArray(); stream.Close(); image.Dispose(); } //var location = await GetLocation().ConfigureAwait(false); var longitude = _location?.Longitude; var latitude = _location?.Latitude; // open a new realm since getlocation causes context switch _docketId = DocketService.CommitDocket(_repository, _docketId, signature, longitude, latitude, customerName, confirm); // update the docket id var profile = _repository.Profiles.First(); profile.CurrentDocketID = _docketId; _repository.SaveChanges(); return(true); }
private void BtnSave_Click(object sender, EventArgs e) { SignatureImage = sign_pad.GetImage(); //byte[] b = new byte[(long)f.Length()]; //f.ReadFully(b); //Java.IO.File file; //Toast.MakeText(Activity, "Signature Saved", ToastLength.Short).Show(); //ByteBuffer buffer = ByteBuffer.Allocate(SignatureImage.ByteCount); //SignatureImage.CopyPixelsToBuffer(buffer); //buffer.Rewind(); ////Byte array signature //IntPtr classHandle = JNIEnv.FindClass("java/nio/ByteBuffer"); //IntPtr methodId = JNIEnv.GetMethodID(classHandle, "array", "()[B"); //IntPtr resultHandle = JNIEnv.CallObjectMethod(buffer.Handle, methodId); //byte[] result = JNIEnv.GetArray<byte>(resultHandle); //JNIEnv.DeleteLocalRef(resultHandle); try { int byteSize = SignatureImage.RowBytes * SignatureImage.Height; int bytes = SignatureImage.ByteCount; MemoryStream stream = new MemoryStream(); SignatureImage.Compress(Bitmap.CompressFormat.Png, 0, stream); byte[] bitmapData = stream.ToArray(); bool uploadsign = SQL_Functions.uploadSignature(bitmapData); Toast.MakeText(Activity, "Signature Uploaded", ToastLength.Short).Show(); } catch (Exception ex) { new Android.Support.V7.App.AlertDialog.Builder(Activity).SetTitle("Indigent App Error").SetMessage("Upload failed: " + ex.Message + "\n \nPlease try again later").SetCancelable(true).Show(); } Dismiss(); }
private void CompleteButton_Click(object sender, EventArgs e) { CheckOutSignatureViewModel viewModel = this.ViewModel as CheckOutSignatureViewModel; if (_signaturePad.IsBlank) { viewModel.DriverSignature = null; } else { var image = _signaturePad.GetImage(AndroidGraphics.Color.Black, AndroidGraphics.Color.White, 0.5f, shouldCrop: false); using (var ms = new MemoryStream()) { image.Compress(AndroidGraphics.Bitmap.CompressFormat.Png, 0, ms); viewModel.DriverSignature = Convert.ToBase64String(ms.ToArray()); } viewModel.CompleteCommand.Execute(null); } }
void DoneButton_Click(object sender, EventArgs e) { var viewModel = (InstructionSignatureViewModel)ViewModel; if (signaturePad.IsBlank || !viewModel.IsSignaturePadEnabled) { viewModel.CustomerSignatureEncodedImage = null; } else { var image = signaturePad.GetImage(AndroidGraphics.Color.Black, AndroidGraphics.Color.White, 0.5f, shouldCrop: false); using (var ms = new MemoryStream()) { image.Compress(AndroidGraphics.Bitmap.CompressFormat.Png, 0, ms); viewModel.CustomerSignatureEncodedImage = Convert.ToBase64String(ms.ToArray()); } } viewModel.InstructionDoneCommand.Execute(null); }
private async void DoneButton_Click(object sender, EventArgs e) { //TODO: can we achieve this using data binding? var viewModel = (SafetyCheckSignatureViewModel)ViewModel; if (_signaturePad.IsBlank) { viewModel.SignatureEncodedImage = null; } else { var image = _signaturePad.GetImage(AndroidGraphics.Color.Black, AndroidGraphics.Color.White, 0.5f, shouldCrop: false); using (var ms = new MemoryStream()) { image.Compress(AndroidGraphics.Bitmap.CompressFormat.Png, 0, ms); viewModel.SignatureEncodedImage = Convert.ToBase64String(ms.ToArray()); } } await viewModel.DoneAsync(); }
private void CaptureSignature() { signature = new SignaturePadView(new CGRect(100, 100, 400, 400)) { StrokeWidth = 3f }; var button = new UIButton(UIButtonType.RoundedRect); button.Frame = new CGRect(400, 505, 100, 50); button.SetTitle("Done", UIControlState.Normal); button.BackgroundColor = UIColor.DarkGray; button.TouchUpInside += (sender, e) => { if (signature.IsBlank) { return; } var image = signature.GetImage(); var imageEncoded = image.AsJPEG().GetBase64EncodedString(NSDataBase64EncodingOptions.None); var capture = new NSMutableDictionary(); capture.Add(NSObject.FromObject("signature"), NSObject.FromObject(imageEncoded)); capture.Add(NSObject.FromObject("refNum"), NSObject.FromObject(RefNumText.Text)); capture.Add(NSObject.FromObject("amount"), NSObject.FromObject(AMOUNT)); capture.Add(NSObject.FromObject("command"), NSObject.FromObject("capture")); CardReader.CaptureSignature(capture); button.RemoveFromSuperview(); signature.RemoveFromSuperview(); }; View.AddSubview(signature); View.AddSubview(button); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); var bounds = UIScreen.MainScreen.Bounds; loading = new LoadingOverlay(bounds, "Updating Signature"); this.SetToolbarItems(new UIBarButtonItem[] { new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (s, e) => { DismissViewController(true, null); Console.WriteLine("Cancel clicked"); }) , new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace) { Width = 50 } , new UIBarButtonItem(UIBarButtonSystemItem.Save, async(s, e) => { //var detail = this.Storyboard.InstantiateViewController("IndigentApplicantsViewController") as IndigentApplicantsViewController; //NavigationController.PopViewController(true); var img = signature.GetImage(); try { // show the loading overlay on the UI thread using the correct orientation sizi View.Add(loading); using (NSData imageData = img.AsPNG()) { Byte[] myByteAray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteAray, 0, Convert.ToInt32(imageData.Length)); await Task.Delay(1000); bool upload = uploadSignature(myByteAray); loading.Hide(); } new UIAlertView("Sucess", "Signature Updated", null, "Ok", null).Show(); } catch (Exception ex) { new UIAlertView("Error", ex.Message, null, "Ok", null).Show(); //new Android.Support.V7.App.AlertDialog.Builder(Activity).SetTitle("Indigent App Error").SetMessage("Upload failed: " + ex.Message + "\n \nPlease try again later").SetCancelable(true).Show(); } backFromsign = true; DismissViewController(true, null); Console.WriteLine("Save clicked"); }) }, false); this.NavigationController.ToolbarHidden = false; }
public override async void ViewDidLoad() { base.ViewDidLoad(); var verifica = new LAContext(); var autoriza = await verifica.EvaluatePolicyAsync (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Autenticación FaceID"); if (autoriza.Item1) { var voz = new AVSpeechUtterance("Está usted autorizado en la Aplicación, sea Bienvenido"); voz.Voice = AVSpeechSynthesisVoice.FromLanguage("es-MX"); habla.SpeakUtterance(voz); lblEstatus.Text = "Autorizado"; } else { lblEstatus.Text = "No Autorizado"; var Gravedad = new UIGravityBehavior(Imagen, btnConfirmar, btnGuardar, lblEstatus); var Colision = new UICollisionBehavior(Imagen, btnConfirmar, btnGuardar, lblEstatus) { TranslatesReferenceBoundsIntoBoundary = false }; var Rebote = new UIDynamicItemBehavior(btnConfirmar) { Elasticity = 1f }; Animador = new UIDynamicAnimator(View); Animador.AddBehaviors(Gravedad, Colision, Rebote); System.Threading.Thread.CurrentThread.Abort(); } var Firma = new SignaturePadView(View.Frame) { StrokeWidth = 3f, StrokeColor = UIColor.Black, BackgroundColor = UIColor.White, }; Firma.Frame = new CGRect(10, 500, 350, 200); Firma.Layer.BorderWidth = 1f; Firma.SignaturePrompt.TextColor = UIColor.Blue; Firma.Caption.TextColor = UIColor.White; Firma.Caption.Text = "Firmar en esta zona"; View.AddSubview(Firma); btnConfirmar.TouchUpInside += delegate { Imagen.Image = Firma.GetImage(); }; btnGuardar.TouchUpInside += delegate { var imagenfirma = Firma.GetImage(); try { imagenfirma.SaveToPhotosAlbum(delegate (UIImage imagen, NSError error) { }); lblEstatus.Text = "Guardado en biblioteca"; } catch (Exception ex) { lblEstatus.Text = ex.Message; } }; }
private void SalvaPedidoPDF() { try { //O PDF sempre será salvo no sdcard string caminho = "mnt/sdcard/Download/invoice.pdf"; System.IO.FileStream fs = new System.IO.FileStream(caminho, System.IO.FileMode.Create); //Create an instance of the document class which represents the PDF document itself. Document document = new Document(PageSize.A4, 25, 25, 30, 30); //Create an instance to the PDF file by creating an instance of the PDF Writer class, using the document and the filestrem in the constructor. PdfWriter writer = PdfWriter.GetInstance(document, fs); //Open the document to enable you to write to the document document.Open(); //Adiciona título Paragraph pgTitulo = new Paragraph(); pgTitulo.Add("Pedido"); pgTitulo.Alignment = Element.ALIGN_CENTER; BaseFont bfTitulo = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); pgTitulo.Font = new Font(bfTitulo, Font.BOLD); document.Add(pgTitulo); // Add a simple and well known phrase to the document in a flow layout manner Paragraph pgPedido = new Paragraph("Pedido: " + FindViewById <TextView>(Resource.Id.txtNumOrdem).Text); pgPedido.Add(" "); pgPedido.Add("Data: " + FindViewById <TextView>(Resource.Id.txtData).Text); pgPedido.Add(" "); pgPedido.Add("Hora: " + FindViewById <TextView>(Resource.Id.txtHora).Text); pgPedido.Alignment = Element.ALIGN_LEFT; pgPedido.SpacingBefore = 20; document.Add(pgPedido); Paragraph pgNome = new Paragraph("Cliente: " + FindViewById <TextView>(Resource.Id.txtNome).Text); pgNome.Alignment = Element.ALIGN_LEFT; document.Add(pgNome); Paragraph pgObservacao = new Paragraph("Observação Geral: " + FindViewById <TextView>(Resource.Id.txtObsGeral).Text); pgObservacao.Alignment = Element.ALIGN_LEFT; document.Add(pgObservacao); PdfPTable myTable = new PdfPTable(3); myTable.WidthPercentage = 100; myTable.HorizontalAlignment = 0; myTable.SpacingBefore = 20; myTable.SpacingAfter = 10; float[] sglTblHdWidths = new float[3]; sglTblHdWidths[0] = 300f; sglTblHdWidths[1] = 60f; sglTblHdWidths[2] = 70f; myTable.SetWidths(sglTblHdWidths); PdfPCell CellOneHdr = new PdfPCell(new Phrase("Produto")); CellOneHdr.HorizontalAlignment = Element.ALIGN_CENTER; myTable.AddCell(CellOneHdr); PdfPCell CellTwoHdr = new PdfPCell(new Phrase("Qtde")); CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER; myTable.AddCell(CellTwoHdr); PdfPCell CellFourHdr = new PdfPCell(new Phrase("Preço")); CellFourHdr.HorizontalAlignment = Element.ALIGN_CENTER; myTable.AddCell(CellFourHdr); foreach (Produto produto in ListaImprimir) { PdfPCell CellOne = new PdfPCell(new Phrase(produto.DESCR_MAT_CADMAT)); CellOne.HorizontalAlignment = Element.ALIGN_LEFT; myTable.AddCell(CellOne); PdfPCell CellTwo = new PdfPCell(new Phrase(produto.QTD_CADMAT.ToString())); CellTwo.HorizontalAlignment = Element.ALIGN_CENTER; myTable.AddCell(CellTwo); PdfPCell CellFour = new PdfPCell(new Phrase(Convert.ToDouble(produto.PRECO_UNIT).ToString("N2"))); CellFour.HorizontalAlignment = Element.ALIGN_RIGHT; myTable.AddCell(CellFour); } document.Add(myTable); Paragraph pgTotal = new Paragraph("Total do Pedido: " + FindViewById <TextView>(Resource.Id.txtTotal).Text); pgTotal.Alignment = Element.ALIGN_RIGHT; pgTotal.SpacingAfter = 30; document.Add(pgTotal); // Converte a assinatura para byte, e depois para iTextImage SignaturePadView signature = FindViewById <SignaturePadView>(Resource.Id.signatureView); Android.Graphics.Bitmap imagen = signature.GetImage(Android.Graphics.Color.Black, Android.Graphics.Color.White); MemoryStream fstream = new MemoryStream(); imagen.Compress(Bitmap.CompressFormat.Jpeg, 100, fstream); byte[] result = fstream.ToArray(); fstream.Flush(); //Adiciona assinatura ao documento Image imgAssinatura = Image.GetInstance(result); imgAssinatura.ScaleAbsolute(300f, 30f); imgAssinatura.Alignment = Element.ALIGN_CENTER; imgAssinatura.SpacingBefore = 20; document.Add(imgAssinatura); Paragraph pgAssinatura = new Paragraph(); pgAssinatura.Add("Cliente: Sara A. H."); pgAssinatura.Alignment = Element.ALIGN_CENTER; document.Add(pgAssinatura); //Adiciona Copyright Paragraph pgFooter = new Paragraph(); pgFooter.Add("Sara Honorato © 2016 All rights reserved "); pgFooter.Alignment = Element.ALIGN_RIGHT; pgFooter.SpacingBefore = 20; pgFooter.SpacingAfter = 20; document.Add(pgFooter); // Close the document document.Close(); // Close the writer instance writer.Close(); // Always close open file handles explicitly fs.Close(); // Abre o pdf salvo OpenPdf(caminho); } catch (System.Exception ex) { Toast toast = Toast.MakeText(this, "Erro: " + ex.Message, ToastLength.Long); toast.SetGravity(GravityFlags.CenterVertical | GravityFlags.CenterHorizontal, 0, 0); toast.Show(); } }