use of ezvcard.VCard in project qksms by moezbhatti.
the class MessageListFragment method openVcard.
private void openVcard(MessageItem messageItem) {
Log.d(TAG, "Vcard: " + messageItem.mBody);
VCard vCard = Ezvcard.parse(messageItem.mBody).first();
ContactOperations operations = new ContactOperations(mContext);
try {
operations.insertContact(vCard);
} catch (Exception e) {
e.printStackTrace();
}
}
use of ezvcard.VCard in project android by nextcloud.
the class ContactsImportJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(@NonNull Params params) {
PersistableBundleCompat bundle = params.getExtras();
String vCardFilePath = bundle.getString(VCARD_FILE_PATH, "");
String accountName = bundle.getString(ACCOUNT_NAME, "");
String accountType = bundle.getString(ACCOUNT_TYPE, "");
int[] intArray = bundle.getIntArray(CHECKED_ITEMS_ARRAY);
File file = new File(vCardFilePath);
ArrayList<VCard> vCards = new ArrayList<>();
Cursor cursor = null;
try {
ContactOperations operations = new ContactOperations(getContext(), accountName, accountType);
vCards.addAll(Ezvcard.parse(file).all());
Collections.sort(vCards, new ContactListFragment.VCardComparator());
cursor = getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
TreeMap<VCard, Long> ownContactList = new TreeMap<>(new ContactListFragment.VCardComparator());
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
VCard vCard = getContactFromCursor(cursor);
if (vCard != null) {
ownContactList.put(vCard, cursor.getLong(cursor.getColumnIndex("NAME_RAW_CONTACT_ID")));
}
cursor.moveToNext();
}
}
for (int i = 0; i < intArray.length; i++) {
VCard vCard = vCards.get(intArray[i]);
if (ContactListFragment.getDisplayName(vCard).length() != 0) {
if (!ownContactList.containsKey(vCard)) {
operations.insertContact(vCard);
} else {
operations.updateContact(vCard, ownContactList.get(vCard));
}
} else {
// Insert All the contacts without name
operations.insertContact(vCard);
}
}
} catch (Exception e) {
Log_OC.e(TAG, e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
}
}
return Result.SUCCESS;
}
use of ezvcard.VCard in project android by nextcloud.
the class ContactsImportJob method getContactFromCursor.
private VCard getContactFromCursor(Cursor cursor) {
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
VCard vCard = null;
try {
InputStream inputStream = getContext().getContentResolver().openInputStream(uri);
ArrayList<VCard> vCardList = new ArrayList<>();
vCardList.addAll(Ezvcard.parse(inputStream).all());
if (vCardList.size() > 0) {
vCard = vCardList.get(0);
}
} catch (IOException e) {
Log_OC.d(TAG, e.getMessage());
}
return vCard;
}
use of ezvcard.VCard in project data-transfer-project by google.
the class GoogleContactsExporter method exportContacts.
private ExportResult<ContactsModelWrapper> exportContacts(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
try {
// Set up connection
Connections.List connectionsListRequest = getOrCreatePeopleService(authData).people().connections().list(SELF_RESOURCE);
// Get next page, if we have a page token
if (pageData.isPresent()) {
StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
connectionsListRequest.setPageToken(paginationToken.getToken());
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsListRequest.setPersonFields(PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = getOrCreatePeopleService(authData).people().getBatchGet().setResourceNames(resourceNames).setPersonFields(PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken nextPageData = null;
if (response.getNextPageToken() != null) {
nextPageData = new StringPaginationToken(response.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
ContactsModelWrapper wrapper = new ContactsModelWrapper(makeVCardString(vCards));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<ContactsModelWrapper>(resultType, wrapper, continuationData);
} catch (IOException e) {
return new ExportResult<ContactsModelWrapper>(ResultType.ERROR, e.getMessage());
}
}
use of ezvcard.VCard in project data-transfer-project by google.
the class GoogleContactsExporter method makeVCardString.
@VisibleForTesting
static String makeVCardString(List<VCard> vCardList) throws IOException {
StringWriter stringWriter = new StringWriter();
JCardWriter jCardWriter = new JCardWriter(stringWriter);
for (VCard vCardProperties : vCardList) {
// needs to be loop so error can be thrown
jCardWriter.write(vCardProperties);
}
jCardWriter.flush();
return stringWriter.toString();
}
Aggregations