How to create an Electronic Signature Capture in Android using Basic4Android
Submitted by donbermoy on Tuesday, February 4, 2014 - 17:47.
Good day! This is my other tutorial on Android creating a Signature Capture using Basic4Android.
An electronic signature is any electronic means that indicates either that a person adopts the contents of an electronic message, or more broadly that the person who claims to have written a message is the one who wrote it and that the message received is the one that was sent. By comparison, a signature is a stylized script associated with a person. In commerce and the law, a signature on a document is an indication that the person adopts the intentions recorded in the document. Thus, creating this electronic signature that can capture of what you entered will be an advantage to the people.
On this, you need to create one panel and named it as "Panel1", two buttons named btnClear and btnSave. Next, named your abstract design as "1". Your abstract designer will be like this one below:
Declare your variable in the Sub_Global like this:
- Sub Globals
- Dim Panel1 As Panel
- Dim Canvas1 As Canvas
- Dim SD As SignatureData 'This object holds the data required for SignatureCapture
- End Sub
Note:
Dim SD As SignatureData
holds the data required for SignatureCapture.
First, we will have to create another module named SignatureCapture as our Code Module aside from our Main Activity Module. Write the following code below in the created Code Module.
- Sub Process_Globals
- Dim px, py As Int
- Type SignatureData (Canvas As Canvas, Panel As Panel, SignatureColor As Int, SignatureWidth As Int)
- End Sub
- Sub Panel_Touch(SD As SignatureData, x As Int,y As Int, Action As Int)
- If Action = 0 Then 'mouse down constant
- px = x
- py = y
- Else
- SD.Canvas.DrawLine(px, py, x, y, SD.SignatureColor, SD.SignatureWidth)
- SD.Panel.Invalidate
- px = x
- py = y
- End If
- End Sub
- Sub Clear(SD As SignatureData)
- SD.Canvas.DrawColor(Colors.White)
- SD.Panel.Invalidate
- End Sub
- Sub Save(SD As SignatureData, Dir As String, Name As String)
- Dim out As OutputStream
- out = File.OpenOutput(Dir, Name, False)
- SD.Canvas.Bitmap.WriteToStream(out, 100, "PNG")
- out.Close
- End Sub
Note:
In ourSub Panel_Touch(SD As SignatureData, x As Int,y As Int, Action As Int)
procedure, we make our signature that can be inputted with a canvas to draw a line with a black color.
In our Sub Save(SD As SignatureData, Dir As String, Name As String)
we put it in this procedure that we save the created signature in File Directory in the SD Card and put as an image of .png extension.
In our Sub Clear(SD As SignatureData)
, we clear the value of our inputted signature in the panel.
Now create our Main Activity. Type the following code below:
- Sub Activity_Create(FirstTime As Boolean)
- Activity.LoadLayout("1")
- Canvas1.Initialize(Panel1)
- SD.Initialize
- SD.Canvas = Canvas1
- SD.Panel = Panel1
- SD.SignatureColor = Colors.Black
- SD.SignatureWidth = 5dip 'Stroke width
- End Sub
Note:
SD.Panel = Panel1
- this syntax holds the signature input in the Panel1.
SD.SignatureColor = Colors.Black
- this syntax turns the Signature color in Black.
SD.SignatureWidth = 5dip
- this syntax turns the Signature stroke in 5dip.
Now your activity when run will look like this:
Now type the folllowing code below:
- Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
- SignatureCapture.Panel_Touch(SD, X, Y, Action)
- End Sub
- Sub btnSave_Click
- SignatureCapture.Save(SD, File.DirRootExternal, "sign.png")
- ToastMessageShow("Signature saved to: " & File.Combine(File.DirRootExternal, "sign.png"), True)
- 'The next line will load the image and set it as the activity background.
- Activity.SetBackgroundImage(LoadBitmap(File.DirRootExternal, "sign.png"))
- End Sub
- Sub btnClear_Click
- SignatureCapture.Clear(SD)
- End Sub
Note:
We already call the value in our Code Module to the specific buttons with their certain functions. Now, you can write your signature in the panel and will look like this. this is just an example of my signature. Then click the Save button and it will save in the SD card and then it will set as your Activity Background like this one below. Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer STI College - Surigao City Mobile: 09488225971 E-mail:[email protected] Follow and add me in my Facebook Account: https://www.facebook.com/donzzskyComments
Add new comment
- Add new comment
- 163 views