Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.interactions; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 18 | |
Sai Cheemalapati | 8ee2e27 | 2014-08-06 10:30:21 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 20 | import android.app.AlertDialog; |
| 21 | import android.app.Dialog; |
Brian Attwell | c2e912c | 2014-10-27 12:29:44 -0700 | [diff] [blame] | 22 | import android.app.DialogFragment; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 23 | import android.app.FragmentManager; |
| 24 | import android.content.Context; |
| 25 | import android.content.DialogInterface; |
Marcus Hagerott | a8b448a | 2016-11-18 12:51:39 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 28 | import android.os.Bundle; |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
| 34 | import android.widget.ArrayAdapter; |
| 35 | import android.widget.TextView; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 36 | |
Arthur Wang | 3f6a244 | 2016-12-05 14:51:59 -0800 | [diff] [blame] | 37 | import com.android.contacts.R; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 38 | import com.android.contacts.activities.SimImportActivity; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 39 | import com.android.contacts.compat.CompatUtils; |
| 40 | import com.android.contacts.compat.PhoneNumberUtilsCompat; |
| 41 | import com.android.contacts.database.SimContactDao; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 42 | import com.android.contacts.editor.SelectAccountDialogFragment; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 43 | import com.android.contacts.model.AccountTypeManager; |
| 44 | import com.android.contacts.model.SimCard; |
| 45 | import com.android.contacts.model.SimContact; |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 46 | import com.android.contacts.model.account.AccountInfo; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 47 | import com.android.contacts.model.account.AccountWithDataSet; |
| 48 | import com.android.contacts.util.AccountSelectionUtil; |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 49 | import com.google.common.util.concurrent.Futures; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 50 | |
| 51 | import java.util.List; |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 52 | import java.util.concurrent.Future; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * An dialog invoked to import/export contacts. |
| 56 | */ |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 57 | public class ImportDialogFragment extends DialogFragment { |
James Laskey | 1e2102f | 2016-09-19 10:09:08 -0700 | [diff] [blame] | 58 | public static final String TAG = "ImportDialogFragment"; |
Wenyi Wang | c33f492 | 2015-09-24 15:28:59 -0700 | [diff] [blame] | 59 | |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 60 | public static final String KEY_RES_ID = "resourceId"; |
| 61 | public static final String KEY_SUBSCRIPTION_ID = "subscriptionId"; |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 62 | |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 63 | public static final String EXTRA_SIM_ONLY = "extraSimOnly"; |
| 64 | |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 65 | public static final String EXTRA_SIM_CONTACT_COUNT_PREFIX = "simContactCount_"; |
| 66 | |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 67 | private boolean mSimOnly = false; |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 68 | private SimContactDao mSimDao; |
Wenyi Wang | c33f492 | 2015-09-24 15:28:59 -0700 | [diff] [blame] | 69 | |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 70 | private Future<List<AccountInfo>> mAccountsFuture; |
| 71 | |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 72 | /** Preferred way to show this dialog */ |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 73 | public static void show(FragmentManager fragmentManager) { |
| 74 | final ImportDialogFragment fragment = new ImportDialogFragment(); |
| 75 | fragment.show(fragmentManager, TAG); |
| 76 | } |
| 77 | |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 78 | public static void show(FragmentManager fragmentManager, List<SimCard> sims, |
| 79 | boolean includeVcf) { |
James Laskey | 1e2102f | 2016-09-19 10:09:08 -0700 | [diff] [blame] | 80 | final ImportDialogFragment fragment = new ImportDialogFragment(); |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 81 | final Bundle args = new Bundle(); |
| 82 | args.putBoolean(EXTRA_SIM_ONLY, !includeVcf); |
| 83 | for (SimCard sim : sims) { |
| 84 | final List<SimContact> contacts = sim.getContacts(); |
| 85 | if (contacts == null) { |
| 86 | continue; |
| 87 | } |
| 88 | args.putInt(EXTRA_SIM_CONTACT_COUNT_PREFIX + sim.getSimId(), contacts.size()); |
| 89 | } |
| 90 | |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 91 | fragment.setArguments(args); |
James Laskey | 1e2102f | 2016-09-19 10:09:08 -0700 | [diff] [blame] | 92 | fragment.show(fragmentManager, TAG); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 96 | public void onCreate(Bundle savedInstanceState) { |
| 97 | super.onCreate(savedInstanceState); |
| 98 | |
Sean Midford | 9da13ab | 2016-11-07 14:15:54 -0800 | [diff] [blame] | 99 | setStyle(STYLE_NORMAL, R.style.ContactsAlertDialogTheme); |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 100 | |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 101 | final Bundle args = getArguments(); |
| 102 | mSimOnly = args != null && args.getBoolean(EXTRA_SIM_ONLY, false); |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 103 | mSimDao = SimContactDao.create(getContext()); |
Marcus Hagerott | 02f5dba | 2016-10-18 12:34:57 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 107 | public void onResume() { |
| 108 | super.onResume(); |
| 109 | |
| 110 | // Start loading the accounts. This is done in onResume in case they were refreshed. |
| 111 | mAccountsFuture = AccountTypeManager.getInstance(getActivity()).filterAccountsAsync( |
| 112 | AccountTypeManager.writableFilter()); |
| 113 | } |
| 114 | |
| 115 | @Override |
Wenyi Wang | 9342fbb | 2015-11-17 19:36:35 -0800 | [diff] [blame] | 116 | public Context getContext() { |
| 117 | return getActivity(); |
| 118 | } |
| 119 | |
| 120 | @Override |
Sai Cheemalapati | 8ee2e27 | 2014-08-06 10:30:21 -0700 | [diff] [blame] | 121 | public void onAttach(Activity activity) { |
| 122 | super.onAttach(activity); |
Sai Cheemalapati | 8ee2e27 | 2014-08-06 10:30:21 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 126 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 127 | final LayoutInflater dialogInflater = (LayoutInflater) |
| 128 | getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 129 | |
| 130 | // Adapter that shows a list of string resources |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 131 | final ArrayAdapter<AdapterEntry> adapter = new ArrayAdapter<AdapterEntry>(getActivity(), |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 132 | R.layout.select_dialog_item) { |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 133 | |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 134 | @Override |
| 135 | public View getView(int position, View convertView, ViewGroup parent) { |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 136 | final View result = convertView != null ? convertView : |
| 137 | dialogInflater.inflate(R.layout.select_dialog_item, parent, false); |
| 138 | final TextView primaryText = (TextView) result.findViewById(R.id.primary_text); |
| 139 | final TextView secondaryText = (TextView) result.findViewById(R.id.secondary_text); |
| 140 | final AdapterEntry entry = getItem(position); |
| 141 | secondaryText.setVisibility(View.GONE); |
| 142 | if (entry.mChoiceResourceId == R.string.import_from_sim) { |
| 143 | final CharSequence secondary = getSimSecondaryText(entry.mSim); |
| 144 | if (TextUtils.isEmpty(secondary)) { |
| 145 | secondaryText.setVisibility(View.GONE); |
| 146 | } else { |
| 147 | secondaryText.setText(secondary); |
| 148 | secondaryText.setVisibility(View.VISIBLE); |
| 149 | } |
| 150 | } |
| 151 | primaryText.setText(entry.mLabel); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 152 | return result; |
| 153 | } |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 154 | |
| 155 | CharSequence getSimSecondaryText(SimCard sim) { |
| 156 | int count = getSimContactCount(sim); |
| 157 | |
| 158 | CharSequence phone = sim.getFormattedPhone(); |
| 159 | if (phone == null) { |
| 160 | phone = sim.getPhone(); |
| 161 | } |
| 162 | if (phone != null) { |
| 163 | phone = PhoneNumberUtilsCompat.createTtsSpannable(phone); |
| 164 | } |
| 165 | |
| 166 | if (count != -1 && phone != null) { |
| 167 | // We use a template instead of format string so that the TTS span is preserved |
| 168 | final CharSequence template = getResources() |
| 169 | .getQuantityString(R.plurals.import_from_sim_secondary_template, count); |
| 170 | return TextUtils.expandTemplate(template, String.valueOf(count), phone); |
| 171 | } else if (phone != null) { |
| 172 | return phone; |
| 173 | } else if (count != -1) { |
| 174 | // count != -1 |
| 175 | return getResources() |
| 176 | .getQuantityString( |
| 177 | R.plurals.import_from_sim_secondary_contact_count_fmt, count, |
| 178 | count); |
| 179 | } else { |
| 180 | return null; |
| 181 | } |
| 182 | } |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 183 | }; |
| 184 | |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 185 | addItems(adapter); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 186 | |
| 187 | final DialogInterface.OnClickListener clickListener = |
| 188 | new DialogInterface.OnClickListener() { |
| 189 | @Override |
| 190 | public void onClick(DialogInterface dialog, int which) { |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 191 | final int resId = adapter.getItem(which).mChoiceResourceId; |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 192 | if (resId == R.string.import_from_sim) { |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 193 | handleSimImportRequest(adapter.getItem(which).mSim); |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 194 | } else if (resId == R.string.import_from_vcf_file) { |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 195 | handleImportRequest(resId, SimCard.NO_SUBSCRIPTION_ID); |
Sailesh Nepal | b4a522e | 2016-02-20 21:17:32 -0800 | [diff] [blame] | 196 | } else { |
Sailesh Nepal | b4a522e | 2016-02-20 21:17:32 -0800 | [diff] [blame] | 197 | Log.e(TAG, "Unexpected resource: " |
| 198 | + getActivity().getResources().getResourceEntryName(resId)); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 199 | } |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 200 | dialog.dismiss(); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 201 | } |
| 202 | }; |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 203 | |
| 204 | final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme()) |
| 205 | .setTitle(R.string.dialog_import) |
| 206 | .setNegativeButton(android.R.string.cancel, null); |
| 207 | if (adapter.isEmpty()) { |
| 208 | // Handle edge case; e.g. SIM card was removed. |
| 209 | builder.setMessage(R.string.nothing_to_import_message); |
| 210 | } else { |
| 211 | builder.setSingleChoiceItems(adapter, -1, clickListener); |
| 212 | } |
| 213 | |
| 214 | return builder.create(); |
| 215 | } |
| 216 | |
| 217 | private int getSimContactCount(SimCard sim) { |
| 218 | if (sim.getContacts() != null) { |
| 219 | return sim.getContacts().size(); |
| 220 | } |
| 221 | final Bundle args = getArguments(); |
| 222 | if (args == null) { |
| 223 | return -1; |
| 224 | } |
| 225 | return args.getInt(EXTRA_SIM_CONTACT_COUNT_PREFIX + sim.getSimId(), -1); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 228 | private void addItems(ArrayAdapter<AdapterEntry> adapter) { |
| 229 | final Resources res = getActivity().getResources(); |
| 230 | if (res.getBoolean(R.bool.config_allow_import_from_vcf_file) && !mSimOnly) { |
| 231 | adapter.add(new AdapterEntry(getString(R.string.import_from_vcf_file), |
| 232 | R.string.import_from_vcf_file)); |
| 233 | } |
| 234 | final List<SimCard> sims = mSimDao.getSimCards(); |
| 235 | |
| 236 | if (sims.size() == 1) { |
| 237 | adapter.add(new AdapterEntry(getString(R.string.import_from_sim), |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 238 | R.string.import_from_sim, sims.get(0))); |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 239 | return; |
| 240 | } |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 241 | for (int i = 0; i < sims.size(); i++) { |
| 242 | final SimCard sim = sims.get(i); |
| 243 | adapter.add(new AdapterEntry(getSimDescription(sim, i), R.string.import_from_sim, sim)); |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 247 | private void handleSimImportRequest(SimCard sim) { |
Marcus Hagerott | a8b448a | 2016-11-18 12:51:39 -0800 | [diff] [blame] | 248 | startActivity(new Intent(getActivity(), SimImportActivity.class) |
| 249 | .putExtra(SimImportActivity.EXTRA_SUBSCRIPTION_ID, sim.getSubscriptionId())); |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 252 | /** |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 253 | * Handle "import from SD". |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 254 | */ |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 255 | private void handleImportRequest(int resId, int subscriptionId) { |
Marcus Hagerott | a181ca6 | 2016-12-21 14:42:13 -0800 | [diff] [blame] | 256 | // Get the accounts. Because this only happens after a user action this should pretty |
| 257 | // much never block since it will usually be at least several seconds before the user |
| 258 | // interacts with the view |
| 259 | final List<AccountWithDataSet> accountList = AccountInfo.extractAccounts( |
| 260 | Futures.getUnchecked(mAccountsFuture)); |
| 261 | |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 262 | // There are three possibilities: |
| 263 | // - more than one accounts -> ask the user |
| 264 | // - just one account -> use the account without asking the user |
| 265 | // - no account -> use phone-local storage without asking the user |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 266 | final int size = accountList.size(); |
| 267 | if (size > 1) { |
| 268 | // Send over to the account selector |
| 269 | final Bundle args = new Bundle(); |
| 270 | args.putInt(KEY_RES_ID, resId); |
Jay Shrauner | cf08222 | 2014-11-25 13:52:50 -0800 | [diff] [blame] | 271 | args.putInt(KEY_SUBSCRIPTION_ID, subscriptionId); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 272 | SelectAccountDialogFragment.show( |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 273 | getFragmentManager(), R.string.dialog_new_contact_account, |
Marcus Hagerott | ee3d3a5 | 2016-12-22 10:35:30 -0800 | [diff] [blame] | 274 | AccountTypeManager.AccountFilter.CONTACTS_WRITABLE, args); |
Wenyi Wang | c332228 | 2016-11-11 14:53:29 -0800 | [diff] [blame] | 275 | } else { |
| 276 | AccountSelectionUtil.doImport(getActivity(), resId, |
| 277 | (size == 1 ? accountList.get(0) : null), |
| 278 | (CompatUtils.isMSIMCompatible() ? subscriptionId : -1)); |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 279 | } |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 280 | } |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 281 | |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 282 | private CharSequence getSimDescription(SimCard sim, int index) { |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 283 | final CharSequence name = sim.getDisplayName(); |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 284 | if (name != null) { |
Marcus Hagerott | 216e297 | 2016-10-26 15:53:42 -0700 | [diff] [blame] | 285 | return getString(R.string.import_from_sim_summary_fmt, name); |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 286 | } else { |
| 287 | return getString(R.string.import_from_sim_summary_fmt, String.valueOf(index)); |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 288 | } |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | private static class AdapterEntry { |
Ihab Awad | 3732180 | 2014-12-05 16:23:11 -0800 | [diff] [blame] | 292 | public final CharSequence mLabel; |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 293 | public final int mChoiceResourceId; |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 294 | public final SimCard mSim; |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 295 | |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 296 | public AdapterEntry(CharSequence label, int resId, SimCard sim) { |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 297 | mLabel = label; |
| 298 | mChoiceResourceId = resId; |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 299 | mSim = sim; |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | public AdapterEntry(String label, int resId) { |
Brian Attwell | 87ffb82 | 2015-02-03 10:28:11 -0800 | [diff] [blame] | 303 | // Store a nonsense value for mSubscriptionId. If this constructor is used, |
| 304 | // the mSubscriptionId value should not be read later. |
Marcus Hagerott | 8636d1e | 2016-10-27 19:14:12 -0700 | [diff] [blame] | 305 | this(label, resId, /* sim= */ null); |
Brian Attwell | c07c8bb | 2014-10-06 14:55:49 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
Chiao Cheng | 6fe32c0 | 2012-12-04 15:44:17 -0800 | [diff] [blame] | 308 | } |