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