SpecialCharSequenceMgrpublic class SpecialCharSequenceMgr extends Object Helper class to listen for some magic character sequences
that are handled specially by the dialer. |
Fields Summary |
---|
private static final String | TAG | private static final String | MMI_IMEI_DISPLAY | private static final String | ADN_PHONE_NUMBER_COLUMN_NAMEThis code is used to handle SIM Contact queries | private static final String | ADN_NAME_COLUMN_NAME | private static final int | ADN_QUERY_TOKEN |
Constructors Summary |
---|
private SpecialCharSequenceMgr()This class is never instantiated.
|
Methods Summary |
---|
static boolean | handleAdnEntry(android.content.Context context, java.lang.String input, android.widget.EditText textField)Handle ADN requests by filling in the SIM contact number into the requested
EditText.
This code works alongside the Asynchronous query handler {@link QueryHandler}
and query cancel handler implemented in {@link SimContactQueryCookie}.
/* ADN entries are of the form "N(N)(N)#" */
// if the phone is keyguard-restricted, then just ignore this
// input. We want to make sure that sim card contacts are NOT
// exposed unless the phone is unlocked, and this code can be
// accessed from the emergency dialer.
KeyguardManager keyguardManager =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager.inKeyguardRestrictedInputMode()) {
return false;
}
int len = input.length();
if ((len > 1) && (len < 5) && (input.endsWith("#"))) {
try {
// get the ordinal number of the sim contact
int index = Integer.parseInt(input.substring(0, len-1));
// The original code that navigated to a SIM Contacts list view did not
// highlight the requested contact correctly, a requirement for PTCRB
// certification. This behaviour is consistent with the UI paradigm
// for touch-enabled lists, so it does not make sense to try to work
// around it. Instead we fill in the the requested phone number into
// the dialer text field.
// create the async query handler
QueryHandler handler = new QueryHandler (context.getContentResolver());
// create the cookie object
SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler,
ADN_QUERY_TOKEN);
// setup the cookie fields
sc.contactNum = index - 1;
sc.setTextField(textField);
// create the progress dialog
sc.progressDialog = new ProgressDialog(context);
sc.progressDialog.setTitle(R.string.simContacts_title);
sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading));
sc.progressDialog.setIndeterminate(true);
sc.progressDialog.setCancelable(true);
sc.progressDialog.setOnCancelListener(sc);
sc.progressDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
// display the progress dialog
sc.progressDialog.show();
// run the query.
handler.startQuery(ADN_QUERY_TOKEN, sc, Uri.parse("content://sim/adn"),
new String[]{ADN_PHONE_NUMBER_COLUMN_NAME}, null, null, null);
return true;
} catch (NumberFormatException ex) {
// Ignore
}
}
return false;
| static boolean | handleChars(android.content.Context context, java.lang.String input, android.widget.EditText textField)
return handleChars(context, input, false, textField);
| static boolean | handleChars(android.content.Context context, java.lang.String input)
return handleChars(context, input, false, null);
| static boolean | handleChars(android.content.Context context, java.lang.String input, boolean useSystemWindow, android.widget.EditText textField)
//get rid of the separators so that the string gets parsed correctly
String dialString = PhoneNumberUtils.stripSeparators(input);
if (handleIMEIDisplay(context, dialString, useSystemWindow)
|| handlePinEntry(context, dialString)
|| handleAdnEntry(context, dialString, textField)
|| handleSecretCode(context, dialString)) {
return true;
}
return false;
| static boolean | handleIMEIDisplay(android.content.Context context, java.lang.String input, boolean useSystemWindow)
if (input.equals(MMI_IMEI_DISPLAY)) {
showIMEIPanel(context, useSystemWindow);
return true;
}
return false;
| static boolean | handlePinEntry(android.content.Context context, java.lang.String input)
if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) {
try {
return ITelephony.Stub.asInterface(ServiceManager.getService("phone"))
.handlePinMmi(input);
} catch (RemoteException e) {
Log.e(TAG, "Failed to handlePinMmi due to remote exception");
return false;
}
}
return false;
| static boolean | handleSecretCode(android.content.Context context, java.lang.String input)Handles secret codes to launch arbitrary activities in the form of *#*##*#*.
If a secret code is encountered an Intent is started with the android_secret_code://
URI.
// Secret codes are in the form *#*#<code>#*#*
int len = input.length();
if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
Intent intent = new Intent(Intents.SECRET_CODE_ACTION,
Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
context.sendBroadcast(intent);
return true;
}
return false;
| static void | showIMEIPanel(android.content.Context context, boolean useSystemWindow)
String imeiStr = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE))
.getDeviceId();
AlertDialog alert = new AlertDialog.Builder(context)
.setTitle(R.string.imei)
.setMessage(imeiStr)
.setPositiveButton(android.R.string.ok, null)
.setCancelable(false)
.show();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE);
|
|