B4A Library FreeDrawView

A partial wrap for this Github project - do with it as you like.

1.gif


Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aFreeDrawView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private fdv1 As FreeDrawView
  
    Private btnRedo As Button
    Private btnUndo As Button
    Private btnUndoAll As Button
    Private btnRedoAll As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    fdv1.PaintColor = Colors.Red
    fdv1.PaintAlpha = 255
    fdv1.PaintWidthDp = 5


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnRedo_Click
  
    fdv1.redoLast
  
End Sub

Sub btnUndo_Click
  
    fdv1.undoLast
  
End Sub

Sub btnUndoAll_Click
  
    fdv1.undoAll
  
End Sub

Sub btnRedoAll_Click
  
    fdv1.redoAll
  
End Sub

Library:

FreeDrawView
Version:
1
  • FreeDrawView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • redoAll
      Re-add all the removed paths and redraw
    • redoLast
      Re-add the first removed path and redraw
    • undoAll
      Remove all the paths and redraw (can be undone with {@link #redoLast()})
    • undoLast
      Cancel the last drawn segment
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • PaintAlpha As Int [write only]
      Set the paint opacity, must be between 0 and 1
    • PaintColor As Int [write only]
    • PaintWidthDp As Float [write only]
      Set the paint width in dp
    • PaintWidthPx As Float [write only]
      Set the paint width in px
    • Parent As Object [read only]
    • RedoCount As Int [read only]
      Get how many redo operations are available
    • Tag As Object
    • Top As Int
    • UndoCount As Int [read only]
      Get how many undo operations are available
    • Visible As Boolean
    • Width As Int
 

Attachments

  • TheJavaCode.zip
    50.1 KB · Views: 297
  • b4aFreeDrawView.zip
    402.3 KB · Views: 312
  • FreeDrawViewLibFiles.zip
    18.9 KB · Views: 297

Johan Schoeman

Expert
Licensed User
Longtime User
Have updated it so that:
1. You can set the background color of the view that you draw on
2. Return a bitmap of the drawing

1.png
 

Attachments

  • FreeDrawViewLibFiles.zip
    19.5 KB · Views: 270
  • TheJavaCode.zip
    50.9 KB · Views: 259
  • b4aFreeDrawView.zip
    405.3 KB · Views: 275

Mahares

Expert
Licensed User
Longtime User
Johan really deserves the utmost respect for his continual contributions, achievements and libraries in this forum. I created a little project modeled after his example by adding a couple of things to his sample and changed it slightly to suit KIDS play. I also included a timer that changes the text color every few seconds. It also allows one to save the text or image they create to a file. If someone likes to add more kids features to it and post, that will be great. Johan has a pretty good idea why I did what I did. Attached is the project.
 

Attachments

  • FreeDrawViewKidsPlay123016.zip
    8.9 KB · Views: 261

Johan Schoeman

Expert
Licensed User
Longtime User
Johan really deserves the utmost respect for his continual contributions, achievements and libraries in this forum. I created a little project modeled after his example by adding a couple of things to his sample and changed it slightly to suit KIDS play. I also included a timer that changes the text color every few seconds. It also allows one to save the text or image they create to a file. If someone likes to add more kids features to it and post, that will be great. Johan has a pretty good idea why I did what I did. Attached is the project.
Hi Ali - 3 things:
1. Thanks for the kind words - much appreciated
2. Your zipped project does not include the /LibRes folder - that is required. I am attaching it to this post. It should be extracted and copied to the B4A project so that folder LibRes is on the same folder level as that of the /Files and /Objects folders of the B4A project
3. There seems to be a problem with your main.bal layout file. App wont run and when I open Designer I get the following error - error in app occurs in
Activity.LoadLayout("main"). Not sure why it happens....

error_layout.png
 

Attachments

  • LibRes.zip
    669 bytes · Views: 278

Mahares

Expert
Licensed User
Longtime User
. There seems to be a problem with your main.bal layout file
Hi Johan:
1 I added the LibRes folder, although I thought it would be automatically added when I export and zip. But it is the new zip attached now.
2. As for the .bal file, I am not sure what it is giving you the error, because mine works well on 3 tested devices: OS 4.2.2, OS 5.1.1 and 6.0.1
I can PM you separately the .bal file if you want to check it out on your devices. The attached project was tested on 3 devices.
 

Attachments

  • FreeDrawView123116.zip
    10.3 KB · Views: 253

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan:
1 I added the LibRes folder, although I thought it would be automatically added when I export and zip. But it is the new zip attached now.
2. As for the .bal file, I am not sure what it is giving you the error, because mine works well on 3 tested devices: OS 4.2.2, OS 5.1.1 and 6.0.1
I can PM you separately the .bal file if you want to check it out on your devices. The attached project was tested on 3 devices.
Very strange - get the same error with your project in post #6 when the layout is loaded....Let me try a different device
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan:
1 I added the LibRes folder, although I thought it would be automatically added when I export and zip. But it is the new zip attached now.
2. As for the .bal file, I am not sure what it is giving you the error, because mine works well on 3 tested devices: OS 4.2.2, OS 5.1.1 and 6.0.1
I can PM you separately the .bal file if you want to check it out on your devices. The attached project was tested on 3 devices.
Same error on a different device...
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 345)
java.lang.RuntimeException: java.lang.RuntimeException: unknown type
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at b4a.example.main._activity_create(main.java:345)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5643)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.RuntimeException: unknown type
    at anywheresoftware.b4a.ConnectorUtils.readMap(ConnectorUtils.java:144)
    at anywheresoftware.b4a.ConnectorUtils.readMap(ConnectorUtils.java:133)
    at anywheresoftware.b4a.ConnectorUtils.readMap(ConnectorUtils.java:133)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:140)
    ... 16 more
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan:
1 I added the LibRes folder, although I thought it would be automatically added when I export and zip. But it is the new zip attached now.
2. As for the .bal file, I am not sure what it is giving you the error, because mine works well on 3 tested devices: OS 4.2.2, OS 5.1.1 and 6.0.1
I can PM you separately the .bal file if you want to check it out on your devices. The attached project was tested on 3 devices.
Hi Ali - can you post your Designer Script code? Will use it to regenerate main.bal
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan:
1 I added the LibRes folder, although I thought it would be automatically added when I export and zip. But it is the new zip attached now.
2. As for the .bal file, I am not sure what it is giving you the error, because mine works well on 3 tested devices: OS 4.2.2, OS 5.1.1 and 6.0.1
I can PM you separately the .bal file if you want to check it out on your devices. The attached project was tested on 3 devices.
Very strange...Have copied your B4A code (Main Activity) into my project in post #3 and then it works 100% when using my original layout. This is puzzling....

1234.png
 

DonManfred

Expert
Licensed User
Longtime User
Today i was searching for a more flexible Signature pad or something. I found exactly this Github project and did a fast wrap for it. It is already done :)
Then i decided to check if there is such lib alread in forum and i found this thread :D
 
Top