Hi. I'm a beginner in this wonderful world!
In my app, I launch a service (a VPN) and wait about 5 seconds for the service to start. During this time, I show some kind of CountDown (with a label) so that the user understands that he has to wait. There are two questions:
1) Is it right as a method?
2) Is it possible to have an effect on the Label (for example that the numbers seem to approach and then disappear, like when the New Year's countdown is shown on TV? (I don't know if I get the idea) I show the code
Thanks for your suggestions
In my app, I launch a service (a VPN) and wait about 5 seconds for the service to start. During this time, I show some kind of CountDown (with a label) so that the user understands that he has to wait. There are two questions:
1) Is it right as a method?
2) Is it possible to have an effect on the Label (for example that the numbers seem to approach and then disappear, like when the New Year's countdown is shown on TV? (I don't know if I get the idea) I show the code
Thanks for your suggestions
B4X:
Private Sub btnStart_Click
'Start VPN and wait 5 seconds'
Wait For (StartVPN) complete (Finish As Boolean)
CalltestIP_VPN
End Sub
Sub StartVPN As ResumableSub
Dim i As Intent
i.Initialize(i.ACTION_MAIN, "")
i.SetComponent("de.blinkt.openvpn/.LaunchVPN")
i.PutExtra("de.blinkt.openvpn.shortcutProfileName", "VPN_Telecontrollo")
i.PutExtra("de.blinkt.openvpn.AUTOCONNECT", True)
StartActivity(i)
'Here wait 5 seconds
timer1.Initialize("timer1", 1000)
StartTimer(5) ' 5 seconds
t = Max(0, targetTime - DateTime.Now)
Do While t > 0
Sleep(0)
Loop
Return True
End Sub
Sub StartTimer (Seconds As Int)
targetTime = DateTime.Now + Seconds * DateTime.TicksPerSecond
timer1.Enabled = True
End Sub
Sub Timer1_Tick
t = Max(0, targetTime - DateTime.Now)
Dim seconds As Int
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
lblCountDown.Text=$"$2.0{seconds}"$ ' the label show the countdown
If t = 0 Then
timer1.Enabled = False
End If
End Sub