com.vodafone360.people.engine.contactsync
Class NativeContactsApi1

java.lang.Object
  extended by com.vodafone360.people.engine.contactsync.NativeContactsApi
      extended by com.vodafone360.people.engine.contactsync.NativeContactsApi1

public class NativeContactsApi1
extends NativeContactsApi

The implementation of the NativeContactsApi for the Android 1.X platform.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.vodafone360.people.engine.contactsync.NativeContactsApi
NativeContactsApi.Account, NativeContactsApi.ContactsObserver
 
Field Summary
private static int CONTACT_METHODS_KIND_ADDRESS
          Contact methods table kind value for postal address.
private static int CONTACT_METHODS_KIND_EMAIL
          Contact methods table kind value for email.
private static java.lang.String[] CONTACTID_PROJECTION
          Convenience Contact ID Projection.
private  NativeContactsApi.ContactsObserver mContactsObserver
          The registered ContactsObserver.
private  ContentObserver mNativeObserver
          The observer for the native contacts.
private  ContentValues mValues
          Values used for writing to NAB
private static java.lang.String[] PEOPLE_PROJECTION
          Convenience Projection for the NATE and NOTES from the People table
private static SparseIntArray sSupportedKeys
          Mapping of supported ContactChange Keys.
 
Fields inherited from class com.vodafone360.people.engine.contactsync.NativeContactsApi
mContext, mCr, mHaveReadOrganization, mMarkedOrganizationIndex, mMarkedTitleIndex, PEOPLE_ACCOUNT_TYPE
 
Constructor Summary
NativeContactsApi1()
           
 
Method Summary
 ContactChange[] addContact(NativeContactsApi.Account account, ContactChange[] ccList)
          Adds a contact.
 boolean addPeopleAccount(java.lang.String username)
          Adds the currently logged in user account to the NAB accounts.
private  boolean deleteDetail(int key, long nabContactId, long nabDetailId)
          Deletes a detail from NAB
 NativeContactsApi.Account[] getAccounts()
          Fetches all the existing Accounts on the device.
 NativeContactsApi.Account[] getAccountsByType(java.lang.String type)
          Fetches all the existing Accounts on the device corresponding to the provided Type Only supported on 2.X.
 ContactChange[] getContact(long nabContactId)
          Gets data for one Contact.
 long[] getContactIds(NativeContactsApi.Account account)
          Retrieves a list of contact IDs for a specific account.
protected  void initialize()
          Method meant to be called only just after createInstance() is invoked.
private  long insertDetail(ContactChange cc, long nabContactId)
          Inserts a new detail to NAB
 boolean isKeySupported(int key)
          Checks whether or not a ContactChange key is supported.
 boolean isPeopleAccountCreated()
          Checks if there is a People Account in the NAB Accounts.
private static int mapFromNabContactMethodType(int nabType)
          Maps a method type from the native value into the ContactChange flags
private static int mapFromNabOrganizationType(int nabType)
          Maps a organization type from the native value into the ContactChange flags
private static int mapFromNabPhoneType(int nabType)
          Maps a phone type from the native value to the ContactChange flags.
private static int mapToNabContactMethodType(int flags)
          Maps ContactChange flags into the native method type.
private static int mapToNabOrganizationType(int flags)
          Maps ContactChange flags into the native organization type.
private static int mapToNabPhoneType(int flags)
          Maps ContactChange flags into the native phone type.
private static VCardHelper.PostalAddress parseRawAddress(java.lang.String rawAddress)
          Utility method used to parse a raw display Address into a VCardHelper.PostalAddress object.
private  void preprocessContactToAdd(ContactChange[] ccList)
          "Pre-processing" of ContactChange list before it can be added to NAB.
private  void processOrganization(ContactChange[] ccList, ContactChange[] idChangeList, long nabContactId)
          Ugly method to process organization for writing to NAB
