1d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee/*
2d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * Copyright (C) 2013 The Android Open Source Project
3d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee *
4d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * Licensed under the Apache License, Version 2.0 (the "License");
5d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * you may not use this file except in compliance with the License.
6d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * You may obtain a copy of the License at
7d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee *
8d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee *      http://www.apache.org/licenses/LICENSE-2.0
9d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee *
10d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * Unless required by applicable law or agreed to in writing, software
11d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * distributed under the License is distributed on an "AS IS" BASIS,
12d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * See the License for the specific language governing permissions and
14d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee * limitations under the License.
15d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee */
16d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpackage com.android.server.telecom;
18d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
19d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leeimport android.app.Activity;
20d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leeimport android.app.AlertDialog;
21d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leeimport android.content.DialogInterface;
22d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leeimport android.content.Intent;
23d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leeimport android.os.Bundle;
24d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
2591d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunn// TODO: Needed for move to system service: import com.android.internal.R;
2691d43cf9c985cc5a83795f256ef5c46ebb8fbdc1Tyler Gunn
27d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee/**
287cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn * Used to display an error dialog from within the Telecom service when an outgoing call fails
29d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee */
30d7255872e2204a074bc5dfb5dceb4da13574864cYorke Leepublic class ErrorDialogActivity extends Activity {
31d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    private static final String TAG = ErrorDialogActivity.class.getSimpleName();
32d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
33d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    public static final String SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA = "show_missing_voicemail";
34d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    public static final String ERROR_MESSAGE_ID_EXTRA = "error_message_id";
35d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
36d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    /**
37d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee     * Intent action to bring up Voicemail Provider settings.
38d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee     */
39d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    public static final String ACTION_ADD_VOICEMAIL =
40d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL";
41d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
42d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    @Override
43d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    protected void onCreate(Bundle savedInstanceState) {
44d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        super.onCreate(savedInstanceState);
45d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        final boolean showVoicemailDialog = getIntent().getBooleanExtra(
46d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA, false);
47d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
48d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        if (showVoicemailDialog) {
49d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            showMissingVoicemailErrorDialog();
50d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        } else {
51d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            final int error = getIntent().getIntExtra(ERROR_MESSAGE_ID_EXTRA, -1);
52d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            if (error == -1) {
53d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                Log.w(TAG, "ErrorDialogActivity called with no error type extra.");
54d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                finish();
55d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            } else {
56d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                showGenericErrorDialog(error);
57d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            }
58d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        }
59d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    }
60d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
61d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    private void showGenericErrorDialog(int resid) {
62d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        final CharSequence msg = getResources().getText(resid);
63d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        final DialogInterface.OnClickListener clickListener;
64d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        final DialogInterface.OnCancelListener cancelListener;
65d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
66d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        clickListener = new DialogInterface.OnClickListener() {
67d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            @Override
68d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            public void onClick(DialogInterface dialog, int which) {
69d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                finish();
70d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            }
71d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        };
72d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
73d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        cancelListener = new DialogInterface.OnCancelListener() {
74d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            @Override
75d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            public void onCancel(DialogInterface dialog) {
76d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                finish();
77d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            }
78d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        };
79d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
80d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        final AlertDialog errorDialog = new AlertDialog.Builder(this)
81d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setMessage(msg).setPositiveButton(android.R.string.ok, clickListener)
82d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        .setOnCancelListener(cancelListener).create();
83d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
84d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        errorDialog.show();
85d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    }
86d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
87d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    private void showMissingVoicemailErrorDialog() {
88d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        new AlertDialog.Builder(this)
89d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setTitle(R.string.no_vm_number)
90d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setMessage(R.string.no_vm_number_msg)
91d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
92d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        @Override
93d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        public void onClick(DialogInterface dialog, int which) {
94d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                            finish();
95d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        }})
96d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setNegativeButton(R.string.add_vm_number_str,
97d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        new DialogInterface.OnClickListener() {
98d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                                @Override
99d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                                public void onClick(DialogInterface dialog, int which) {
100d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                                    addVoiceMailNumberPanel(dialog);
101d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                                }})
102d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                .setOnCancelListener(new DialogInterface.OnCancelListener() {
103d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        @Override
104d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        public void onCancel(DialogInterface dialog) {
105d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                            finish();
106d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee                        }}).show();
107d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    }
108d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
109d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
110d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    private void addVoiceMailNumberPanel(DialogInterface dialog) {
111d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        if (dialog != null) {
112d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee            dialog.dismiss();
113d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        }
114d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
115d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        // Navigate to the Voicemail setting in the Call Settings activity.
116d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        Intent intent = new Intent(ACTION_ADD_VOICEMAIL);
117d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        startActivity(intent);
118d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        finish();
119d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    }
120d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee
121d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    @Override
122d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    public void finish() {
123d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        super.finish();
124d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        // Don't show the return to previous task animation to avoid showing a black screen.
125d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        // Just dismiss the dialog and undim the previous activity immediately.
126d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee        overridePendingTransition(0, 0);
127d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee    }
128d7255872e2204a074bc5dfb5dceb4da13574864cYorke Lee}
129