B4A Library [Lib] CustomProgressDialog

This library will allow you to customize a Progress Dialog.

Requirements:

- B4A 3.x

How to install:

- Copy the CustomProgressDialog.jar and CustomProgressDialog.xml to your additional libraries directory.

How to use:

B4X:
'Initialize the library
Dim myProgressDialog As CustomProgressDialog

'Create your ProgressDialog
'Leaving the animation parameter blank will display the default spinner.
'Entering -1 on LEFT or TOP parameters will center the CustomProgressDialog
myProgressDialog.Initialize(Activity, 95%x, -1, -1, "", Colors.DarkGray, 0, "")  

'Display it
myProgressDialog.Show("Tap the BACK key to stop...", Colors.White)

B4X:
'Hide/Close the CustomProgressDialog
myProgressDialog.Hide

That's it!!

The included animations are: Spinner, Laser, Bounce, Domino and Holo.


You can also customize a ProgressDialog with a ProgressBar, look at the attached sample for more details.

NOTE: Updated to version 2.20, added a new animation named "Holo".
 

Attachments

  • CustomProgressDialog_Sample.zip
    13 KB · Views: 1,208
  • CustomProgressDialog_Lib_2.20.zip
    19.1 KB · Views: 1,295
Last edited:

melamoud

Active Member
Licensed User
Longtime User
is the anoimation works in the UI thread ? so I cant use ths on blocking operations ?
 

melamoud

Active Member
Licensed User
Longtime User
Not sure I understood your answer.
Can I call show ans then run a long blocking sql query and when its done call hide

Will I see the animation while the query run?

Thanks.
 

moster67

Expert
Licensed User
Longtime User
Very nice NJ! :icon_clap:

Tested on JB and GB - this will be very useful.

Thanks for sharing
 

Scantech

Well-Known Member
Licensed User
Longtime User
NJ,

Is there a way to bring the progress dialog to the front without the need to reinitialize? BringtoFront property is needed in my situation.

When you use the progress dialog, hide it, then if any views are brought up to front, it will make the progress dialog hidden behind the view (listview in my situation).

Otherwise, I like it so far and just what i was looking for.

Thank you
 

Scantech

Well-Known Member
Licensed User
Longtime User
Thanks NJ. Latest version fixed it.

However, using Bounce/Laser and continuously changing the message causes the drawing to jitter or off place. If you understand what I am trying to say. Nice, smooth back and forth motion will be nice. Only happens when changing message rapidly one after another. It's not a big deal, but thought I mentioned it.

Thanks again!
 

NJDude

Expert
Licensed User
Longtime User
Thanks NJ. Latest version fixed it.

However, using Bounce/Laser and continuously changing the message causes the drawing to jitter or off place. If you understand what I am trying to say. Nice, smooth back and forth motion will be nice. Only happens when changing message rapidly one after another. It's not a big deal, but thought I mentioned it.

Thanks again!

Yes, the Laser, Bounce or Domino animations are meant to be for static messages, however, I'll try to see if I can improve the code to do what you mentioned.
 

Mahares

Expert
Licensed User
Longtime User
Thank you NJDude. You are a powerhouse.
1. I tried to use it in conjunction with the Table class to display a query result set. If the btnLoadTable is automaticaly activated inside the Activity_Create, the laser, domino and bounce effects do not show. I can only see a static message, although I do not change the message. If I manually click the button, it shows the animation effect, albeit sluggish.
2. The ability to position the location of the progress dialog, other than in the center of the screen if possible, may also be desirable in ceratin situations.

B4X:
btnLoadTable_Click  'In Activity_Create: automatically display table at start-up


B4X:
Sub btnLoadTable_Click
      
   myProgressDialog.Initialize(Activity, 95%x, "", Colors.DarkGray, Colors.Cyan, "Laser") 
   myProgressDialog.Show("Stand by. Lots of records", Colors.White)   

  Table1.Clear
   For i=0 To Cursor1.RowCount-1
         Cursor1.Position=i
             Table1.AddRow(Array As String(Cursor1.GetString(Col_Name(0)), Cursor1.GetString(Col_Name(1)), _ 
         Cursor1.GetString(Col_Name(2)),Cursor1.GetString(Col_Name(3)), _
         Cursor1.GetString(Col_Name(4)),Cursor1.GetString(Col_Name(5)), _
         Cursor1.GetString(Col_Name(6)),Cursor1.GetString(Col_Name(7)), _
         Cursor1.GetString(Col_Name(8)),Cursor1.GetString(Col_Name(9)), _
         Cursor1.GetString(Col_Name(10)), Cursor1.GetString(Col_Name(11)) ))
         If i Mod 50 =0 Then DoEvents
   Next

            myProgressDialog.Hide
End sub
 

NJDude

Expert
Licensed User
Longtime User
You might need to add a DoEvents after or before the Dialog show, regarding the positioning, I'll put that on my To Do list, maybe having default = center, or selecting Top and Bottom.
 

Mahares

Expert
Licensed User
Longtime User
@ NJDude: I tried Doevents before and after the show progress, but neither helps. I think it has to do with the static animations: Laser, Domino and Bounce/ if you leave the animation BLANK as in the conventional progress, it is OK.
Please also, see Freddy's ( Informatix: Happy Birthday Fred) post as I pre-empted it.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Not sure I understood your answer.
Can I call show ans then run a long blocking sql query and when its done call hide

Will I see the animation while the query run?

Thanks.
From the android guidelines, you should run long blocking statements on another thread. Erel added async querries so I think you can use those.
The fact is that the thread is blocked, and the ProgressDialog is on the same thread (and it has to be since it is the UI thread).
 

melamoud

Active Member
Licensed User
Longtime User
pressing back

hi,

is it possible that the lib is doing something with the back key ?
I'm pressing back in the middle of the progress run, and it get frozen,
I tried to catch the backkey (in the acitivity) and call hide, the call did nothing,

BTW when my action (async SQL) finished and I called hide it worked,

any idea ?
 

NJDude

Expert
Licensed User
Longtime User
hi,

is it possible that the lib is doing something with the back key ?
I'm pressing back in the middle of the progress run, and it get frozen,
I tried to catch the backkey (in the acitivity) and call hide, the call did nothing

The sample uses a timer which will stop when the progress reaches 100%, that's why you see that effect, that's just for illustration purposes you can adapt it any way you like it.
 
Top