summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2013-10-08 15:32:28 -0700
committerSteve Kondik <shade@chemlab.org>2013-10-08 15:32:28 -0700
commitf8ea61c804b14f2bb8dbd6f015dfe875e21a554e (patch)
treecad49b46bf3a38d27df685a0b15d6731c214281e
parentf6cead9ebee24fdfa12db93bebda8fcd0284913d (diff)
parent02f4ca058bf97862b74eb641cf4eab2a17b4ef19 (diff)
downloadandroid_packages_apps_ContactsCommon-qcril.tar.gz
android_packages_apps_ContactsCommon-qcril.tar.bz2
android_packages_apps_ContactsCommon-qcril.zip
Merge branch 'jb_mr2' of git://codeaurora.org/platform/packages/apps/ContactsCommon into qcrilqcril
-rw-r--r--res/values/strings.xml12
-rw-r--r--src/com/android/contacts/common/interactions/ImportExportDialogFragment.java92
-rw-r--r--src/com/android/contacts/common/util/AccountSelectionUtil.java97
3 files changed, 194 insertions, 7 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a45ab8f8..e5d8ae47 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -415,8 +415,11 @@ a ren't members of any other group. [CHAR LIMIT=25] -->
<string name="dialog_new_contact_account">Create contact under account</string>
- <!-- Action string for selecting SIM for importing contacts -->
- <string name="import_from_sim">Import from SIM card</string>
+ <!-- Action string for managing SIM contacts -->
+ <string name="manage_sim_contacts"> Manage SIM card contacts</string>
+
+ <!-- Action that exports all contacts to SIM -->
+ <string name="export_to_sim">Export to SIM card</string>
<!-- Action string for selecting (USB) storage for importing contacts [CHAR LIMIT=30] -->
<string name="import_from_sdcard" product="default">Import from storage</string>
@@ -719,5 +722,10 @@ a ren't members of any other group. [CHAR LIMIT=25] -->
This is especially valuable for views without textual representation like ImageView.
-->
<string name="description_dial_phone_number">Dial phone <xliff:g id="name">%1$s</xliff:g></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 232fcad6..7e848bad 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.
@@ -22,12 +24,14 @@ import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.res.Resources;
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;
@@ -54,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
@@ -97,9 +104,23 @@ 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.import_from_sim);
+ adapter.add(R.string.manage_sim_contacts);
+ adapter.add(R.string.export_to_sim);
}
if (res.getBoolean(R.bool.config_allow_import_from_sdcard)) {
adapter.add(R.string.import_from_sdcard);
@@ -122,7 +143,7 @@ public class ImportExportDialogFragment extends DialogFragment
boolean dismissDialog;
final int resId = adapter.getItem(which);
switch (resId) {
- case R.string.import_from_sim:
+ case R.string.manage_sim_contacts:
case R.string.import_from_sdcard: {
dismissDialog = handleImportRequest(resId);
break;
@@ -140,6 +161,18 @@ public class ImportExportDialogFragment extends DialogFragment
doShareVisibleContacts();
break;
}
+ case R.string.export_to_sim: {
+ dismissDialog = true;
+ if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
+ displaySIMSelection();
+ } else {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setClassName("com.android.phone",
+ "com.android.phone.ExportContactsToSim");
+ startActivity(intent);
+ }
+ break;
+ }
default: {
dismissDialog = true;
Log.e(TAG, "Unexpected resource: "
@@ -242,4 +275,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 ab327369..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;
@@ -152,8 +160,13 @@ public class AccountSelectionUtil {
public static void doImport(Context context, int resId, AccountWithDataSet account) {
switch (resId) {
- case R.string.import_from_sim: {
- doImportFromSim(context, account);
+ case R.string.manage_sim_contacts: {
+ 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();
+ }
}