Hi everyone,
here is my first library "Contacts", written in the great B4A editor.
It's a redesign and enhancement of the great "ContactUtils" class from Erel.
What can you do with this library:
With this library you can add / remove / find / edit contacts.
In the contacts you can:
- add / get / remove address entries
- add / get / remove email address entries
- add / get / remove event entries
- add / get / remove im (Instant Messanger) entries
- add / get / remove nickname entries
- add / get / remove note entry
- add / get / remove phone numbers entries
- add / get / remove organization entries
- add / get / remove relation entries
- add / get / remove sip address entries
- add / get / remove thumbnail bitmap
- add / get / remove website entries
- get / set the display name
- get / set starred state
- get / set the structured name
- get the full size display photo
- get / set primary phonenumber and/or email address
Needed Permissions:
Permissions for that lib must be set in the manifest editor by your self:
Used libraries in this library:
- ContentResolver (>= 1.0)
- JavaObject (>= 2.05)
- SQL (>= 1.30)
How to use:
First a instance of ContactBook class is needed:
Now a new contact can be added:
Or a contact can be found:
A list of all visible contacts:
With a valid ContactItem class instance the contact can be edit directly:
Something to know about the contact classes:
ContactAddress, ContactEmailAddress, ContactEvent, ContactIM, ContactNickname, ContactOrganization, ContactPhoneNumber, ContactRelation, ContactSipAddress and ContactWebsite.
All of these classes has a TYP property. This property will be set to a default value on initalizing a class. For example a new ContactAddress class object has "home" as default type. The TYP property must have an exact value out of the diffrent type maps that can be found under the ContactStatics module. For example:
If you know all these exact typenames you can set it by your self to the TYP property.
The classes have also a LABEL property. This property can be used for a custom type name. But before a label can be set correctly, the TYP property must be set to "custom".
Versions:
V1.0 Release Version
V1.01 Fixed
- Thumbnail set error removed
- new class ContactItemSnapshot, to get a memory snapshot of a contactitem
- new function GetSnapshot at ContactItem class, to get a snapshot of the given contactitem
- new function GetAllContacts2 at ContactBook class, to get a sorted list of contactitem's
V1.02
- new functions ReadFrom and WriteTo (re)added to ContactItemSnapshot, to store a contact to stream
V>1.02
- For now the source code is free for everyone. I don't have the time to fix something.
- Please upload your bugfixes here for the community.
The attached test project will list all visible contacts and its data entries. A long press will change the
contacts starred state.
here is my first library "Contacts", written in the great B4A editor.
It's a redesign and enhancement of the great "ContactUtils" class from Erel.
What can you do with this library:
With this library you can add / remove / find / edit contacts.
In the contacts you can:
- add / get / remove address entries
- add / get / remove email address entries
- add / get / remove event entries
- add / get / remove im (Instant Messanger) entries
- add / get / remove nickname entries
- add / get / remove note entry
- add / get / remove phone numbers entries
- add / get / remove organization entries
- add / get / remove relation entries
- add / get / remove sip address entries
- add / get / remove thumbnail bitmap
- add / get / remove website entries
- get / set the display name
- get / set starred state
- get / set the structured name
- get the full size display photo
- get / set primary phonenumber and/or email address
Needed Permissions:
Permissions for that lib must be set in the manifest editor by your self:
B4X:
AddPermission("android.permission.READ_CONTACTS")
AddPermission("android.permission.WRITE_CONTACTS") 'if write access is required
Used libraries in this library:
- ContentResolver (>= 1.0)
- JavaObject (>= 2.05)
- SQL (>= 1.30)
How to use:
First a instance of ContactBook class is needed:
B4X:
Dim cBook As ContactBook
cBook.Initialize
Now a new contact can be added:
B4X:
Dim cItem As ContactItem
cItem = cBook.AddContact("Max Anyone")
Or a contact can be found:
B4X:
Dim cItem As ContactItem
Dim foundContactItems As List
foundContactItems = cBook.GetContactsByName("Max Anyone", False, True)
If foundContactItems.Size > 0 Then
cItem = foundContactItems.Get(0)
End If
A list of all visible contacts:
B4X:
Dim cItem As ContactItem
Dim contactItems As List
contactItems = cBook.GetAllContacts(True) 'Unsorted
If contactItems.Size > 0 Then
Dim cItem As ContactItem
cItem = contactItems.Get(0)
End If
'With lib version >= 1.01, the contacts can be get sorted by displayname
contactItems = cBook.GetAllContacts2(True, True) 'Sorted
If contactItems.Size > 0 Then
Dim cItem As ContactItem
cItem = contactItems.Get(0)
End If
With a valid ContactItem class instance the contact can be edit directly:
B4X:
'Add a phone number simple way:
cItem.AddPhoneNumberSimple("00328888888", ContactStatics.PhoneNumberTypes.Get("1"))
'Or add a phone number like this:
Dim cPhoneNumber As ContactPhoneNumber
cPhoneNumber.Initialize
cPhoneNumber.Number = "00328888888"
cPhoneNumber.Typ = ContactStatics.PhoneNumberTypes.Get("1") ' "home" type
cItem.AddPhoneNumber(cPhoneNumber)
'After a phone number was added it can be set as primary, or use an existing phone number of this contact item:
Dim phoneNumbers() As ContactPhoneNumber
phoneNumbers = cItem.PhoneNumbers
If phoneNumbers.Length > 0 Then
cPhoneNumber = phoneNumbers(0)
End If
cItem.SetPrimaryPhoneNumber(cPhoneNumber)
Something to know about the contact classes:
ContactAddress, ContactEmailAddress, ContactEvent, ContactIM, ContactNickname, ContactOrganization, ContactPhoneNumber, ContactRelation, ContactSipAddress and ContactWebsite.
All of these classes has a TYP property. This property will be set to a default value on initalizing a class. For example a new ContactAddress class object has "home" as default type. The TYP property must have an exact value out of the diffrent type maps that can be found under the ContactStatics module. For example:
B4X:
Dim address As ContactAddress
address.Typ = ContactStatics.AddressTypes.Get("1") ' same as "home"
address.Typ = "home" 'set one of the exact values by your self is also allowed
Dim phoneNumber As ContactPhoneNumber
phoneNumber.Typ = ContactStatics.PhoneNumberTypes.Get("2") ' "mobile"
phoneNumber.Typ = "mobile"
The classes have also a LABEL property. This property can be used for a custom type name. But before a label can be set correctly, the TYP property must be set to "custom".
B4X:
Dim website As ContactWebsite
website.Typ = ContactStatics.WebsiteTypes.Get("0") ' same as = "custom"
website.Label = "Forum"
Versions:
V1.0 Release Version
V1.01 Fixed
- Thumbnail set error removed
- new class ContactItemSnapshot, to get a memory snapshot of a contactitem
- new function GetSnapshot at ContactItem class, to get a snapshot of the given contactitem
- new function GetAllContacts2 at ContactBook class, to get a sorted list of contactitem's
V1.02
- new functions ReadFrom and WriteTo (re)added to ContactItemSnapshot, to store a contact to stream
V>1.02
- For now the source code is free for everyone. I don't have the time to fix something.
- Please upload your bugfixes here for the community.
The attached test project will list all visible contacts and its data entries. A long press will change the
contacts starred state.
Attachments
Last edited: