B4A Library GaugeView

This is a wrapper for the project that you can find here. The project is quite large and does not fit the max upload limits of the forum. Therefore I am uploading it in parts and will explain what to do:

1. GaugeView.zip is the B4A project
2. gaugeview.zip contains the library files (JAR & XML) - copy them to your additional library folder
3. res.zip is the res folder that should be in the /Objects folder of the B4A project
4. Files.zip is the Files folder of the B4A project.

Thus, the project should looks as follows when you assemble it (create a root directory called b4aGaugeView):

4baGaugeView
Files ----------> this is the attached Files.zip file​
Objects​

res ----------> this is the attached res.zip file
GaugeView (B4A Source Code) ----------> this is the attached GaugeView.zip file
As mentioned above, gaugeview.zip contains the library files (JAR & XML) - copy them to your additional library folder.

I have also uploaded the zipped project to DROPBOX in case someone has difficulty to reassemble the project.

The project makes use of the /Objects/res/values/arrays.xml and /Objects/res/values/attrs.xml files. They should therefore be included in any project that you might create from this.

Edit: Updated library files and explanation in post #3


GaugeView.png


You can download and test any posting of mine in this thread but if you want to use it then you need to
 

Attachments

  • GaugeView.zip
    1.2 KB · Views: 502
  • gaugeview.zip
    14.6 KB · Views: 487
  • res.zip
    291.3 KB · Views: 498
  • Files.zip
    30.5 KB · Views: 509
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
How do you change the limits of the gauge (from 0-100 to something else) ?
Attached are new library files (JAR & XML) that will allow you to set 1 of 8 possible maximum values (10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 750.0, 1000.0). Replace your library files with this.

Code example:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim t As Timer

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 gv As GaugeView
    Private Label1 As Label
    Dim ev As Float

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")

    t.Initialize("t",1500)
    gv.TargetValue = 0
    ev = 200.0                  'Set ev to one of the following values only else error will occur ---> 10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 750.0, 1000.0
    gv.ScaleEndValue = ev

End Sub

Sub Activity_Resume

t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

t.Enabled = False

End Sub
Sub t_tick

Dim tgtValue, upper As Int
upper = ev
tgtValue = Rnd(0,upper+1)
Label1.Text = "Random Value Generate = " & tgtValue
gv.TargetValue = tgtValue


End Sub

GaugeView
Version:
1
  • GaugeView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • 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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • ScaleEndValue As Float [write only]
    • ShowText As Boolean [write only]
    • Tag As Object
    • TargetValue As Float [write only]
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • GaugeView.zip
    14.8 KB · Views: 451
  • GaugeView.png
    GaugeView.png
    84 KB · Views: 425
Last edited:

RauchG

Active Member
Licensed User
Longtime User
It is also possible to determine the colors of the scaling itself?

ev < 50.0 = Colors.Red
ev >= 50.0 = Colors.Green

ev = 100.0
gv.ScaleEndValue = ev


greeting
RauchG
 

Johan Schoeman

Expert
Licensed User
Longtime User
It is also possible to determine the colors of the scaling itself?

ev < 50.0 = Colors.Red
ev >= 50.0 = Colors.Green

ev = 100.0
gv.ScaleEndValue = ev


greeting
RauchG
Not at present @RauchG. Java Code will need a bit of open heart surgery to do that - but not impossible to do.
 

u2005k

Member
Licensed User
Longtime User
Attached are new library files (JAR & XML) that will allow you to set 1 of 8 possible maximum values (10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 750.0, 1000.0). Replace your library files with this.

Code example:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim t As Timer

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 gv As GaugeView
    Private Label1 As Label
    Dim ev As Float

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")

    t.Initialize("t",1500)
    gv.TargetValue = 0
    ev = 200.0                  'Set ev to one of the following values only else error will occur ---> 10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 750.0, 1000.0
    gv.ScaleEndValue = ev

End Sub

Sub Activity_Resume

t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

t.Enabled = False

End Sub
Sub t_tick

Dim tgtValue, upper As Int
upper = ev
tgtValue = Rnd(0,upper+1)
Label1.Text = "Random Value Generate = " & tgtValue
gv.TargetValue = tgtValue


End Sub

GaugeView
Version:
1
  • GaugeView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • 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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • ScaleEndValue As Float [write only]
    • ShowText As Boolean [write only]
    • Tag As Object
    • TargetValue As Float [write only]
    • Top As Int
    • Visible As Boolean
    • Width As Int
