B4A Library ProgressWheel

Johan Schoeman

Expert
Licensed User
The attached project wraps this. Library files are in the /files folder of the attached project. Copy them to your additional libraries folder. Play around with the calls to the 29 different methods presented in the code. It uses file attrs.xml in the Object/res/values folder.

Enjoy

(Thanks Teacher...;))

ProgressWheel.png

Some sample code:
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 pw1, pw2 As ProgressWheel
    Dim brlng As Int = 0

    Private pw3 As ProgressWheel
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",50)

    pw1.CircleColor = Colors.ARGB(100,0,0,255)
    pw1.BarLength = brlng
    pw1.RimColor = Colors.Yellow
    pw1.RimWidth = 20                          'limit this to 20
    pw1.BarColor = Colors.Red
    pw1.BarWidth = 20
    pw1.Left = 10%x
    pw1.Width = 20%x
    pw1.Height = 20%x
    pw1.Top = 50%y - (pw1.Height/2)
    pw1.ContourColor = Colors.Green            'make the contour around the inner and outer of the blue rim grey
    pw1.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw1.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw1.Text = "B4A"
    pw1.TextColor = Colors.LightGray
    pw1.TextSize = 20
    pw1.PaddingBottom = 30
    pw1.PaddingLeft = 10
    pw1.PaddingTop = 30
    pw1.PaddingRight = 10
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFFFF, 0xFFFFFFFF)
'    pw1.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw1.spin

    pw3.CircleColor = Colors.ARGB(100,200,200,255)
    pw3.BarLength = brlng
    pw3.RimColor = Colors.Yellow
    pw3.RimWidth = 20                          'limit this to 20
    pw3.BarColor = Colors.White
    pw3.BarWidth = 10
    pw3.Left = 40%x
    pw3.Width = 20%x
    pw3.Height = 20%x
    pw3.Top = 50%y - (pw3.Height/2)
    pw3.ContourColor = Colors.Red              'make the contour around the inner and outer of the blue rim grey
    pw3.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw3.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw3.Text = "B4A"
    pw3.TextColor = Colors.Green
    pw3.TextSize = 30
    pw3.PaddingBottom = 20
    pw3.PaddingLeft = 20
    pw3.PaddingTop = 20
    pw3.PaddingRight = 20
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF0000FF, 0xFF0000FF)
    pw3.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw3.Progress = 90
    pw3.spin    

    pw2.CircleColor = Colors.Black
    pw2.BarLength = brlng
    pw2.RimColor = Colors.Yellow
    pw2.RimWidth = 20                          'limit this to 20
    pw2.BarColor = Colors.Black
    pw2.BarWidth = 5
    pw2.Left = 70%x
    pw2.Width = 20%x
    pw2.Height = 20%x
    pw2.Top = 50%y - (pw2.Height/2)
    pw2.ContourColor = Colors.Green            'make the contour around the inner and outer of the blue rim grey
    pw2.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw2.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw2.Text = "B4A"
    pw2.TextColor = Colors.White
    pw2.TextSize = 15
    pw2.PaddingBottom = 10
    pw2.PaddingLeft = 30
    pw2.PaddingTop = 10
    pw2.PaddingRight = 30
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFF00, 0xFFFF0000)
'    pw2.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw2.Progress = 90
    pw2.spin



'   OTHER METHODS THAT YOU CAN TEST AND USE:

'   pw1.stopSpinning
'    pw1.Color = Colors.Gray
'   pw1.incrementProgress
'   pw1.Progress
'    pw1.DelayMillis = 1000
'   pw1.resetCount
End Sub

Sub Activity_Resume

t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

t.Enabled = False

End Sub
Sub t_tick

brlng = brlng + 10
If brlng = 360 Then brlng = 0
pw1.BarLength = brlng
pw2.BarLength = brlng
pw3.BarLength = brlng

End Sub

ProgressWheel
Version:
1
  • ProgressWheel
    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)
    • incrementProgress
    • resetCount
    • spin
    • stopSpinning
    Properties:
    • Background As Drawable
    • BarColor As Int [write only]
    • BarLength As Int [write only]
    • BarWidth As Int [write only]
    • CircleColor As Int [write only]
    • Color As Int [write only]
    • ContourColor As Int [write only]
    • ContourSize As Float [write only]
    • DelayMillis As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • PaddingBottom As Int [write only]
    • PaddingLeft As Int [write only]
    • PaddingRight As Int [write only]
    • PaddingTop As Int [write only]
    • Progress As Int [write only]
    • RimColor As Int [write only]
    • RimShader() As Int [write only]
    • RimWidth As Int [write only]
    • SpinSpeed As Int [write only]
    • Tag As Object
    • Text As String [write only]
    • TextColor As Int [write only]
    • TextSize As Int [write only]
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

Last edited:

Johan Schoeman

