summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaiyiz <kaiyiz@codeaurora.org>2014-10-20 11:39:35 +0800
committerXiaojing Zhang <zhangx@codeaurora.org>2014-11-04 20:33:02 -0800
commit11fe6c0f24504d90d5e6a991a878c6b68d1e62fa (patch)
tree0d74a4ebf0ad8fa81425cb63c5fad6162547030b
parent7e90d115961e175c6d026db19c6bba3ef3c89307 (diff)
downloadpackages_apps_Contacts-11fe6c0f24504d90d5e6a991a878c6b68d1e62fa.tar.gz
packages_apps_Contacts-11fe6c0f24504d90d5e6a991a878c6b68d1e62fa.tar.bz2
packages_apps_Contacts-11fe6c0f24504d90d5e6a991a878c6b68d1e62fa.zip
Contacts: Customize default storage behavior and storage position
- Add a new bool resource to customize contacts default storage behavior enable or not. - Add a new integer resource to customize contacts default storage position. Change-Id: Ib7e78e128649c279c2ae0b761f1e6089f2ca238e
-rw-r--r--res/values/customize.xml41
-rwxr-xr-xsrc/com/android/contacts/editor/ContactEditorFragment.java3
-rw-r--r--src/com/android/contacts/editor/ContactEditorUtils.java42
3 files changed, 85 insertions, 1 deletions
diff --git a/res/values/customize.xml b/res/values/customize.xml
new file mode 100644
index 000000000..51d5843cf
--- /dev/null
+++ b/res/values/customize.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (c) 2014, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<resources>
+
+ <!-- Contacts storage default or not when have not only one writable account,default false -->
+ <bool name="def_storage_behavior_enabled">false</bool>
+
+ <!--
+ store_contacts_position is less than 3,default 0 store contacts in phone,
+ 0:phone,1:sim1,2:sim2
+ -->
+ <integer name="def_storage_position" translatable="false">0</integer>
+
+</resources>
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index d68a412d1..6ef766b5e 100755
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -674,7 +674,8 @@ public class ContactEditorFragment extends Fragment implements
// If there is no default account or the accounts have changed such that we need to
// prompt the user again, then launch the account prompt.
- if (mEditorUtils.shouldShowAccountChangedNotification()) {
+ if (mEditorUtils.shouldShowAccountChangedNotification() &&
+ !mContext.getResources().getBoolean(R.bool.def_storage_behavior_enabled)) {
Intent intent = new Intent(mContext, ContactEditorAccountsChangedActivity.class);
mStatus = Status.SUB_ACTIVITY;
startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
diff --git a/src/com/android/contacts/editor/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java
index b132217fb..8f71596b9 100644
--- a/src/com/android/contacts/editor/ContactEditorUtils.java
+++ b/src/com/android/contacts/editor/ContactEditorUtils.java
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
@@ -30,6 +31,8 @@ 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.android.contacts.R;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
@@ -49,6 +52,10 @@ public class ContactEditorUtils {
// Key to tell the first time launch.
private static final String KEY_ANYTHING_SAVED = "ContactEditorUtils_anything_saved";
+ private static final int DEFAULT_STORAGE_PHONE = 0;
+ private static final int DEFAULT_STORAGE_SIM_1 = 1;
+ private static final int DEFAULT_STORAGE_SIM_2 = 2;
+
private static final List<AccountWithDataSet> EMPTY_ACCOUNTS = ImmutableList.of();
private static ContactEditorUtils sInstance;
@@ -144,6 +151,41 @@ public class ContactEditorUtils {
* Also note that the returned account may have been removed already.
*/
public AccountWithDataSet getDefaultAccount() {
+ // if set the value of store contacts defalut
+ if (mContext.getResources().getBoolean(R.bool.def_storage_behavior_enabled)) {
+ List<AccountWithDataSet> accounts = getWritableAccounts();
+ if (accounts != null && accounts.size() != 0) {
+ String name = "";
+ String type = "";
+ // default Contacts storage postion
+ int store_pos = mContext.getResources().getInteger(R.integer.def_storage_position);
+ switch (store_pos) {
+ case DEFAULT_STORAGE_PHONE:
+ name = SimContactsConstants.PHONE_NAME;
+ type = SimContactsConstants.ACCOUNT_TYPE_PHONE;
+ break;
+ case DEFAULT_STORAGE_SIM_1:
+ name = TelephonyManager.getDefault().isMultiSimEnabled() ?
+ SimContactsConstants.SIM_NAME_1 : SimContactsConstants.SIM_NAME;
+ type = SimContactsConstants.ACCOUNT_TYPE_SIM;
+ break;
+ case DEFAULT_STORAGE_SIM_2:
+ name = SimContactsConstants.SIM_NAME_2;
+ type = SimContactsConstants.ACCOUNT_TYPE_SIM;
+ break;
+ default:
+ Log.e(TAG, "Bad default contacts storage position," +
+ " def_storage_position is " + store_pos);
+ break;
+ }
+
+ for (AccountWithDataSet account : accounts) {
+ if (name.equals(account.name) && type.equals(account.type)) {
+ return account;
+ }
+ }
+ }
+ }
final String saved = mPrefs.getString(KEY_DEFAULT_ACCOUNT, null);
if (TextUtils.isEmpty(saved)) {
return null;