B4A Library LEDView

This is a wrap for this Githubproject.

LEDView
Version:
1
  • LEDView
    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)
    • initLED (str As String, ledColor As Int, ledTextSize As Int, ledPixel As Int)
    • run
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • LEDColor As Int [read only]
    • LEDText As String [read only]
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Attached:
LedViewEx.zip The Example
LEDViewVx.x.zip The Library (copy the content to your additional libs folder)
Java source

Unfortunately the lib (Github-project) does not provide much properties.
And i dont know how to change the speed or to stop the animation...
 

Attachments

  • java-src.zip
    4.2 KB · Views: 393
  • LEDViewV1.0.zip
    9.4 KB · Views: 468
  • LEDViewEx.zip
    7.8 KB · Views: 464
Last edited:

jimmyF

Active Member
Licensed User
Longtime User
Very cool! :)
Thank you for this.
 

jimmyF

Active Member
Licensed User
Longtime User
When I do this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    LED.initLED("My string of text",Colors.Magenta,28,120)
    LED.run
End Sub

It all works except the text does not change from your default text.
It still displays "Hello LED". The other parameters take effect.
 

Peter Simpson

Expert
Licensed User
Longtime User

demasi

Active Member
Licensed User
Longtime User
Good Job! This is a very nice looking view.
You included the lib's java source, so how we can do to compile this lib source? Using Eclipse? I know a little java but only using inline in B4A.
I want to learn more about creating java libs and how to wrap java projects.
Thank you.
 

Peter Simpson

Expert
Licensed User
Longtime User
When I do this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    LED.initLED("My string of text",Colors.Magenta,28,120)
    LED.run
End Sub

It all works except the text does not change from your default text.
It still displays "Hello LED". The other parameters take effect.

Jimmy, you can use Sleep(0) followed by LED.initLED to clear text or write new text, you can then keep changing the text without using Sleep.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
 
    Sleep(0)
    LED.initLED("Hello Jimmy", Colors.Green, 16, 60)
End Sub
 
Last edited:

jimmyF

Active Member
Licensed User
Longtime User
Bingo!
Thanks Peter! Works like a charm!
 

Didier9

Well-Known Member
Licensed User
Longtime User
I would like to check this example but this is apparently incompatible with B4A v6.31.
The error seems to come from the library itself. Do I need to upgrade or is there a work around for v6.31?
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 31 (Main)
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 java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    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:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5343)
    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:905)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
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)
    ... 20 more
** Activity (main) Resume **
 

Didier9

Well-Known Member
Licensed User
Longtime User
The error comes from the layout file which is not compatible with B4A v6.3. You will need to recreate the layout file.

When trying to add the LEDView to the layout, I get an error "The given key was not present in the dictionary".

I know I should just upgrade, but my copy is not yet a year old and I am trying to old on for another 3 months...

I want to understand the potential difficulties in running an older version of the tool, so this is more like an exercise.

If it just will not work, that's OK, but I want to know if I should even try.

Thanks again for your help.
 

Didier9

Well-Known Member
Licensed User
Longtime User
Remove the layout from the example. It is made with b4a 7. Create a new layout with your b4a version.

This is what I did. When I tried to add the LEDView custom view, I got the error message "The given key was not present in the dictionary" in the designer.
 

Attachments

  • Designer error.png
    Designer error.png
    77.8 KB · Views: 322

Didier9

Well-Known Member
Licensed User
Longtime User
B4A version 6.31

Java: C:\Program Files (x86)\Java\jdk1.8.0_102\bin\javac.exe

SDK: C:\Android\android-sdk\platforms\android-16\android.jar

I tried it on two different computers, both running Win 7 64bit and I believe both have the same version of java and sdk. I get the same error on both.
 
Top