B4A Library CircleProgressMaster

Similar threads

B4A Library IPCamView
B4A Library PDFium - Pdfview2
B4A Library msEmoji V1.0.0
B4A Library CreditsRollView V1.0.0
B4A Library VRCalendarView
B4A Library Firebase Realtimedatabase

Johan Schoeman

Expert
Licensed User
The attached project wraps this Github project. Library files are in the /files folder of the attached B4A project. Copy them to your additional libraries folder.
The ArcProgress view (second from right) and the DonutProgress view indicate the actual battery level of my device. Have added some inline Java code to extract the battery level. It uses the JavaObject Library and I have therefore included JavaObject XML and JAR in the /files folder of the attached project (for in case someone don't have them or has an older version of it).
Also attaching the Java source code (src.zip)
Thanks teacher....;)

Edit: See update in post #6


pic2.png

CircleProgressMaster
Version:
1
  • ArcProgressMaster
    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)
    Properties:
    • ArcAngle As Float
    • Background As Drawable
    • BottomText As String
    • BottomTextSize As Float
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • Height As Int
    • Left As Int
    • Max As Int
    • Progress As Int
    • StrokeWidth As Float
    • SuffixText As String
    • SuffixTextPadding As Float
    • SuffixTextSize As Float
    • Tag As Object
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • Visible As Boolean
    • Width As Int
  • CircleProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedColor As Int [write only]
    • Height As Int
    • Left As Int
    • Max As Int [write only]
    • PrefixText As String [write only]
    • Progress As Int [write only]
    • SuffixText As String [write only]
    • Tag As Object
    • TextColor As Int [write only]
    • TextSize As Float [write only]
    • Top As Int
    • UnfinishedColor As Int [write only]
    • Visible As Boolean
    • Width As Int
  • DonutProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • FinishedStrokeWidth As Float
    • Height As Int
    • InnerBackgroundColor As Int
    • InnerBottomText As String
    • InnerBottomTextColor As Int
    • InnerBottomTextSize As Float
    • Left As Int
    • Max As Int
    • PrefixText As String
    • Progress As Int
    • SuffixText As String
    • Tag As Object
    • Text As String
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • UnfinishedStrokeWidth As Float
    • Visible As Boolean
    • Width As Int
 

Attachments

Last edited:
D

Deleted member 30048

Guest
Hi! There is a chance to change in which angle begins the progress on donut?

It always starts at the angle 0 (right of donut), would be great to have the option of deciding the starting angle, eg, 90 (above)

Sorry for my English. Thanks
 

Johan Schoeman

Expert
Licensed User
Hi! There is a chance to change in which angle begins the progress on donut?

It always starts at the angle 0 (right of donut), would be great to have the option of deciding the starting angle, eg, 90 (above)

Sorry for my English. Thanks
Here you go. New library files are in the /files folder of the B4A project. Copy them to your additional libraries folder. The attached B4A project demonstrates only the DonutProgressMaster with starting points at 0, 90, 180, and 270 degrees. Other code relating to the CircleProgress and ArcProgress have been commented out. Also posting the updated java source code.

pic3.png


CircleProgressMaster
Version:
1
  • ArcProgressMaster
    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)
    Properties:
    • ArcAngle As Float
    • Background As Drawable
    • BottomText As String
    • BottomTextSize As Float
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • Height As Int
    • Left As Int
    • Max As Int
    • Progress As Int
    • StrokeWidth As Float
    • SuffixText As String
    • SuffixTextPadding As Float
    • SuffixTextSize As Float
    • Tag As Object
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • Visible As Boolean
    • Width As Int
  • CircleProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedColor As Int [write only]
    • Height As Int
    • Left As Int
    • Max As Int [write only]
    • PrefixText As String [write only]
    • Progress As Int [write only]
    • SuffixText As String [write only]
    • Tag As Object
    • TextColor As Int [write only]
    • TextSize As Float [write only]
    • Top As Int
    • UnfinishedColor As Int [write only]
    • Visible As Boolean
    • Width As Int
  • DonutProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • FinishedStrokeWidth As Float
    • Height As Int
    • InnerBackgroundColor As Int
    • InnerBottomText As String
    • InnerBottomTextColor As Int
    • InnerBottomTextSize As Float
    • Left As Int
    • Max As Int
    • PrefixText As String
    • Progress As Int
    • StartAngle As Int [write only]
    • SuffixText As String
    • Tag As Object
    • Text As String
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • UnfinishedStrokeWidth As Float
    • Visible As Boolean
    • Width As Int
 

Attachments

Harris

Expert
Licensed User
Very nice....
I have tried others but this is so much LESS complex and all inclusive.

I do notice that one must invalidate the view else progress value text becomes a mess (98 will stack up on 97, 96, 95 and so on).

The code below is run on a timer (every 30 seconds)
B4X:
Sub IncPB1(np1 As ArcProgressMaster, val As Int, mymax As Int)

    Dim remain, maxVal, vdip As Int
    maxVal = mymax
      
    vdip = (val / maxVal) * 100
    remain = 100 - vdip
    np1.Progress = remain

    If (remain >= 15) And (remain <= 200) Then
               np1.FinishedStrokeColor = Colors.RGB(76,152,0) ' a nice green...
    Else If    (remain >= 10) And (remain < 15) Then
               np1.FinishedStrokeColor = Colors.Yellow
    Else
               np1.FinishedStrokeColor = Colors.Red
    End If
 
    np1.Invalidate

