Sub Process_Globals
Dim cu As ContactsUtils
End Sub
Sub Globals
Dim lstContacts As ListView
Dim ImageView1 As ImageView
Dim EditText1 As EditText
Private lblPhonenum As Label
Private lstPhonenums As ListView
Dim TreadContacts As Thread
End Sub
Sub Contacts(org As Object) ' The thread
Dim phonelist As List = org
Dim Params(1) As Object
Log($"Contacs_started(${org})"$)
'Log($"cu.FindContactsByPhone()"$)
For Each c As cuContact In cu.FindContactsByPhone("", False, False)
Dim Map1 As Map
Map1.Initialize
Map1.Put("DisplayName",c.DisplayName)
Map1.Put("Id",c.Id)
'Log($"${c.DisplayName}"$)
'Log($"${c.Id}"$)
Dim phones As List
phones.Initialize
'Log($"cu.GetPhones(${c.Id})"$)
For Each phone As cuPhone In cu.GetPhones(c.Id)
phones.Add(phone.Number)
'Log($"Phone.Number(${phone.Number})"$)
'lstContacts.AddTwoLines2(c.DisplayName,Phone.Number, Phone)
Next
Map1.Put("Phones",phones)
phonelist.Add(Map1)
Log($"Phonelist.Size ${phonelist.Size}"$)
Next
Params(0) = phonelist
' The list is ready filled and is prepared to used by the next command which will send the reult to the mainthread
TreadContacts.RunOnGuiThread("ContactsReady",Params)
TreadContacts.Sleep(10)
End Sub
Sub Contacs_Ended(endedOK As Boolean, error As String) 'The thread has terminated. If endedOK is False error holds the reason for failure
Log($"Contacs_Ended(${endedOK}, ${error})"$)
End Sub
Sub ContactsReady(contactslist As Object)
Log($"ContactsReady()"$)
lstContacts.Clear
Dim clist As List = contactslist
For i=0 To clist.Size-1
Dim contact As Map = clist.Get(i)
lstContacts.AddTwoLines(contact.Get("DisplayName"),contact.Get("Id"))
Dim phones As List = contact.Get("Phones")
For o = 0 To phones.Size-1
lstContacts.AddSingleLine(phones.Get(o))
Next
Log(clist.Get(i))
Next
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
cu.Initialize
End If
Activity.LoadLayout("1")
Dim MyList As List
MyList.Initialize
TreadContacts.Initialise("Contacts")
TreadContacts.Start(Me,"Contacts", Array As Object(MyList))
'For Each c As cuContact In cu.FindAllContacts(True)
'lstContacts.AddSingleLine2(c.DisplayName, c)
'Next
End Sub