1840243470b96950fa03e4036de58901f77a20e74Andrew Lee/* 2840243470b96950fa03e4036de58901f77a20e74Andrew Lee * Copyright (C) 2014 The Android Open Source Project 3840243470b96950fa03e4036de58901f77a20e74Andrew Lee * 4840243470b96950fa03e4036de58901f77a20e74Andrew Lee * Licensed under the Apache License, Version 2.0 (the "License"); 5840243470b96950fa03e4036de58901f77a20e74Andrew Lee * you may not use this file except in compliance with the License. 6840243470b96950fa03e4036de58901f77a20e74Andrew Lee * You may obtain a copy of the License at 7840243470b96950fa03e4036de58901f77a20e74Andrew Lee * 8840243470b96950fa03e4036de58901f77a20e74Andrew Lee * http://www.apache.org/licenses/LICENSE-2.0 9840243470b96950fa03e4036de58901f77a20e74Andrew Lee * 10840243470b96950fa03e4036de58901f77a20e74Andrew Lee * Unless required by applicable law or agreed to in writing, software 11840243470b96950fa03e4036de58901f77a20e74Andrew Lee * distributed under the License is distributed on an "AS IS" BASIS, 12840243470b96950fa03e4036de58901f77a20e74Andrew Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13840243470b96950fa03e4036de58901f77a20e74Andrew Lee * See the License for the specific language governing permissions and 14840243470b96950fa03e4036de58901f77a20e74Andrew Lee * limitations under the License 15840243470b96950fa03e4036de58901f77a20e74Andrew Lee */ 16840243470b96950fa03e4036de58901f77a20e74Andrew Lee 17840243470b96950fa03e4036de58901f77a20e74Andrew Leepackage com.android.phone.settings; 18840243470b96950fa03e4036de58901f77a20e74Andrew Lee 19840243470b96950fa03e4036de58901f77a20e74Andrew Leeimport android.app.AlertDialog; 20840243470b96950fa03e4036de58901f77a20e74Andrew Leeimport android.app.Dialog; 21840243470b96950fa03e4036de58901f77a20e74Andrew Leeimport android.app.ProgressDialog; 22840243470b96950fa03e4036de58901f77a20e74Andrew Leeimport android.view.WindowManager; 23840243470b96950fa03e4036de58901f77a20e74Andrew Lee 24840243470b96950fa03e4036de58901f77a20e74Andrew Leeimport com.android.phone.R; 25840243470b96950fa03e4036de58901f77a20e74Andrew Lee 26840243470b96950fa03e4036de58901f77a20e74Andrew Leepublic class VoicemailDialogUtil { 27840243470b96950fa03e4036de58901f77a20e74Andrew Lee 28840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Voicemail dialog identifiers. 29840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_NOCHANGE_ERROR_DIALOG = 400; 30840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_RESPONSE_ERROR_DIALOG = 500; 31840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int FWD_SET_RESPONSE_ERROR_DIALOG = 501; 32840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int FWD_GET_RESPONSE_ERROR_DIALOG = 502; 33840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_CONFIRM_DIALOG = 600; 34840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_FWD_SAVING_DIALOG = 601; 35840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_FWD_READING_DIALOG = 602; 36840243470b96950fa03e4036de58901f77a20e74Andrew Lee public static final int VM_REVERTING_DIALOG = 603; 373d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar public static final int TTY_SET_RESPONSE_ERROR = 800; 38840243470b96950fa03e4036de58901f77a20e74Andrew Lee 39bf07f76dd57457da159b5d5504e391afbb4a3592Andrew Lee public static Dialog getDialog(VoicemailSettingsActivity parent, int id) { 40840243470b96950fa03e4036de58901f77a20e74Andrew Lee if ((id == VM_RESPONSE_ERROR_DIALOG) || (id == VM_NOCHANGE_ERROR_DIALOG) || 41840243470b96950fa03e4036de58901f77a20e74Andrew Lee (id == FWD_SET_RESPONSE_ERROR_DIALOG) || (id == FWD_GET_RESPONSE_ERROR_DIALOG) || 423d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar (id == VM_CONFIRM_DIALOG) || (id == TTY_SET_RESPONSE_ERROR)) { 43840243470b96950fa03e4036de58901f77a20e74Andrew Lee 44840243470b96950fa03e4036de58901f77a20e74Andrew Lee AlertDialog.Builder b = new AlertDialog.Builder(parent); 45840243470b96950fa03e4036de58901f77a20e74Andrew Lee 46840243470b96950fa03e4036de58901f77a20e74Andrew Lee int msgId; 47840243470b96950fa03e4036de58901f77a20e74Andrew Lee int titleId = R.string.error_updating_title; 48840243470b96950fa03e4036de58901f77a20e74Andrew Lee switch (id) { 49840243470b96950fa03e4036de58901f77a20e74Andrew Lee case VM_CONFIRM_DIALOG: 50840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.vm_changed; 51840243470b96950fa03e4036de58901f77a20e74Andrew Lee titleId = R.string.voicemail; 52840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Set Button 2 53840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setNegativeButton(R.string.close_dialog, parent); 54840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 55840243470b96950fa03e4036de58901f77a20e74Andrew Lee case VM_NOCHANGE_ERROR_DIALOG: 56840243470b96950fa03e4036de58901f77a20e74Andrew Lee // even though this is technically an error, 57840243470b96950fa03e4036de58901f77a20e74Andrew Lee // keep the title friendly. 58840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.no_change; 59840243470b96950fa03e4036de58901f77a20e74Andrew Lee titleId = R.string.voicemail; 60840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Set Button 2 61840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setNegativeButton(R.string.close_dialog, parent); 62840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 63840243470b96950fa03e4036de58901f77a20e74Andrew Lee case VM_RESPONSE_ERROR_DIALOG: 64840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.vm_change_failed; 65840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Set Button 1 66840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setPositiveButton(R.string.close_dialog, parent); 67840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 68840243470b96950fa03e4036de58901f77a20e74Andrew Lee case FWD_SET_RESPONSE_ERROR_DIALOG: 69840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.fw_change_failed; 70840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Set Button 1 71840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setPositiveButton(R.string.close_dialog, parent); 72840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 73840243470b96950fa03e4036de58901f77a20e74Andrew Lee case FWD_GET_RESPONSE_ERROR_DIALOG: 74840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.fw_get_in_vm_failed; 75840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setPositiveButton(R.string.alert_dialog_yes, parent); 76840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setNegativeButton(R.string.alert_dialog_no, parent); 77840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 783d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar case TTY_SET_RESPONSE_ERROR: 793d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar titleId = R.string.tty_mode_option_title; 803d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar msgId = R.string.tty_mode_not_allowed_video_call; 813d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar b.setIconAttribute(android.R.attr.alertDialogIcon); 823d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar b.setPositiveButton(R.string.ok, parent); 833d8ea0e60c00436c4c3596d83fa164640f10b098Rekha Kumar break; 84840243470b96950fa03e4036de58901f77a20e74Andrew Lee default: 85840243470b96950fa03e4036de58901f77a20e74Andrew Lee msgId = R.string.exception_error; 86840243470b96950fa03e4036de58901f77a20e74Andrew Lee // Set Button 3, tells the activity that the error is 87840243470b96950fa03e4036de58901f77a20e74Andrew Lee // not recoverable on dialog exit. 88840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setNeutralButton(R.string.close_dialog, parent); 89840243470b96950fa03e4036de58901f77a20e74Andrew Lee break; 90840243470b96950fa03e4036de58901f77a20e74Andrew Lee } 91840243470b96950fa03e4036de58901f77a20e74Andrew Lee 92840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setTitle(parent.getText(titleId)); 93840243470b96950fa03e4036de58901f77a20e74Andrew Lee String message = parent.getText(msgId).toString(); 94840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setMessage(message); 95840243470b96950fa03e4036de58901f77a20e74Andrew Lee b.setCancelable(false); 96840243470b96950fa03e4036de58901f77a20e74Andrew Lee AlertDialog dialog = b.create(); 97840243470b96950fa03e4036de58901f77a20e74Andrew Lee 98840243470b96950fa03e4036de58901f77a20e74Andrew Lee // make the dialog more obvious by bluring the background. 99840243470b96950fa03e4036de58901f77a20e74Andrew Lee dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 100840243470b96950fa03e4036de58901f77a20e74Andrew Lee 101840243470b96950fa03e4036de58901f77a20e74Andrew Lee return dialog; 102840243470b96950fa03e4036de58901f77a20e74Andrew Lee } else if (id == VM_FWD_SAVING_DIALOG || id == VM_FWD_READING_DIALOG || 103840243470b96950fa03e4036de58901f77a20e74Andrew Lee id == VM_REVERTING_DIALOG) { 104840243470b96950fa03e4036de58901f77a20e74Andrew Lee ProgressDialog dialog = new ProgressDialog(parent); 105840243470b96950fa03e4036de58901f77a20e74Andrew Lee dialog.setTitle(parent.getText(R.string.call_settings)); 106840243470b96950fa03e4036de58901f77a20e74Andrew Lee dialog.setIndeterminate(true); 107840243470b96950fa03e4036de58901f77a20e74Andrew Lee dialog.setCancelable(false); 108840243470b96950fa03e4036de58901f77a20e74Andrew Lee dialog.setMessage(parent.getText( 109840243470b96950fa03e4036de58901f77a20e74Andrew Lee id == VM_FWD_SAVING_DIALOG ? R.string.updating_settings : 110840243470b96950fa03e4036de58901f77a20e74Andrew Lee (id == VM_REVERTING_DIALOG ? R.string.reverting_settings : 111840243470b96950fa03e4036de58901f77a20e74Andrew Lee R.string.reading_settings))); 112840243470b96950fa03e4036de58901f77a20e74Andrew Lee return dialog; 113840243470b96950fa03e4036de58901f77a20e74Andrew Lee } 114840243470b96950fa03e4036de58901f77a20e74Andrew Lee 115840243470b96950fa03e4036de58901f77a20e74Andrew Lee return null; 116840243470b96950fa03e4036de58901f77a20e74Andrew Lee } 117840243470b96950fa03e4036de58901f77a20e74Andrew Lee} 118