B4A Library SpeedometerView

1.png


The attached project wraps this Github project. The library files are in the /files folder of the attached B4A project. Copy them to your additional libraries folder. I have also added JavaObject.XML and JavaObject.JAR in the /files folder for in case you do not have the latest version. Copy these two files to your default B4A libraries folder.

Attached the B4A project as well as the java source code. The meter at top left will display the present battery level of your device while the meter at the bottom right has been set to a value of 95. You can adjust the color ranges to your liking.

Enjoy!

speedometerview
Author:
Johan Schoeman
Version: 1
  • SpeedometerView
    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)
    • addColoredRange (begin As Double, end As Double, color As Int)
    • clearColoredRanges
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • DefaultColor As Int
    • Enabled As Boolean
    • Height As Int
    • LabelTextSize As Int
    • Left As Int
    • MajorTickStep As Double
    • MaxSpeed As Double
    • MinorTicks As Int
    • Speed As Double
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • b4aSpeedometerView.zip
    86.4 KB · Views: 585
  • src.zip
    32.7 KB · Views: 506

ArminKH

Well-Known Member
thank u
is this cutomizable?
for example change the speed indicator to our own image
 

Johan Schoeman

Expert
Licensed User
Longtime User
thank u
is this cutomizable?
for example change the speed indicator to our own image
Unfortunately not Armin - 99% of the image is drawn by the project that has been wrapped. Only the centre dot that the needle protrudes from comes from a PNG file. :)
 

jh201161

New Member
Licensed User
Longtime User
Hello Johan,

I have tested your SpeedometerView. It runs with your example.
But when I try to add the view in my application I get the following error during execution of the Activity.LoadLayout Statement

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at Wolpert.Info.main.afterFirstLayout(main.java:102)
at Wolpert.Info.main.access$000(main.java:17)
at Wolpert.Info.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:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 17 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at main.java.com.cardiomood.android.speedometer.SpeedometerView.init(SpeedometerView.java:397)
at main.java.com.cardiomood.android.speedometer.SpeedometerView.<init>(SpeedometerView.java:62)
at speedometerviewwrapper.speedoMeterViewWrapper._initialize(speedoMeterViewWrapper.java:58)
... 20 more

best regards

Jürgen
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hello Johan,

I have tested your SpeedometerView. It runs with your example.
But when I try to add the view in my application I get the following error during execution of the Activity.LoadLayout Statement

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at Wolpert.Info.main.afterFirstLayout(main.java:102)
at Wolpert.Info.main.access$000(main.java:17)
at Wolpert.Info.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:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 17 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at main.java.com.cardiomood.android.speedometer.SpeedometerView.init(SpeedometerView.java:397)
at main.java.com.cardiomood.android.speedometer.SpeedometerView.<init>(SpeedometerView.java:62)
at speedometerviewwrapper.speedoMeterViewWrapper._initialize(speedoMeterViewWrapper.java:58)
... 20 more

best regards

Jürgen
Can you upload your project?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Dear Johan,
Exact problem faced by me!
With my project in post #1 or with your own project? If your own project - can you upload it (or put it in Dropbox and PM me the link)?
 

rbghongade

Active Member
Licensed User
Longtime User
Dear Johan,
Your example works flawlessly! My project exhibits this error. Some observations:
1. The error occurs while executing the layout
2. Any other custom view object (different library) if combined with this library causes the same problem
 

Attachments

  • BA_CLIENT_DS18B20 V3.zip
    9.2 KB · Views: 270
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Dear Johan,
Your example works flawlessly! My project exhibits this error. Some observations:
1. The error occurs while executing the layout
2. Any other custom view object (different library) if combined with this library causes the same problem
Take a look inside the /Objects/res/drawable folder of the B4A project that I have posted. There is a png file (spot_mask.png) that is missing from your project. Make sure this file is there and that it is set to READ ONLY.

EDIT:
I have done a small modification to your project - have moved the additional resources to the /Resources folder and have uncommented
B4X:
#AdditionalRes: ..\Resources

It should prevent similar problems where the READ ONLY property for some reason gets changed when unzipping the zipped file.

1.png
 

Attachments

  • BA_CLIENT_DS18B20 V3.zip
    495.3 KB · Views: 333
Last edited:

rbghongade

Active Member
Licensed User
Longtime User
Dear Johan,
Thanks for the reply and the great library. It works great now!
Donated USD 5.00 (455610034R551454W)
regards,
 

Attachments

  • Screenshot.png
    Screenshot.png
    123 KB · Views: 306
Last edited:

SumanR

Member
Licensed User
Dear All,
I want to move speedometer hand on the basis my input in EditTextbox.
How Can I use this speedometer as this way?
Thanka
 

DonManfred

Expert
Licensed User
Longtime User
How Can I use this speedometer as this way?
B4X:
speedometer.speed = 5
?

With opther word. RTFM (read the fine Manual (Documentation).
Try what you can find. If you THEN have a question. Ask it.

But i fear you DID NOT SEARCH at all

To be honest: I do not have the library installed and i did not checked the Example! I JUST looked at Post #1 of this thread and found a possible answer. It took me a few seconds to find the answer
 
Last edited:
Top