commit 28/12/2024 13_08
This commit is contained in:
202
refusi/orologio_analogico_cronometro.b4a
Normal file
202
refusi/orologio_analogico_cronometro.b4a
Normal file
@@ -0,0 +1,202 @@
|
||||
Build1=Default,b4a.example
|
||||
File1=Main_Layout.bal
|
||||
FileGroup1=Default Group
|
||||
Group=Default Group
|
||||
Library1=core
|
||||
Library2=xui
|
||||
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~
|
||||
Module1=AnalogClock
|
||||
Module2=Starter
|
||||
NumberOfFiles=1
|
||||
NumberOfLibraries=2
|
||||
NumberOfModules=2
|
||||
Version=13
|
||||
@EndOfDesignText@
|
||||
#Region Project Attributes
|
||||
#ApplicationLabel: Orologio Analogico
|
||||
#VersionCode: 1
|
||||
#VersionName: 1.0
|
||||
#CanInstallToExternalStorage: False
|
||||
#End Region
|
||||
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: True
|
||||
#End Region
|
||||
|
||||
Sub Process_Globals
|
||||
Private Timer1 As Timer
|
||||
Private Running As Boolean = False
|
||||
Private StartTime As Long = 0
|
||||
Private ElapsedTime As Long = 0
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
Private Canvas1 As Canvas
|
||||
Private Panel1 As Panel
|
||||
Private BtnStart As Button
|
||||
Private BtnPause As Button
|
||||
Private BtnReset As Button
|
||||
Private BtnSync As Button
|
||||
|
||||
Private lblElapsedTime As Label
|
||||
Private pnlClock As Panel
|
||||
Private Timer1 As Timer
|
||||
Private myClock As AnalogClock
|
||||
Log("lblElapsedTime nel Sub Globals: " & lblElapsedTime.IsInitialized)
|
||||
End Sub
|
||||
|
||||
'Sub Activity_Create(FirstTime As Boolean)
|
||||
' Activity.LoadLayout("Main_Layout") 'Layout file to be created in the designer.
|
||||
' Log("Layout caricato correttamente.")
|
||||
'
|
||||
' ' Impostazioni Timer
|
||||
' Log("Panel1 inizializzato: " & Panel1.IsInitialized)
|
||||
' Log("Numero di viste in Panel1: " & Panel1.NumberOfViews)
|
||||
'
|
||||
' ' Sincronizza inizialmente
|
||||
' SynchronizeClock
|
||||
'End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
Activity.LoadLayout("Main_Layout")
|
||||
Log("Layout caricato correttamente.")
|
||||
|
||||
'Inizializza l'orologio
|
||||
myClock.Initialize(pnlClock, 50) ' L'orologio avrà un diametro pari al 50% della larghezza del pannello
|
||||
|
||||
' Imposta il timer per aggiornare l'orologio
|
||||
Timer1.Initialize("Timer1", 1000) ' Aggiornamento ogni secondo
|
||||
Timer1.Enabled = True
|
||||
' ' Cerca tra tutte le viste dell'Activity
|
||||
' For i = 0 To Activity.NumberOfViews - 1
|
||||
' Dim v As View = Activity.GetView(i)
|
||||
' Log("Vista trovata: " & v)
|
||||
'
|
||||
' ' Controlla se la vista è un Label
|
||||
' If v Is Label Then
|
||||
' Dim tempLabel As Label = v
|
||||
' Log("Label trovato: " & tempLabel.Text)
|
||||
' If tempLabel.Text = "Tempo: 00:00:00" Then ' Verifica basata sul testo iniziale
|
||||
' lblElapsedTime = tempLabel
|
||||
' Log("lblElapsedTime assegnato correttamente!")
|
||||
' End If
|
||||
' End If
|
||||
' Next
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Sub Timer1_Tick
|
||||
myClock.DrawClock
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
|
||||
End Sub
|
||||
|
||||
' Disegna l'orologio
|
||||
Sub DrawClock
|
||||
Canvas1.Initialize(Activity)
|
||||
Dim now As Long = DateTime.Now
|
||||
Dim Hours As Int = DateTime.GetHour(now) Mod 12
|
||||
Dim Minutes As Int = DateTime.GetMinute(now)
|
||||
Dim Seconds As Int = DateTime.GetSecond(now)
|
||||
|
||||
' Centro
|
||||
Dim x As Int = Activity.Width / 2
|
||||
Dim y As Int = Activity.Height / 2
|
||||
Dim Radius As Int = Min(x, y) - 10
|
||||
|
||||
' Cancella il canvas
|
||||
Canvas1.DrawColor(Colors.White)
|
||||
|
||||
' Cerchio esterno
|
||||
Canvas1.DrawCircle(x, y, Radius, Colors.Black, False, 5)
|
||||
|
||||
' Lancetta ore
|
||||
Dim HourAngle As Float = -90 + Hours * 30 + Minutes / 2
|
||||
DrawHand(x, y, Radius * 0.5, HourAngle, 8, Colors.Black)
|
||||
|
||||
' Lancetta minuti
|
||||
Dim MinuteAngle As Float = -90 + Minutes * 6
|
||||
DrawHand(x, y, Radius * 0.7, MinuteAngle, 5, Colors.Blue)
|
||||
|
||||
' Lancetta secondi
|
||||
Dim SecondAngle As Float = -90 + Seconds * 6
|
||||
DrawHand(x, y, Radius * 0.9, SecondAngle, 2, Colors.Red)
|
||||
End Sub
|
||||
|
||||
Sub DrawHand(x As Int, y As Int, length As Float, angle As Float, width As Int, color As Int)
|
||||
Dim endX As Float = x + length * CosD(angle)
|
||||
Dim endY As Float = y + length * SinD(angle)
|
||||
Canvas1.DrawLine(x, y, endX, endY, color, width)
|
||||
End Sub
|
||||
|
||||
' Aggiorna l'orologio e il cronometro
|
||||
'Sub Timer1_Tick
|
||||
' DrawClock
|
||||
' If lblElapsedTime.IsInitialized Then
|
||||
' DrawClock
|
||||
' If Running Then
|
||||
' ElapsedTime = DateTime.Now - StartTime
|
||||
' lblElapsedTime.Text = "Tempo: " & FormatElapsedTime(ElapsedTime)
|
||||
' End If
|
||||
' Else
|
||||
' Log("lblElapsedTime non è inizializzato.")
|
||||
' End If
|
||||
'
|
||||
'
|
||||
'
|
||||
'
|
||||
'End Sub
|
||||
|
||||
' Formatta il tempo in HH:MM:SS
|
||||
Sub FormatElapsedTime(ms As Long) As String
|
||||
Dim seconds As Int = ms / 1000
|
||||
Dim minutes As Int = seconds / 60
|
||||
Dim hours As Int = minutes / 60
|
||||
seconds = seconds Mod 60
|
||||
minutes = minutes Mod 60
|
||||
Return NumberFormat(hours, 2, 0) & ":" & NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0)
|
||||
End Sub
|
||||
|
||||
' Pulsante Start
|
||||
Sub BtnStart_Click
|
||||
If Not(Running) Then
|
||||
Running = True
|
||||
|
||||
Timer1.Initialize("Timer1",1000)
|
||||
|
||||
Timer1.Enabled = True
|
||||
StartTime = DateTime.Now - ElapsedTime
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' Pulsante Pause
|
||||
Sub BtnPause_Click
|
||||
Running = False
|
||||
End Sub
|
||||
|
||||
' Pulsante Reset
|
||||
Sub BtnReset_Click
|
||||
Running = False
|
||||
ElapsedTime = 0
|
||||
lblElapsedTime.Text = "Tempo: 00:00:00"
|
||||
End Sub
|
||||
|
||||
' Pulsante Sync
|
||||
Sub BtnSync_Click
|
||||
SynchronizeClock
|
||||
End Sub
|
||||
|
||||
' Sincronizza l'orologio
|
||||
Sub SynchronizeClock
|
||||
DrawClock
|
||||
End Sub
|
||||
Reference in New Issue
Block a user