summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2014-02-09 03:23:42 +0100
committerSteve Kondik <shade@chemlab.org>2014-12-04 17:06:19 +0000
commit7189fda4cbcd162555d59ee335709173ee46bbea (patch)
tree6a80bd7c0ef3d5535e28be96b90f02d1e227f6f6
parenteb45d3cef394816e6d036aa6d54a53aa39b0089f (diff)
downloadandroid_packages_apps_ContactsCommon-7189fda4cbcd162555d59ee335709173ee46bbea.tar.gz
android_packages_apps_ContactsCommon-7189fda4cbcd162555d59ee335709173ee46bbea.tar.bz2
android_packages_apps_ContactsCommon-7189fda4cbcd162555d59ee335709173ee46bbea.zip
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 <jorge@ruesga.com> Conflicts: src/com/android/contacts/common/interactions/ImportExportDialogFragment.java Change-Id: I0120861479a4dcced11a430803513fc21a2e130b
-rw-r--r--res/values/cm_strings.xml21
-rwxr-xr-xsrc/com/android/contacts/common/interactions/ImportExportDialogFragment.java10
-rwxr-xr-xsrc/com/android/contacts/common/model/account/AccountType.java6
-rwxr-xr-xsrc/com/android/contacts/common/util/AccountsListAdapter.java5
-rw-r--r--src/com/android/contacts/common/vcard/SelectAccountActivity.java37
5 files changed, 54 insertions, 25 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
new file mode 100644
index 00000000..75b9f0ab
--- /dev/null
+++ b/res/values/cm_strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Virtual local storage account name -->
+ <string name="local_storage_account" product="tablet">Local tablet account</string>
+ <string name="local_storage_account" product="default">Local phone account</string>
+</resources>
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<AccountWithDataSet> 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
@@ -59,6 +59,12 @@ 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.
*/
public String accountType = null;
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<AccountWithDataSet> 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();
}
};