From 7189fda4cbcd162555d59ee335709173ee46bbea Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sun, 9 Feb 2014 03:23:42 +0100 Subject: contacts-common: Add support for import contacts to local phone storage This change allow to select the local storage account to add/import contacts when others cloud/corporate accounts exists. If one or more account exists just ask the user to select the destination account Depends on: http://review.cyanogenmod.org/#/c/59352/ JIRA: CYAN-391 Issue: https://jira.cyanogenmod.org/browse/CYAN-391 Signed-off-by: Jorge Ruesga Conflicts: src/com/android/contacts/common/interactions/ImportExportDialogFragment.java Change-Id: I0120861479a4dcced11a430803513fc21a2e130b --- .../interactions/ImportExportDialogFragment.java | 10 +++--- .../contacts/common/model/account/AccountType.java | 6 ++++ .../contacts/common/util/AccountsListAdapter.java | 5 +++ .../common/vcard/SelectAccountActivity.java | 37 +++++++++++----------- 4 files changed, 33 insertions(+), 25 deletions(-) (limited to 'src/com/android/contacts') diff --git a/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java b/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java index 40603e90..7103ad37 100755 --- a/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java +++ b/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java @@ -309,14 +309,13 @@ public class ImportExportDialogFragment extends AnalyticsDialogFragment * @return {@code true} if the dialog show be closed. {@code false} otherwise. */ private boolean handleImportRequest(int resId) { - // There are three possibilities: - // - more than one accounts -> ask the user - // - just one account -> use the account without asking the user + // There are two possibilities: + // - one or more than one accounts -> ask the user (user can select phone-local also) // - no account -> use phone-local storage without asking the user final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mActivity); final List accountList = accountTypes.getAccounts(true); final int size = accountList.size(); - if (size > 1) { + if (size > 0) { // Send over to the account selector final Bundle args = new Bundle(); args.putInt(KEY_RES_ID, resId); @@ -331,8 +330,7 @@ public class ImportExportDialogFragment extends AnalyticsDialogFragment return false; } - AccountSelectionUtil.doImport(mActivity, resId, - (size == 1 ? accountList.get(0) : null)); + AccountSelectionUtil.doImport(mActivity, resId, null); return true; // Close the dialog. } diff --git a/src/com/android/contacts/common/model/account/AccountType.java b/src/com/android/contacts/common/model/account/AccountType.java index f7b9772c..27b5bc5f 100755 --- a/src/com/android/contacts/common/model/account/AccountType.java +++ b/src/com/android/contacts/common/model/account/AccountType.java @@ -58,6 +58,12 @@ import java.util.Map; public abstract class AccountType { private static final String TAG = "AccountType"; + /** + * Local phone-storage account + * @hide + */ + public static final String LOCAL_ACCOUNT = "phone-local"; + /** * The {@link RawContacts#ACCOUNT_TYPE} these constraints apply to. */ diff --git a/src/com/android/contacts/common/util/AccountsListAdapter.java b/src/com/android/contacts/common/util/AccountsListAdapter.java index 0b2e24af..2e1c44ae 100755 --- a/src/com/android/contacts/common/util/AccountsListAdapter.java +++ b/src/com/android/contacts/common/util/AccountsListAdapter.java @@ -67,6 +67,11 @@ public final class AccountsListAdapter extends BaseAdapter { mContext = context; mAccountTypes = AccountTypeManager.getInstance(context); mAccounts = getAccounts(accountListFilter); + + // Add a virtual local storage account to allow user to store its contacts in the phone + String localAccountName = context.getString(R.string.local_storage_account); + mAccounts.add(0, new AccountWithDataSet(localAccountName, AccountType.LOCAL_ACCOUNT, null)); + if (currentAccount != null && !mAccounts.isEmpty() && !mAccounts.get(0).equals(currentAccount) diff --git a/src/com/android/contacts/common/vcard/SelectAccountActivity.java b/src/com/android/contacts/common/vcard/SelectAccountActivity.java index d05810db..5ee36bc6 100644 --- a/src/com/android/contacts/common/vcard/SelectAccountActivity.java +++ b/src/com/android/contacts/common/vcard/SelectAccountActivity.java @@ -24,6 +24,7 @@ import android.util.Log; import com.android.contacts.common.R; 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.util.AccountSelectionUtil; @@ -52,30 +53,25 @@ public class SelectAccountActivity extends Activity { protected void onCreate(Bundle bundle) { super.onCreate(bundle); - // There's three possibilities: - // - more than one accounts -> ask the user - // - just one account -> use the account without asking the user + // There are two possibilities: + // - one or more than one accounts -> ask the user (user can select phone-local also) // - no account -> use phone-local storage without asking the user final int resId = R.string.import_from_sdcard; final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); final List accountList = accountTypes.getAccounts(true); if (accountList.size() == 0) { - Log.w(LOG_TAG, "Account does not exist"); - finish(); - return; - } else if (accountList.size() == 1) { - final AccountWithDataSet account = accountList.get(0); - final Intent intent = new Intent(); - intent.putExtra(ACCOUNT_NAME, account.name); - intent.putExtra(ACCOUNT_TYPE, account.type); - intent.putExtra(DATA_SET, account.dataSet); - setResult(RESULT_OK, intent); + Log.w(LOG_TAG, "Select phone-local storage account"); finish(); return; } Log.i(LOG_TAG, "The number of available accounts: " + accountList.size()); + // Add a virtual local storage account to allow user to store its contacts in the phone + AccountWithDataSet localAccount = new AccountWithDataSet( + getString(R.string.local_storage_account), AccountType.LOCAL_ACCOUNT, null); + accountList.add(0, localAccount); + // Multiple accounts. Let users to select one. mAccountSelectionListener = new AccountSelectionUtil.AccountSelectedListener( @@ -83,12 +79,15 @@ public class SelectAccountActivity extends Activity { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); - final AccountWithDataSet account = mAccountList.get(which); - final Intent intent = new Intent(); - intent.putExtra(ACCOUNT_NAME, account.name); - intent.putExtra(ACCOUNT_TYPE, account.type); - intent.putExtra(DATA_SET, account.dataSet); - setResult(RESULT_OK, intent); + // Position 0 contains the phone-local account + if (which > 0) { + final AccountWithDataSet account = mAccountList.get(which); + final Intent intent = new Intent(); + intent.putExtra(ACCOUNT_NAME, account.name); + intent.putExtra(ACCOUNT_TYPE, account.type); + intent.putExtra(DATA_SET, account.dataSet); + setResult(RESULT_OK, intent); + } finish(); } }; -- cgit v1.2.3