End Sub
WAIT.... Even with Invalidate the center value text is not clearing...
Very odd indeed... I must be doing something wrong.... Seems to happen when value gets below 90 percent????
See pic attached...

Thanks


overwrite.png
 

Attachments

Johan Schoeman

Expert
Licensed User
WAIT.... Even with Invalidate the center value text is not clearing...
Very odd indeed... I must be doing something wrong.... Seems to happen when value gets below 90 percent????
Have just tried the code below and seems to be working fine. Will look into your example when back from work this afternoon..

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

#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.
    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 cv1 As ArcProgressMaster
    Dim cnt As Int = 0
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",200)
    cv1.FinishedStrokeColor = Colors.Green
    cv1.StrokeWidth = 10
    cv1.Max = 200
    cv1.BottomText = "Testing"
    cv1.BottomTextSize = 20
    cv1.SuffixText = "  (a value)"
    cv1.SuffixTextSize = 20

End Sub

Sub Activity_Resume

t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

t.Enabled = False

End Sub
Sub t_tick

cnt = cnt + 1
If cnt = cv1.Max Then cnt = 0
cv1.Progress = cnt

End Sub
 

Johan Schoeman

Expert
Licensed User
Solution:

Don't declare np1 As ArcProgressMaster in Sub IncPB1. np1 (or whatever you might have used as a variable name in your declaration) should be declared in Sub Globals and will then be visible throughout the B4A main module code.

Change
Sub IncPB1(np1 As ArcProgressMaster, val As Int, mymax As Int)
to
Sub IncPB1(val As Int, mymax As Int)

and don't pass np1 (or whatever you might have used as a variable name in your declaration) as a parameter from the timer sub that calls Sub IncPB1. Use the variable name that you have declared in Sub Globals through out the B4A main module code.
 

Harris

Expert
Licensed User
It has been solved.
I was incorrectly adding this view in code over and over again - without removing the original view.

Thanks to Johan for pointing this out. The lib works great!
 

aidymp

Active Member
Licensed User
Here you go. New library files are in the /files folder of the B4A project. Copy them to your additional libraries folder. The attached B4A project demonstrates only the DonutProgressMaster with starting points at 0, 90, 180, and 270 degrees. Other code relating to the CircleProgress and ArcProgress have been commented out. Also posting the updated java source code.

View attachment 35887


CircleProgressMaster
Version:
1
  • ArcProgressMaster
    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)
    Properties:
    • ArcAngle As Float
    • Background As Drawable
    • BottomText As String
    • BottomTextSize As Float
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • Height As Int
    • Left As Int
    • Max As Int
    • Progress As Int
    • StrokeWidth As Float
    • SuffixText As String
    • SuffixTextPadding As Float
    • SuffixTextSize As Float
    • Tag As Object
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • Visible As Boolean
    • Width As Int
  • CircleProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedColor As Int [write only]
    • Height As Int
    • Left As Int
    • Max As Int [write only]
    • PrefixText As String [write only]
    • Progress As Int [write only]
    • SuffixText As String [write only]
    • Tag As Object
    • TextColor As Int [write only]
    • TextSize As Float [write only]
    • Top As Int
    • UnfinishedColor As Int [write only]
    • Visible As Boolean
    • Width As Int
  • DonutProgressMaster
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • FinishedStrokeColor As Int
    • FinishedStrokeWidth As Float
    • Height As Int
    • InnerBackgroundColor As Int
    • InnerBottomText As String
    • InnerBottomTextColor As Int
    • InnerBottomTextSize As Float
    • Left As Int
    • Max As Int
    • PrefixText As String
    • Progress As Int
    • StartAngle As Int [write only]
    • SuffixText As String
    • Tag As Object
    • Text As String
    • TextColor As Int
    • TextSize As Float
    • Top As Int
    • UnfinishedStrokeColor As Int
    • UnfinishedStrokeWidth As Float
    • Visible As Boolean
    • Width As Int
Hi,

Is it possible to use this in B4J?

Thanks

Aidy
 

Kwame Twum

Active Member
Licensed User
Hello everyone,
I tired to update progress of a DonutProgressMaster in a listview from a service..

B4X:
'Call from service
Sub download_Progress(progressvalue As Long, index As int)
If IsPaused(ActivityName) = False Then CallSub3(ActivityName, "Report_Prog",progressvalue,index)
B4X:
'ACTIVITY - (ActivityName)
Sub Report_Prog(value As Long,index As Int)
    Try
        Dim pon As Panel = cv.GetPanel(index)
        Dim card As MSCardView = pan.GetView(0)        'There's a cardview on the panel holding the DonutProgressMaster
        Dim prga As DonutProgressMaster = card.Panel.GetView(2)         'The DonutProgressMaster is the 3rd view on the cardview's panel
        prga.Progress = value
        Return
    Catch
        Log(LastException)
    End Try
End Sub
I get the following during compile:
B4X:
error: cannot find symbol
mostCurrent._prga.setObject((main.java.com.github.lzyzsd.circleprogress.DonutProgress)(_codx.getPanel().GetView((int) (2)).getObject()));
  symbol:   class java
  location: class main
Kindly note that this works when the respective view is a ProgressBar and not a DonutProgressMaster.
 

panagiotisden2

Active Member
Licensed User
hey Johan!
is it possible to change the side of the filled space?
let me explain it.
i want to convert this
pic2.png

to this(done in photoshop)


pic22.png

and the text to still be 47% not 53%?

thank you.
 

Johan Schoeman

Expert
Licensed User
Top