private  void putContactMethodValues(ContactChange cc, int kind, long nabContactId)
          Put Contact Methods detail into the values
private  void putPhoneValues(ContactChange cc, long nabContactId)
          Put Phone detail into the values
private  ContactChange readContactMethod(Cursor cursor)
          Reads one Contact Method Detail from the supplied cursor into a ContactChange
private  void readContactMethods(java.util.List<ContactChange> ccList, long nabContactId)
          Reads Contact Method details from a Contact into the provided ContactChange List
private  void readContactOrganization(Cursor cursor, java.util.List<ContactChange> ccList, long nabContactId)
          Reads one Organization Detail from the supplied cursor into a ContactChange Note that this method may actually read up to 2 into Contact Changes.
private  void readContactOrganizations(java.util.List<ContactChange> ccList, long nabContactId)
          Reads Organization details from a Contact into the provided ContactChange List
private  ContactChange readContactPhoneNumber(Cursor cursor)
          Reads one Phone Number Detail from the supplied cursor into a ContactChange
private  void readContactPhoneNumbers(java.util.List<ContactChange> ccList, long nabContactId)
          Reads Phone Number details from a Contact into the provided ContactChange List
 void registerObserver(NativeContactsApi.ContactsObserver observer)
          Registers a content observer.
 void removeContact(long nabContactId)
          Removes a contact
 void removePeopleAccount()
          Removes the (first found) People Account from the NAB accounts.
 void unregisterObserver()
          Unregister the previously registered content observer.
 ContactChange[] updateContact(ContactChange[] ccList)
          Updates an existing contact.
private  boolean updateDetail(ContactChange cc)
          Updates a detail.
private  long updateOrganization(ContactChange[] ccList, long nabContactId)
          Updates the Organization detail in the context of a Contact Update operation.
private  void writeDetails(ContactChange[] ccList, ContactChange[] idChangeList, long nabContactId)
          Writes new details from a provided ContactChange list into the NAB.
private  long writeOrganization(ContactChange[] ccList, long nabContactId)
          Write Organization detail to NAB
 
Methods inherited from class com.vodafone360.people.engine.contactsync.NativeContactsApi
createInstance, destroyInstance, getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTACTID_PROJECTION

private static final java.lang.String[] CONTACTID_PROJECTION
Convenience Contact ID Projection.


PEOPLE_PROJECTION

private static final java.lang.String[] PEOPLE_PROJECTION
Convenience Projection for the NATE and NOTES from the People table


CONTACT_METHODS_KIND_EMAIL

private static final int CONTACT_METHODS_KIND_EMAIL
Contact methods table kind value for email.

See Also:
Constant Field Values

CONTACT_METHODS_KIND_ADDRESS

private static final int CONTACT_METHODS_KIND_ADDRESS
Contact methods table kind value for postal address.

See Also:
Constant Field Values

sSupportedKeys

private static final SparseIntArray sSupportedKeys
Mapping of supported ContactChange Keys.


mValues

private final ContentValues mValues
Values used for writing to NAB


mContactsObserver

private NativeContactsApi.ContactsObserver mContactsObserver
The registered ContactsObserver.

See Also:
NativeContactsApi.registerObserver(ContactsObserver)

mNativeObserver

private ContentObserver mNativeObserver
The observer for the native contacts.

Constructor Detail

NativeContactsApi1

public NativeContactsApi1()
Method Detail

initialize

protected void initialize()
Description copied from class: NativeContactsApi
Method meant to be called only just after createInstance() is invoked. This method effectively acts as a replacement for the constructor because of the use of reflection.

Specified by:
initialize in class NativeContactsApi
See Also:
NativeContactsApi.initialize()

registerObserver

public void registerObserver(NativeContactsApi.ContactsObserver observer)
Description copied from class: NativeContactsApi
Registers a content observer. Note: the method only supports one observer at a time.

