use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method putName.
/**
* Put Name detail into the values
*
* @param cc {@link ContactChange} to read values from
*/
private void putName(ContactChange cc) {
final Name name = VCardHelper.getName(cc.getValue());
if (name == null) {
// Nothing to do
return;
}
mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
mValues.put(StructuredName.GIVEN_NAME, name.firstname);
mValues.put(StructuredName.FAMILY_NAME, name.surname);
mValues.put(StructuredName.PREFIX, name.title);
mValues.put(StructuredName.MIDDLE_NAME, name.midname);
mValues.put(StructuredName.SUFFIX, name.suffixes);
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method readName.
/**
* Reads an name detail as a {@link ContactChange} from the provided cursor.
* For this type of detail we need to use a VCARD (semicolon separated)
* value.
*
* @param cursor Cursor to read from
* @param ccList List of Contact Changes to add read detail data
* @param nabContactId ID of the NAB Contact
*/
private void readName(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
// Using display name only to check if there is a valid name to read
final String displayName = CursorUtils.getString(cursor, StructuredName.DISPLAY_NAME);
if (!TextUtils.isEmpty(displayName)) {
final long nabDetailId = CursorUtils.getLong(cursor, StructuredName._ID);
// VCard Helper data type (CAB)
final Name name = new Name();
// NAB: Given name -> CAB: First name
name.firstname = CursorUtils.getString(cursor, StructuredName.GIVEN_NAME);
// NAB: Family name -> CAB: Surname
name.surname = CursorUtils.getString(cursor, StructuredName.FAMILY_NAME);
// NAB: Prefix -> CAB: Title
name.title = CursorUtils.getString(cursor, StructuredName.PREFIX);
// NAB: Middle name -> CAB: Middle name
name.midname = CursorUtils.getString(cursor, StructuredName.MIDDLE_NAME);
// NAB: Suffix -> CAB: Suffixes
name.suffixes = CursorUtils.getString(cursor, StructuredName.SUFFIX);
// NOTE: Ignoring Phonetics (DATA7, DATA8 and DATA9)!
// TODO: Need to get middle name and concatenate into value
final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
cc.setNabContactId(nabContactId);
cc.setNabDetailId(nabDetailId);
ccList.add(cc);
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method updateOrganization.
/**
* 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.
*
* @param ccList {@link ContactChange} list where Organization and Title may
* be found
* @param nabContactId The NAB ID of the Contact
*/
private void updateOrganization(ContactChange[] ccList, long nabContactId) {
if (mMarkedOrganizationIndex < 0 && mMarkedTitleIndex < 0) {
// no organization or title to update - do nothing
return;
}
// First we check if there is an existing Organization detail in NAB
final Uri uri = Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, nabContactId), RawContacts.Data.CONTENT_DIRECTORY);
Cursor cursor = mCr.query(uri, null, ORGANIZATION_DETAIL_WHERE_CLAUSE, null, RawContacts.Data._ID);
String company = null;
String department = null;
String title = null;
int flags = ContactChange.FLAG_NONE;
try {
if (cursor != null && cursor.moveToNext()) {
// Found an organization detail
company = CursorUtils.getString(cursor, Organization.COMPANY);
department = CursorUtils.getString(cursor, Organization.DEPARTMENT);
title = CursorUtils.getString(cursor, Organization.TITLE);
flags = mapFromNabOrganizationType(CursorUtils.getInt(cursor, Organization.TYPE));
final boolean isPrimary = CursorUtils.getInt(cursor, Organization.IS_PRIMARY) > 0;
if (isPrimary) {
flags |= ContactChange.FLAG_PREFERRED;
}
mExistingOrganizationId = CursorUtils.getLong(cursor, Organization._ID);
}
} finally {
CursorUtils.closeCursor(cursor);
// make it a candidate for the GC
cursor = null;
}
if (mMarkedOrganizationIndex >= 0) {
// Have an Organization (Company + Department) to update
final ContactChange cc = ccList[mMarkedOrganizationIndex];
if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
final String value = cc.getValue();
if (value != null) {
final Organisation organization = VCardHelper.getOrg(value);
company = organization.name;
if (organization.unitNames.size() > 0) {
department = organization.unitNames.get(0);
}
}
flags = cc.getFlags();
} else {
// Delete case
company = null;
department = null;
}
}
if (mMarkedTitleIndex >= 0) {
// Have a Title to update
final ContactChange cc = ccList[mMarkedTitleIndex];
title = cc.getValue();
if (cc.getType() != ContactChange.TYPE_UPDATE_DETAIL) {
flags = cc.getFlags();
}
}
if (company != null || department != null || title != null) {
/*
* If any of the above are present we assume a insert or update is
* needed.
*/
mValues.clear();
mValues.put(Organization.LABEL, (String) null);
mValues.put(Organization.COMPANY, company);
mValues.put(Organization.DEPARTMENT, department);
mValues.put(Organization.TITLE, title);
mValues.put(Organization.TYPE, mapToNabOrganizationType(flags));
mValues.put(Organization.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
if (mExistingOrganizationId != ContactChange.INVALID_ID) {
// update is needed
addUpdateValuesToBatch(mExistingOrganizationId);
} else {
// insert is needed
// not a new contact
addValuesToBatch(nabContactId);
}
} else if (mExistingOrganizationId != ContactChange.INVALID_ID) {
/*
* Had an Organization but now all values are null, delete is in
* order.
*/
addDeleteDetailToBatch(mExistingOrganizationId);
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method putOrganization.
// PHOTO NOT USED
// /**
// * Do a GET request and retrieve up to maxBytes bytes
// *
// * @param url
// * @param maxBytes
// * @return
// * @throws IOException
// */
// public static byte[] doGetAndReturnBytes(URL url, int maxBytes) throws
// IOException {
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// conn.setRequestMethod("GET");
// InputStream istr = null;
// try {
// int rc = conn.getResponseCode();
// if (rc != 200) {
// throw new IOException("code " + rc + " '" + conn.getResponseMessage() +
// "'");
// }
// istr = new BufferedInputStream(conn.getInputStream(), 512);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// copy(istr, baos, maxBytes);
// return baos.toByteArray();
// } finally {
// if (istr != null) {
// istr.close();
// }
// }
// }
//
// /**
// * Copy maxBytes from an input stream to an output stream.
// * @param in
// * @param out
// * @param maxBytes
// * @return
// * @throws IOException
// */
// private static int copy(InputStream in, OutputStream out, int maxBytes)
// throws IOException {
// byte[] buf = new byte[512];
// int bytesRead = 1;
// int totalBytes = 0;
// while (bytesRead > 0) {
// bytesRead = in.read(buf, 0, Math.min(512, maxBytes - totalBytes));
// if (bytesRead > 0) {
// out.write(buf, 0, bytesRead);
// totalBytes += bytesRead;
// }
// }
// return totalBytes;
// }
//
// /**
// * Put Photo detail into the values
// * @param cc {@link ContactChange} to read values from
// */
// private void putPhoto(ContactChange cc) {
// try {
// // File file = new File(cc.getValue());
// // InputStream is = new FileInputStream(file);
// // byte[] bytes = new byte[(int) file.length()];
// // is.read(bytes);
// // is.close();
// final URL url = new URL(cc.getValue());
// byte[] bytes = doGetAndReturnBytes(url, 1024 * 100);
// mValues.put(Photo.PHOTO, bytes);
// mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
// } catch(Exception ex) {
// LogUtils.logE("Unable to put Photo detail because of exception:"+ex);
// }
// }
/**
* Put Organization detail into the values
*
* @param cc {@link ContactChange} to read values from
*/
private void putOrganization(ContactChange[] ccList) {
mValues.clear();
int flags = ContactChange.FLAG_NONE;
if (mMarkedOrganizationIndex > -1) {
final ContactChange cc = ccList[mMarkedOrganizationIndex];
flags |= cc.getFlags();
final Organisation organization = VCardHelper.getOrg(cc.getValue());
if (organization != null) {
mValues.put(Organization.COMPANY, organization.name);
if (organization.unitNames.size() > 0) {
// Only considering one unit name (department) as that's all
// we support
mValues.put(Organization.DEPARTMENT, organization.unitNames.get(0));
} else {
mValues.putNull(Organization.DEPARTMENT);
}
}
}
if (mMarkedTitleIndex > -1) {
final ContactChange cc = ccList[mMarkedTitleIndex];
flags |= cc.getFlags();
// No need to check for empty values as there is only one
mValues.put(Organization.TITLE, cc.getValue());
}
if (mValues.size() > 0) {
mValues.put(Organization.LABEL, (String) null);
mValues.put(Organization.TYPE, mapToNabOrganizationType(flags));
mValues.put(Organization.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class FetchSmsLogEvents method addSmsData.
/**
* Create TimelineSummaryItem from Native message-log item.
*
* @param id ID of item from Native log.
*/
private void addSmsData(int id) {
ActivityItem.Type type = nativeToNpTypeConvert(mSmsCursor.getInt(COLUMN_SMS_TYPE));
if (type == null) {
return;
}
TimelineSummaryItem item = new TimelineSummaryItem();
String address = null;
/* Francisco: Unknown contact SMS sending bug resolved here
* I am keeping previous case SN_MESSAGE_RECEIVED besides MESSAGE_SMS_RECEIVED just to be safe.
*/
if (type == ActivityItem.Type.SN_MESSAGE_RECEIVED || type == ActivityItem.Type.MESSAGE_SMS_RECEIVED) {
item.mIncoming = TimelineSummaryItem.Type.INCOMING;
} else {
item.mIncoming = TimelineSummaryItem.Type.OUTGOING;
}
item.mNativeItemId = id;
item.mNativeItemType = ActivitiesTable.TimelineNativeTypes.SmsLog.ordinal();
item.mType = type;
item.mTimestamp = mSmsCursor.getLong(COLUMN_SMS_DATE);
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
item.mNativeThreadId = mSmsCursor.getInt(COLUMN_SMS_THREAD_ID);
item.mDescription = null;
if (!mSmsCursor.isNull(COLUMN_SMS_SUBJECT)) {
item.mDescription = mSmsCursor.getString(COLUMN_SMS_SUBJECT);
}
if (item.mDescription == null || item.mDescription.length() == 0) {
if (!mSmsCursor.isNull(COLUMN_SMS_BODY)) {
item.mDescription = mSmsCursor.getString(COLUMN_SMS_BODY);
}
}
if (!mSmsCursor.isNull(COLUMN_SMS_ADDRESS)) {
address = mSmsCursor.getString(COLUMN_SMS_ADDRESS);
}
item.mContactName = address;
item.mContactAddress = address;
Contact c = new Contact();
ContactDetail phoneDetail = new ContactDetail();
ServiceStatus status = mDb.fetchContactInfo(address, c, phoneDetail);
if (ServiceStatus.SUCCESS == status) {
item.mLocalContactId = c.localContactID;
item.mContactId = c.contactID;
item.mUserId = c.userID;
item.mContactName = null;
for (ContactDetail d : c.details) {
switch(d.key) {
case VCARD_NAME:
final VCardHelper.Name name = d.getName();
if (name != null) {
item.mContactName = d.getName().toString();
}
break;
case VCARD_IMADDRESS:
item.mContactNetwork = d.alt;
break;
default:
// do nothing
break;
}
}
}
if (item.mContactId == null) {
LogUtils.logI("FetchSmsLogEvents.addSmsData: id " + item.mNativeItemId + ", time " + item.mTitle + ", description " + item.mDescription);
} else {
LogUtils.logI("FetchSmsLogEvents.addSmsData: id " + item.mNativeItemId + ", name = " + item.mContactName + ", time " + item.mTitle + ", description " + item.mDescription);
}
mSyncItemList.add(item);
}
Aggregations