#Region Activity Attributes
#FullScreen: False
#IncludeTitle: false
#End Region
Sub Process_Globals
Dim noti As Notification
Dim timer1 As Timer
End Sub
Sub Globals
Private Panel1 As Panel
Private lstAlarms As ListView
Private lblTitle6 As Label
Private Panel2 As Panel
Private Panel3 As Panel
Private ImageView1 As ImageView
Private lblAlarm As Label
Private EditText1 As EditText
Private EditText2 As EditText
Private EditText3 As EditText
Private Button2 As Button
Private lblCancelAlarm As Label
Private ImageView2 As ImageView
Dim MyList As List
Dim FilePath As String =File.DirRootExternal & "/AlarmS/"
Dim FileName As String ="alarm.txt"
Dim lblNextAlarm As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("frmAlarm")
MyList.Initialize
lstAlarms.TwoLinesAndBitmap.Label.TextColor=Colors.Blue
lstAlarms.TwoLinesAndBitmap.Label.TextSize=22
lstAlarms.TwoLinesAndBitmap.SecondLabel.TextColor=Colors.Black
lstAlarms.TwoLinesAndBitmap.SecondLabel.TextSize=13
lstAlarms.TwoLinesAndBitmap.Label.Gravity = Gravity.LEFT
lstAlarms.TwoLinesAndBitmap.SecondLabel.Visible = True
Dim r As Reflector
If r.GetStaticField("android.os.Build$VERSION", "SDK_INT") >= 10 Then
r.Target = lstAlarms
r.RunMethod4("setOverscrollFooter", Array As Object(Null), _
Array As String("android.graphics.drawable.Drawable"))
End If
ReadTextFile
timer1.Initialize("timer1", 5000)
timer1.Enabled=True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub lstAlarms_ItemClick (Position As Int, Value As Object)
ToastMessageShow("Value: " & Value & " Position: " & Position,True)
End Sub
Sub lstAlarms_ItemLongClick (Position As Int, Value As Object)
StopService(AlarmService)
CancelScheduledService(AlarmService)
Dim Answ As Int
Dim txt As String
txt = "Do you want to delete alarm?"
Answ = Msgbox2(txt, "Info", "Yes", "", "No", Null) ' MessageBox
If Answ = DialogResponse.POSITIVE Then
lstAlarms.RemoveAt(Position)
MyList.Get(Position)
MyList.RemoveAt(Position)
File.WriteList(File.DirRootExternal & "/AlarmS/", "alarm.txt",MyList)
StartService(AlarmService)
Else
StartService(AlarmService)
End If
Log(Position)
Log(Value)
End Sub
Sub ImageView1_Click
StopService(AlarmService)
StopService(AlarmService2)
Dim td As TimeDialog
Dim today As Long
DateTime.DateFormat = "dd.MM.yyyy"
Dim dd As DateDialog
dd.ShowCalendar=False
dd.Year=DateTime.GetYear(DateTime.Now)
dd.Month=DateTime.GetMonth(DateTime.Now)
dd.DayOfMonth=DateTime.GetDayOfMonth(DateTime.Now)
td.Hour= DateTime.GetHour(DateTime.Now)
td.Minute=DateTime.GetMinute(DateTime.Now)
td.Is24Hours=True
Dim bb As InputDialog
If bb.Show("Enter small notification...", "Alarm", "OK", "", "No",Null) = DialogResponse.POSITIVE Then
Log(bb.Input)
If bb.Input="" Then
Msgbox("There is no any notification info!","Info")
StartService(AlarmService)
Return
End If
Else
StartService(AlarmService)
Return
End If
If dd.Show("NOTIFICATION","Select date","OK","","Cancel",Null)=DialogResponse.POSITIVE Then
today=dd.DateTicks
NumberFormat(dd.Month,2,0)
EditText1.Text=NumberFormat (dd.DayOfMonth,2,0) & "." & NumberFormat(dd.Month,2,0) & "." & dd.Year
Log("today: " & today)
Else
StartService(AlarmService)
Return
End If
If td.Show("Select time", "ALARM", "Ok", "Cancel", "", Null) = DialogResponse.POSITIVE Then
EditText2.Text=NumberFormat(td.Hour,2,0) & ":" & NumberFormat(td.Minute,2,0) & ":" & "00"
If DateTime.Now > DateTime.DateTimeParse(EditText1.Text,EditText2.Text) Then
Msgbox("Tima have already past!", "Info")
StartService(AlarmService)
Return
End If
End If
ToastMessageShow("Next alarm set for : " & EditText1.Text & " - " & EditText2.Text,True)
EditText3.Text= bb.Input & ";" & EditText1.Text & "-" & EditText2.text & ";" & EditText1.text
lstAlarms.AddTwoLinesAndBitmap2(bb.Input,EditText1.Text & "-" & EditText2.text,LoadBitmap(File.DirAssets,"bee.png"),EditText3.text)
MyList.Add(EditText3.Text)
Try
File.WriteList(File.DirRootExternal & "/AlarmS/","alarm.txt",MyList)
Catch
Log("Error: " & LastException.Message)
ToastMessageShow("Error: " & LastException.Message,True)
End Try
Button2_Click
End Sub
Sub Button2_Click
DateTime.DateFormat = "dd.MM.yyyy"
DateTime.TimeFormat = "HH:mm:ss"
StartService(AlarmService)
'StartServiceAt(AlarmService, DateTime.DateTimeParse(EditText1.text,EditText2.text),True)
End Sub
Sub ImageView2_Click
noti.Initialize
noti.Cancel(1)
StopService(AlarmService)
CancelScheduledService(AlarmService)
StopService(AlarmService2)
CancelScheduledService(AlarmService2)
Log("Alarm service - canceled.")
ToastMessageShow("All timers are off!",True)
End Sub
Sub ReadTextFile
If MyList.IsInitialized=False Then
MyList.Initialize
End If
MyList.Clear
lstAlarms.Clear
Dim reader As TextReader
reader.Initialize(File.OpenInput(FilePath,FileName))
Dim line As String
line = reader.ReadLine
Do While line <> Null
MyList.add(line)
line = reader.ReadLine
Loop
reader.Close
Dim x As String
Dim y As String
Dim b As String
For i=0 To MyList.Size-1
Dim line As String =MyList.Get(i)
Dim arrLine() As String = Regex.Split(";",line)
x = arrLine(0)
y = arrLine(1)
b = arrLine(2)
Log("List: " & x & " - " & y)
lstAlarms.AddTwoLinesAndBitmap2(x,y,LoadBitmap(File.DirAssets,"bee.png"),b)
Next
End Sub
Sub timer1_tick
CallSubDelayed(AlarmService,"Info")
If IsPaused(AlarmService) = True Then
'lblNextAlarm.Text="All alarms are ON!"
Else
'lblNextAlarm.Text="-=|||=-"
End If
End Sub
Sub GetResult(Result As String)
lblNextAlarm.Text= Result
Log("Rezultat callsubdelayed: " & Result)
End Sub