• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.phone;
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.util.Log;
25 
26 import com.android.phone.settings.VoicemailSettingsActivity;
27 
28 /**
29  * Used to display an error dialog from within the Telephony service when an outgoing call fails
30  */
31 public class ErrorDialogActivity extends Activity {
32     private static final String TAG = ErrorDialogActivity.class.getSimpleName();
33 
34     public static final String SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA = "show_missing_voicemail";
35     public static final String ERROR_MESSAGE_ID_EXTRA = "error_message_id";
36 
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40 
41         final boolean showVoicemailDialog = getIntent().getBooleanExtra(
42                 SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA, false);
43 
44         if (showVoicemailDialog) {
45             showMissingVoicemailErrorDialog();
46         } else {
47             final int error = getIntent().getIntExtra(ERROR_MESSAGE_ID_EXTRA, -1);
48             if (error == -1) {
49                 Log.e(TAG, "ErrorDialogActivity called with no error type extra.");
50                 finish();
51             }
52             showGenericErrorDialog(error);
53         }
54     }
55 
showGenericErrorDialog(int resid)56     private void showGenericErrorDialog(int resid) {
57         final CharSequence msg = getResources().getText(resid);
58 
59         final DialogInterface.OnClickListener clickListener;
60 
61         final DialogInterface.OnCancelListener cancelListener;
62         clickListener = new DialogInterface.OnClickListener() {
63             @Override
64             public void onClick(DialogInterface dialog, int which) {
65                 finish();
66             }
67         };
68         cancelListener = new DialogInterface.OnCancelListener() {
69             @Override
70             public void onCancel(DialogInterface dialog) {
71                 finish();
72             }
73         };
74 
75         final AlertDialog errorDialog = new AlertDialog.Builder(this)
76                 .setMessage(msg).setPositiveButton(R.string.ok, clickListener)
77                         .setOnCancelListener(cancelListener).create();
78 
79         errorDialog.show();
80     }
81 
showMissingVoicemailErrorDialog()82     private void showMissingVoicemailErrorDialog() {
83         final AlertDialog missingVoicemailDialog = new AlertDialog.Builder(this)
84         .setTitle(R.string.no_vm_number)
85         .setMessage(R.string.no_vm_number_msg)
86         .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
87                 @Override
88                 public void onClick(DialogInterface dialog, int which) {
89                     dontAddVoiceMailNumber();
90                 }})
91         .setNegativeButton(R.string.add_vm_number_str, new DialogInterface.OnClickListener() {
92                 @Override
93                 public void onClick(DialogInterface dialog, int which) {
94                     addVoiceMailNumberPanel(dialog);
95                 }})
96         .setOnCancelListener(new DialogInterface.OnCancelListener() {
97                 @Override
98                 public void onCancel(DialogInterface dialog) {
99                     dontAddVoiceMailNumber();
100                 }}).show();
101     }
102 
103 
addVoiceMailNumberPanel(DialogInterface dialog)104     private void addVoiceMailNumberPanel(DialogInterface dialog) {
105         if (dialog != null) {
106             dialog.dismiss();
107         }
108 
109         // navigate to the Voicemail setting in the Call Settings activity.
110         Intent intent = new Intent(VoicemailSettingsActivity.ACTION_ADD_VOICEMAIL);
111         intent.setClass(this, VoicemailSettingsActivity.class);
112         startActivity(intent);
113         finish();
114     }
115 
dontAddVoiceMailNumber()116     private void dontAddVoiceMailNumber() {
117         finish();
118     }
119 }
120