Search in sources :

Example 1 with EditType

use of com.android.contacts.common.model.account.AccountType.EditType in project packages_apps_Contacts by AOKP.

the class LabeledEditorView method createCustomDialog.

/**
 * Prepare dialog for entering a custom label. The input value is trimmed: white spaces before
 * and after the input text is removed.
 * <p>
 * If the final value is empty, this change request is ignored;
 * no empty text is allowed in any custom label.
 */
private Dialog createCustomDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
    builder.setTitle(R.string.customLabelPickerTitle);
    final View view = layoutInflater.inflate(R.layout.contact_editor_label_name_dialog, null);
    final EditText editText = (EditText) view.findViewById(R.id.custom_dialog_content);
    editText.setInputType(INPUT_TYPE_CUSTOM);
    editText.setSaveEnabled(true);
    builder.setView(view);
    editText.requestFocus();
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String customText = editText.getText().toString().trim();
            if (ContactsUtils.isGraphic(customText)) {
                final List<EditType> allTypes = RawContactModifier.getValidTypes(mState, mKind, null, true, null, true);
                mType = null;
                for (EditType editType : allTypes) {
                    if (editType.customColumn != null) {
                        mType = editType;
                        break;
                    }
                }
                if (mType == null)
                    return;
                mEntry.put(mKind.typeColumn, mType.rawValue);
                mEntry.put(mType.customColumn, customText);
                rebuildLabel();
                requestFocusForFirstEditField();
                onLabelRebuilt();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            updateCustomDialogOkButtonState(dialog, editText);
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            updateCustomDialogOkButtonState(dialog, editText);
        }
    });
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) DialogShowingView(com.android.contacts.util.DialogManager.DialogShowingView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OnShowListener(android.content.DialogInterface.OnShowListener) EditType(com.android.contacts.common.model.account.AccountType.EditType) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List)

Example 2 with EditType

use of com.android.contacts.common.model.account.AccountType.EditType in project packages_apps_Contacts by AOKP.

the class LabeledEditorView method onTypeSelectionChange.

protected void onTypeSelectionChange(int position) {
    EditType selected = mEditTypeAdapter.getItem(position);
    // See if the selection has in fact changed
    if (mEditTypeAdapter.hasCustomSelection() && selected == CUSTOM_SELECTION) {
        return;
    }
    if (mType == selected && mType.customColumn == null) {
        return;
    }
    if (selected.customColumn != null) {
        showDialog(DIALOG_ID_CUSTOM);
    } else {
        // User picked type, and we're sure it's ok to actually write the entry.
        mType = selected;
        mEntry.put(mKind.typeColumn, mType.rawValue);
        rebuildLabel();
        requestFocusForFirstEditField();
        onLabelRebuilt();
    }
}
Also used : EditType(com.android.contacts.common.model.account.AccountType.EditType)

Example 3 with EditType

use of com.android.contacts.common.model.account.AccountType.EditType 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();
}
Also used : EditType(com.android.contacts.common.model.account.AccountType.EditType) ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind)

Example 4 with EditType

use of com.android.contacts.common.model.account.AccountType.EditType in project packages_apps_Contacts by AOKP.

the class CompactKindSectionView method addNonNameEditorView.

private View addNonNameEditorView(RawContactDelta rawContactDelta, DataKind dataKind, ValuesDelta valuesDelta, Editor.EditorListener editorListener) {
    // Inflate the layout
    final View view = mLayoutInflater.inflate(EditorUiUtils.getLayoutResourceId(dataKind.mimeType), mEditors, false);
    boolean email = true;
    view.setEnabled(isEnabled());
    if (view instanceof Editor) {
        final Editor editor = (Editor) view;
        editor.setDeletable(true);
        editor.setEditorListener(editorListener);
        if (rawContactDelta.getAccountType() != null && SimContactsConstants.ACCOUNT_TYPE_SIM.equals(rawContactDelta.getAccountType())) {
            int sub = SimContactsConstants.SLOT1;
            if (SimContactsConstants.SIM_NAME_2.equals(rawContactDelta.getAccountName())) {
                sub = SimContactsConstants.SLOT2;
            }
            if (Phone.CONTENT_ITEM_TYPE.equals(dataKind.mimeType)) {
                EditType typeHome = new EditType(Phone.TYPE_HOME, Phone.getTypeLabelResource(Phone.TYPE_HOME));
                if (!MoreContactUtils.canSaveAnr(getContext(), sub)) {
                    dataKind.typeOverallMax = 1;
                    if (null != dataKind.typeList) {
                        // When the sim card is not 3g the interface should
                        // remove the TYPE_HOME number view.
                        dataKind.typeList.remove(typeHome);
                    }
                } else {
                    dataKind.typeOverallMax = MoreContactUtils.getOneSimAnrCount(getContext(), sub) + 1;
                    if (null != dataKind.typeList && !dataKind.typeList.contains(typeHome)) {
                        // When the sim card is 3g the interface should
                        // add the TYPE_HOME number view.
                        dataKind.typeList.add(typeHome);
                    }
                }
            } else if (Email.CONTENT_ITEM_TYPE.equals(dataKind.mimeType)) {
                if (MoreContactUtils.canSaveEmail(getContext(), sub)) {
                    dataKind.typeOverallMax = MoreContactUtils.getOneSimEmailCount(getContext(), sub);
                } else {
                    email = false;
                }
            }
        }
        editor.setValues(dataKind, valuesDelta, rawContactDelta, !dataKind.editable, mViewIdGenerator);
    }
    if (email) {
        mEditors.addView(view);
    } else {
        mIcon.setVisibility(View.GONE);
    }
    return view;
}
Also used : EditType(com.android.contacts.common.model.account.AccountType.EditType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Aggregations

EditType (com.android.contacts.common.model.account.AccountType.EditType)4 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 OnShowListener (android.content.DialogInterface.OnShowListener)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 AdapterView (android.widget.AdapterView)1 EditText (android.widget.EditText)1 ValuesDelta (com.android.contacts.common.model.ValuesDelta)1 DataKind (com.android.contacts.common.model.dataitem.DataKind)1 DialogShowingView (com.android.contacts.util.DialogManager.DialogShowingView)1 List (java.util.List)1