Specified by:
registerObserver in class NativeContactsApi
Parameters:
observer - ContactsObserver currently observing native address book changes
See Also:
NativeContactsApi.registerObserver(ContactsObserver)

unregisterObserver

public void unregisterObserver()
Description copied from class: NativeContactsApi
Unregister the previously registered content observer.

Specified by:
unregisterObserver in class NativeContactsApi
See Also:
NativeContactsApi.unregisterObserver()

getAccounts

public NativeContactsApi.Account[] getAccounts()
Description copied from class: NativeContactsApi
Fetches all the existing Accounts on the device. Only supported on 2.X. The 1.X implementation always returns null.

Specified by:
getAccounts in class NativeContactsApi
Returns:
An array containing all the Accounts on the device, or null if none exist
See Also:
NativeContactsApi.getAccounts()

getAccountsByType

public NativeContactsApi.Account[] getAccountsByType(java.lang.String type)
Description copied from class: NativeContactsApi
Fetches all the existing Accounts on the device corresponding to the provided Type Only supported on 2.X. The 1.X implementation always returns null.

Specified by:
getAccountsByType in class NativeContactsApi
Parameters:
type - The Type of Account to fetch
Returns:
An array containing all the Accounts of the provided Type, or null if none exist
See Also:
NativeContactsApi.getAccountsByType(String)

addPeopleAccount

public boolean addPeopleAccount(java.lang.String username)
Description copied from class: NativeContactsApi
Adds the currently logged in user account to the NAB accounts. Only supported on 2.X. The 1.X implementation does nothing.

Specified by:
addPeopleAccount in class NativeContactsApi
Returns:
true if successful, false if not
See Also:
NativeContactsApi.addPeopleAccount(String)

isPeopleAccountCreated

public boolean isPeopleAccountCreated()
Description copied from class: NativeContactsApi
Checks if there is a People Account in the NAB Accounts. Only supported on 2.X The 1.X implementation does nothing.

Specified by:
isPeopleAccountCreated in class NativeContactsApi
Returns:
true if an account exists, false if not.
See Also:
NativeContactsApi.isPeopleAccountCreated()

removePeopleAccount

public void removePeopleAccount()
Description copied from class: NativeContactsApi
Removes the (first found) People Account from the NAB accounts. Only supported on 2.X. The 1.X implementation does nothing.

Specified by:
removePeopleAccount in class NativeContactsApi
See Also:
NativeContactsApi.removePeopleAccount()

getContactIds

public long[] getContactIds(NativeContactsApi.Account account)
Description copied from class: NativeContactsApi
Retrieves a list of contact IDs for a specific account. In 1.X devices only the null account is supported, i.e., a non null account always uses null as a return value.

Specified by:
getContactIds in class NativeContactsApi
Parameters:
account - The account to get contact IDs from (may be null)
Returns:
List of contact IDs from the native address book
See Also:
NativeContactsApi.getContactIds(Account)

getContact

public ContactChange[] getContact(long nabContactId)
Description copied from class: NativeContactsApi
Gets data for one Contact.

Specified by:
getContact in class NativeContactsApi
Parameters:
nabContactId - Native ID for the contact
Returns:
A ContactChange array with contact's data or null
See Also:
NativeContactsApi.getContact(long)

addContact

public ContactChange[] addContact(NativeContactsApi.Account account,
                                  ContactChange[] ccList)
Description copied from class: NativeContactsApi
Adds a contact. Note that the returned ID data will be the same size of ccList plus one change containing the NAB Contact ID (at the first position). The remaining IDs correspond to the details in the original change list. Null IDs among these remaining IDs are possible when these correspond to unsupported details. On 1.X Devices only a null account parameter is expected.

Specified by:
addContact in class NativeContactsApi
Parameters:
account - Account to be associated with the added contact (may be null).
ccList - The Contact data as a ContactChange array
Returns:
A ContactChange array with contact's new ID data or null in case of failure.
See Also:
NativeContactsApi.addContact(Account, ContactChange[])

