com.vodafone360.people.engine.contactsync
Class NativeContactsApi

java.lang.Object
  extended by com.vodafone360.people.engine.contactsync.NativeContactsApi
Direct Known Subclasses:
NativeContactsApi1, NativeContactsApi2

public abstract class NativeContactsApi
extends java.lang.Object

Class that provides an abstraction layer for accessing the Native Contacts API. The underlying API to be used should be the most suitable for the SDK version of the device.


Nested Class Summary
static class NativeContactsApi.Account
          This Account class represents an available account on the device where the native synchronization can be performed.
static interface NativeContactsApi.ContactsObserver
          The Observer interface to receive notifications about changes in the native address book.
 
Field Summary
protected  Context mContext
          Context to be used by the Instance
protected  ContentResolver mCr
          ContentResolver be used by the Instance
protected  boolean mHaveReadOrganization
          Sadly have to have this so that only one organization may be read from a NAB Contact
protected  int mMarkedOrganizationIndex
          Sadly have to have this because Organization detail is split into two details in CAB
protected  int mMarkedTitleIndex
          Sadly have to have this because Organization detail is split into two details in CAB
protected static java.lang.String PEOPLE_ACCOUNT_TYPE
          Account type for 360 People in the Native Accounts.
private static NativeContactsApi sInstance
          NativeContactsApi the singleton instance providing access to the correct Contacts API interface
 
Constructor Summary
NativeContactsApi()
           
 
Method Summary
abstract  ContactChange[] addContact(NativeContactsApi.Account account, ContactChange[] ccList)
          Adds a contact.
abstract  boolean addPeopleAccount(java.lang.String username)
          Adds the currently logged in user account to the NAB accounts.
static void createInstance(Context context)
          Create NativeContactsApi singleton instance for later usage.
static void destroyInstance()
          Destroy NativeContactsApi singleton instance if created.
abstract  NativeContactsApi.Account[] getAccounts()
          Fetches all the existing Accounts on the device.
abstract  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.
abstract  ContactChange[] getContact(long nabContactId)
          Gets data for one Contact.
abstract  long[] getContactIds(NativeContactsApi.Account account)
          Retrieves a list of contact IDs for a specific account.
static NativeContactsApi getInstance()
          Retrieves singleton instance providing access to the native contacts api.
protected abstract  void initialize()
          Method meant to be called only just after createInstance() is invoked.
abstract  boolean isKeySupported(int key)
          Checks whether or not a ContactChange key is supported.
abstract  boolean isPeopleAccountCreated()
          Checks if there is a People Account in the NAB Accounts.
abstract  void registerObserver(NativeContactsApi.ContactsObserver observer)
          Registers a content observer.
abstract  void removeContact(long nabContactId)
          Removes a contact
abstract  void removePeopleAccount()
          Removes the (first found) People Account from the NAB accounts.
abstract  void unregisterObserver()
          Unregister the previously registered content observer.
abstract  ContactChange[] updateContact(ContactChange[] ccList)
          Updates an existing contact.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PEOPLE_ACCOUNT_TYPE

protected static final java.lang.String PEOPLE_ACCOUNT_TYPE
Account type for 360 People in the Native Accounts. MUST be a copy of type in 'res/xml/authenticator.xml'

See Also:
Constant Field Values

sInstance

private static NativeContactsApi sInstance
NativeContactsApi the singleton instance providing access to the correct Contacts API interface


mContext

protected Context mContext
Context to be used by the Instance


mCr

protected ContentResolver mCr
ContentResolver be used by the Instance


mHaveReadOrganization

protected boolean mHaveReadOrganization
Sadly have to have this so that only one organization may be read from a NAB Contact


mMarkedOrganizationIndex

protected int mMarkedOrganizationIndex
Sadly have to have this because Organization detail is split into two details in CAB


mMarkedTitleIndex

protected int mMarkedTitleIndex
Sadly have to have this because Organization detail is split into two details in CAB

Constructor Detail

NativeContactsApi

public NativeContactsApi()
Method Detail

createInstance

public static void createInstance(Context context)
Create NativeContactsApi singleton instance for later usage. The instance can retrieved by calling getInstance(). * The instance can be destroyed by calling destroyInstance()

Parameters:
context - The context to be used by the singleton
See Also:
getInstance(), destroyInstance()

destroyInstance

public static void destroyInstance()
Destroy NativeContactsApi singleton instance if created. The instance can be recreated by calling createInstance()

See Also:
NativeContactsApi#createInstance()

getInstance

public static NativeContactsApi getInstance()
Retrieves singleton instance providing access to the native contacts api.

Returns:
NativeContactsApi appropriate subclass instantiation

initialize

protected abstract void initialize()
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.


registerObserver

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

Parameters:
observer - ContactsObserver currently observing native address book changes
Throws:
java.lang.RuntimeException - if a new observer is being registered without having unregistered the previous one

unregisterObserver

public abstract void unregisterObserver()
Unregister the previously registered content observer.


getAccounts

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

Returns:
An array containing all the Accounts on the device, or null if none exist

getAccountsByType

public abstract 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. The 1.X implementation always returns null.

Parameters:
type - The Type of Account to fetch
Returns:
An array containing all the Accounts of the provided Type, or null if none exist

addPeopleAccount

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

Returns:
true if successful, false if not

isPeopleAccountCreated

public abstract boolean isPeopleAccountCreated()
Checks if there is a People Account in the NAB Accounts. Only supported on 2.X The 1.X implementation does nothing.

Returns:
true if an account exists, false if not.

removePeopleAccount

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


getContactIds

public abstract long[] getContactIds(NativeContactsApi.Account account)
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.

Parameters:
account - The account to get contact IDs from (may be null)
Returns:
List of contact IDs from the native address book

getContact

public abstract ContactChange[] getContact(long nabContactId)
Gets data for one Contact.

Parameters:
nabContactId - Native ID for the contact
Returns:
A ContactChange array with contact's data or null

addContact

public abstract ContactChange[] addContact(NativeContactsApi.Account account,
                                           ContactChange[] ccList)
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.

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.

updateContact

public abstract ContactChange[] updateContact(ContactChange[] ccList)
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.

Parameters:
ccList - The Contact update data as a ContactChange array
Returns:
A ContactChange array with the contact's new ID data or null

removeContact

public abstract void removeContact(long nabContactId)
Removes a contact

Parameters:
nabContactId - Native ID of the contact to remove

isKeySupported

public abstract boolean isKeySupported(int key)
Checks whether or not a ContactChange key is supported. Results may vary in 1.X and 2.X

Parameters:
key - Key to check for support
Returns:
true if supported, false if not


JavaDoc