Expert
Licensed User
How to Initialize the view in the code without designer ?
Here you go - new library files and B4A project attached. You now don't need to add the Customviews via designer - you can do it via B4A code.

Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: ProgressWheel
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #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 pw1, pw2 As ProgressWheel
    Dim brlng As Int = 15
   
    Private pw3 As ProgressWheel
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",50)
   
    pw1.Initialize("")
    pw2.Initialize("")
    pw3.Initialize("")       
   
    Activity.AddView(pw1, 10%x, 50%y - 10%x, 20%x, 20%x)
    Activity.AddView(pw2, 40%x, 50%y - 10%x, 20%x, 20%x)   
    Activity.AddView(pw3, 70%x, 50%y - 10%x, 20%x, 20%x)       

    pw1.CircleColor = Colors.ARGB(100,0,0,255)
    pw1.BarLength = brlng
    pw1.RimColor = Colors.Yellow
    pw1.RimWidth = 20                          'limit this to 20
    pw1.BarColor = Colors.Red
    pw1.BarWidth = 20
    pw1.Left = 10%x
    pw1.Width = 20%x
    pw1.Height = 20%x
    pw1.Top = 50%y - (pw1.Height/2)
    pw1.ContourColor = Colors.Green            'make the contour around the inner and outer of the blue rim grey
    pw1.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw1.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw1.Text = "B4A"
    pw1.TextColor = Colors.LightGray
    pw1.TextSize = 20
    pw1.PaddingBottom = 30
    pw1.PaddingLeft = 10
    pw1.PaddingTop = 30
    pw1.PaddingRight = 10
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFFFF, 0xFFFFFFFF)
'    pw1.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw1.spin
   
    pw3.CircleColor = Colors.ARGB(100,200,200,255)
    pw3.BarLength = brlng
    pw3.RimColor = Colors.Yellow
    pw3.RimWidth = 20                          'limit this to 20
    pw3.BarColor = Colors.White
    pw3.BarWidth = 10
    pw3.Left = 40%x
    pw3.Width = 20%x
    pw3.Height = 20%x
    pw3.Top = 50%y - (pw3.Height/2)
    pw3.ContourColor = Colors.Red              'make the contour around the inner and outer of the blue rim grey
    pw3.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw3.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw3.Text = "B4A"
    pw3.TextColor = Colors.Green
    pw3.TextSize = 30
    pw3.PaddingBottom = 20
    pw3.PaddingLeft = 20
    pw3.PaddingTop = 20
    pw3.PaddingRight = 20
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF0000FF, 0xFF0000FF)
    pw3.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw3.Progress = 90
    pw3.spin       
   
    pw2.CircleColor = Colors.Black
    pw2.BarLength = brlng
    pw2.RimColor = Colors.Black
    pw2.RimWidth = 20                          'limit this to 20
    pw2.BarColor = Colors.White
    pw2.BarWidth = 5
    pw2.Left = 70%x
    pw2.Width = 20%x
    pw2.Height = 20%x
    pw2.Top = 50%y - (pw2.Height/2)
    pw2.ContourColor = Colors.Blue            'make the contour around the inner and outer of the blue rim grey
    pw2.ContourSize = 5                        'set the size of the contour inner and outer around the blue rim
    pw2.SpinSpeed = 5                          'the bigger the number the faster it goes around
    pw2.Text = "B4A"
    pw2.TextColor = Colors.Red
    pw2.TextSize = 15
    pw2.PaddingBottom = 10
    pw2.PaddingLeft = 30
    pw2.PaddingTop = 10
    pw2.PaddingRight = 30
    Dim mycolors(8) As Int = Array As Int (0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFF00, 0xFFFF0000)
'    pw2.RimShader = mycolors                    'does funny stuff to the rim - read up on android.graphics.Shader
    pw2.Progress = 90
    pw2.spin   



'   OTHER METHODS THAT YOU CAN TEST AND USE:

'   pw1.stopSpinning
'    pw1.Color = Colors.Gray
'   pw1.incrementProgress
'   pw1.Progress
'    pw1.DelayMillis = 1000
'   pw1.resetCount
End Sub

Sub Activity_Resume

t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

t.Enabled = False

End Sub
Sub t_tick

brlng = brlng + 10
If brlng = 345 Then brlng = 15
pw1.BarLength = brlng
pw2.BarLength = brlng
pw3.BarLength = brlng

End Sub
 

Attachments

Brian Robinson

Active Member
Licensed User
Hi, firstly, thanks for all your work on these libraries.

I tried this one, but the example did not work.

There are no Initialize methods in the library?

I added via the designer and it all looks good from there.

[EDIT]

Ahh, ok... Looks like the lib files in the example are maybe the old ones. The ones in the separate "ProgressWheelLibFiles" zip file contain the newer ones.

Cheers
Brian
 

Johan Schoeman

Expert
Licensed User
Hi, firstly, thanks for all your work on these libraries.

I tried this one, but the example did not work.

There are no Initialize methods in the library?

I added via the designer and it all looks good from there.

[EDIT]

Ahh, ok... Looks like the lib files in the example are maybe the old ones. The ones in the separate "ProgressWheelLibFiles" zip file contain the newer ones.

Cheers
Brian
That is correct. You need to use the new library files in post #3 above. I just forgot to remove the older lib files from the /files folder before I zipped the B4A project that I have posted in post #3 above.
 
Top