updateContact

public ContactChange[] updateContact(ContactChange[] ccList)
Description copied from class: NativeContactsApi
Updates an existing contact. The returned ID data will be the same size of the ccList. However, if a null or empty ccList is passed as an argument then null is returned. Null IDs among the ID data are also possible when these correspond to unsupported details.

Specified by:
updateContact in class NativeContactsApi
Parameters:
ccList - The Contact update data as a ContactChange array
Returns:
A ContactChange array with the contact's new ID data or null
See Also:
NativeContactsApi.updateContact(ContactChange[])

removeContact

public void removeContact(long nabContactId)
Description copied from class: NativeContactsApi
Removes a contact

Specified by:
removeContact in class NativeContactsApi
Parameters:
nabContactId - Native ID of the contact to remove
See Also:
NativeContactsApi.removeContact(long)

isKeySupported

public boolean isKeySupported(int key)
Description copied from class: NativeContactsApi
Checks whether or not a ContactChange key is supported. Results may vary in 1.X and 2.X

Specified by:
isKeySupported in class NativeContactsApi
Parameters:
key - Key to check for support
Returns:
true if supported, false if not
See Also:
NativeContactsApi.isKeySupported(int)

readContactPhoneNumbers

private void readContactPhoneNumbers(java.util.List<ContactChange> ccList,
                                     long nabContactId)
Reads Phone Number details from a Contact into the provided ContactChange List

Parameters:
ccList - ContactChange list to add details into
nabContactId - ID of the NAB Contact

readContactPhoneNumber

private ContactChange readContactPhoneNumber(Cursor cursor)
Reads one Phone Number Detail from the supplied cursor into a ContactChange

Parameters:
cursor - Cursor to read from
Returns:
Read Phone Number Detail or null

readContactMethods

private void readContactMethods(java.util.List<ContactChange> ccList,
                                long nabContactId)
Reads Contact Method details from a Contact into the provided ContactChange List

Parameters:
ccList - ContactChange list to add details into
nabContactId - ID of the NAB Contact

readContactMethod

private ContactChange readContactMethod(Cursor cursor)
Reads one Contact Method Detail from the supplied cursor into a ContactChange

Parameters:
cursor - Cursor to read from
Returns:
Read Contact Method Detail or null

readContactOrganizations

private void readContactOrganizations(java.util.List<ContactChange> ccList,
                                      long nabContactId)
Reads Organization details from a Contact into the provided ContactChange List

Parameters:
ccList - ContactChange list to add details into
nabContactId - ID of the NAB Contact

readContactOrganization

private void readContactOrganization(Cursor cursor,
                                     java.util.List<ContactChange> ccList,
                                     long nabContactId)
Reads one Organization Detail from the supplied cursor into a ContactChange Note that this method may actually read up to 2 into Contact Changes. However, Organization and Title may only be read if a boolean flag is not set

Parameters:
cursor - Cursor to read from
ccList - ContactChange list to add details to

preprocessContactToAdd

private void preprocessContactToAdd(ContactChange[] ccList)
"Pre-processing" of ContactChange list before it can be added to NAB. This needs to be done because of issues on the 1.X NAB and our CAB In 1.X NAB: Name and Note which are stored differently from other details In our CAB: Organization and Title are separate details contrary to the NAB

Parameters:
ccList - ContactChange list for the add operation

writeDetails

private void writeDetails(ContactChange[] ccList,
                          ContactChange[] idChangeList,
                          long nabContactId)
Writes new details from a provided ContactChange list into the NAB. The resulting detail IDs are put in another provided ContactChange list.

Parameters:
ccList - ContactChange list to write from
idChangeList - ContatChange list where IDs for the written details are put
nabContactId - ID of the NAB Contact

insertDetail

private long insertDetail(ContactChange cc,
                          long nabContactId)
Inserts a new detail to NAB

