blob: a57e2ee57b7fae3f588aa8c60c41c68b9deae3cd [file] [log] [blame]
Chiao Cheng91197042012-08-24 14:19:37 -07001/*
2 * Copyright (C) 2006 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
17package com.android.dialer;
18
Nancy Chen675af1f2014-10-16 18:33:51 -070019import android.app.Activity;
Chiao Cheng91197042012-08-24 14:19:37 -070020import android.app.AlertDialog;
Jay Shrauner384eaad2015-04-03 16:03:41 -070021import android.app.DialogFragment;
Chiao Cheng91197042012-08-24 14:19:37 -070022import android.app.KeyguardManager;
23import android.app.ProgressDialog;
Jake Hamby1d6fb572013-04-09 15:49:56 -070024import android.content.ActivityNotFoundException;
Chiao Cheng91197042012-08-24 14:19:37 -070025import android.content.ContentResolver;
26import android.content.Context;
27import android.content.DialogInterface;
28import android.content.Intent;
29import android.database.Cursor;
30import android.net.Uri;
31import android.os.Looper;
Jeff Sharkeyf4f47662014-04-16 17:21:12 -070032import android.provider.Settings;
Yorke Lee3af7e562015-04-15 11:05:54 -070033import android.telecom.PhoneAccount;
Nancy Chen675af1f2014-10-16 18:33:51 -070034import android.telecom.PhoneAccountHandle;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070035import android.telecom.TelecomManager;
Chiao Cheng91197042012-08-24 14:19:37 -070036import android.telephony.PhoneNumberUtils;
37import android.telephony.TelephonyManager;
Nancy Chen0f4ec2a2015-03-23 15:03:03 -070038import android.text.TextUtils;
Chiao Cheng91197042012-08-24 14:19:37 -070039import android.util.Log;
40import android.view.WindowManager;
41import android.widget.EditText;
42import android.widget.Toast;
43
Jay Shraunerede67ec2014-09-11 15:03:36 -070044import com.android.common.io.MoreCloseables;
Chiao Cheng07af7642012-09-14 12:05:14 -070045import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler;
Nancy Chen675af1f2014-10-16 18:33:51 -070046import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
47import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener;
48import com.android.dialer.calllog.PhoneAccountUtils;
Yorke Lee4aece952015-05-02 22:22:54 -070049import com.android.dialer.util.TelecomUtil;
Chiao Cheng91197042012-08-24 14:19:37 -070050
Nancy Chen675af1f2014-10-16 18:33:51 -070051import java.util.Arrays;
Nancy Chen8c258ac2014-10-20 19:33:55 -070052import java.util.ArrayList;
53import java.util.List;
54
Chiao Cheng91197042012-08-24 14:19:37 -070055/**
56 * Helper class to listen for some magic character sequences
57 * that are handled specially by the dialer.
58 *
59 * Note the Phone app also handles these sequences too (in a couple of
Jake Hamby1d6fb572013-04-09 15:49:56 -070060 * relatively obscure places in the UI), so there's a separate version of
Chiao Cheng91197042012-08-24 14:19:37 -070061 * this class under apps/Phone.
62 *
63 * TODO: there's lots of duplicated code between this class and the
64 * corresponding class under apps/Phone. Let's figure out a way to
65 * unify these two classes (in the framework? in a common shared library?)
66 */
67public class SpecialCharSequenceMgr {
68 private static final String TAG = "SpecialCharSequenceMgr";
Jake Hamby1d6fb572013-04-09 15:49:56 -070069
Jay Shrauner384eaad2015-04-03 16:03:41 -070070 private static final String TAG_SELECT_ACCT_FRAGMENT = "tag_select_acct_fragment";
71
Yorke Leef90dada2013-12-09 11:50:28 -080072 private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
Chiao Cheng91197042012-08-24 14:19:37 -070073 private static final String MMI_IMEI_DISPLAY = "*#06#";
Jake Hamby1d6fb572013-04-09 15:49:56 -070074 private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#";
Chiao Cheng91197042012-08-24 14:19:37 -070075
76 /**
77 * Remembers the previous {@link QueryHandler} and cancel the operation when needed, to
78 * prevent possible crash.
79 *
80 * QueryHandler may call {@link ProgressDialog#dismiss()} when the screen is already gone,
81 * which will cause the app crash. This variable enables the class to prevent the crash
82 * on {@link #cleanup()}.
83 *
84 * TODO: Remove this and replace it (and {@link #cleanup()}) with better implementation.
Jake Hamby1d6fb572013-04-09 15:49:56 -070085 * One complication is that we have SpecialCharSequenceMgr in Phone package too, which has
Chiao Cheng91197042012-08-24 14:19:37 -070086 * *slightly* different implementation. Note that Phone package doesn't have this problem,
87 * so the class on Phone side doesn't have this functionality.
88 * Fundamental fix would be to have one shared implementation and resolve this corner case more
89 * gracefully.
90 */
91 private static QueryHandler sPreviousAdnQueryHandler;
92
93 /** This class is never instantiated. */
94 private SpecialCharSequenceMgr() {
95 }
96
97 public static boolean handleChars(Context context, String input, EditText textField) {
Chiao Cheng91197042012-08-24 14:19:37 -070098 //get rid of the separators so that the string gets parsed correctly
99 String dialString = PhoneNumberUtils.stripSeparators(input);
100
Nancy Chen8c258ac2014-10-20 19:33:55 -0700101 if (handleDeviceIdDisplay(context, dialString)
Jake Hamby1d6fb572013-04-09 15:49:56 -0700102 || handleRegulatoryInfoDisplay(context, dialString)
Chiao Cheng91197042012-08-24 14:19:37 -0700103 || handlePinEntry(context, dialString)
104 || handleAdnEntry(context, dialString, textField)
105 || handleSecretCode(context, dialString)) {
106 return true;
107 }
108
109 return false;
110 }
111
112 /**
113 * Cleanup everything around this class. Must be run inside the main thread.
114 *
115 * This should be called when the screen becomes background.
116 */
117 public static void cleanup() {
118 if (Looper.myLooper() != Looper.getMainLooper()) {
119 Log.wtf(TAG, "cleanup() is called outside the main thread");
120 return;
121 }
122
123 if (sPreviousAdnQueryHandler != null) {
124 sPreviousAdnQueryHandler.cancel();
125 sPreviousAdnQueryHandler = null;
126 }
127 }
128
129 /**
130 * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
131 * If a secret code is encountered an Intent is started with the android_secret_code://<code>
132 * URI.
133 *
134 * @param context the context to use
135 * @param input the text to check for a secret code in
136 * @return true if a secret code was encountered
137 */
138 static boolean handleSecretCode(Context context, String input) {
139 // Secret codes are in the form *#*#<code>#*#*
140 int len = input.length();
141 if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
Yorke Leef90dada2013-12-09 11:50:28 -0800142 final Intent intent = new Intent(SECRET_CODE_ACTION,
Chiao Cheng91197042012-08-24 14:19:37 -0700143 Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
144 context.sendBroadcast(intent);
145 return true;
146 }
147
148 return false;
149 }
150
151 /**
152 * Handle ADN requests by filling in the SIM contact number into the requested
153 * EditText.
154 *
155 * This code works alongside the Asynchronous query handler {@link QueryHandler}
156 * and query cancel handler implemented in {@link SimContactQueryCookie}.
157 */
Nancy Chen18c52ff2014-10-30 10:25:00 -0700158 static boolean handleAdnEntry(final Context context, String input, EditText textField) {
Chiao Cheng91197042012-08-24 14:19:37 -0700159 /* ADN entries are of the form "N(N)(N)#" */
160
161 TelephonyManager telephonyManager =
162 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
163 if (telephonyManager == null
Yorke Lee62280c72013-11-22 18:24:59 -0800164 || telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) {
Chiao Cheng91197042012-08-24 14:19:37 -0700165 return false;
166 }
167
168 // if the phone is keyguard-restricted, then just ignore this
169 // input. We want to make sure that sim card contacts are NOT
170 // exposed unless the phone is unlocked, and this code can be
171 // accessed from the emergency dialer.
172 KeyguardManager keyguardManager =
173 (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
174 if (keyguardManager.inKeyguardRestrictedInputMode()) {
175 return false;
176 }
177
178 int len = input.length();
179 if ((len > 1) && (len < 5) && (input.endsWith("#"))) {
180 try {
181 // get the ordinal number of the sim contact
Nancy Chen18c52ff2014-10-30 10:25:00 -0700182 final int index = Integer.parseInt(input.substring(0, len-1));
Chiao Cheng91197042012-08-24 14:19:37 -0700183
184 // The original code that navigated to a SIM Contacts list view did not
185 // highlight the requested contact correctly, a requirement for PTCRB
186 // certification. This behaviour is consistent with the UI paradigm
187 // for touch-enabled lists, so it does not make sense to try to work
188 // around it. Instead we fill in the the requested phone number into
189 // the dialer text field.
190
191 // create the async query handler
Nancy Chen18c52ff2014-10-30 10:25:00 -0700192 final QueryHandler handler = new QueryHandler (context.getContentResolver());
Chiao Cheng91197042012-08-24 14:19:37 -0700193
194 // create the cookie object
Nancy Chen18c52ff2014-10-30 10:25:00 -0700195 final SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler,
Chiao Cheng91197042012-08-24 14:19:37 -0700196 ADN_QUERY_TOKEN);
197
198 // setup the cookie fields
199 sc.contactNum = index - 1;
200 sc.setTextField(textField);
201
202 // create the progress dialog
203 sc.progressDialog = new ProgressDialog(context);
204 sc.progressDialog.setTitle(R.string.simContacts_title);
205 sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading));
206 sc.progressDialog.setIndeterminate(true);
207 sc.progressDialog.setCancelable(true);
208 sc.progressDialog.setOnCancelListener(sc);
209 sc.progressDialog.getWindow().addFlags(
210 WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
211
Nancy Chen18c52ff2014-10-30 10:25:00 -0700212 final TelecomManager telecomManager =
213 (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Nancy Chen39c18f22014-12-03 16:37:45 -0800214 List<PhoneAccountHandle> subscriptionAccountHandles =
Nancy Chen18c52ff2014-10-30 10:25:00 -0700215 PhoneAccountUtils.getSubscriptionPhoneAccounts(context);
Chiao Cheng91197042012-08-24 14:19:37 -0700216
Nancy Chen39c18f22014-12-03 16:37:45 -0800217 boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
Yorke Lee3af7e562015-04-15 11:05:54 -0700218 telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL));
Chiao Cheng91197042012-08-24 14:19:37 -0700219
Nancy Chen39c18f22014-12-03 16:37:45 -0800220 if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
Nancy Chen18c52ff2014-10-30 10:25:00 -0700221 Uri uri = telecomManager.getAdnUriForPhoneAccount(null);
222 handleAdnQuery(handler, sc, uri);
Nancy Chen39c18f22014-12-03 16:37:45 -0800223 } else if (subscriptionAccountHandles.size() > 1){
Nancy Chen18c52ff2014-10-30 10:25:00 -0700224 SelectPhoneAccountListener listener = new SelectPhoneAccountListener() {
225 @Override
226 public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle,
227 boolean setDefault) {
228 Uri uri =
229 telecomManager.getAdnUriForPhoneAccount(selectedAccountHandle);
230 handleAdnQuery(handler, sc, uri);
231 //TODO: show error dialog if result isn't valid
232 }
233 @Override
234 public void onDialogDismissed() {}
235 };
236
Jay Shrauner384eaad2015-04-03 16:03:41 -0700237 // NOTE: If you want to support rotation of this dialog need
238 // to refactor the listener and set it in DialpadFragment.onCreate()
239 DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(
240 subscriptionAccountHandles, listener);
241 dialogFragment.show(((Activity) context).getFragmentManager(),
242 TAG_SELECT_ACCT_FRAGMENT);
Nancy Chen18c52ff2014-10-30 10:25:00 -0700243 } else {
244 return false;
Chiao Cheng91197042012-08-24 14:19:37 -0700245 }
Nancy Chen18c52ff2014-10-30 10:25:00 -0700246
Chiao Cheng91197042012-08-24 14:19:37 -0700247 return true;
248 } catch (NumberFormatException ex) {
249 // Ignore
250 }
251 }
252 return false;
253 }
254
Nancy Chen18c52ff2014-10-30 10:25:00 -0700255 private static void handleAdnQuery(QueryHandler handler, SimContactQueryCookie cookie,
256 Uri uri) {
257 if (handler == null || cookie == null || uri == null) {
258 Log.w(TAG, "queryAdn parameters incorrect");
259 return;
260 }
261
262 // display the progress dialog
263 cookie.progressDialog.show();
264
265 // run the query.
266 handler.startQuery(ADN_QUERY_TOKEN, cookie, uri, new String[]{ADN_PHONE_NUMBER_COLUMN_NAME},
267 null, null, null);
268
269 if (sPreviousAdnQueryHandler != null) {
270 // It is harmless to call cancel() even after the handler's gone.
271 sPreviousAdnQueryHandler.cancel();
272 }
273 sPreviousAdnQueryHandler = handler;
274 }
275
Yorke Lee4aece952015-05-02 22:22:54 -0700276 static boolean handlePinEntry(final Context context, final String input) {
Chiao Cheng91197042012-08-24 14:19:37 -0700277 if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) {
Nancy Chen675af1f2014-10-16 18:33:51 -0700278 final TelecomManager telecomManager =
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700279 (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Nancy Chen39c18f22014-12-03 16:37:45 -0800280 List<PhoneAccountHandle> subscriptionAccountHandles =
Nancy Chen675af1f2014-10-16 18:33:51 -0700281 PhoneAccountUtils.getSubscriptionPhoneAccounts(context);
Nancy Chen39c18f22014-12-03 16:37:45 -0800282 boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
Yorke Lee3af7e562015-04-15 11:05:54 -0700283 telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL));
Nancy Chen675af1f2014-10-16 18:33:51 -0700284
Nancy Chen39c18f22014-12-03 16:37:45 -0800285 if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
Nancy Chen675af1f2014-10-16 18:33:51 -0700286 // Don't bring up the dialog for single-SIM or if the default outgoing account is
287 // a subscription account.
Yorke Lee4aece952015-05-02 22:22:54 -0700288 return TelecomUtil.handleMmi(context, input, null);
Nancy Chen39c18f22014-12-03 16:37:45 -0800289 } else if (subscriptionAccountHandles.size() > 1){
Nancy Chen675af1f2014-10-16 18:33:51 -0700290 SelectPhoneAccountListener listener = new SelectPhoneAccountListener() {
291 @Override
292 public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle,
293 boolean setDefault) {
Yorke Lee4aece952015-05-02 22:22:54 -0700294 TelecomUtil.handleMmi(context.getApplicationContext(),
295 input, selectedAccountHandle);
Nancy Chen675af1f2014-10-16 18:33:51 -0700296 //TODO: show error dialog if result isn't valid
297 }
298 @Override
299 public void onDialogDismissed() {}
300 };
301
Jay Shrauner384eaad2015-04-03 16:03:41 -0700302 // NOTE: If you want to support rotation of this dialog need
303 // to refactor the listener and set it in DialpadFragment.onCreate()
304 DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(
305 subscriptionAccountHandles, listener);
306 dialogFragment.show(((Activity) context).getFragmentManager(),
307 TAG_SELECT_ACCT_FRAGMENT);
Nancy Chen675af1f2014-10-16 18:33:51 -0700308 }
309 return true;
310 }
311 return false;
312 }
313
Nancy Chen8c258ac2014-10-20 19:33:55 -0700314 // TODO: Use TelephonyCapabilities.getDeviceIdLabel() to get the device id label instead of a
315 // hard-coded string.
316 static boolean handleDeviceIdDisplay(Context context, String input) {
Chiao Cheng91197042012-08-24 14:19:37 -0700317 TelephonyManager telephonyManager =
318 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Chiao Cheng91197042012-08-24 14:19:37 -0700319
Nancy Chen8c258ac2014-10-20 19:33:55 -0700320 if (telephonyManager != null && input.equals(MMI_IMEI_DISPLAY)) {
321 int labelResId = (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) ?
322 R.string.imei : R.string.meid;
323
324 List<String> deviceIds = new ArrayList<String>();
325 for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {
Nancy Chen0f4ec2a2015-03-23 15:03:03 -0700326 String deviceId = telephonyManager.getDeviceId(slot);
327 if (!TextUtils.isEmpty(deviceId)) {
328 deviceIds.add(deviceId);
329 }
Nancy Chen8c258ac2014-10-20 19:33:55 -0700330 }
331
332 AlertDialog alert = new AlertDialog.Builder(context)
333 .setTitle(labelResId)
334 .setItems(deviceIds.toArray(new String[deviceIds.size()]), null)
Nancy Chen0f4ec2a2015-03-23 15:03:03 -0700335 .setPositiveButton(android.R.string.ok, null)
Nancy Chen8c258ac2014-10-20 19:33:55 -0700336 .setCancelable(false)
337 .show();
338 return true;
339 }
Chiao Cheng91197042012-08-24 14:19:37 -0700340 return false;
341 }
342
Jake Hamby1d6fb572013-04-09 15:49:56 -0700343 private static boolean handleRegulatoryInfoDisplay(Context context, String input) {
344 if (input.equals(MMI_REGULATORY_INFO_DISPLAY)) {
345 Log.d(TAG, "handleRegulatoryInfoDisplay() sending intent to settings app");
Jeff Sharkeyf4f47662014-04-16 17:21:12 -0700346 Intent showRegInfoIntent = new Intent(Settings.ACTION_SHOW_REGULATORY_INFO);
Jake Hamby1d6fb572013-04-09 15:49:56 -0700347 try {
348 context.startActivity(showRegInfoIntent);
349 } catch (ActivityNotFoundException e) {
350 Log.e(TAG, "startActivity() failed: " + e);
351 }
352 return true;
353 }
354 return false;
355 }
356
Chiao Cheng91197042012-08-24 14:19:37 -0700357 /*******
358 * This code is used to handle SIM Contact queries
359 *******/
360 private static final String ADN_PHONE_NUMBER_COLUMN_NAME = "number";
361 private static final String ADN_NAME_COLUMN_NAME = "name";
362 private static final int ADN_QUERY_TOKEN = -1;
363
364 /**
365 * Cookie object that contains everything we need to communicate to the
366 * handler's onQuery Complete, as well as what we need in order to cancel
367 * the query (if requested).
368 *
369 * Note, access to the textField field is going to be synchronized, because
370 * the user can request a cancel at any time through the UI.
371 */
372 private static class SimContactQueryCookie implements DialogInterface.OnCancelListener{
373 public ProgressDialog progressDialog;
374 public int contactNum;
375
376 // Used to identify the query request.
377 private int mToken;
378 private QueryHandler mHandler;
379
380 // The text field we're going to update
381 private EditText textField;
382
383 public SimContactQueryCookie(int number, QueryHandler handler, int token) {
384 contactNum = number;
385 mHandler = handler;
386 mToken = token;
387 }
388
389 /**
390 * Synchronized getter for the EditText.
391 */
392 public synchronized EditText getTextField() {
393 return textField;
394 }
395
396 /**
397 * Synchronized setter for the EditText.
398 */
399 public synchronized void setTextField(EditText text) {
400 textField = text;
401 }
402
403 /**
404 * Cancel the ADN query by stopping the operation and signaling
405 * the cookie that a cancel request is made.
406 */
407 public synchronized void onCancel(DialogInterface dialog) {
408 // close the progress dialog
409 if (progressDialog != null) {
410 progressDialog.dismiss();
411 }
412
413 // setting the textfield to null ensures that the UI does NOT get
414 // updated.
415 textField = null;
416
417 // Cancel the operation if possible.
418 mHandler.cancelOperation(mToken);
419 }
420 }
421
422 /**
423 * Asynchronous query handler that services requests to look up ADNs
424 *
Jake Hamby1d6fb572013-04-09 15:49:56 -0700425 * Queries originate from {@link #handleAdnEntry}.
Chiao Cheng91197042012-08-24 14:19:37 -0700426 */
Chiao Cheng07af7642012-09-14 12:05:14 -0700427 private static class QueryHandler extends NoNullCursorAsyncQueryHandler {
Chiao Cheng91197042012-08-24 14:19:37 -0700428
429 private boolean mCanceled;
430
431 public QueryHandler(ContentResolver cr) {
432 super(cr);
433 }
434
435 /**
436 * Override basic onQueryComplete to fill in the textfield when
437 * we're handed the ADN cursor.
438 */
439 @Override
Chiao Cheng07af7642012-09-14 12:05:14 -0700440 protected void onNotNullableQueryComplete(int token, Object cookie, Cursor c) {
Jay Shraunerede67ec2014-09-11 15:03:36 -0700441 try {
442 sPreviousAdnQueryHandler = null;
443 if (mCanceled) {
444 return;
445 }
Chiao Cheng91197042012-08-24 14:19:37 -0700446
Jay Shraunerede67ec2014-09-11 15:03:36 -0700447 SimContactQueryCookie sc = (SimContactQueryCookie) cookie;
Chiao Cheng91197042012-08-24 14:19:37 -0700448
Jay Shraunerede67ec2014-09-11 15:03:36 -0700449 // close the progress dialog.
450 sc.progressDialog.dismiss();
Chiao Cheng91197042012-08-24 14:19:37 -0700451
Jay Shraunerede67ec2014-09-11 15:03:36 -0700452 // get the EditText to update or see if the request was cancelled.
453 EditText text = sc.getTextField();
Chiao Cheng91197042012-08-24 14:19:37 -0700454
Nancy Chen18c52ff2014-10-30 10:25:00 -0700455 // if the TextView is valid, and the cursor is valid and positionable on the
456 // Nth number, then we update the text field and display a toast indicating the
457 // caller name.
Jay Shraunerede67ec2014-09-11 15:03:36 -0700458 if ((c != null) && (text != null) && (c.moveToPosition(sc.contactNum))) {
459 String name = c.getString(c.getColumnIndexOrThrow(ADN_NAME_COLUMN_NAME));
Nancy Chen18c52ff2014-10-30 10:25:00 -0700460 String number =
461 c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME));
Chiao Cheng91197042012-08-24 14:19:37 -0700462
Jay Shraunerede67ec2014-09-11 15:03:36 -0700463 // fill the text in.
464 text.getText().replace(0, 0, number);
Chiao Cheng91197042012-08-24 14:19:37 -0700465
Jay Shraunerede67ec2014-09-11 15:03:36 -0700466 // display the name as a toast
467 Context context = sc.progressDialog.getContext();
468 name = context.getString(R.string.menu_callNumber, name);
469 Toast.makeText(context, name, Toast.LENGTH_SHORT)
470 .show();
471 }
472 } finally {
473 MoreCloseables.closeQuietly(c);
Chiao Cheng91197042012-08-24 14:19:37 -0700474 }
475 }
476
477 public void cancel() {
478 mCanceled = true;
Nancy Chen18c52ff2014-10-30 10:25:00 -0700479 // Ask AsyncQueryHandler to cancel the whole request. This will fail when the query is
480 // already started.
Chiao Cheng91197042012-08-24 14:19:37 -0700481 cancelOperation(ADN_QUERY_TOKEN);
482 }
483 }
484}