1 /* 2 * Copyright (C) 2014 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.settings; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.ProgressDialog; 22 import android.view.WindowManager; 23 24 import com.android.phone.CallFeaturesSetting; 25 import com.android.phone.R; 26 27 public class VoicemailDialogUtil { 28 29 // Voicemail dialog identifiers. 30 public static final int VM_NOCHANGE_ERROR_DIALOG = 400; 31 public static final int VM_RESPONSE_ERROR_DIALOG = 500; 32 public static final int FWD_SET_RESPONSE_ERROR_DIALOG = 501; 33 public static final int FWD_GET_RESPONSE_ERROR_DIALOG = 502; 34 public static final int VM_CONFIRM_DIALOG = 600; 35 public static final int VM_FWD_SAVING_DIALOG = 601; 36 public static final int VM_FWD_READING_DIALOG = 602; 37 public static final int VM_REVERTING_DIALOG = 603; 38 getDialog(CallFeaturesSetting parent, int id)39 public static Dialog getDialog(CallFeaturesSetting parent, int id) { 40 if ((id == VM_RESPONSE_ERROR_DIALOG) || (id == VM_NOCHANGE_ERROR_DIALOG) || 41 (id == FWD_SET_RESPONSE_ERROR_DIALOG) || (id == FWD_GET_RESPONSE_ERROR_DIALOG) || 42 (id == VM_CONFIRM_DIALOG)) { 43 44 AlertDialog.Builder b = new AlertDialog.Builder(parent); 45 46 int msgId; 47 int titleId = R.string.error_updating_title; 48 switch (id) { 49 case VM_CONFIRM_DIALOG: 50 msgId = R.string.vm_changed; 51 titleId = R.string.voicemail; 52 // Set Button 2 53 b.setNegativeButton(R.string.close_dialog, parent); 54 break; 55 case VM_NOCHANGE_ERROR_DIALOG: 56 // even though this is technically an error, 57 // keep the title friendly. 58 msgId = R.string.no_change; 59 titleId = R.string.voicemail; 60 // Set Button 2 61 b.setNegativeButton(R.string.close_dialog, parent); 62 break; 63 case VM_RESPONSE_ERROR_DIALOG: 64 msgId = R.string.vm_change_failed; 65 // Set Button 1 66 b.setPositiveButton(R.string.close_dialog, parent); 67 break; 68 case FWD_SET_RESPONSE_ERROR_DIALOG: 69 msgId = R.string.fw_change_failed; 70 // Set Button 1 71 b.setPositiveButton(R.string.close_dialog, parent); 72 break; 73 case FWD_GET_RESPONSE_ERROR_DIALOG: 74 msgId = R.string.fw_get_in_vm_failed; 75 b.setPositiveButton(R.string.alert_dialog_yes, parent); 76 b.setNegativeButton(R.string.alert_dialog_no, parent); 77 break; 78 default: 79 msgId = R.string.exception_error; 80 // Set Button 3, tells the activity that the error is 81 // not recoverable on dialog exit. 82 b.setNeutralButton(R.string.close_dialog, parent); 83 break; 84 } 85 86 b.setTitle(parent.getText(titleId)); 87 String message = parent.getText(msgId).toString(); 88 b.setMessage(message); 89 b.setCancelable(false); 90 AlertDialog dialog = b.create(); 91 92 // make the dialog more obvious by bluring the background. 93 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 94 95 return dialog; 96 } else if (id == VM_FWD_SAVING_DIALOG || id == VM_FWD_READING_DIALOG || 97 id == VM_REVERTING_DIALOG) { 98 ProgressDialog dialog = new ProgressDialog(parent); 99 dialog.setTitle(parent.getText(R.string.call_settings)); 100 dialog.setIndeterminate(true); 101 dialog.setCancelable(false); 102 dialog.setMessage(parent.getText( 103 id == VM_FWD_SAVING_DIALOG ? R.string.updating_settings : 104 (id == VM_REVERTING_DIALOG ? R.string.reverting_settings : 105 R.string.reading_settings))); 106 return dialog; 107 } 108 109 return null; 110 } 111 } 112