B4A Library ProgressButton

ProgressButton is a toggleable button which displays a circular progress indicator.

This library wraps the open source ProgressButton, details of which can be found here:
http://f2prateek.com/progressbutton/

Copyright 2013 Prateek Srivastava
Copyright 2012 Roman Nurik

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

ProgressButton
Version:
1.00
  • ProgressButton
    Events:
    • CheckedChanged (ProgressButton1 As ProgressButton, IsChecked As Boolean)
    Methods:
    • BringToFront
    • Initialize
      Initializes the ProgressButton.
    • 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)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetOnCheckedChangedListener (EventName As String)
      Adds an OnCheckedChangedListener to the ProgressButton.
      Raises the event CheckedChanged(ProgressButton1 As ProgressButton, IsChecked As Boolean).
      Pass Null as the EventName to remove any previously added OnCheckedChangedListener.
    • Toggle
      Toggles the checked state of the ProgressButton.
    Properties:
    • Background As Drawable
    • Checked As Boolean
      Gets or Sets whether the ProgressButton is checked.
    • CheckedDrawable As Drawable [write only]
      Sets the Drawable to be displayed for the ProgressButton checked state.
    • CircleColor As Int
      Gets or Sets the ProgressButton background circle color.
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • InnerSize As Int
      Gets or Sets the ProgressButton circle diameter.
    • Left As Int
    • Max As Int
      Gets or Sets the ProgressButton maximum progress value.
    • Progress As Int
      Gets or Sets the ProgressButton progress value.
    • ProgressColor As Int
      Gets or Sets the ProgressButton progress circle color.
    • ShadowDrawable As Drawable [write only]
      Sets the Drawable to be displayed for the ProgressButton shadow.
    • Tag As Object
    • Top As Int
    • UncheckedDrawable As Drawable [write only]
      Sets the Drawable to be displayed for the ProgressButton unchecked state.
    • Visible As Boolean
    • Width As Int

As you can see the ProgressButton has all of the 'standard' b4a View methods and properties plus of course a few of it's own.

Note that the library contains a small number of resources that must be copied to your project's Objects/res folder and marked as read-only.

Martin.
 

Attachments

  • ProgressButton_library_files_v1_00.zip
    24.3 KB · Views: 764

warwound

Expert
Licensed User
Longtime User
An example project using the ProgressButton:

B4X:
Sub Process_Globals
   Dim Checked As Boolean=False
   Dim Progress As Int=0
   Dim Timer1 As Timer
End Sub

Sub Globals
   Dim ProgressButton1 As ProgressButton

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     Timer1.Initialize("Timer1", 200)
   End If
   
   '   Activity.Color=Colors.LightGray
   
   Dim ButtonDiameter As Int=64dip
   
   ProgressButton1.Initialize
   '   ProgressButton1.CircleColor=Colors.LightGray
   ProgressButton1.Checked=Checked
   ProgressButton1.InnerSize=ButtonDiameter
   '   ProgressButton1.Max=60
   ProgressButton1.Progress=Progress
   '   ProgressButton1.ProgressColor=Colors.Green
   ProgressButton1.SetOnCheckedChangedListener("ProgressButton1")
   
   Activity.AddView(ProgressButton1, 50%x-(ButtonDiameter/2), 50%y-(ButtonDiameter/2), ButtonDiameter, ButtonDiameter)
   
   Timer1.Enabled=Checked
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Timer1.Enabled=False
End Sub

Sub ProgressButton1_CheckedChanged(ProgressButton2 As ProgressButton, IsChecked As Boolean)
   Log("ProgressButton1_CheckedChanged "&IsChecked)
   Checked=IsChecked
   Timer1.Enabled=Checked
End Sub

Sub Timer1_Tick
   Progress=Progress+1
   If Progress>ProgressButton1.Max Then
     Progress=0
   End If
   ProgressButton1.Progress=Progress
End Sub

The project adds a ProgressButton to the center of the Activity, the ProgressButton by default is unchecked.
Tap the ProgressButton and a Timer advances the ProgressButton's Progress by 1 every 200 milliseconds.
The ProgressButton by default has a maximum value of 100, when that value is reached the Progress is reset to 0.
Tapping the ProgressButton toggle the Timer on and off.

Uncomment the commented out lines to see the effect of setting various properties.

Martin.
 

Attachments

  • ProgressButton_demo.zip
    13.7 KB · Views: 599

RayLee

Member
Licensed User
Longtime User
Merry Chirstmas !!
What a nice addition! 3Q!

However, I have a mistake
-----------------------------------------------------------------------------------------
Parsing code. 0.00
Compiling code. 0.05
Compiling layouts code. 0.00
Generating R file. Error
res\values\styles.xml:33: error: Error: No resource found that matches the given name: attr 'android:selectableItemBackground'.
---------------------------------------------------------------------------------------

Maybe it caused by : android-8.jar .
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Merry Chirstmas !!
What a nice addition! 3Q!

However, I have a mistake
-----------------------------------------------------------------------------------------
Parsing code. 0.00
Compiling code. 0.05
Compiling layouts code. 0.00
Generating R file. Error
res\values\styles.xml:33: error: Error: No resource found that matches the given name: attr 'android:selectableItemBackground'.
---------------------------------------------------------------------------------------

Maybe it caused by : android-8.jar .

I found the changelog page: https://github.com/f2prateek/progressbutton/blob/master/CHANGELOG.md where it states that a version 2 update is being developed which will Extend compatibility to API level 8.

From that i think we can infer that API level 8 is not supported in version 1 :(.

Martin.
 
Top