Methods Summary |
---|
void | addContactListContent(com.android.im.engine.ContactList list)
String selection = Im.ContactList.NAME + "=? AND "
+ Im.ContactList.PROVIDER + "=? AND "
+ Im.ContactList.ACCOUNT + "=?";
String[] selectionArgs = { list.getName(),
Long.toString(mProviderId),
Long.toString(mAccountId) };
Cursor cursor = mResolver.query(Im.ContactList.CONTENT_URI,
CONTACT_LIST_ID_PROJECTION,
selection,
selectionArgs,
null); // no sort order
long listId = 0;
Uri uri = null;
try {
if (cursor.moveToFirst()) {
listId = cursor.getLong(0);
uri = ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, listId);
//Log.d(TAG,"Found and removing ContactList with name "+list.getName());
}
} finally {
cursor.close();
}
if (uri != null) {
// remove existing ContactList and Contacts of that list for replacement by the newly
// downloaded list
mResolver.delete(mContactUrl, Im.Contacts.CONTACTLIST + "=?",
new String[]{Long.toString(listId)});
mResolver.delete(uri, selection, selectionArgs);
}
ContentValues contactListValues = new ContentValues(3);
contactListValues.put(Im.ContactList.NAME, list.getName());
contactListValues.put(Im.ContactList.PROVIDER, mProviderId);
contactListValues.put(Im.ContactList.ACCOUNT, mAccountId);
//Log.d(TAG, "Adding ContactList name="+list.getName());
mValidatedContactLists.add(list.getName());
uri = mResolver.insert(Im.ContactList.CONTENT_URI, contactListValues);
listId = ContentUris.parseId(uri);
synchronized (mContactLists) {
mContactLists.put(list.getAddress(),
new ContactListAdapter(list, listId));
}
Collection<Contact> contacts = list.getContacts();
if (contacts == null || contacts.size() == 0) {
return;
}
Iterator<Contact> iter = contacts.iterator();
while(iter.hasNext()) {
Contact c = iter.next();
String address = c.getAddress().getFullName();
if(isTemporary(address)) {
moveTemporaryContactToList(address, listId);
iter.remove();
}
mValidatedContacts.add(address);
}
ArrayList<String> usernames = new ArrayList<String>();
ArrayList<String> nicknames = new ArrayList<String>();
ArrayList<String> contactTypeArray = new ArrayList<String>();
for (Contact c : contacts) {
String username = c.getAddress().getFullName();
String nickname = c.getName();
int type = Im.Contacts.TYPE_NORMAL;
if(isTemporary(username)) {
type = Im.Contacts.TYPE_TEMPORARY;
}
if (isBlocked(username)) {
type = Im.Contacts.TYPE_BLOCKED;
}
usernames.add(username);
nicknames.add(nickname);
contactTypeArray.add(String.valueOf(type));
}
ContentValues values = new ContentValues(6);
values.put(Im.Contacts.PROVIDER, mProviderId);
values.put(Im.Contacts.ACCOUNT, mAccountId);
values.put(Im.Contacts.CONTACTLIST, listId);
values.putStringArrayList(Im.Contacts.USERNAME, usernames);
values.putStringArrayList(Im.Contacts.NICKNAME, nicknames);
values.putStringArrayList(Im.Contacts.TYPE, contactTypeArray);
mResolver.insert(Im.Contacts.BULK_CONTENT_URI, values);
|
public void | approveSubscription(java.lang.String address)
mAdaptee.approveSubscriptionRequest(address);
|
public int | blockContact(java.lang.String address)
try {
mAdaptee.blockContactAsync(address);
} catch (ImException e) {
return e.getImError().getCode();
}
return ImErrorInfo.NO_ERROR;
|
void | clearHistoryMessages(java.lang.String contact)
Uri uri = Im.Messages.getContentUriByContact(mProviderId,
mAccountId, contact);
mResolver.delete(uri, null, null);
|
public void | clearOnLogout()
clearValidatedContactsAndLists();
clearTemporaryContacts();
clearPresence();
|
void | clearPresence()Clears the presence of the all contacts. As contacts are persist between
IM sessions, the presence need to be cleared after logout.
StringBuilder where = new StringBuilder();
where.append(Im.Presence.CONTACT_ID);
where.append(" in (select _id from contacts where ");
where.append(Im.Contacts.ACCOUNT);
where.append("=");
where.append(mAccountId);
where.append(")");
mResolver.delete(Im.Presence.CONTENT_URI, where.toString(), null);
|
private void | clearTemporaryContacts()Clear the temporary contacts in the database. As contacts are persist between
IM sessions, the temporary contacts need to be cleared after logout.
String selection = Im.Contacts.CONTACTLIST + "=" + FAKE_TEMPORARY_LIST_ID;
mResolver.delete(mContactUrl, selection, null);
|
private void | clearValidatedContactsAndLists()Clears the list of validated contacts and contact lists.
As contacts and contacts lists are added after login, contacts and contact lists are
stored as "validated contacts". After initial download of contacts is complete, any contacts
and contact lists that remain in the database, but are not in the validated list, are
obsolete and should be removed. This function resets that list for use upon login.
// clear the list of validated contacts, contact lists, and blocked contacts
mValidatedContacts.clear();
mValidatedContactLists.clear();
mValidatedBlockedContacts.clear();
|
void | closeChatSession(java.lang.String address)
ChatSessionManagerAdapter sessionManager =
(ChatSessionManagerAdapter) mConn.getChatSessionManager();
ChatSessionAdapter session =
(ChatSessionAdapter) sessionManager.getChatSession(address);
if(session != null) {
session.leave();
}
|
public static int | convertPresenceStatus(com.android.im.engine.Presence presence)Converts the presence status to the value defined for ImProvider.
switch (presence.getStatus()) {
case Presence.AVAILABLE:
return Im.Presence.AVAILABLE;
case Presence.IDLE:
return Im.Presence.IDLE;
case Presence.AWAY:
return Im.Presence.AWAY;
case Presence.DO_NOT_DISTURB:
return Im.Presence.DO_NOT_DISTURB;
case Presence.OFFLINE:
return Im.Presence.OFFLINE;
}
// impossible...
Log.e(TAG, "Illegal presence status value " + presence.getStatus());
return Im.Presence.AVAILABLE;
|
public int | createContactList(java.lang.String name, java.util.List contacts)
try {
mAdaptee.createContactListAsync(name, contacts);
} catch (ImException e) {
return e.getImError().getCode();
}
return ImErrorInfo.NO_ERROR;
|
public com.android.im.engine.Contact | createTemporaryContact(java.lang.String address)
Contact c = mAdaptee.createTemporaryContact(address);
insertTemporary(c);
return c;
|
public void | declineSubscription(java.lang.String address)
mAdaptee.declineSubscriptionRequest(address);
|
void | deleteContactFromDataBase(com.android.im.engine.Contact contact, com.android.im.engine.ContactList list)
String selection = Im.Contacts.USERNAME
+ "=? AND " + Im.Contacts.CONTACTLIST + "=?";
long listId = getContactListAdapter(list.getAddress()).getDataBaseId();
String username = contact.getAddress().getFullName();
String[] selectionArgs = {username, Long.toString(listId)};
mResolver.delete(mContactUrl, selection, selectionArgs);
// clear the history message if the contact doesn't exist in any list
// anymore.
if(mAdaptee.getContact(contact.getAddress()) == null) {
clearHistoryMessages(username);
}
|
public int | deleteContactList(java.lang.String name)
try {
mAdaptee.deleteContactListAsync(name);
} catch (ImException e) {
return e.getImError().getCode();
}
return ImErrorInfo.NO_ERROR;
|
public com.android.im.engine.Contact | getContactByAddress(java.lang.String address)
Contact c = mAdaptee.getContact(address);
if(c == null) {
synchronized (mTemporaryContacts) {
return mTemporaryContacts.get(address);
}
} else {
return c;
}
|
private android.content.ContentValues | getContactContentValues(com.android.im.engine.Contact contact, long listId)
final String username = contact.getAddress().getFullName();
final String nickname = contact.getName();
int type = Im.Contacts.TYPE_NORMAL;
if(isTemporary(username)) {
type = Im.Contacts.TYPE_TEMPORARY;
}
if (isBlocked(username)) {
type = Im.Contacts.TYPE_BLOCKED;
}
ContentValues values = new ContentValues(4);
values.put(Im.Contacts.USERNAME, username);
values.put(Im.Contacts.NICKNAME, nickname);
values.put(Im.Contacts.CONTACTLIST, listId);
values.put(Im.Contacts.TYPE, type);
return values;
|
public com.android.im.IContactList | getContactList(java.lang.String name)
return getContactListAdapter(name);
|
ContactListAdapter | getContactListAdapter(java.lang.String name)
synchronized (mContactLists) {
for (ContactListAdapter list : mContactLists.values()) {
if (name.equals(list.getName())) {
return list;
}
}
return null;
}
|
ContactListAdapter | getContactListAdapter(com.android.im.engine.Address address)
synchronized (mContactLists) {
return mContactLists.get(address);
}
|
public java.util.List | getContactLists()
synchronized (mContactLists) {
return new ArrayList<ContactListAdapter>(mContactLists.values());
}
|
java.lang.String | getDisplayableAddress(java.lang.String impsAddress)
if (impsAddress.startsWith("wv:")) {
return impsAddress.substring(3);
}
return impsAddress;
|
private android.content.ContentValues | getPresenceValues(long contactId, com.android.im.engine.Presence p)
ContentValues values = new ContentValues(3);
values.put(Im.Presence.CONTACT_ID, contactId);
values.put(Im.Contacts.PRESENCE_STATUS, convertPresenceStatus(p));
values.put(Im.Contacts.PRESENCE_CUSTOM_STATUS, p.getStatusText());
values.put(Im.Presence.CLIENT_TYPE, translateClientType(p));
return values;
|
public int | getState()
return mAdaptee.getState();
|
void | insertBlockedContactToDataBase(com.android.im.engine.Contact contact)
// Remove the blocked contact if it already exists, to avoid duplicates and
// handle the odd case where a blocked contact's nickname has changed
removeBlockedContactFromDataBase(contact);
Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, mProviderId);
ContentUris.appendId(builder, mAccountId);
Uri uri = builder.build();
String username = contact.getAddress().getFullName();
ContentValues values = new ContentValues(2);
values.put(Im.BlockedList.USERNAME, username);
values.put(Im.BlockedList.NICKNAME, contact.getName());
mResolver.insert(uri, values);
mValidatedBlockedContacts.add(username);
|
android.net.Uri | insertContactContent(com.android.im.engine.Contact contact, long listId)
ContentValues values = getContactContentValues(contact, listId);
Uri uri = mResolver.insert(mContactUrl, values);
ContentValues presenceValues = getPresenceValues(ContentUris.parseId(uri),
contact.getPresence());
mResolver.insert(Im.Presence.CONTENT_URI, presenceValues);
return uri;
|
android.net.Uri | insertOrUpdateSubscription(java.lang.String username, java.lang.String nickname, int subscriptionType, int subscriptionStatus)Insert or update subscription request from user into the database.
Cursor cursor = mResolver.query(mContactUrl, new String[]{ Im.Contacts._ID },
Im.Contacts.USERNAME + "=?", new String[]{username}, null);
if (cursor == null) {
Log.w(TAG, "query contact " + username + " failed");
return null;
}
Uri uri;
if (cursor.moveToFirst()) {
ContentValues values = new ContentValues(2);
values.put(Im.Contacts.SUBSCRIPTION_TYPE, subscriptionType);
values.put(Im.Contacts.SUBSCRIPTION_STATUS, subscriptionStatus);
long contactId = cursor.getLong(0);
uri = ContentUris.withAppendedId(Im.Contacts.CONTENT_URI, contactId);
mResolver.update(uri, values, null, null);
} else {
ContentValues values = new ContentValues(6);
values.put(Im.Contacts.USERNAME, username);
values.put(Im.Contacts.NICKNAME, nickname);
values.put(Im.Contacts.TYPE, Im.Contacts.TYPE_NORMAL);
values.put(Im.Contacts.CONTACTLIST, FAKE_TEMPORARY_LIST_ID);
values.put(Im.Contacts.SUBSCRIPTION_TYPE, subscriptionType);
values.put(Im.Contacts.SUBSCRIPTION_STATUS, subscriptionStatus);
uri = mResolver.insert(mContactUrl, values);
}
cursor.close();
return uri;
|
private long | insertTemporary(com.android.im.engine.Contact c)
synchronized (mTemporaryContacts) {
mTemporaryContacts.put(c.getAddress().getFullName(), c);
}
Uri uri = insertContactContent(c, FAKE_TEMPORARY_LIST_ID);
return ContentUris.parseId(uri);
|
public boolean | isBlocked(java.lang.String address)
try {
return mAdaptee.isBlocked(address);
} catch (ImException e) {
Log.e(TAG, e.getMessage());
return false;
}
|
public boolean | isTemporary(java.lang.String address)Tells if a contact is a temporary one which is not in the list of
contacts that we subscribe presence for. Usually created because of the
user is having a chat session with this contact.
synchronized (mTemporaryContacts) {
return mTemporaryContacts.containsKey(address);
}
|
public void | loadContactLists()
if(mAdaptee.getState() == ContactListManager.LISTS_NOT_LOADED){
clearValidatedContactsAndLists();
mAdaptee.loadContactListsAsync();
}
|
void | moveTemporaryContactToList(java.lang.String address, long listId)
synchronized (mTemporaryContacts) {
mTemporaryContacts.remove(address);
}
ContentValues values = new ContentValues(2);
values.put(Im.Contacts.TYPE, Im.Contacts.TYPE_NORMAL);
values.put(Im.Contacts.CONTACTLIST, listId);
String selection = Im.Contacts.USERNAME + "=? AND " + Im.Contacts.TYPE + "="
+ Im.Contacts.TYPE_TEMPORARY;
String[] selectionArgs = { address };
mResolver.update(mContactUrl, values, selection, selectionArgs);
|
public long | queryOrInsertContact(com.android.im.engine.Contact c)
long result;
String username = c.getAddress().getFullName();
String selection = Im.Contacts.USERNAME + "=?";
String[] selectionArgs = { username };
String[] projection = {Im.Contacts._ID};
Cursor cursor = mResolver.query(mContactUrl, projection, selection,
selectionArgs, null);
if(cursor != null && cursor.moveToFirst()) {
result = cursor.getLong(0);
} else {
result = insertTemporary(c);
}
if(cursor != null) {
cursor.close();
}
return result;
|
public void | registerContactListListener(com.android.im.IContactListListener listener)
if (listener != null) {
mRemoteContactListeners.register(listener);
}
|
public void | registerSubscriptionListener(com.android.im.ISubscriptionListener listener)
if (listener != null) {
mRemoteSubscriptionListeners.register(listener);
}
|
void | removeBlockedContactFromDataBase(com.android.im.engine.Contact contact)
String address = contact.getAddress().getFullName();
Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, mProviderId);
ContentUris.appendId(builder, mAccountId);
Uri uri = builder.build();
mResolver.delete(uri, Im.BlockedList.USERNAME + "=?", new String[]{ address });
int type = isTemporary(address) ? Im.Contacts.TYPE_TEMPORARY
: Im.Contacts.TYPE_NORMAL;
updateContactType(address, type);
|
public int | removeContact(java.lang.String address)
if(isTemporary(address)) {
// For temporary contact, just close the session and delete him in
// database.
closeChatSession(address);
String selection = Im.Contacts.USERNAME + "=?";
String[] selectionArgs = { address };
mResolver.delete(mContactUrl, selection, selectionArgs);
synchronized (mTemporaryContacts) {
mTemporaryContacts.remove(address);
}
} else {
synchronized (mContactLists) {
for(ContactListAdapter list : mContactLists.values()) {
int resCode = list.removeContact(address);
if (ImErrorInfo.ILLEGAL_CONTACT_ADDRESS == resCode) {
// Did not find in this list, continue to remove from
// other list.
continue;
}
if (ImErrorInfo.NO_ERROR != resCode) {
return resCode;
}
}
}
}
return ImErrorInfo.NO_ERROR;
|
ContactListAdapter | removeContactListFromDataBase(java.lang.String name)
ContactListAdapter listAdapter = getContactListAdapter(name);
if (listAdapter == null) {
return null;
}
long id = listAdapter.getDataBaseId();
// delete contacts of this list first
mResolver.delete(mContactUrl,
Im.Contacts.CONTACTLIST + "=?", new String[]{Long.toString(id)});
mResolver.delete(ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, id), null, null);
synchronized (mContactLists) {
return mContactLists.remove(listAdapter.getAddress());
}
|
private void | removeObsoleteContactsAndLists()
// remove all contacts for this provider & account which have not been
// added since login, yet still exist in db from a prior login
Exclusion exclusion = new Exclusion(Im.Contacts.USERNAME, mValidatedContacts);
mResolver.delete(mContactUrl, exclusion.getSelection(), exclusion.getSelectionArgs());
// remove all blocked contacts for this provider & account which have not been
// added since login, yet still exist in db from a prior login
exclusion = new Exclusion(Im.BlockedList.USERNAME, mValidatedBlockedContacts);
Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, mProviderId);
ContentUris.appendId(builder, mAccountId);
Uri uri = builder.build();
mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());
// remove all contact lists for this provider & account which have not been
// added since login, yet still exist in db from a prior login
exclusion = new Exclusion(Im.ContactList.NAME, mValidatedContactLists);
builder = Im.ContactList.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, mProviderId);
ContentUris.appendId(builder, mAccountId);
uri = builder.build();
mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());
|
private int | translateClientType(com.android.im.engine.Presence presence)
int clientType = presence.getClientType();
switch (clientType) {
case Presence.CLIENT_TYPE_MOBILE:
return Im.Presence.CLIENT_TYPE_MOBILE;
default:
return Im.Presence.CLIENT_TYPE_DEFAULT;
}
|
public int | unBlockContact(java.lang.String address)
try {
mAdaptee.unblockContactAsync(address);
} catch (ImException e) {
Log.e(TAG, e.getMessage());
return e.getImError().getCode();
}
return ImErrorInfo.NO_ERROR;
|
public void | unregisterContactListListener(com.android.im.IContactListListener listener)
if (listener != null) {
mRemoteContactListeners.unregister(listener);
}
|
public void | unregisterSubscriptionListener(com.android.im.ISubscriptionListener listener)
if (listener != null) {
mRemoteSubscriptionListeners.unregister(listener);
}
|
void | updateAvatarsContent(com.android.im.engine.Contact[] contacts)
ArrayList<ContentValues> avatars = new ArrayList<ContentValues>();
ArrayList<String> usernames = new ArrayList<String>();
for (Contact contact : contacts) {
byte[] avatarData = contact.getPresence().getAvatarData();
if (avatarData == null) {
continue;
}
String username = contact.getAddress().getFullName();
ContentValues values = new ContentValues(2);
values.put(Im.Avatars.CONTACT, username);
values.put(Im.Avatars.DATA, avatarData);
avatars.add(values);
usernames.add(username);
}
if (avatars.size() > 0) {
// ImProvider will replace the avatar content if it already exist.
mResolver.bulkInsert(mAvatarUrl, avatars.toArray(
new ContentValues[avatars.size()]));
// notify avatar changed
Intent i = new Intent(ImServiceConstants.ACTION_AVATAR_CHANGED);
i.putExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS, usernames);
i.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, mProviderId);
i.putExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, mAccountId);
mContext.sendBroadcast(i);
}
|
void | updateChatPresence(java.lang.String address, java.lang.String nickname, com.android.im.engine.Presence p)
ChatSessionManagerAdapter sessionManager =
(ChatSessionManagerAdapter) mConn.getChatSessionManager();
// TODO: This only find single chat sessions, we need to go through all
// active chat sessions and find if the contact is a participant of the
// session.
ChatSessionAdapter session =
(ChatSessionAdapter) sessionManager.getChatSession(address);
if(session != null) {
session.insertPresenceUpdatesMsg(nickname, p);
}
|
void | updateContact(java.lang.String username, android.content.ContentValues values)
String selection = Im.Contacts.USERNAME + "=?";
String[] selectionArgs = { username };
mResolver.update(mContactUrl, values, selection, selectionArgs);
|
void | updateContactType(java.lang.String address, int type)
ContentValues values = new ContentValues(1);
values.put(Im.Contacts.TYPE, type);
updateContact(address, values);
|
void | updateListNameInDataBase(com.android.im.engine.ContactList list)
ContactListAdapter listAdapter = getContactListAdapter(list.getAddress());
Uri uri = ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, listAdapter.getDataBaseId());
ContentValues values = new ContentValues(1);
values.put(Im.ContactList.NAME, list.getName());
mResolver.update(uri, values, null, null);
|
void | updatePresenceContent(com.android.im.engine.Contact[] contacts)
ArrayList<String> usernames = new ArrayList<String>();
ArrayList<String> statusArray = new ArrayList<String>();
ArrayList<String> customStatusArray = new ArrayList<String>();
ArrayList<String> clientTypeArray = new ArrayList<String>();
for(Contact c : contacts) {
String username = c.getAddress().getFullName();
Presence p = c.getPresence();
int status = convertPresenceStatus(p);
String customStatus = p.getStatusText();
int clientType = translateClientType(p);
usernames.add(username);
statusArray.add(String.valueOf(status));
customStatusArray.add(customStatus);
clientTypeArray.add(String.valueOf(clientType));
}
ContentValues values = new ContentValues();
values.put(Im.Contacts.ACCOUNT, mAccountId);
values.putStringArrayList(Im.Contacts.USERNAME, usernames);
values.putStringArrayList(Im.Presence.PRESENCE_STATUS, statusArray);
values.putStringArrayList(Im.Presence.PRESENCE_CUSTOM_STATUS, customStatusArray);
values.putStringArrayList(Im.Presence.CONTENT_TYPE, clientTypeArray);
mResolver.update(Im.Presence.BULK_CONTENT_URI, values, null, null);
|