use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.
the class RawContactEditorView method setState.
/**
* Set the internal state for this view, given a current
* {@link RawContactDelta} state and the {@link AccountType} that
* apply to that state.
*/
@Override
public void setState(RawContactDelta state, AccountType type, ViewIdGenerator vig, boolean isProfile) {
mState = state;
// Remove any existing sections
mFields.removeAllViews();
// Bail if invalid state or account type
if (state == null || type == null)
return;
setId(vig.getId(state, null, null, ViewIdGenerator.NO_VIEW_INDEX));
// Make sure we have a StructuredName
RawContactModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE);
mRawContactId = state.getRawContactId();
// Fill in the account info
final Pair<String, String> accountInfo = isProfile ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type) : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
if (accountInfo.first == null) {
// Hide this view so the other text view will be centered vertically
mAccountHeaderNameTextView.setVisibility(View.GONE);
} else {
mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
mAccountHeaderNameTextView.setText(accountInfo.first);
}
mAccountHeaderTypeTextView.setText(accountInfo.second);
updateAccountHeaderContentDescription();
// The account selector and header are both used to display the same information.
mAccountSelectorTypeTextView.setText(mAccountHeaderTypeTextView.getText());
mAccountSelectorTypeTextView.setVisibility(mAccountHeaderTypeTextView.getVisibility());
mAccountSelectorNameTextView.setText(mAccountHeaderNameTextView.getText());
mAccountSelectorNameTextView.setVisibility(mAccountHeaderNameTextView.getVisibility());
// Showing the account header at the same time as the account selector drop down is
// confusing. They should be mutually exclusive.
mAccountHeader.setVisibility(mAccountSelector.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
mAccountIconImageView.setImageDrawable(state.getRawContactAccountType(getContext()).getDisplayIcon(getContext()));
// Show photo editor when supported
RawContactModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE);
setHasPhotoEditor((type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null));
getPhotoEditor().setEnabled(isEnabled());
mName.setEnabled(isEnabled());
mPhoneticName.setEnabled(isEnabled());
// Show and hide the appropriate views
mFields.setVisibility(View.VISIBLE);
mName.setVisibility(View.VISIBLE);
mPhoneticName.setVisibility(View.VISIBLE);
mGroupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
if (mGroupMembershipKind != null) {
mGroupMembershipView = (GroupMembershipView) mInflater.inflate(R.layout.item_group_membership, mFields, false);
mGroupMembershipView.setKind(mGroupMembershipKind);
mGroupMembershipView.setEnabled(isEnabled());
}
// Create editor sections for each possible data kind
for (DataKind kind : type.getSortedDataKinds()) {
// Skip kind of not editable
if (!kind.editable)
continue;
final String mimeType = kind.mimeType;
if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
// Handle special case editor for structured name
final ValuesDelta primary = state.getPrimaryEntry(mimeType);
mName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME), primary, state, false, vig);
if (!(SimContactsConstants.ACCOUNT_TYPE_SIM).equals(type.accountType)) {
mPhoneticName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME), primary, state, false, vig);
// It is useful to use Nickname outside of a KindSectionView so that we can
// treat it as a part of StructuredName's fake KindSectionView, even though
// it uses adifferent CP2 mime-type. We do a bit of extra work below to make
// this possible.
final DataKind nickNameKind = type.getKindForMimetype(Nickname.CONTENT_ITEM_TYPE);
if (nickNameKind != null) {
ValuesDelta primaryNickNameEntry = state.getPrimaryEntry(nickNameKind.mimeType);
if (primaryNickNameEntry == null) {
primaryNickNameEntry = RawContactModifier.insertChild(state, nickNameKind);
}
mNickName.setValues(nickNameKind, primaryNickNameEntry, state, false, vig);
mNickName.setDeletable(false);
} else {
mPhoneticName.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.editor_padding_between_editor_views));
mNickName.setVisibility(View.GONE);
}
} else {
// sim card can't store expand fields,so set it disabled.
mName.setExpansionViewContainerDisabled();
mPhoneticName.setVisibility(View.GONE);
mNickName.setVisibility(View.GONE);
}
} else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
// Handle special case editor for photos
final ValuesDelta primary = state.getPrimaryEntry(mimeType);
getPhotoEditor().setValues(kind, primary, state, false, vig);
} else if (GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) {
if (mGroupMembershipView != null) {
mGroupMembershipView.setState(state);
mFields.addView(mGroupMembershipView);
}
} else if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType) || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType) || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) {
// Don't create fields for each of these mime-types. They are handled specially.
continue;
} else {
// Otherwise use generic section-based editors
if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) {
if (SimContactsConstants.ACCOUNT_TYPE_SIM.equals(type.accountType)) {
int sub = SimContactsConstants.SLOT1;
if (SimContactsConstants.SIM_NAME_2.equals(state.getAccountName())) {
sub = SimContactsConstants.SLOT2;
}
EditType typeHome = new EditType(Phone.TYPE_HOME, Phone.getTypeLabelResource(Phone.TYPE_HOME));
if (!MoreContactUtils.canSaveAnr(getContext(), sub)) {
kind.typeOverallMax = 1;
if (null != kind.typeList) {
// When the sim card is not 3g the interface should
// remove the TYPE_HOME number view.
kind.typeList.remove(typeHome);
}
} else {
kind.typeOverallMax = MoreContactUtils.getOneSimAnrCount(getContext(), sub) + 1;
if (null != kind.typeList && !kind.typeList.contains(typeHome)) {
// When the sim card is 3g the interface should
// add the TYPE_HOME number view.
kind.typeList.add(typeHome);
}
}
}
} else if (Email.CONTENT_ITEM_TYPE.equals(mimeType)) {
if (SimContactsConstants.ACCOUNT_TYPE_SIM.equals(type.accountType)) {
int sub = SimContactsConstants.SLOT1;
if (SimContactsConstants.SIM_NAME_2.equals(state.getAccountName())) {
sub = SimContactsConstants.SLOT2;
}
if (!MoreContactUtils.canSaveEmail(getContext(), sub)) {
continue;
} else {
kind.typeOverallMax = MoreContactUtils.getOneSimEmailCount(getContext(), sub);
}
}
}
if (kind.fieldList == null)
continue;
final KindSectionView section = (KindSectionView) mInflater.inflate(R.layout.item_kind_section, mFields, false);
section.setEnabled(isEnabled());
section.setState(kind, state, /* readOnly =*/
false, vig);
mFields.addView(section);
}
}
addToDefaultGroupIfNeeded();
}
use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.
the class RawContactReadOnlyEditorView method setState.
/**
* Set the internal state for this view, given a current
* {@link RawContactDelta} state and the {@link AccountType} that
* apply to that state.
*/
@Override
public void setState(RawContactDelta state, AccountType type, ViewIdGenerator vig, boolean isProfile) {
// Remove any existing sections
mGeneral.removeAllViews();
// Bail if invalid state or source
if (state == null || type == null)
return;
// Make sure we have StructuredName
RawContactModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE);
// Fill in the header info
mAccountName = state.getAccountName();
mAccountType = state.getAccountType();
mDataSet = state.getDataSet();
final Pair<String, String> accountInfo = isProfile ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type) : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
if (accountInfo.first == null) {
// Hide this view so the other text view will be centered vertically
mAccountHeaderNameTextView.setVisibility(View.GONE);
} else {
mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
mAccountHeaderNameTextView.setText(accountInfo.first);
}
mAccountHeaderTypeTextView.setText(accountInfo.second);
updateAccountHeaderContentDescription();
mAccountIconImageView.setImageDrawable(state.getRawContactAccountType(getContext()).getDisplayIcon(getContext()));
// TODO: Expose data set in the UI somehow?
mRawContactId = state.getRawContactId();
ValuesDelta primary;
// Photo
DataKind kind = type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
if (kind != null) {
RawContactModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE);
boolean hasPhotoEditor = type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null;
setHasPhotoEditor(hasPhotoEditor);
primary = state.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
getPhotoEditor().setValues(kind, primary, state, !type.areContactsWritable(), vig);
}
// Name
primary = state.getPrimaryEntry(StructuredName.CONTENT_ITEM_TYPE);
mName.setText(primary != null ? primary.getAsString(StructuredName.DISPLAY_NAME) : getContext().getString(R.string.missing_name));
if (type.getEditContactActivityClassName() != null) {
mEditExternallyButton.setVisibility(View.VISIBLE);
} else {
mEditExternallyButton.setVisibility(View.GONE);
}
final Resources res = getContext().getResources();
// Phones
final ArrayList<ValuesDelta> phones = state.getMimeEntries(Phone.CONTENT_ITEM_TYPE);
final Drawable phoneDrawable = getResources().getDrawable(R.drawable.ic_phone_24dp);
final String phoneContentDescription = res.getString(R.string.header_phone_entry);
if (phones != null) {
boolean isFirstPhoneBound = true;
for (ValuesDelta phone : phones) {
final String phoneNumber = phone.getPhoneNumber();
if (TextUtils.isEmpty(phoneNumber)) {
continue;
}
final String formattedNumber = PhoneNumberUtilsCompat.formatNumber(phoneNumber, phone.getPhoneNormalizedNumber(), GeoUtil.getCurrentCountryIso(getContext()));
CharSequence phoneType = null;
if (phone.hasPhoneType()) {
phoneType = Phone.getTypeLabel(res, phone.getPhoneType(), phone.getPhoneLabel());
}
bindData(phoneDrawable, phoneContentDescription, formattedNumber, phoneType, isFirstPhoneBound, true);
isFirstPhoneBound = false;
}
}
// Emails
final ArrayList<ValuesDelta> emails = state.getMimeEntries(Email.CONTENT_ITEM_TYPE);
final Drawable emailDrawable = getResources().getDrawable(R.drawable.ic_email_24dp);
final String emailContentDescription = res.getString(R.string.header_email_entry);
if (emails != null) {
boolean isFirstEmailBound = true;
for (ValuesDelta email : emails) {
final String emailAddress = email.getEmailData();
if (TextUtils.isEmpty(emailAddress)) {
continue;
}
CharSequence emailType = null;
if (email.hasEmailType()) {
emailType = Email.getTypeLabel(res, email.getEmailType(), email.getEmailLabel());
}
bindData(emailDrawable, emailContentDescription, emailAddress, emailType, isFirstEmailBound);
isFirstEmailBound = false;
}
}
// Hide mGeneral if it's empty
if (mGeneral.getChildCount() > 0) {
mGeneral.setVisibility(View.VISIBLE);
} else {
mGeneral.setVisibility(View.GONE);
}
}
use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.
the class EventFieldEditorView method createDatePickerDialog.
/**
* Prepare dialog for entering a date
*/
private Dialog createDatePickerDialog() {
final String column = getKind().fieldList.get(0).column;
final String oldValue = getEntry().getAsString(column);
final DataKind kind = getKind();
final Calendar calendar = Calendar.getInstance(DateUtils.UTC_TIMEZONE, Locale.US);
final int defaultYear = calendar.get(Calendar.YEAR);
// Check whether the year is optional
final boolean isYearOptional = getType().isYearOptional();
final int oldYear, oldMonth, oldDay;
if (TextUtils.isEmpty(oldValue)) {
// Default to the current date
oldYear = defaultYear;
oldMonth = calendar.get(Calendar.MONTH);
oldDay = calendar.get(Calendar.DAY_OF_MONTH);
} else {
// Try parsing with year
Calendar cal = DateUtils.parseDate(oldValue, false);
if (cal != null) {
if (DateUtils.isYearSet(cal)) {
oldYear = cal.get(Calendar.YEAR);
} else {
// cal.set(Calendar.YEAR, 0);
oldYear = isYearOptional ? DatePickerDialog.NO_YEAR : defaultYear;
}
oldMonth = cal.get(Calendar.MONTH);
oldDay = cal.get(Calendar.DAY_OF_MONTH);
} else {
return null;
}
}
final OnDateSetListener callBack = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if (year == 0 && !isYearOptional)
throw new IllegalStateException();
final Calendar outCalendar = Calendar.getInstance(DateUtils.UTC_TIMEZONE, Locale.US);
// If no year specified, set it to 2000 (we could pick any leap year here).
// The format string will ignore that year.
// For formats other than Exchange, the time of the day is ignored
outCalendar.clear();
outCalendar.set(year == DatePickerDialog.NO_YEAR ? 2000 : year, monthOfYear, dayOfMonth, CommonDateUtils.DEFAULT_HOUR, 0, 0);
final String resultString;
if (year == 0) {
resultString = kind.dateFormatWithoutYear.format(outCalendar.getTime());
} else {
resultString = kind.dateFormatWithYear.format(outCalendar.getTime());
}
onFieldChanged(column, resultString);
rebuildDateView();
}
};
final DatePickerDialog resultDialog = new DatePickerDialog(getContext(), callBack, oldYear, oldMonth, oldDay, isYearOptional);
return resultDialog;
}
use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.
the class CompactKindSectionView method setState.
/**
* Binds views for the given {@link KindSectionData} list.
*
* We create a structured name and phonetic name editor for each {@link DataKind} with a
* {@link StructuredName#CONTENT_ITEM_TYPE} mime type. The number and order of editors are
* rendered as they are given to {@link #setState}.
*
* Empty name editors are never added and at least one structured name editor is always
* displayed, even if it is empty.
*/
public void setState(KindSectionDataList kindSectionDataList, ViewIdGenerator viewIdGenerator, CompactRawContactsEditorView.Listener listener, ValuesDelta primaryValuesDelta) {
mKindSectionDataList = kindSectionDataList;
mViewIdGenerator = viewIdGenerator;
mListener = listener;
// Set the icon using the first DataKind
final DataKind dataKind = mKindSectionDataList.getDataKind();
if (dataKind != null) {
mIcon.setImageDrawable(EditorUiUtils.getMimeTypeDrawable(getContext(), dataKind.mimeType));
if (mIcon.getDrawable() != null) {
mIcon.setContentDescription(dataKind.titleRes == -1 || dataKind.titleRes == 0 ? "" : getResources().getString(dataKind.titleRes));
}
}
rebuildFromState(primaryValuesDelta);
updateEmptyEditors(/* shouldAnimate = */
false);
}
use of com.android.contacts.common.model.dataitem.DataKind in project packages_apps_Contacts by AOKP.
the class InvisibleContactUtil method addToDefaultGroup.
public static void addToDefaultGroup(Contact contactData, Context context) {
final long defaultGroupId = getDefaultGroupId(contactData.getGroupMetaData());
// but let's be safe here
if (defaultGroupId == -1)
return;
// add the group membership to the current state
final RawContactDeltaList contactDeltaList = contactData.createRawContactDeltaList();
final RawContactDelta rawContactEntityDelta = contactDeltaList.get(0);
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context);
final AccountType type = rawContactEntityDelta.getAccountType(accountTypes);
final DataKind groupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
final ValuesDelta entry = RawContactModifier.insertChild(rawContactEntityDelta, groupMembershipKind);
if (entry == null)
return;
entry.setGroupRowId(defaultGroupId);
// and fire off the intent. we don't need a callback, as the database listener
// should update the ui
final Intent intent = ContactSaveService.createSaveContactIntent(context, contactDeltaList, "", 0, false, QuickContactActivity.class, Intent.ACTION_VIEW, null, /* joinContactIdExtraKey =*/
null, /* joinContactId =*/
null);
ContactSaveService.startService(context, intent);
}
Aggregations