diff options
| author | Steve Kondik <shade@chemlab.org> | 2010-11-18 07:06:17 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2010-11-18 07:06:17 +0000 |
| commit | fade1bb287785c89108a133a6d5440929a9f0cdb (patch) | |
| tree | 9f9e5978e5660a3df8ad35ef2091cc1c3bc5deb3 | |
| parent | 186b07360795786dc06d5ddef29cc2e098e5008e (diff) | |
| parent | acd3213bb9fa52ef556c99864a9f9dfa0c01f180 (diff) | |
| download | packages_apps_Contacts-fade1bb287785c89108a133a6d5440929a9f0cdb.tar.gz packages_apps_Contacts-fade1bb287785c89108a133a6d5440929a9f0cdb.tar.bz2 packages_apps_Contacts-fade1bb287785c89108a133a6d5440929a9f0cdb.zip | |
Merge "Allow user to add a phone only contact even when other contact accounts are available" into froyo
5 files changed, 40 insertions, 15 deletions
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java index 2e88927e5..5cb1839f6 100644 --- a/src/com/android/contacts/ContactsListActivity.java +++ b/src/com/android/contacts/ContactsListActivity.java @@ -1583,7 +1583,7 @@ public class ContactsListActivity extends ListActivity implements View.OnCreateC // - just one account -> use the account without asking the user // - no account -> use phone-local storage without asking the user final Sources sources = Sources.getInstance(this); - final List<Account> accountList = sources.getAccounts(true); + final List<Account> accountList = sources.getAccounts(true, true); final int size = accountList.size(); if (size > 1) { showDialog(resId); diff --git a/src/com/android/contacts/ImportVCardActivity.java b/src/com/android/contacts/ImportVCardActivity.java index 0a324fe79..d770b9851 100644 --- a/src/com/android/contacts/ImportVCardActivity.java +++ b/src/com/android/contacts/ImportVCardActivity.java @@ -734,7 +734,9 @@ public class ImportVCardActivity extends Activity { super.onCreate(bundle); final Intent intent = getIntent(); + boolean accountIsNull = false; if (intent != null) { + accountIsNull = intent.getBooleanExtra("account_isnull", false); final String accountName = intent.getStringExtra("account_name"); final String accountType = intent.getStringExtra("account_type"); if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) { @@ -745,13 +747,13 @@ public class ImportVCardActivity extends Activity { } // The caller often does not know account information at all, so we show the UI instead. - if (mAccount == null) { + if (!accountIsNull && mAccount == null) { // There's three possibilities: // - more than one accounts -> ask the user // - just one account -> use the account without asking the user // - no account -> use phone-local storage without asking the user final Sources sources = Sources.getInstance(this); - final List<Account> accountList = sources.getAccounts(true); + final List<Account> accountList = sources.getAccounts(true, true); final int size = accountList.size(); if (size > 1) { final int resId = R.string.import_from_sdcard; diff --git a/src/com/android/contacts/model/Sources.java b/src/com/android/contacts/model/Sources.java index 68e7754df..e9c36041d 100644 --- a/src/com/android/contacts/model/Sources.java +++ b/src/com/android/contacts/model/Sources.java @@ -246,11 +246,15 @@ public class Sources extends BroadcastReceiver implements OnAccountsUpdateListen return null; } + public ArrayList<Account> getAccounts(boolean writableOnly) { + return getAccounts(writableOnly, false); + } + /** * Return list of all known, writable {@link ContactsSource}. Sources * returned may require inflation before they can be used. */ - public ArrayList<Account> getAccounts(boolean writableOnly) { + public ArrayList<Account> getAccounts(boolean writableOnly, boolean addPhoneOnlyDummy) { final AccountManager am = mAccountManager; final Account[] accounts = am.getAccounts(); final ArrayList<Account> matching = Lists.newArrayList(); @@ -265,6 +269,10 @@ public class Sources extends BroadcastReceiver implements OnAccountsUpdateListen matching.add(account); } } + + if (addPhoneOnlyDummy) + matching.add(null); + return matching; } diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java index 3e248ea93..b3b6fedf4 100644 --- a/src/com/android/contacts/ui/EditContactActivity.java +++ b/src/com/android/contacts/ui/EditContactActivity.java @@ -1206,7 +1206,7 @@ public final class EditContactActivity extends Activity @Override protected ArrayList<Account> doInBackground(final EditContactActivity target, Void... params) { - return Sources.getInstance(target).getAccounts(true); + return Sources.getInstance(target).getAccounts(true, true); } @Override @@ -1250,11 +1250,17 @@ public final class EditContactActivity extends Activity final TextView text2 = (TextView)convertView.findViewById(android.R.id.text2); final Account account = this.getItem(position); - final ContactsSource source = sources.getInflatedSource(account.type, - ContactsSource.LEVEL_SUMMARY); + final ContactsSource source = + sources.getInflatedSource(account != null ? account.type : null, + ContactsSource.LEVEL_SUMMARY); - text1.setText(account.name); - text2.setText(source.getDisplayLabel(EditContactActivity.this)); + if (account == null) { + text1.setText(source.getDisplayLabel(EditContactActivity.this)); + text2.setText(""); + } else { + text1.setText(account.name); + text2.setText(source.getDisplayLabel(EditContactActivity.this)); + } return convertView; } diff --git a/src/com/android/contacts/util/AccountSelectionUtil.java b/src/com/android/contacts/util/AccountSelectionUtil.java index cc46d2b09..d10402ac7 100644 --- a/src/com/android/contacts/util/AccountSelectionUtil.java +++ b/src/com/android/contacts/util/AccountSelectionUtil.java @@ -90,7 +90,7 @@ public class AccountSelectionUtil { DialogInterface.OnClickListener onClickListener, DialogInterface.OnCancelListener onCancelListener) { final Sources sources = Sources.getInstance(context); - final List<Account> writableAccountList = sources.getAccounts(true); + final List<Account> writableAccountList = sources.getAccounts(true, true); // Assume accountList.size() > 1 @@ -119,12 +119,17 @@ public class AccountSelectionUtil { final Account account = this.getItem(position); final ContactsSource source = - sources.getInflatedSource(account.type, + sources.getInflatedSource(account != null ? account.type : null, ContactsSource.LEVEL_SUMMARY); final Context context = getContext(); - text1.setText(account.name); - text2.setText(source.getDisplayLabel(context)); + if (account == null) { + text1.setText(source.getDisplayLabel(context)); + text2.setText(""); + } else { + text1.setText(account.name); + text2.setText(source.getDisplayLabel(context)); + } return convertView; } @@ -169,7 +174,9 @@ public class AccountSelectionUtil { Intent importIntent = new Intent(Intent.ACTION_VIEW); importIntent.setType("vnd.android.cursor.item/sim-contact"); - if (account != null) { + if (account == null) { + importIntent.putExtra("account_isnull", true); + } else { importIntent.putExtra("account_name", account.name); importIntent.putExtra("account_type", account.type); } @@ -183,7 +190,9 @@ public class AccountSelectionUtil { } Intent importIntent = new Intent(context, ImportVCardActivity.class); - if (account != null) { + if (account == null) { + importIntent.putExtra("account_isnull", true); + } else { importIntent.putExtra("account_name", account.name); importIntent.putExtra("account_type", account.type); } |
