blob: 4bcc68e33228013f90e06c4965f054275e42b268 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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
17package com.android.incallui;
18
19import android.app.AlertDialog;
20import android.app.Dialog;
21import android.content.DialogInterface;
22import android.os.Bundle;
23import android.support.v4.app.DialogFragment;
24import com.android.incallui.call.TelecomAdapter;
25
26/**
27 * Pop up an alert dialog with OK and Cancel buttons to allow user to Accept or Reject the WAIT
28 * inserted as part of the Dial string.
29 */
30public class PostCharDialogFragment extends DialogFragment {
31
32 private static final String STATE_CALL_ID = "CALL_ID";
33 private static final String STATE_POST_CHARS = "POST_CHARS";
34
linyuh183cb712017-12-27 17:02:37 -080035 private String callId;
36 private String postDialStr;
Eric Erfanianccca3152017-02-22 16:32:36 -080037
38 public PostCharDialogFragment() {}
39
40 public PostCharDialogFragment(String callId, String postDialStr) {
linyuh183cb712017-12-27 17:02:37 -080041 this.callId = callId;
42 this.postDialStr = postDialStr;
Eric Erfanianccca3152017-02-22 16:32:36 -080043 }
44
45 @Override
46 public Dialog onCreateDialog(Bundle savedInstanceState) {
47 super.onCreateDialog(savedInstanceState);
48
linyuh183cb712017-12-27 17:02:37 -080049 if (postDialStr == null && savedInstanceState != null) {
50 callId = savedInstanceState.getString(STATE_CALL_ID);
51 postDialStr = savedInstanceState.getString(STATE_POST_CHARS);
Eric Erfanianccca3152017-02-22 16:32:36 -080052 }
53
54 final StringBuilder buf = new StringBuilder();
55 buf.append(getResources().getText(R.string.wait_prompt_str));
linyuh183cb712017-12-27 17:02:37 -080056 buf.append(postDialStr);
Eric Erfanianccca3152017-02-22 16:32:36 -080057
58 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
59 builder.setMessage(buf.toString());
60
61 builder.setPositiveButton(
62 R.string.pause_prompt_yes,
63 new DialogInterface.OnClickListener() {
64 @Override
65 public void onClick(DialogInterface dialog, int whichButton) {
linyuh183cb712017-12-27 17:02:37 -080066 TelecomAdapter.getInstance().postDialContinue(callId, true);
Eric Erfanianccca3152017-02-22 16:32:36 -080067 }
68 });
69 builder.setNegativeButton(
70 R.string.pause_prompt_no,
71 new DialogInterface.OnClickListener() {
72 @Override
73 public void onClick(DialogInterface dialog, int whichButton) {
74 dialog.cancel();
75 }
76 });
77
78 final AlertDialog dialog = builder.create();
79 return dialog;
80 }
81
82 @Override
83 public void onCancel(DialogInterface dialog) {
84 super.onCancel(dialog);
85
linyuh183cb712017-12-27 17:02:37 -080086 TelecomAdapter.getInstance().postDialContinue(callId, false);
Eric Erfanianccca3152017-02-22 16:32:36 -080087 }
88
89 @Override
90 public void onSaveInstanceState(Bundle outState) {
91 super.onSaveInstanceState(outState);
92
linyuh183cb712017-12-27 17:02:37 -080093 outState.putString(STATE_CALL_ID, callId);
94 outState.putString(STATE_POST_CHARS, postDialStr);
Eric Erfanianccca3152017-02-22 16:32:36 -080095 }
96}