use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class StructuredNameEditorView method switchFromFullNameToStructuredName.
private void switchFromFullNameToStructuredName() {
ValuesDelta values = getValues();
if (!mChanged) {
for (String field : NameConverter.STRUCTURED_NAME_FIELDS) {
values.put(field, mSnapshot.getContentValues().getAsString(field));
}
return;
}
String displayName = values.getDisplayName();
Map<String, String> structuredNameMap = NameConverter.displayNameToStructuredName(getContext(), displayName);
if (!structuredNameMap.isEmpty()) {
eraseFullName(values);
for (String field : structuredNameMap.keySet()) {
values.put(field, structuredNameMap.get(field));
}
}
mSnapshot.getContentValues().clear();
mSnapshot.getContentValues().putAll(values.getCompleteValues());
mSnapshot.setDisplayName(displayName);
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class GroupMembershipView method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ListView list = (ListView) parent;
int count = mAdapter.getCount();
if (list.isItemChecked(count - 1)) {
list.setItemChecked(count - 1, false);
createNewGroup();
return;
}
for (int i = 0; i < count; i++) {
mAdapter.getItem(i).setChecked(list.isItemChecked(i));
}
// First remove the memberships that have been unchecked
ArrayList<ValuesDelta> entries = mState.getMimeEntries(GroupMembership.CONTENT_ITEM_TYPE);
if (entries != null) {
for (ValuesDelta entry : entries) {
if (!entry.isDelete()) {
Long groupId = entry.getGroupRowId();
if (groupId != null && groupId != mFavoritesGroupId && (groupId != mDefaultGroupId || mDefaultGroupVisible) && !isGroupChecked(groupId)) {
entry.markDeleted();
}
}
}
}
// Now add the newly selected items
for (int i = 0; i < count; i++) {
GroupSelectionItem item = mAdapter.getItem(i);
long groupId = item.getGroupId();
if (item.isChecked() && !hasMembership(groupId)) {
ValuesDelta entry = RawContactModifier.insertChild(mState, mKind);
if (entry != null) {
entry.setGroupRowId(groupId);
}
}
}
updateView();
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class KindSectionView method updateEmptyEditors.
/**
* Updates the editors being displayed to the user removing extra empty
* {@link Editor}s, so there is only max 1 empty {@link Editor} view at a time.
*/
public void updateEmptyEditors(boolean shouldAnimate) {
final List<View> emptyEditors = getEmptyEditors();
// If there is more than 1 empty editor, then remove it from the list of editors.
if (emptyEditors.size() > 1) {
for (final View emptyEditorView : emptyEditors) {
// editor, in which case this editor has focus.
if (emptyEditorView.findFocus() == null) {
final Editor editor = (Editor) emptyEditorView;
if (shouldAnimate) {
editor.deleteEditor();
} else {
mEditors.removeView(emptyEditorView);
}
}
}
} else if (mKind == null) {
// There is nothing we can do.
return;
} else if (isReadOnly()) {
// We don't show empty editors for read only data kinds.
return;
} else if (!RawContactModifier.canInsert(mState, mKind)) {
// We have already reached the maximum number of editors. Lets not add any more.
return;
} else if (emptyEditors.size() == 1) {
// We have already reached the maximum number of empty editors. Lets not add any more.
return;
} else {
final ValuesDelta values = RawContactModifier.insertChild(mState, mKind);
final View newField = createEditorView(values);
if (shouldAnimate) {
newField.setVisibility(View.GONE);
EditorAnimator.getInstance().showFieldFooter(newField);
}
}
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class KindSectionView method rebuildFromState.
/**
* Build editors for all current {@link #mState} rows.
*/
private void rebuildFromState() {
// Remove any existing editors
mEditors.removeAllViews();
// Check if we are displaying anything here
boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
if (hasEntries) {
for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
// Skip entries that aren't visible
if (!entry.isVisible())
continue;
if (isEmptyNoop(entry))
continue;
createEditorView(entry);
}
}
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class PhotoSelectionHandler method getDeltaForAttachingPhotoToContact.
/**
* Utility method to retrieve the entity delta for attaching the given bitmap to the contact.
* This will attach the photo to the first contact-writable account that provided data to the
* contact. It is the caller's responsibility to apply the delta.
* @return An entity delta list that can be applied to associate the bitmap with the contact,
* or null if the photo could not be parsed or none of the accounts associated with the
* contact are writable.
*/
public RawContactDeltaList getDeltaForAttachingPhotoToContact() {
// Find the first writable entity.
int writableEntityIndex = getWritableEntityIndex();
if (writableEntityIndex != -1) {
// We are guaranteed to have contact data if we have a writable entity index.
final RawContactDelta delta = mState.get(writableEntityIndex);
// Need to find the right account so that EntityModifier knows which fields to add
final ContentValues entityValues = delta.getValues().getCompleteValues();
final String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE);
final String dataSet = entityValues.getAsString(RawContacts.DATA_SET);
final AccountType accountType = AccountTypeManager.getInstance(mContext).getAccountType(type, dataSet);
final ValuesDelta child = RawContactModifier.ensureKindExists(delta, accountType, Photo.CONTENT_ITEM_TYPE);
child.setFromTemplate(false);
child.setSuperPrimary(true);
return mState;
}
return null;
}
Aggregations