summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorc_yunong <yunong@codeaurora.org>2016-08-11 16:07:55 +0800
committerLinux Build Service Account <lnxbuild@localhost>2016-08-24 08:07:28 -0600
commita8a1c073a31c074df0bfdfcf79afd1e6b34cf16b (patch)
tree52eaf6fdeb48e3287d4eec055dd177fcdbeb722f
parent917e9b2404f9c70b6a6f98ae807f07c3eb1976e1 (diff)
downloadpackages_apps_Contacts-staging/cm-14.0-caf.tar.gz
packages_apps_Contacts-staging/cm-14.0-caf.tar.bz2
packages_apps_Contacts-staging/cm-14.0-caf.zip
Contacts: Customize default storage behavior and storage positionstaging/cm-14.0-caf
- 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 CRs-Fixed: 1043367
-rw-r--r--res/values/customize.xml41
-rw-r--r--src/com/android/contacts/editor/ContactEditorUtils.java60
2 files changed, 100 insertions, 1 deletions
diff --git a/res/values/customize.xml b/res/values/customize.xml
new file mode 100644
index 000000000..8b75e0ce5
--- /dev/null
+++ b/res/values/customize.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (c) 2016, 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/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java
index 97e23dc75..d14b69a2e 100644
--- a/src/com/android/contacts/editor/ContactEditorUtils.java
+++ b/src/com/android/contacts/editor/ContactEditorUtils.java
@@ -22,6 +22,8 @@ import android.app.Activity;
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;
@@ -46,7 +48,13 @@ import java.util.Set;
public class ContactEditorUtils {
private static final String TAG = "ContactEditorUtils";
+ private static final String KEY_DEFAULT_ACCOUNT = "ContactEditorUtils_default_account";
private static final String KEY_KNOWN_ACCOUNTS = "ContactEditorUtils_known_accounts";
+ // 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();
@@ -141,6 +149,45 @@ public class ContactEditorUtils {
editor.apply();
}
+ private AccountWithDataSet getOverlayDefualtAccount() {
+ // 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:
+ TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ name = tm.getPhoneCount() > 1 ?
+ 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;
+ }
+ }
+ }
+ }
+ return null;
+ }
/**
* @return the default account saved with {@link #saveDefaultAndAllAccounts}.
*
@@ -151,12 +198,18 @@ public class ContactEditorUtils {
* Also note that the returned account may have been removed already.
*/
public AccountWithDataSet getDefaultAccount() {
+
+ AccountWithDataSet overlayDefaultAccount = getOverlayDefualtAccount();
+ if (overlayDefaultAccount != null) {
+ return overlayDefaultAccount;
+ }
+
final List<AccountWithDataSet> currentWritableAccounts = getWritableAccounts();
if (currentWritableAccounts.size() == 1) {
return currentWritableAccounts.get(0);
}
- final String saved = mPrefs.getString(mDefaultAccountKey, null);
+ final String saved = mPrefs.getString(KEY_DEFAULT_ACCOUNT, null);
if (TextUtils.isEmpty(saved)) {
return null;
}
@@ -215,6 +268,11 @@ public class ContactEditorUtils {
*/
@NeededForTesting
public boolean shouldShowAccountChangedNotification() {
+ // If default account is defined, accounts change should not show.
+ final AccountWithDataSet overlayDefaultAccount = getOverlayDefualtAccount();
+ if (overlayDefaultAccount != null) {
+ return false;
+ }
if (isFirstLaunch()) {
return true;
}