Android Question Wait For with While (httpjob)

Hello Everyone!

I have a LogIn page with a LogIn button.
When the button is pressed, an http job gets initialized and after that I use a wait for statement until the job is completed, like so:

httpjob:
    j.Initialize("", Me)
    j.PostString(link, m.As(JSON).ToCompactString)
    j.GetRequest.SetContentType("application/json")
    Wait For (j) JobDone (j As HttpJob)

I want to show the app logo while waiting for the job to be completed. Is this possible?
I want to use a while loop like so:

1. while job not completed 2. show logo and make it darker and lighter 3. end while

Also if there is a standard way to make a .png lighter and darker, please let me know!

Thanks in advance.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I want to show the app logo while waiting for the job to be completed. Is this possible?
I don't have time to write a demo at the moment, but I think that this is how it can be done.

1. Display the logo.
2. Start a timer. In the timer tick event change the logo shade (see below).
3. Now call your resumable sub. When that sub reaches the Wait For the program flow will return. Your timer ticks will still operate.
4. After JobDone in the resumable sub turn off the timer and reset or remove your logo image.

Also if there is a standard way to make a .png lighter and darker, please let me know!
The usual way to do this is to use BitmapCreator.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
What about ProgressDialogShow2?

B4X:
    j.Initialize("", Me)
    j.PostString(link, m.As(JSON).ToCompactString)
    j.GetRequest.SetContentType("application/json")
   
    ProgressDialogShow2("text",false)
    Wait For (j) JobDone (j As HttpJob)
    ProgressDialogHide
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is a very simple demo. I have used Sleep(5000) to simulate a five second download operation. As you might notice, I have not worked much with ImageViews and I am probably not loading the bitmaps in the right way, but it is good enough to demonstrate the principles and I don't have time just now to do more. I simply switch images to indicate that the download is in progress, but you can add a more sophisticated style if you wish.

B4X:
Private Sub tmr_Tick
    If switch Then                                                            ' Change logo according to switch value
        imageView1.SetBackgroundImage(logo).Gravity = Gravity.CENTER
    Else
        imageView1.SetBackgroundImage(logo1).Gravity = Gravity.CENTER
    End If
    switch = Not(switch)
End Sub

Private Sub Button1_Click
    If downloading Then Return                                    ' Prevent a double invocation
    timer.Enabled = True                                                ' Get timer ready
    download                                                                        ' Start the download
End Sub

Private Sub download
    downloading = True
    Sleep(5000)                                                                    ' Simulates a five-second download
    downloading = False
    timer.Enabled = False                                                ' Cancel the timer and reset logo
    imageView1.SetBackgroundImage(logo).Gravity = Gravity.CENTER
End Sub

Here is the project ...
 

Attachments

  • WaitingLogo.zip
    50.9 KB · Views: 58
Upvote 0
Top