Parameters:
cc - ContactChange to read data from
nabContactId - ID of the NAB Contact
Returns:
The created detail's ID

updateDetail

private boolean updateDetail(ContactChange cc)
Updates a detail.

Parameters:
cc - ContactChange to read data from
nabContactId - ID of the NAB Contact
Returns:
true if the detail was updated, false if not

deleteDetail

private boolean deleteDetail(int key,
                             long nabContactId,
                             long nabDetailId)
Deletes a detail from NAB

Parameters:
key - The detail key
nabContactId - ID of the NAB Contact
nabDetailId - ID of the NAB Detail
Returns:
true if the detail was deleted, false if not

putPhoneValues

private void putPhoneValues(ContactChange cc,
                            long nabContactId)
Put Phone detail into the values

Parameters:
cc -
nabContactId - ID of the NAB Contact

putContactMethodValues

private void putContactMethodValues(ContactChange cc,
                                    int kind,
                                    long nabContactId)
Put Contact Methods detail into the values

Parameters:
cc - ContactChange to read values from
kind - The kind of contact method (email or address)
nabContactId - ID of the NAB Contact

processOrganization

private void processOrganization(ContactChange[] ccList,
                                 ContactChange[] idChangeList,
                                 long nabContactId)
Ugly method to process organization for writing to NAB

Parameters:
ccList - ContactChange list to fetch organization from
idChangeList - ContatChange list where IDs for the written organization are put
nabContactId - ID of the NAB Contact

writeOrganization

private long writeOrganization(ContactChange[] ccList,
                               long nabContactId)
Write Organization detail to NAB

Parameters:
ccList - ContactChange list where Organization and Title are found
nabContactId - ID of the NAB Contact
Returns:
ID of the NAB Contact

updateOrganization

private long updateOrganization(ContactChange[] ccList,
                                long nabContactId)
Updates the Organization detail in the context of a Contact Update operation. The end of result of this is that the Organization may be inserted, updated or deleted depending on the update data. For example, if the title is deleted but there is also a company name then the Organization is just updated. However, if there was no company name then the detail should be deleted altogether.

Parameters:
ccList - ContactChange list where Organization and Title may be found
nabContactId - The NAB ID of the Contact
Returns:
In the Organization insertion case this should contain the new ID and in the update case should contain the existing ID

mapFromNabPhoneType

private static int mapFromNabPhoneType(int nabType)
Maps a phone type from the native value to the ContactChange flags.

Parameters:
nabType - Given native phone number type
Returns:
ContactChange flags

mapToNabPhoneType

private static int mapToNabPhoneType(int flags)
Maps ContactChange flags into the native phone type.

Parameters:
flags - ContactChange flags
Returns:
Native phone type

mapFromNabContactMethodType

private static int mapFromNabContactMethodType(int nabType)
Maps a method type from the native value into the ContactChange flags

Parameters:
nabType - Native method type
Returns:
ContactChange flags

mapToNabContactMethodType

private static int mapToNabContactMethodType(int flags)
Maps ContactChange flags into the native method type.

Parameters:
flags - ContactChange flags
Returns:
Native method type

mapFromNabOrganizationType

private static int mapFromNabOrganizationType(int nabType)
Maps a organization type from the native value into the ContactChange flags

Parameters:
nabType - Given native organization type
Returns:
ContactChange flags

mapToNabOrganizationType

private static int mapToNabOrganizationType(int flags)
Maps ContactChange flags into the native organization type.

Parameters:
flags - ContactChange flags
Returns:
Native Organization type

parseRawAddress

private static VCardHelper.PostalAddress parseRawAddress(java.lang.String rawAddress)
Utility method used to parse a raw display Address into a VCardHelper.PostalAddress object. The purpose of this method is simply to remove '\n' separators. It does not aim to correctly map address components to the right place, e.g. it is not guaranteed that 'PostalAddress.Country' will really be the Country.



JavaDoc