Share My Creation The Simplest digital clock as widget

Hi,

after I have no simple digital clock found, without weather, advertising or other I programmed myself a Widget.

My HomeClock
 

Attachments

  • Screenshot_01.png
    Screenshot_01.png
    163.7 KB · Views: 3,252
D

Deleted member 103

Guest
r u using a sticky service for it?
This is my service:
B4X:
#Region  Service Attributes
    #StartAtBoot: true
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Private rv As RemoteViews
End Sub

Sub Service_Create
    rv = ConfigureHomeWidget("frmWidget", "rv", 0, "HomeClock", True)
    rv.SetTextSize("lblTime", 110)
   
    DateTime.TimeFormat="HH:mm"
    DateTime.DateFormat="EEEE, dd MMM"
End Sub

Sub Service_Start (StartingIntent As Intent)
'    Log("StartingIntent.Action=" & StartingIntent.Action)
       
    'Reschedule the service every minute, so the clock gets updated correctly
    StartServiceAt(Me, TimeToNextMinute, False)
    rv_RequestUpdate

    If rv.HandleWidgetEvents(StartingIntent) Then Return   
End Sub

Sub Service_Destroy

End Sub

'Calculate the time to the next full minute
Sub TimeToNextMinute As Long
    Dim ret As Long

    ret = DateTime.Now + DateTime.TicksPerMinute
    ret = ret - (ret Mod DateTime.TicksPerMinute)   
    Return ret
End Sub

Sub SetTime
    rv.SetText("lblTime", DateTime.Time(DateTime.Now))
    rv.SetText("lblDate", DateTime.Date(DateTime.Now))
End Sub

Sub rv_RequestUpdate
    SetTime
    rv.UpdateWidget
End Sub

Sub rv_Disabled
    StopService("")
End Sub
 

ilan

Expert
Licensed User
Longtime User
Top