From 735ed91ec5c35024969c57153c8bba69315ae291 Mon Sep 17 00:00:00 2001 From: Raj Yengisetty Date: Mon, 8 Dec 2014 12:35:46 -0800 Subject: Import feature - auto prompt for importing SIM contacts Change-Id: I1c24094c3d588edf2d1182d8369882523e6f6512 --- res/values/cm_strings.xml | 5 +++ .../ImportSIMContactsDialogFragment.java | 36 ++++++++++++++++++++++ .../common/preference/ContactsPreferences.java | 28 +++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100755 src/com/android/contacts/common/interactions/ImportSIMContactsDialogFragment.java diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 75b9f0ab..e014ca4e 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -18,4 +18,9 @@ Local tablet account Local phone account + + + Import contacts from SIM? + Import + Cancel diff --git a/src/com/android/contacts/common/interactions/ImportSIMContactsDialogFragment.java b/src/com/android/contacts/common/interactions/ImportSIMContactsDialogFragment.java new file mode 100755 index 00000000..5cf1d08a --- /dev/null +++ b/src/com/android/contacts/common/interactions/ImportSIMContactsDialogFragment.java @@ -0,0 +1,36 @@ +package com.android.contacts.common.interactions; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +import com.android.contacts.common.R; + +/** + * An dialog invoked to import/export contacts. + */ +public class ImportSIMContactsDialogFragment extends DialogFragment { + public static final String TAG = "ImportSIMContactsDialogFragment"; + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(R.string.import_contacts_sim) + .setPositiveButton(R.string.import_contacts_sim_confirm, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + ImportExportDialogFragment.show(getFragmentManager(), + false, ImportSIMContactsDialogFragment.class); + }}) + .setNegativeButton(R.string.import_contacts_sim_cancel, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // Nothing to do + dismiss(); + }}); + // Create the AlertDialog object and return it + return builder.create(); + } +} diff --git a/src/com/android/contacts/common/preference/ContactsPreferences.java b/src/com/android/contacts/common/preference/ContactsPreferences.java index 311d0075..5c07f83f 100644 --- a/src/com/android/contacts/common/preference/ContactsPreferences.java +++ b/src/com/android/contacts/common/preference/ContactsPreferences.java @@ -27,6 +27,7 @@ import android.provider.ContactsContract; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; +import android.text.TextUtils; import com.android.contacts.common.R; /** @@ -53,6 +54,11 @@ public final class ContactsPreferences implements OnSharedPreferenceChangeListen public static final String SORT_ORDER_KEY = "android.contacts.SORT_ORDER"; + /** + * The values of SIMs serial numbers that have been imported + */ + public static final String IMPORTED_SIMS_SNS = "android.contacts.IMPORTED_SIMS"; + /** * The value for the SORT_ORDER key corresponding to sort by family name first. */ @@ -105,6 +111,28 @@ public final class ContactsPreferences implements OnSharedPreferenceChangeListen editor.commit(); } + public String[] getImportedSims() { + String imported = mPreferences.getString(IMPORTED_SIMS_SNS, ""); + if (!TextUtils.isEmpty(imported)) { + return imported.split("\\|"); + } else { + return new String[0]; + } + } + + public void addImportedSims(String simSN) { + String imported = mPreferences.getString(IMPORTED_SIMS_SNS, ""); + if (!TextUtils.isEmpty(imported)) { + imported += "|" + simSN; + } else { + imported = simSN; + } + + final Editor editor = mPreferences.edit(); + editor.putString(IMPORTED_SIMS_SNS, imported); + editor.commit(); + } + public boolean isDisplayOrderUserChangeable() { return mContext.getResources().getBoolean(R.bool.config_display_order_user_changeable); } -- cgit v1.2.3