Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
| 21 | import android.content.DialogInterface; |
| 22 | import android.content.Intent; |
| 23 | import android.os.Bundle; |
| 24 | import android.telecomm.TelecommManager; |
| 25 | |
| 26 | /** |
| 27 | * Used to display an error dialog from within the Telecomm service when an outgoing call fails |
| 28 | */ |
| 29 | public class ErrorDialogActivity extends Activity { |
| 30 | private static final String TAG = ErrorDialogActivity.class.getSimpleName(); |
| 31 | |
| 32 | public static final String SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA = "show_missing_voicemail"; |
| 33 | public static final String ERROR_MESSAGE_ID_EXTRA = "error_message_id"; |
| 34 | |
| 35 | /** |
| 36 | * Intent action to bring up Voicemail Provider settings. |
| 37 | */ |
| 38 | public static final String ACTION_ADD_VOICEMAIL = |
| 39 | "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL"; |
| 40 | |
| 41 | @Override |
| 42 | protected void onCreate(Bundle savedInstanceState) { |
| 43 | super.onCreate(savedInstanceState); |
| 44 | final boolean showVoicemailDialog = getIntent().getBooleanExtra( |
| 45 | SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA, false); |
| 46 | |
| 47 | if (showVoicemailDialog) { |
| 48 | showMissingVoicemailErrorDialog(); |
| 49 | } else { |
| 50 | final int error = getIntent().getIntExtra(ERROR_MESSAGE_ID_EXTRA, -1); |
| 51 | if (error == -1) { |
| 52 | Log.w(TAG, "ErrorDialogActivity called with no error type extra."); |
| 53 | finish(); |
| 54 | } else { |
| 55 | showGenericErrorDialog(error); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private void showGenericErrorDialog(int resid) { |
| 61 | final CharSequence msg = getResources().getText(resid); |
| 62 | final DialogInterface.OnClickListener clickListener; |
| 63 | final DialogInterface.OnCancelListener cancelListener; |
| 64 | |
| 65 | clickListener = new DialogInterface.OnClickListener() { |
| 66 | @Override |
| 67 | public void onClick(DialogInterface dialog, int which) { |
| 68 | finish(); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | cancelListener = new DialogInterface.OnCancelListener() { |
| 73 | @Override |
| 74 | public void onCancel(DialogInterface dialog) { |
| 75 | finish(); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | final AlertDialog errorDialog = new AlertDialog.Builder(this) |
| 80 | .setMessage(msg).setPositiveButton(android.R.string.ok, clickListener) |
| 81 | .setOnCancelListener(cancelListener).create(); |
| 82 | |
| 83 | errorDialog.show(); |
| 84 | } |
| 85 | |
| 86 | private void showMissingVoicemailErrorDialog() { |
| 87 | new AlertDialog.Builder(this) |
| 88 | .setTitle(R.string.no_vm_number) |
| 89 | .setMessage(R.string.no_vm_number_msg) |
| 90 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 91 | @Override |
| 92 | public void onClick(DialogInterface dialog, int which) { |
| 93 | finish(); |
| 94 | }}) |
| 95 | .setNegativeButton(R.string.add_vm_number_str, |
| 96 | new DialogInterface.OnClickListener() { |
| 97 | @Override |
| 98 | public void onClick(DialogInterface dialog, int which) { |
| 99 | addVoiceMailNumberPanel(dialog); |
| 100 | }}) |
| 101 | .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 102 | @Override |
| 103 | public void onCancel(DialogInterface dialog) { |
| 104 | finish(); |
| 105 | }}).show(); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | private void addVoiceMailNumberPanel(DialogInterface dialog) { |
| 110 | if (dialog != null) { |
| 111 | dialog.dismiss(); |
| 112 | } |
| 113 | |
| 114 | // Navigate to the Voicemail setting in the Call Settings activity. |
| 115 | Intent intent = new Intent(ACTION_ADD_VOICEMAIL); |
| 116 | startActivity(intent); |
| 117 | finish(); |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void finish() { |
| 122 | super.finish(); |
| 123 | // Don't show the return to previous task animation to avoid showing a black screen. |
| 124 | // Just dismiss the dialog and undim the previous activity immediately. |
| 125 | overridePendingTransition(0, 0); |
| 126 | } |
| 127 | } |