Italian Countdown da (Visuallizzare missilescondo con il Timer)

IlCasti

Active Member
Licensed User
Longtime User
Ciao a tutti
Mi serviva un countdown con stop e resume, e, dopo aver spulciato il forum, dove non ho trovato nulla di esaustivo, ho approfittato del thread dei millisecondi del timer e ne ho fatto uno semplice semplice che nel caso potrebbe servire a qualcuno come spunto ed eventualmente (senza eventualmente) migliorarlo.

Incollo il codice e allego lo zip (il progetto contiene un riferimento alla libreria stringfunction)

IlCasti

B4X:
#Region  Project Attributes
  #ApplicationLabel: B4A Example
  #VersionCode: 1
  #VersionName:
  'SupportedOrientations possible values: unspecified, landscape or portrait.
  #SupportedOrientations: unspecified
  #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
  #FullScreen: False
  #IncludeTitle: True
#End Region

Sub Process_Globals
   
  Dim TempoCountdown As Timer
   
End Sub

Sub Globals
   
  Dim StrUt As StringFunctions
  StrUt.Initialize
       
  Dim StartTime As Long
   
  Dim InizioTimer As Long
  Dim TempoVisualizzato As Long
  Dim FineTimer As Long
   
  Private Clock As Button
  Private TimeClock As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
  Activity.LoadLayout("Clock")

  TempoCountdown.Initialize("Countdown",100)
   
  InizioTimer = DateTime.TimeParse("00:00:10")
  FineTimer = DateTime.TimeParse("00:00:00")
   
  TempoVisualizzato = InizioTimer
   
  TimeClock.Text = "00:10:0"
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Countdown_Tick
  TimeClock.Text = ConvertTicksToHHMMSSMS(TempoVisualizzato)
End Sub

Sub ConvertTicksToHHMMSSMS(Time As Long) As String

  Dim Diff As Long = DateTime.Now - StartTime
       
  TempoVisualizzato = InizioTimer - Diff
   
  Dim HH,MM,SS,MS As Int
  Dim T As Long=Abs(Time)
       
  If TempoVisualizzato < FineTimer Then
    TempoCountdown.Enabled = False
    Return "00:00:0"
  Else
    MS = T Mod 1000
    SS = (T/1000) Mod 60
    MM = (T/60000) Mod 60
    HH = (T/3600000) Mod 24
    Return NumberFormat(MM,2,0) & ":" & NumberFormat(SS,2,0) & "." & StrUt.Left(NumberFormat(MS, 2 ,0),1)
  End If
       
End Sub
Sub Clock_Click
  If Clock.Tag = "START" Then
    Clock.Tag="STOP"
    Clock.Text = ">"
    StartTime = DateTime.Now
    TempoCountdown.Enabled = True
  Else
    Clock.Tag="START"
    Clock.Text="||"
    TempoCountdown.Enabled = False
    InizioTimer = TempoVisualizzato
  End If
End Sub
 

Attachments

  • CountdownTimer.zip
    7.3 KB · Views: 254
Top