diff options
author | Rakesh Pallerla <rakesh@codeaurora.org> | 2012-11-04 23:18:26 +0530 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2014-09-02 14:06:10 -0700 |
commit | ef652dcb29df2c15316d9d9584ad2381a6ff9a2d (patch) | |
tree | 983a2487276e3bd0505d7495bd7308b94d9060a4 | |
parent | 5e3a1afba35cf12d1b322d0af0b159bc10bd58f8 (diff) | |
download | packages_apps_ContactsCommon-ef652dcb29df2c15316d9d9584ad2381a6ff9a2d.tar.gz packages_apps_ContactsCommon-ef652dcb29df2c15316d9d9584ad2381a6ff9a2d.tar.bz2 packages_apps_ContactsCommon-ef652dcb29df2c15316d9d9584ad2381a6ff9a2d.zip |
Add support for Manage SIM Contacts for MultiSim.
Add support to show UI options
1) Manage sim contacts.
User can select required subscription or can
import contacts from all available SIM's.
2) Export contacts to sim card.
User can select the SIM card to export contacts to SIM.
Change-Id: I7e727181634d5bfe8eb5f1d273031948be922e4c
3 files changed, 179 insertions, 5 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index cb110bf2..f08bf614 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -25,4 +25,9 @@ <!-- Action that exports all contacts to SIM --> <string name="export_to_sim">Export to SIM card</string> + <string name="Import_All">Import Contacts From All SIMs</string> + <string name="ok">OK</string> + <string name="cancel">Cancel</string> + + <string name="select_sim">Select SIM</string> </resources> diff --git a/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java b/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java index 9d583f90..dc71b962 100644 --- a/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java +++ b/src/com/android/contacts/common/interactions/ImportExportDialogFragment.java @@ -1,5 +1,7 @@ /* * Copyright (C) 2010 The Android Open Source Project + * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Not a Contribution. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +31,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract.Contacts; +import android.telephony.MSimTelephonyManager; import android.telephony.TelephonyManager; import android.util.Log; import android.view.LayoutInflater; @@ -55,9 +58,12 @@ import java.util.List; public class ImportExportDialogFragment extends DialogFragment implements SelectAccountDialogFragment.Listener { public static final String TAG = "ImportExportDialogFragment"; + private static final String SIM_INDEX = "sim_index"; private static final String KEY_RES_ID = "resourceId"; private static final String ARG_CONTACTS_ARE_AVAILABLE = "CONTACTS_ARE_AVAILABLE"; + private static int SIM_ID_INVALID = -1; + private static int mSelectedSim = SIM_ID_INVALID; private final String[] LOOKUP_PROJECTION = new String[] { Contacts.LOOKUP_KEY @@ -98,7 +104,20 @@ public class ImportExportDialogFragment extends DialogFragment } }; - if (TelephonyManager.getDefault().hasIccCard() + boolean hasIccCard = false; + + if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) { + for (int i = 0; i < MSimTelephonyManager.getDefault().getPhoneCount(); i++) { + hasIccCard = MSimTelephonyManager.getDefault().hasIccCard(i); + if (hasIccCard) { + break; + } + } + } else { + hasIccCard = TelephonyManager.getDefault().hasIccCard(); + } + + if (hasIccCard && res.getBoolean(R.bool.config_allow_sim_import)) { adapter.add(R.string.manage_sim_contacts); adapter.add(R.string.export_to_sim); @@ -144,10 +163,14 @@ public class ImportExportDialogFragment extends DialogFragment } case R.string.export_to_sim: { dismissDialog = true; - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setClassName("com.android.phone", + if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) { + displaySIMSelection(); + } else { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setClassName("com.android.phone", "com.android.phone.ExportContactsToSim"); - startActivity(intent); + startActivity(intent); + } break; } default: { @@ -250,4 +273,57 @@ public class ImportExportDialogFragment extends DialogFragment // See onAccountChosen() -- at this point the dialog is still showing. Close it. dismiss(); } + + private void displaySIMSelection() { + Log.d(TAG, "displayMyDialog"); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.select_sim); + mSelectedSim = SIM_ID_INVALID; + int numPhones = MSimTelephonyManager.getDefault().getPhoneCount(); + CharSequence[] subList = new CharSequence[numPhones]; + int i; + for (i = 1; i <= numPhones; i++) { + subList[i-1] = "SIM" + i; + } + builder.setSingleChoiceItems(subList, -1, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, int arg1) { + Log.d(TAG, "onClicked Dialog on arg1 = " + arg1); + mSelectedSim = arg1; + } + }); + + AlertDialog dialog = builder.create(); + dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.d(TAG, "onClicked OK"); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setClassName("com.android.phone", + "com.android.phone.ExportContactsToSim"); + intent.putExtra(SIM_INDEX, mSelectedSim); + if (mSelectedSim != SIM_ID_INVALID) { + ((AlertDialog)dialog).getContext().startActivity(intent); + } + } + }); + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.d(TAG, "onClicked Cancel"); + } + }); + + dialog.setOnDismissListener(new OnDismissListener () { + @Override + public void onDismiss(DialogInterface dialog) { + Log.d(TAG, "onDismiss"); + Log.d(TAG, "Selected SUB = " + mSelectedSim); + } + }); + dialog.show(); + } } diff --git a/src/com/android/contacts/common/util/AccountSelectionUtil.java b/src/com/android/contacts/common/util/AccountSelectionUtil.java index e0ffa88c..ac6b8cc0 100644 --- a/src/com/android/contacts/common/util/AccountSelectionUtil.java +++ b/src/com/android/contacts/common/util/AccountSelectionUtil.java @@ -1,5 +1,7 @@ /* * Copyright (C) 2009 The Android Open Source Project + * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Not a Contribution. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +24,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.telephony.MSimTelephonyManager; import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -46,6 +49,11 @@ public class AccountSelectionUtil { private static final String LOG_TAG = "AccountSelectionUtil"; public static boolean mVCardShare = false; + private static int SIM_ID_INVALID = -1; + private static int mSelectedSim = SIM_ID_INVALID; + private static final String SIM_INDEX = "sim_index"; + // Constant value to know option is import from all SIM's + private static int IMPORT_FROM_ALL = 8; public static Uri mPath; @@ -153,7 +161,12 @@ public class AccountSelectionUtil { public static void doImport(Context context, int resId, AccountWithDataSet account) { switch (resId) { case R.string.manage_sim_contacts: { - doImportFromSim(context, account); + if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) { + SimSelectedListener simSelListner = new SimSelectedListener(context, account); + displaySelectSimDialog(context, simSelListner); + } else { + doImportFromSim(context, account); + } break; } case R.string.import_from_sdcard: { @@ -175,6 +188,20 @@ public class AccountSelectionUtil { context.startActivity(importIntent); } + public static void doImportFromMultiSim(Context context, AccountWithDataSet account, + int selectedSim) { + Intent importIntent = new Intent(Intent.ACTION_VIEW); + importIntent.setType("vnd.android.cursor.item/sim-contact"); + if (account != null) { + importIntent.putExtra("account_name", account.name); + importIntent.putExtra("account_type", account.type); + importIntent.putExtra("data_set", account.dataSet); + } + importIntent.setClassName("com.android.phone", "com.android.phone.MSimContacts"); + importIntent.putExtra(SIM_INDEX, selectedSim); + context.startActivity(importIntent); + } + public static void doImportFromSdCard(Context context, AccountWithDataSet account) { Intent importIntent = new Intent(context, ImportVCardActivity.class); if (account != null) { @@ -191,4 +218,70 @@ public class AccountSelectionUtil { mPath = null; context.startActivity(importIntent); } + + public static class SimSelectedListener + implements DialogInterface.OnClickListener { + + final private Context mContext; + final private AccountWithDataSet mAccount; + + public SimSelectedListener(Context context, AccountWithDataSet account) { + mContext = context; + mAccount = account; + } + + public void onClick(DialogInterface dialog, int which) { + Log.d(LOG_TAG, "onClick OK: mSelectedSim = " + mSelectedSim); + if (mSelectedSim != SIM_ID_INVALID) { + doImportFromMultiSim(mContext, mAccount, mSelectedSim); + } + } + } + + private static void displaySelectSimDialog(Context context, + SimSelectedListener simSelListner) { + Log.d(LOG_TAG, "displaySelectSimDialog"); + + mSelectedSim = SIM_ID_INVALID; + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.select_sim); + final int numPhones = MSimTelephonyManager.getDefault().getPhoneCount(); + CharSequence[] sub_list = new CharSequence[numPhones + 1]; + int i; + for (i = 1; i <= numPhones; i++) { + sub_list[i-1] = "SIM" + i; + } + sub_list[i-1] = context.getString(R.string.Import_All); + builder.setSingleChoiceItems(sub_list, -1, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.d(LOG_TAG, "onClicked Dialog on which = " + which); + mSelectedSim = which; + if (mSelectedSim == numPhones) { + mSelectedSim = IMPORT_FROM_ALL; + } + } + }); + + AlertDialog dialog = builder.create(); + dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.ok), + simSelListner); + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.cancel), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.d(LOG_TAG, "onClicked Cancel"); + } + }); + + dialog.setOnDismissListener(new DialogInterface.OnDismissListener () { + @Override + public void onDismiss(DialogInterface dialog) { + Log.d(LOG_TAG, "onDismiss"); + Log.d(LOG_TAG, "Selected SUB = " + mSelectedSim); + } + }); + dialog.show(); + } } |