Android Question New Year App

Douglas Farias

Expert
Licensed User
Longtime User
hi i m not programer and i want to make a new year countdown app .
how can i make this ?

left 00:00:00 for new year exemple ?

if anyone know help me pls.
thx too all
 

DonManfred

Expert
Licensed User
Longtime User
Better than an app is a widget. Feel free do write it by your own but there are also good ones available. For example https://play.google.com/store/apps/details?id=smsr.com.cw

If you want to write it by yourself you have to deal with DATEs, a label to display, and calculating the days between two dates.
For most of them you find all infos in the tutorials here in the forum. For the rest you should search the forum.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2013-12-18_09.21.51.png


Here:
B4X:
Sub Process_Globals
   Private target As Long
   Private timer1 As Timer
End Sub

Sub Globals
   Dim lbl As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     target = DateUtils.SetDate(DateTime.GetYear(DateTime.Now) + 1, 1, 1)
     timer1.Initialize("timer1", 1000)
   End If
   lbl.Initialize("")
   Activity.AddView(lbl, 20dip, 20dip, 300dip, 100dip)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   Dim p As Period = DateUtils.PeriodBetweenInDays(DateTime.Now, target)
   lbl.Text = Format(p.Days) & " days, " & Format(p.Hours) & " hours, " _
     & Format(p.Minutes) & " minutes, " & Format(p.Seconds) & " seconds"
End Sub

Sub Format(n As Int) As String
   Return NumberFormat(n, 2, 0)
End Sub
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Erel how can i transform this in a label ?
i try this

Label1.text = lbl
and it show a crazy code : android 3333 asd4w8110d8 o_O

how i transform this
Activity.AddView(lbl, 20dip, 20dip, 300dip, 100dip)

in a label1 ?

i need a label 1 to make a 25 size font and
or how to change the font size in this
Activity.AddView(lbl, 20dip, 20dip, 300dip, 100dip)
?

later a sugestion move this to tutorials *-*
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Douglas,

I faced a very similar challenge for my first B4A app only a few weeks ago.
A few hints you may find useful:
1. countdown halting
I find more realistic for a countdown that when it reaches all 0's it should stop there. So in Activity.Create I check for a still valid countdown before I even initialize and start the timer. Note: Erel's code is always valid since it counts down to every NEXT year's end based on today date.
2. event timezone
In a earlier thread I received instructions on how to take in account for timezones; this is useful if the countdown refers to a specific time of an event to be held somewhere in the world (e.g. next FIFA world cup in Brazil)
3. multi-language
It could be nice to have those few labels art of a simple app to be showed in your user's device language; for this task I used the AHLocale library.

I you find it useful I could zip and publish my far from optimal project.

Umberto
 
Upvote 0
Top