Hi,

I am trying out GaugeView library and example above. However App crashes on Activity.LoadLayout("main") statement. Here is crash dump.
Installing file.
PackageAdded: package:b4a.gaugeview
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 34 (Main)
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 b4a.gaugeview.main._activity_create(main.java:358)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
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.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.gaugeview.main.afterFirstLayout(main.java:102)
at b4a.gaugeview.main.access$000(main.java:17)
at b4a.gaugeview.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5062)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:658)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 22 more
Caused by: java.lang.NullPointerException
at android.graphics.BitmapShader.<init>(BitmapShader.java:45)
at org.codeandmagic.android.gauge.GaugeView.getDefaultOuterRimPaint(GaugeView.java:388)
at org.codeandmagic.android.gauge.GaugeView.initDrawingTools(GaugeView.java:339)
at org.codeandmagic.android.gauge.GaugeView.init(GaugeView.java:295)
at org.codeandmagic.android.gauge.GaugeView.<init>(GaugeView.java:174)
at org.codeandmagic.android.gauge.GaugeView.<init>(GaugeView.java:182)
at gaugeviewrapper.gaugeViewWrapper._initialize(gaugeViewWrapper.java:54)
... 26 more
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


How to fix this error? DROPBOX link is also not working.

Thanks a lot
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi,

I am trying out GaugeView library and example above. However App crashes on Activity.LoadLayout("main") statement. Here is crash dump.
Installing file.
PackageAdded: package:b4a.gaugeview
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 34 (Main)
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 b4a.gaugeview.main._activity_create(main.java:358)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
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.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.gaugeview.main.afterFirstLayout(main.java:102)
at b4a.gaugeview.main.access$000(main.java:17)
at b4a.gaugeview.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5062)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:658)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 22 more
Caused by: java.lang.NullPointerException
at android.graphics.BitmapShader.<init>(BitmapShader.java:45)
at org.codeandmagic.android.gauge.GaugeView.getDefaultOuterRimPaint(GaugeView.java:388)
at org.codeandmagic.android.gauge.GaugeView.initDrawingTools(GaugeView.java:339)
at org.codeandmagic.android.gauge.GaugeView.init(GaugeView.java:295)
at org.codeandmagic.android.gauge.GaugeView.<init>(GaugeView.java:174)
at org.codeandmagic.android.gauge.GaugeView.<init>(GaugeView.java:182)
at gaugeviewrapper.gaugeViewWrapper._initialize(gaugeViewWrapper.java:54)
... 26 more
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


How to fix this error? DROPBOX link is also not working.

Thanks a lot

Here is the whole lot
https://www.dropbox.com/s/8he3vvewax82ske/b4aGaugeView.zip?dl=0
The library files are in the /Files folder of the B4A project. Copy them to your additional library folder.
 

u2005k

Member
Licensed User
Longtime User
Hi Johan,

Thanks a lot. It worked well. As a token of appreciation of your work I am donating USD 10.

Regards...
Uday
 

u2005k

Member
Licensed User
Longtime User
Hi Johan,

Can you please guide me on how to change the scale color? In your example 0-10 is Red, 10-20 is Orange then Yellow and finally Green.
In my App I want say 0-50 Green, 50-80 Yellow and 80-100 Red.

Thanks a lot.
Regards...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Can you please guide me on how to change the scale color? In your example 0-10 is Red, 10-20 is Orange then Yellow and finally Green.
In my App I want say 0-50 Green, 50-80 Yellow and 80-100 Red.

Thanks a lot.
Regards...
See post #5
 

u2005k

Member
Licensed User
Longtime User
Hi Johan,
Thanks a lot for quick reply but it is very important in our project. Any suggestions?

Regards...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,
Thanks a lot for quick reply but it is very important in our project. Any suggestions?

Regards...
I will have to revisit the project and try and do some amendments to the original code posted in Github. Will look into that later this week.
 

u2005k

Member
Licensed User
Longtime User
Hi Johan,

In the meantime if you can post source for this view (B4A wrapper) and let me see if I can make these changes. If I am successful, I will post updated library and changed source code back to you.

Thanks & regards...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

In the meantime if you can post source for this view (B4A wrapper) and let me see if I can make these changes. If I am successful, I will post updated library and changed source code back to you.

Thanks & regards...

Here you go....
 

Attachments

  • TheJavaCode.zip
    10.2 KB · Views: 313
Top