diff options
author | blong <blong@codeaurora.org> | 2016-04-20 17:31:17 +0800 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2016-08-24 08:07:10 -0600 |
commit | 9039ae103dd2734d17b18852b1384b9caded2f3d (patch) | |
tree | abee76cb3838d5c4656943caafb2540e37d1a452 | |
parent | 06896b90ca0debd0db0e083e064e09f4b2a9d4e9 (diff) | |
download | packages_apps_Contacts-9039ae103dd2734d17b18852b1384b9caded2f3d.tar.gz packages_apps_Contacts-9039ae103dd2734d17b18852b1384b9caded2f3d.tar.bz2 packages_apps_Contacts-9039ae103dd2734d17b18852b1384b9caded2f3d.zip |
Add supports for SIM contacts
- Support to update/insert/delete SIM contacts
- Support to save anr and email for SIM contacts
- Filter internal account when add new account
Change-Id: I4158ce966936780c1444ed1d4bd874c7ee3aa386
-rwxr-xr-x[-rw-r--r--] | res/values-zh-rCN/strings.xml | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | res/values/strings.xml | 13 | ||||
-rwxr-xr-x | src/com/android/contacts/ContactSaveService.java | 201 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/activities/ContactEditorBaseActivity.java | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/editor/CompactKindSectionView.java | 52 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/editor/ContactEditorBaseFragment.java | 73 | ||||
-rw-r--r-- | src/com/android/contacts/editor/ContactEditorUtils.java | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/editor/LabeledEditorView.java | 11 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/editor/RawContactEditorView.java | 85 | ||||
-rw-r--r-- | src/com/android/contacts/editor/TextFieldsEditorView.java | 19 | ||||
-rw-r--r-- | src/com/android/contacts/list/ContactPickerFragment.java | 2 | ||||
-rw-r--r-- | src/com/android/contacts/list/JoinContactListAdapter.java | 15 |
12 files changed, 457 insertions, 37 deletions
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 578d98276..9dc9de551 100644..100755 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -119,6 +119,16 @@ <string name="contactJoinErrorToast" msgid="3977932531264809035">"无法关联该联系人。"</string> <string name="contactGenericErrorToast" msgid="7774911165341591714">"保存此联系人时出错。"</string> <string name="contactPhotoSavedErrorToast" msgid="4079032272022979114">"无法保存联系人照片更改。"</string> + <string name="contactSavedToSimCardError">"发生错误,保存至SIM卡失败。"</string> + <string name="number_anr_too_long">"发生错误,电话号码过长。"</string> + <string name="email_address_too_long">"发生错误,邮箱地址过长。"</string> + <string name="sim_card_full">"发生错误,SIM卡已满。"</string> + <string name="tag_too_long">"发生错误,联系人姓名过长。"</string> + <string name="no_phone_number">请输入手机号码。</string> + <string name="invalid_phone_number">"发生错误,电话号码不合法。"</string> + <string name="invalid_number_type">"发生错误,号码类型不合法。"</string> + <string name="no_phone_number_or_email">请输入手机号码或者邮箱地址。</string> + <string name="importConfirmation_title" msgid="1418215926447642260">"要导入联系人吗?"</string> <string name="groupSavedToast" msgid="1168756874239833756">"群组已保存。"</string> <string name="groupSavedErrorToast" msgid="7984466936615304740">"无法保存所做的群组更改。"</string> <plurals name="listTotalPhoneContacts" formatted="false" msgid="3692277679143308755"> diff --git a/res/values/strings.xml b/res/values/strings.xml index d8bcd57a1..5069735e2 100644..100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -329,7 +329,18 @@ <!-- Toast displayed when saving a contact photo failed. [CHAR LIMIT=NONE] --> <string name="contactPhotoSavedErrorToast">Couldn\'t save contact photo changes.</string> - + <!-- Toast displayed when saving a contact to sim card failed --> + <string name="contactSavedToSimCardError">Error, Save to SIM card fail.</string> + <string name="number_anr_too_long">Error, Number is too long.</string> + <string name="email_address_too_long">Error, Email Address is too long.</string> + <string name="sim_card_full">Error, Sim Card is full.</string> + <string name="tag_too_long">Error, Contact name is too long.</string> + <string name="no_phone_number">Please insert phone number.</string> + <string name="invalid_phone_number">Error, Number is invalid.</string> + <string name="invalid_number_type">Error, Number type is invalid.</string> + <string name="no_phone_number_or_email">Please insert phone number or email address.</string> + <string name="importConfirmation_title">Import contact?</string> + <!-- Toast displayed when a group is saved [CHAR LIMIT=NONE] --> <!-- Toast displayed when a group is saved [CHAR LIMIT=NONE] --> <string name="groupSavedToast">Group saved.</string> diff --git a/src/com/android/contacts/ContactSaveService.java b/src/com/android/contacts/ContactSaveService.java index 5c9c899c3..56a0c4683 100755 --- a/src/com/android/contacts/ContactSaveService.java +++ b/src/com/android/contacts/ContactSaveService.java @@ -45,10 +45,17 @@ import android.provider.ContactsContract.Groups; import android.provider.ContactsContract.Profile; import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContactsEntity; +import android.text.TextUtils; +import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionManager; +import android.telephony.SubscriptionInfo; import android.util.Log; import android.widget.Toast; import com.android.contacts.activities.ContactEditorBaseActivity; +import com.android.contacts.common.MoreContactUtils; +import com.android.contacts.common.SimContactsConstants; +import com.android.contacts.common.SimContactsOperation; import com.android.contacts.common.compat.CompatUtils; import com.android.contacts.common.database.ContactUpdateUtils; import com.android.contacts.common.model.AccountTypeManager; @@ -61,7 +68,6 @@ import com.android.contacts.common.util.PermissionsUtil; import com.android.contacts.compat.PinnedPositionsCompat; import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor.SaveMode; import com.android.contacts.util.ContactPhotoUtils; - import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -93,6 +99,7 @@ public class ContactSaveService extends IntentService { public static final String EXTRA_SAVE_IS_PROFILE = "saveIsProfile"; public static final String EXTRA_SAVE_SUCCEEDED = "saveSucceeded"; public static final String EXTRA_UPDATED_PHOTOS = "updatedPhotos"; + public static final String SAVE_CONTACT_RESULT = "saveResult"; public static final String ACTION_CREATE_GROUP = "createGroup"; public static final String ACTION_RENAME_GROUP = "renameGroup"; @@ -147,6 +154,28 @@ public class ContactSaveService extends IntentService { private static final int PERSIST_TRIES = 3; + public static final int RESULT_UNCHANGED = 0; + public static final int RESULT_SUCCESS = 1; + public static final int RESULT_FAILURE = 2; + public static final int RESULT_NO_NUMBER_AND_EMAIL = 3; + public static final int RESULT_SIM_FAILURE = 4; //only for sim operation failure + public static final int RESULT_EMAIL_FAILURE = 5; // only for sim email operation failure + // only for sim failure of number or anr is too long + public static final int RESULT_NUMBER_ANR_FAILURE = 6; + public static final int RESULT_SIM_FULL_FAILURE = 7; // only for sim card is full + public static final int RESULT_TAG_FAILURE = 8; // only for sim failure of name is too long + public static final int RESULT_NUMBER_INVALID = 9; // only for sim failure of number is valid + + public static final int RESULT_MEMORY_FULL_FAILURE = 11; //for memory full exception + public static final int RESULT_NUMBER_TYPE_FAILURE =12; //only for sim failure of number TYPE + + private final int MAX_NUM_LENGTH = 20; + private final int MAX_EMAIL_LENGTH = 40; + private final int MAX_EN_LENGTH = 14; + private final int MAX_CH_LENGTH = 6; + + private static SimContactsOperation mSimContactsOperation; + private SubscriptionManager mSubscriptionManager; private static final int MAX_CONTACTS_PROVIDER_BATCH_SIZE = 499; public interface Listener { @@ -164,6 +193,12 @@ public class ContactSaveService extends IntentService { mMainHandler = new Handler(Looper.getMainLooper()); } + @Override + public void onCreate() { + super.onCreate(); + mSubscriptionManager = SubscriptionManager.from(this); + } + public static void registerListener(Listener listener) { if (!(listener instanceof Activity)) { throw new ClassCastException("Only activities can be registered to" @@ -424,8 +459,28 @@ public class ContactSaveService extends IntentService { long insertedRawContactId = -1; // Attempt to persist changes + Integer result = RESULT_FAILURE; + + ArrayList<Long> rawContactsList = new ArrayList<Long>(); + boolean isCardOperation = false; + for (int i=0; i < state.size(); i++) { + final RawContactDelta entity = state.get(i); + final String accountType = entity.getValues().getAsString(RawContacts.ACCOUNT_TYPE); + final String accountName = entity.getValues().getAsString(RawContacts.ACCOUNT_NAME); + rawContactsList.add(entity.getRawContactId()); + + final int subscription = MoreContactUtils.getSubscription( + accountType, accountName); + isCardOperation = (subscription != SubscriptionManager.INVALID_SUBSCRIPTION_ID) ? + true : false; + if (isCardOperation) { + result = doSaveToSimCard(entity, resolver, subscription); + Log.d(TAG, "doSaveToSimCard result is " + result); + } + } int tries = 0; while (tries++ < PERSIST_TRIES) { + if (result == RESULT_SUCCESS || result == RESULT_FAILURE) { try { // Build operations and try applying final ArrayList<CPOWrapper> diffWrapper = state.buildDiffWrapper(); @@ -546,6 +601,7 @@ public class ContactSaveService extends IntentService { if (isProfile) { for (RawContactDelta delta : state) { delta.setProfileQueryUri(); + } } } } @@ -584,6 +640,132 @@ public class ContactSaveService extends IntentService { } } + private Integer doSaveToSimCard(RawContactDelta entity, ContentResolver resolver, + int subscription) { + + boolean isInsert = entity.isContactInsert(); + Integer result = RESULT_SIM_FAILURE; + mSimContactsOperation = new SimContactsOperation(this); + + ContentValues values = entity.buildSimDiff(); + String tag = null; + String number = null; + String anr = null; + String email = null; + + if(entity.isContactInsert()){ + tag = values.getAsString(SimContactsConstants.STR_TAG); + number = values.getAsString(SimContactsConstants.STR_NUMBER); + anr = values.getAsString(SimContactsConstants.STR_ANRS); + email = values.getAsString(SimContactsConstants.STR_EMAILS); + } else { + tag = values.getAsString(SimContactsConstants.STR_NEW_TAG); + number = values.getAsString(SimContactsConstants.STR_NEW_NUMBER); + anr = values.getAsString(SimContactsConstants.STR_NEW_ANRS); + email = values.getAsString(SimContactsConstants.STR_NEW_EMAILS); + } + + if (TextUtils.isEmpty(number) && TextUtils.isEmpty(anr) && TextUtils.isEmpty(email)) { + return RESULT_NO_NUMBER_AND_EMAIL; + } + + if (!TextUtils.isEmpty(number)) { + if (number.length() > MAX_NUM_LENGTH) { + return RESULT_NUMBER_ANR_FAILURE; + } else if (number.contains(SimContactsConstants.STR_ANRS)) { + return RESULT_NUMBER_TYPE_FAILURE; + } + } + + if (!TextUtils.isEmpty(anr)) { + String[] anrs = anr.split(SimContactsConstants.ANR_SEP); + if (anrs != null) { + if (anrs.length > MoreContactUtils + .getOneSimAnrCount(subscription)) { + return RESULT_NUMBER_TYPE_FAILURE; + } + for (String mAnr : anrs) { + if (mAnr.length() > MAX_NUM_LENGTH) { + return RESULT_NUMBER_ANR_FAILURE; + } + } + } + } + + if (!TextUtils.isEmpty(number) && TextUtils.isEmpty(PhoneNumberUtils + .stripSeparators(number))) { + return RESULT_NUMBER_INVALID; + } + + if (!TextUtils.isEmpty(email)) { + String[] emails = email.split(SimContactsConstants.EMAIL_SEP); + for (String mEmail : emails) { + if (mEmail != null && mEmail.length() > MAX_EMAIL_LENGTH) { + return RESULT_EMAIL_FAILURE; + } + } + } + + if (!TextUtils.isEmpty(tag)) { + if (tag.getBytes().length > tag.length()) { + if (tag.length() > MAX_CH_LENGTH) { + return RESULT_TAG_FAILURE; + } + } else { + if (tag.getBytes().length > MAX_EN_LENGTH) { + return RESULT_TAG_FAILURE; + } + } + } + + if (entity.isContactInsert()) { + int count = 0; + Cursor c = null; + Uri iccUri; + SubscriptionInfo subInfoRecord = null; + try { + subInfoRecord = mSubscriptionManager + .getActiveSubscriptionInfoForSimSlotIndex(subscription); + } catch (SecurityException e) { + Log.w(TAG, "SecurityException thrown, lack permission for" + + " getActiveSubscriptionInfoList", e); + } + if (subInfoRecord == null) { + iccUri = Uri.parse(SimContactsConstants.SIM_URI); + } else { + iccUri = Uri.parse(SimContactsConstants.SIM_SUB_URI + + subInfoRecord.getSubscriptionId()); + } + try { + c = resolver.query(iccUri, null, null, null, null); + if (c != null) { + count = c.getCount(); + } + } finally { + if (c != null) { + c.close(); + } + } + + if (count == MoreContactUtils.getAdnCount(subscription)) { + return RESULT_SIM_FULL_FAILURE; + } + } + + if (isInsert) { + Uri resultUri = mSimContactsOperation.insert(values, + subscription); + if (resultUri != null) + result = RESULT_SUCCESS; + } else { + int resultInt = mSimContactsOperation.update(values, + subscription); + if (resultInt == 1) + result = RESULT_SUCCESS; + } + return result; + } + /** * Splits "diff" into subsets based on "MAX_CONTACTS_PROVIDER_BATCH_SIZE", applies each of the * subsets, adds the returned array to "results". @@ -1083,12 +1265,27 @@ public class ContactSaveService extends IntentService { private void deleteContact(Intent intent) { Uri contactUri = intent.getParcelableExtra(EXTRA_CONTACT_URI); + mSimContactsOperation = new SimContactsOperation(this); if (contactUri == null) { Log.e(TAG, "Invalid arguments for deleteContact request"); return; } - getContentResolver().delete(contactUri, null, null); + final List<String> segments = contactUri.getPathSegments(); + // Contains an Id. + final long uriContactId = Long.parseLong(segments.get(3)); + int subscription = mSimContactsOperation + .getSimSubscription(uriContactId); + if (subscription != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + ContentValues values = mSimContactsOperation + .getSimAccountValues(uriContactId); + int result = mSimContactsOperation.delete(values, subscription); + if (result == RESULT_SUCCESS) { + getContentResolver().delete(contactUri, null, null); + } + } else { + getContentResolver().delete(contactUri, null, null); + } } private void deleteMultipleContacts(Intent intent) { diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java index ffbeb49d8..50fa0ff23 100644..100755 --- a/src/com/android/contacts/activities/ContactEditorBaseActivity.java +++ b/src/com/android/contacts/activities/ContactEditorBaseActivity.java @@ -172,7 +172,7 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity * Invoked after the contact is saved. */ void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded, - Uri contactLookupUri, Long joinContactId); + Uri contactLookupUri, Long joinContactId, int result); /** * Invoked after the contact is joined. @@ -259,7 +259,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity ContactEditor.SaveMode.CLOSE), intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false), intent.getData(), - intent.getLongExtra(ContactEditorFragment.JOIN_CONTACT_ID_EXTRA_KEY, -1)); + intent.getLongExtra(ContactEditorFragment.JOIN_CONTACT_ID_EXTRA_KEY, -1), + intent.getIntExtra(ContactSaveService.SAVE_CONTACT_RESULT, 0)); } else if (ACTION_JOIN_COMPLETED.equals(action)) { mFragment.onJoinCompleted(intent.getData()); } diff --git a/src/com/android/contacts/editor/CompactKindSectionView.java b/src/com/android/contacts/editor/CompactKindSectionView.java index 7e5ff1176..ae9fb8a07 100644..100755 --- a/src/com/android/contacts/editor/CompactKindSectionView.java +++ b/src/com/android/contacts/editor/CompactKindSectionView.java @@ -21,10 +21,15 @@ import com.android.contacts.common.model.RawContactDelta; import com.android.contacts.common.model.RawContactModifier; import com.android.contacts.common.model.ValuesDelta; import com.android.contacts.common.model.account.AccountType; +import com.android.contacts.common.model.account.AccountType.EditType; import com.android.contacts.common.model.dataitem.DataKind; +import com.android.contacts.common.SimContactsConstants; +import com.android.contacts.common.MoreContactUtils; import android.content.Context; import android.database.Cursor; +import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.CommonDataKinds.Nickname; @@ -376,11 +381,19 @@ public class CompactKindSectionView extends LinearLayout { nameView.setValues( accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME), valuesDelta, rawContactDelta, /* readOnly =*/ false, mViewIdGenerator); - + if (rawContactDelta.getAccountType() != null + && rawContactDelta.getAccountType().equals( + SimContactsConstants.ACCOUNT_TYPE_SIM)) { + nameView.setExpansionViewContainerDisabled(); + } // Correct start margin since there is a second icon in the structured name layout nameView.findViewById(R.id.kind_icon).setVisibility(View.GONE); mEditors.addView(nameView); - + if (rawContactDelta.getAccountType() != null + && rawContactDelta.getAccountType().equals( + SimContactsConstants.ACCOUNT_TYPE_SIM)) { + return; + } // Phonetic name final PhoneticNameEditorView phoneticNameView = (PhoneticNameEditorView) mLayoutInflater .inflate(R.layout.phonetic_name_editor_view, mEditors, /* attachToRoot =*/ false); @@ -395,6 +408,7 @@ public class CompactKindSectionView extends LinearLayout { LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(0, 0, 0, 0); phoneticNameView.setLayoutParams(layoutParams); + mEditors.addView(phoneticNameView); } @@ -421,9 +435,43 @@ public class CompactKindSectionView extends LinearLayout { 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(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(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(sub)) { + dataKind.typeOverallMax = MoreContactUtils.getOneSimEmailCount(sub); + } + } + } editor.setValues(dataKind, valuesDelta, rawContactDelta, !dataKind.editable, mViewIdGenerator); } + mEditors.addView(view); return view; diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java index 4182e1ff8..61374506c 100644..100755 --- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java +++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java @@ -26,6 +26,7 @@ import com.android.contacts.R; import com.android.contacts.activities.ContactEditorAccountsChangedActivity; import com.android.contacts.activities.ContactEditorBaseActivity; import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor; +import com.android.contacts.common.SimContactsConstants; import com.android.contacts.common.model.AccountTypeManager; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; @@ -36,6 +37,7 @@ import com.android.contacts.common.model.RawContactModifier; import com.android.contacts.common.model.ValuesDelta; import com.android.contacts.common.model.account.AccountType; import com.android.contacts.common.model.account.AccountWithDataSet; +import com.android.contacts.common.model.account.SimAccountType; import com.android.contacts.common.util.ImplicitIntentsUtil; import com.android.contacts.common.util.MaterialColorMapUtils; import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion; @@ -404,6 +406,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements // edit a read-only contact (to which the new raw contact was joined) protected StructuredNameEditorView mReadOnlyNameEditorView; + private boolean isSimAccount = false; /** * The contact data loader listener. */ @@ -770,6 +773,10 @@ abstract public class ContactEditorBaseFragment extends Fragment implements // Set visibility of menus + if (mState != null && mState.size() > 0 && mState.get(0).getAccountType() !=null) { + isSimAccount = mState.get(0).getAccountType() + .equals(SimAccountType.ACCOUNT_TYPE); + } // help menu depending on whether this is inserting or editing if (isInsert(mAction) || mRawContactIdToDisplayAlone != -1) { HelpUtils.prepareHelpMenuItem(mContext, helpMenu, R.string.help_url_people_add); @@ -778,7 +785,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements deleteMenu.setVisible(false); } else if (isEdit(mAction)) { HelpUtils.prepareHelpMenuItem(mContext, helpMenu, R.string.help_url_people_edit); - splitMenu.setVisible(canUnlinkRawContacts()); + if (!isSimAccount) { + splitMenu.setVisible(canUnlinkRawContacts()); + } else { + joinMenu.setVisible(false); + } // Cannot join a user profile joinMenu.setVisible(!isEditingUserProfile()); deleteMenu.setVisible(!mDisableDeleteMenuOption && !isEditingUserProfile()); @@ -798,7 +809,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements // if we don't have a telephone or are editing a new contact. sendToVoiceMailMenu.setChecked(mSendToVoicemailState); sendToVoiceMailMenu.setVisible(mArePhoneOptionsChangable); - ringToneMenu.setVisible(mArePhoneOptionsChangable); + ringToneMenu.setVisible(mArePhoneOptionsChangable && !isSimAccount); } int size = menu.size(); @@ -962,7 +973,9 @@ abstract public class ContactEditorBaseFragment extends Fragment implements return true; } onSaveCompleted(/* hadChanges =*/ false, saveMode, - /* saveSucceeded =*/ mLookupUri != null, mLookupUri, /* joinContactId =*/ null); + /* saveSucceeded =*/ mLookupUri != null, mLookupUri, /* joinContactId =*/ null + , getActivity().getIntent().getIntExtra( + ContactSaveService.SAVE_CONTACT_RESULT, 0)); return true; } @@ -1438,12 +1451,16 @@ abstract public class ContactEditorBaseFragment extends Fragment implements @Override public void onJoinCompleted(Uri uri) { - onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri, /* joinContactId */ null); - } + onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri, /* joinContactId */ null, + getActivity().getIntent().getIntExtra( + ContactSaveService.SAVE_CONTACT_RESULT, 0)); + } @Override public void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded, - Uri contactLookupUri, Long joinContactId) { + Uri contactLookupUri, Long joinContactId, int result) { + Log.d(TAG, "onSaveCompleted(" + saveMode + ", " + contactLookupUri + ", saveResult:" + + result); if (hadChanges) { if (saveSucceeded) { switch (saveMode) { @@ -1459,7 +1476,49 @@ abstract public class ContactEditorBaseFragment extends Fragment implements } } else { - Toast.makeText(mContext, R.string.contactSavedErrorToast, Toast.LENGTH_LONG).show(); + switch (result) { + case ContactSaveService.RESULT_NUMBER_INVALID: { + Toast.makeText(mContext, R.string.invalid_phone_number, + Toast.LENGTH_LONG).show(); + break; + } + case ContactSaveService.RESULT_SIM_FAILURE: { + Toast.makeText(mContext, + R.string.contactSavedToSimCardError, + Toast.LENGTH_LONG).show(); + break; + } + case ContactSaveService.RESULT_NUMBER_ANR_FAILURE: { + Toast.makeText(mContext, R.string.number_anr_too_long, + Toast.LENGTH_LONG).show(); + break; + } + case ContactSaveService.RESULT_EMAIL_FAILURE: { + Toast.makeText(mContext, R.string.email_address_too_long, + Toast.LENGTH_LONG).show(); + break; + } + case ContactSaveService.RESULT_SIM_FULL_FAILURE: { + Toast.makeText(mContext, R.string.sim_card_full, + Toast.LENGTH_LONG).show(); + break; + } + case ContactSaveService.RESULT_TAG_FAILURE: { + Toast.makeText(mContext, R.string.tag_too_long, + Toast.LENGTH_SHORT).show(); + break; + } + case ContactSaveService.RESULT_NO_NUMBER_AND_EMAIL: { + Toast.makeText(mContext, R.string.no_phone_number_or_email, + Toast.LENGTH_SHORT).show(); + break; + } + default: { + Toast.makeText(mContext, R.string.contactSavedErrorToast, + Toast.LENGTH_LONG).show(); + break; + } + } } } switch (saveMode) { diff --git a/src/com/android/contacts/editor/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java index 3aae92380..97e23dc75 100644 --- a/src/com/android/contacts/editor/ContactEditorUtils.java +++ b/src/com/android/contacts/editor/ContactEditorUtils.java @@ -30,6 +30,7 @@ import com.android.contacts.common.testing.NeededForTesting; import com.android.contacts.common.model.AccountTypeManager; import com.android.contacts.common.model.account.AccountType; import com.android.contacts.common.model.account.AccountWithDataSet; +import com.android.contacts.common.SimContactsConstants; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -246,7 +247,12 @@ public class ContactEditorUtils { String[] getWritableAccountTypeStrings() { final Set<String> types = Sets.newHashSet(); for (AccountType type : mAccountTypes.getAccountTypes(true)) { - types.add(type.accountType); + if (type.accountType.equals(SimContactsConstants.ACCOUNT_TYPE_SIM) + || type.accountType.equals(SimContactsConstants.ACCOUNT_TYPE_PHONE)) { + continue; + } else { + types.add(type.accountType); + } } return types.toArray(new String[types.size()]); } diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java index 63d75d8de..53584cc64 100644..100755 --- a/src/com/android/contacts/editor/LabeledEditorView.java +++ b/src/com/android/contacts/editor/LabeledEditorView.java @@ -50,6 +50,7 @@ import com.android.contacts.common.model.ValuesDelta; import com.android.contacts.common.model.RawContactModifier; import com.android.contacts.common.model.account.AccountType.EditType; import com.android.contacts.common.model.dataitem.DataKind; +import com.android.contacts.common.model.account.SimAccountType; import com.android.contacts.util.DialogManager; import com.android.contacts.util.DialogManager.DialogShowingView; @@ -232,6 +233,14 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor, } } + private boolean isSimAccount() { + if (mState != null && mState.getAccountType() != null + && mState.getAccountType().equals(SimAccountType.ACCOUNT_TYPE)) { + return true; + } + return false; + } + public void setDeleteButtonVisible(boolean visible) { if (mIsDeletable) { mDeleteContainer.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); @@ -403,7 +412,7 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor, setVisibility(View.VISIBLE); // Display label selector if multiple types available - final boolean hasTypes = RawContactModifier.hasEditTypes(kind); + final boolean hasTypes = RawContactModifier.hasEditTypes(kind) && !isSimAccount(); setupLabelButton(hasTypes); mLabel.setEnabled(!readOnly && isEnabled()); mLabel.setContentDescription(getContext().getResources().getString(mKind.titleRes)); diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java index 5a4c9dbbf..da3632dd7 100644..100755 --- a/src/com/android/contacts/editor/RawContactEditorView.java +++ b/src/com/android/contacts/editor/RawContactEditorView.java @@ -20,8 +20,10 @@ import android.content.Context; import android.database.Cursor; import android.os.Bundle; import android.os.Parcelable; +import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.CommonDataKinds.Nickname; +import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.Contacts; @@ -37,12 +39,14 @@ import android.widget.TextView; import com.android.contacts.GroupMetaDataLoader; import com.android.contacts.R; +import com.android.contacts.common.MoreContactUtils; import com.android.contacts.common.model.account.AccountType; import com.android.contacts.common.model.account.AccountType.EditType; import com.android.contacts.common.model.dataitem.DataKind; import com.android.contacts.common.model.RawContactDelta; import com.android.contacts.common.model.ValuesDelta; import com.android.contacts.common.model.RawContactModifier; +import com.android.contacts.common.SimContactsConstants; import com.google.common.base.Objects; @@ -262,23 +266,34 @@ public class RawContactEditorView extends BaseRawContactEditorView { mName.setValues( type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME), primary, state, false, vig); - 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 a - // different 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); + 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); } - 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)); + //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)) { @@ -297,6 +312,46 @@ public class RawContactEditorView extends BaseRawContactEditorView { 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(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(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(sub)) { + continue; + } else { + kind.typeOverallMax = MoreContactUtils.getOneSimEmailCount(sub); + } + } + } + if (kind.fieldList == null) continue; final KindSectionView section = (KindSectionView)mInflater.inflate( R.layout.item_kind_section, mFields, false); diff --git a/src/com/android/contacts/editor/TextFieldsEditorView.java b/src/com/android/contacts/editor/TextFieldsEditorView.java index f705819ec..bc133f2d5 100644 --- a/src/com/android/contacts/editor/TextFieldsEditorView.java +++ b/src/com/android/contacts/editor/TextFieldsEditorView.java @@ -382,10 +382,12 @@ public class TextFieldsEditorView extends LabeledEditorView { mHideOptional = ss.mHideOptional; - int numChildren = Math.min(mFieldEditTexts == null ? 0 : mFieldEditTexts.length, - ss.mVisibilities == null ? 0 : ss.mVisibilities.length); - for (int i = 0; i < numChildren; i++) { - mFieldEditTexts[i].setVisibility(ss.mVisibilities[i]); + if (mFieldEditTexts != null) { + int numChildren = Math.min(mFieldEditTexts == null ? 0 : mFieldEditTexts.length, + ss.mVisibilities == null ? 0 : ss.mVisibilities.length); + for (int i = 0; i < numChildren; i++) { + mFieldEditTexts[i].setVisibility(ss.mVisibilities[i]); + } } } @@ -434,4 +436,13 @@ public class TextFieldsEditorView extends LabeledEditorView { } } } + /** + * use for account type is ACCOUNT_TYPE_SIM only because that sim card + * can not store expand fields. + */ + + public void setExpansionViewContainerDisabled() { + mExpansionViewContainer.setEnabled(false); + mExpansionView.setVisibility(View.INVISIBLE); + } } diff --git a/src/com/android/contacts/list/ContactPickerFragment.java b/src/com/android/contacts/list/ContactPickerFragment.java index 4e8138916..fa1d2679c 100644 --- a/src/com/android/contacts/list/ContactPickerFragment.java +++ b/src/com/android/contacts/list/ContactPickerFragment.java @@ -165,7 +165,7 @@ public class ContactPickerFragment extends ContactEntryListFragment<ContactEntry HeaderEntryContactListAdapter adapter = new HeaderEntryContactListAdapter(getActivity()); adapter.setFilter(ContactListFilter.createFilterWithType( - ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS)); + ContactListFilter.FILTER_TYPE_ALL_WITHOUT_SIM)); adapter.setSectionHeaderDisplayEnabled(true); adapter.setDisplayPhotos(true); adapter.setQuickContactEnabled(false); diff --git a/src/com/android/contacts/list/JoinContactListAdapter.java b/src/com/android/contacts/list/JoinContactListAdapter.java index f08fcbbe3..553993702 100644 --- a/src/com/android/contacts/list/JoinContactListAdapter.java +++ b/src/com/android/contacts/list/JoinContactListAdapter.java @@ -24,6 +24,7 @@ import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts.AggregationSuggestions; import android.provider.ContactsContract.Directory; +import android.provider.ContactsContract.RawContacts; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -34,6 +35,7 @@ import com.android.contacts.R; import com.android.contacts.common.list.ContactListAdapter; import com.android.contacts.common.list.ContactListItemView; import com.android.contacts.common.list.DirectoryListLoader; +import com.android.contacts.common.SimContactsConstants; import com.android.contacts.common.preference.ContactsPreferences; public class JoinContactListAdapter extends ContactListAdapter { @@ -81,7 +83,10 @@ public class JoinContactListAdapter extends ContactListAdapter { } builder.appendQueryParameter("limit", String.valueOf(MAX_SUGGESTIONS)); - + builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, + SimContactsConstants.ACCOUNT_TYPE_SIM); + builder.appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, + "true"); loader.setSuggestionUri(builder.build()); // TODO simplify projection @@ -92,11 +97,19 @@ public class JoinContactListAdapter extends ContactListAdapter { .appendEncodedPath(Uri.encode(filter)) .appendQueryParameter( ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)) + .appendQueryParameter(RawContacts.ACCOUNT_TYPE, + SimContactsConstants.ACCOUNT_TYPE_SIM) + .appendQueryParameter( + SimContactsConstants.WITHOUT_SIM_FLAG, "true") .build(); } else { allContactsUri = buildSectionIndexerUri(Contacts.CONTENT_URI).buildUpon() .appendQueryParameter( ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)) + .appendQueryParameter(RawContacts.ACCOUNT_TYPE, + SimContactsConstants.ACCOUNT_TYPE_SIM) + .appendQueryParameter( + SimContactsConstants.WITHOUT_SIM_FLAG, "true") .build(); } loader.setUri(allContactsUri); |