summaryrefslogtreecommitdiffstats
path: root/src/com/android/contacts/common/util
diff options
context:
space:
mode:
authorRakesh Pallerla <rakesh@codeaurora.org>2014-08-22 19:50:34 +0530
committerLinux Build Service Account <lnxbuild@localhost>2014-11-04 08:54:02 -0700
commit14e31e5757aebed4e88b6c72a4a66974aa753871 (patch)
tree87a2cb25f41f2e2eae3ddfabd5495a9d70f5cfae /src/com/android/contacts/common/util
parent0fbe644b9300d0157e4ac18bdb2ceb2477c333d6 (diff)
downloadandroid_packages_apps_ContactsCommon-14e31e5757aebed4e88b6c72a4a66974aa753871.tar.gz
android_packages_apps_ContactsCommon-14e31e5757aebed4e88b6c72a4a66974aa753871.tar.bz2
android_packages_apps_ContactsCommon-14e31e5757aebed4e88b6c72a4a66974aa753871.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
Diffstat (limited to 'src/com/android/contacts/common/util')
-rw-r--r--src/com/android/contacts/common/util/AccountSelectionUtil.java96
1 files changed, 95 insertions, 1 deletions
diff --git a/src/com/android/contacts/common/util/AccountSelectionUtil.java b/src/com/android/contacts/common/util/AccountSelectionUtil.java
index e0ffa88c..8f314882 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.TelephonyManager;
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 (TelephonyManager.getDefault().getPhoneCount() > 1) {
+ SimSelectedListener simSelListner = new SimSelectedListener(context, account);
+ displaySelectSimDialog(context, simSelListner);
+ } else {
+ doImportFromSim(context, account);
+ }
break;
}
case R.string.import_from_sdcard: {
@@ -172,6 +185,21 @@ public class AccountSelectionUtil {
importIntent.putExtra("data_set", account.dataSet);
}
importIntent.setClassName("com.android.phone", "com.android.phone.SimContacts");
+ importIntent.putExtra(SIM_INDEX, TelephonyManager.getDefault().getDefaultSim());
+ 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.SimContacts");
+ importIntent.putExtra(SIM_INDEX, selectedSim);
context.startActivity(importIntent);
}
@@ -191,4 +219,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 = TelephonyManager.getDefault().getPhoneCount();
+ CharSequence[] subList = new CharSequence[numPhones + 1];
+ int i;
+ for (i = 1; i <= numPhones; i++) {
+ subList[i-1] = "SIM" + i;
+ }
+ subList[i-1] = context.getString(R.string.Import_All);
+ builder.setSingleChoiceItems(subList, -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(com.android.internal.R.string.ok), simSelListner);
+ dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(
+ com.android.internal.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();
+ }
}