public class VCardComposer extends Object
The class for composing vCard from Contacts information.
Usually, this class should be used like this.
VCardComposer composer = null; try { composer = new VCardComposer(context); composer.addHandler( composer.new HandlerForOutputStream(outputStream)); if (!composer.init()) { // Do something handling the situation. return; } while (!composer.isAfterLast()) { if (mCanceled) { // Assume a user may cancel this operation during the export. return; } if (!composer.createOneEntry()) { // Do something handling the error situation. return; } } } finally { if (composer != null) { composer.terminate(); } }
Users have to manually take care of memory efficiency. Even one vCard may contain image of non-trivial size for mobile devices.
VCardBuilder
is used to build each vCard.
Modifier and Type | Class and Description |
---|---|
static class |
VCardComposer.RawContactEntitlesInfo
Class that store rawContactEntitlesUri and contactId
|
static interface |
VCardComposer.RawContactEntitlesInfoCallback
Listener for getting raw contact entitles info
|
Modifier and Type | Field and Description |
---|---|
static String |
FAILURE_REASON_FAILED_TO_GET_DATABASE_INFO |
static String |
FAILURE_REASON_NO_ENTRY |
static String |
FAILURE_REASON_NOT_INITIALIZED |
static String |
FAILURE_REASON_UNSUPPORTED_URI
Should be visible only from developers...
|
static String |
NO_ERROR |
Constructor and Description |
---|
VCardComposer(Context context) |
VCardComposer(Context context,
ContentResolver resolver,
int vcardType,
String charset,
boolean careHandlerErrors)
Just for testing for now.
|
VCardComposer(Context context,
int vcardType)
The variant which sets charset to null and sets careHandlerErrors to true.
|
VCardComposer(Context context,
int vcardType,
boolean careHandlerErrors)
The variant which sets charset to null.
|
VCardComposer(Context context,
int vcardType,
String charset) |
VCardComposer(Context context,
int vcardType,
String charset,
boolean careHandlerErrors)
Constructs for supporting call log entry vCard composing.
|
Modifier and Type | Method and Description |
---|---|
String |
buildVCard(Map<String,List<ContentValues>> contentValuesListMap)
Builds and returns vCard using given map, whose key is CONTENT_ITEM_TYPE defined in
{ContactsContract}.
|
String |
createOneEntry() |
String |
createOneEntry(Method getEntityIteratorMethod) |
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
getCount() |
String |
getErrorReason() |
boolean |
init()
Initializes this object using default
ContactsContract.Contacts.CONTENT_URI . |
boolean |
init(Cursor cursor)
Just for testing for now.
|
boolean |
init(String selection,
String[] selectionArgs)
Initializes this object using default
ContactsContract.Contacts.CONTENT_URI and given selection
arguments. |
boolean |
init(Uri contentUri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder,
Uri contentUriForRawContactsEntity)
A variant of init().
|
boolean |
init(Uri contentUri,
String selection,
String[] selectionArgs,
String sortOrder)
Note that this is unstable interface, may be deleted in the future.
|
boolean |
init(Uri contentUri,
String selection,
String[] selectionArgs,
String sortOrder,
Uri contentUriForRawContactsEntity) |
boolean |
initWithCallback(Cursor cursor,
VCardComposer.RawContactEntitlesInfoCallback rawContactEntitlesInfoCallback) |
boolean |
initWithRawContactsEntityUri(Uri contentUriForRawContactsEntity)
Deprecated.
Use
init(Uri, String[], String, String[], String, Uri) if you really
need to change the default Uri. |
boolean |
isAfterLast() |
void |
setPhoneNumberTranslationCallback(VCardPhoneNumberTranslationCallback callback)
Set a callback for phone number formatting.
|
void |
terminate() |
public static final String FAILURE_REASON_FAILED_TO_GET_DATABASE_INFO
public static final String FAILURE_REASON_NO_ENTRY
public static final String FAILURE_REASON_NOT_INITIALIZED
public static final String FAILURE_REASON_UNSUPPORTED_URI
public static final String NO_ERROR
public VCardComposer(Context context)
public VCardComposer(Context context, int vcardType)
public VCardComposer(Context context, int vcardType, boolean careHandlerErrors)
public VCardComposer(Context context, int vcardType, String charset, boolean careHandlerErrors)
context
- Context to be used during the composition.vcardType
- The type of vCard, typically available via VCardConfig
.charset
- The charset to be used. Use null when you don't need the charset.careHandlerErrors
- If true, This object returns false everytimepublic VCardComposer(Context context, ContentResolver resolver, int vcardType, String charset, boolean careHandlerErrors)
resolver
- ContentResolver
which used by this object.public boolean init()
ContactsContract.Contacts.CONTENT_URI
.
You can call this method or a variant of this method just once. In other words, you cannot
reuse this object.@Deprecated public boolean initWithRawContactsEntityUri(Uri contentUriForRawContactsEntity)
init(Uri, String[], String, String[], String, Uri)
if you really
need to change the default Uri.ContactsContract.RawContactsEntity
from
ContentResolver
with BaseColumns._ID
.
String selection = Data.CONTACT_ID + "=?";
String[] selectionArgs = new String[] {contactId};
Cursor cursor = mContentResolver.query(
contentUriForRawContactsEntity, null, selection, selectionArgs, null)
You can call this method or a variant of this method just once. In other words, you cannot
reuse this object.public boolean init(String selection, String[] selectionArgs)
ContactsContract.Contacts.CONTENT_URI
and given selection
arguments.public boolean init(Uri contentUri, String selection, String[] selectionArgs, String sortOrder)
public boolean init(Uri contentUri, String selection, String[] selectionArgs, String sortOrder, Uri contentUriForRawContactsEntity)
contentUri
- Uri for obtaining the list of contactId. Used with
ContentResolver.query(Uri, String[], String, String[], String)
selection
- selection used with
ContentResolver.query(Uri, String[], String, String[], String)
selectionArgs
- selectionArgs used with
ContentResolver.query(Uri, String[], String, String[], String)
sortOrder
- sortOrder used with
ContentResolver.query(Uri, String[], String, String[], String)
contentUriForRawContactsEntity
- Uri for obtaining entries relevant to each
contactId.
Note that this is an unstable interface, may be deleted in the future.public boolean init(Uri contentUri, String[] projection, String selection, String[] selectionArgs, String sortOrder, Uri contentUriForRawContactsEntity)
Cursor
for the list of contactId.
Cursor cursorForId = mContentResolver.query(
contentUri, projection, selection, selectionArgs, sortOrder);
After that, we'll obtain data for each contactId in the list.
Cursor cursorForContent = mContentResolver.query(
contentUriForRawContactsEntity, null,
Data.CONTACT_ID + "=?", new String[] {contactId}, null)
createOneEntry()
or its variants let the caller obtain each entry from
cursorForContent
above.contentUri
- Uri for obtaining the list of contactId. Used with
ContentResolver.query(Uri, String[], String, String[], String)
projection
- projection used with
ContentResolver.query(Uri, String[], String, String[], String)
selection
- selection used with
ContentResolver.query(Uri, String[], String, String[], String)
selectionArgs
- selectionArgs used with
ContentResolver.query(Uri, String[], String, String[], String)
sortOrder
- sortOrder used with
ContentResolver.query(Uri, String[], String, String[], String)
contentUriForRawContactsEntity
- Uri for obtaining entries relevant to each
contactId.public boolean init(Cursor cursor)
public boolean initWithCallback(Cursor cursor, VCardComposer.RawContactEntitlesInfoCallback rawContactEntitlesInfoCallback)
cursor
- Cursor that used to get contact idrawContactEntitlesInfoCallback
- Callback that return RawContactEntitlesInfo
Note that this is an unstable interface, may be deleted in the future.public String createOneEntry()
public void setPhoneNumberTranslationCallback(VCardPhoneNumberTranslationCallback callback)
Set a callback for phone number formatting. It will be called every time when this object receives a phone number for printing.
When this is set VCardConfig.FLAG_REFRAIN_PHONE_NUMBER_FORMATTING
will be ignored
and the callback should be responsible for everything about phone number formatting.
Caution: This interface will change. Please don't use without any strong reason.
public String buildVCard(Map<String,List<ContentValues>> contentValuesListMap)
public void terminate()
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public int getCount()
init()
is not called
or when terminate()
is already called).public boolean isAfterLast()
public String getErrorReason()