blob: 1d06fd4871f6f995c884268fe07ee0f5c75f44c3 [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
yuega489f512018-04-25 12:01:09 -070058 final AlertDialog.Builder builder =
59 new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
Eric Erfanianccca3152017-02-22 16:32:36 -080060 builder.setMessage(buf.toString());
61
62 builder.setPositiveButton(
63 R.string.pause_prompt_yes,
64 new DialogInterface.OnClickListener() {
65 @Override
66 public void onClick(DialogInterface dialog, int whichButton) {
linyuh183cb712017-12-27 17:02:37 -080067 TelecomAdapter.getInstance().postDialContinue(callId, true);
Eric Erfanianccca3152017-02-22 16:32:36 -080068 }
69 });
70 builder.setNegativeButton(
71 R.string.pause_prompt_no,
72 new DialogInterface.OnClickListener() {
73 @Override
74 public void onClick(DialogInterface dialog, int whichButton) {
75 dialog.cancel();
76 }
77 });
78
79 final AlertDialog dialog = builder.create();
80 return dialog;
81 }
82
83 @Override
84 public void onCancel(DialogInterface dialog) {
85 super.onCancel(dialog);
86
linyuh183cb712017-12-27 17:02:37 -080087 TelecomAdapter.getInstance().postDialContinue(callId, false);
Eric Erfanianccca3152017-02-22 16:32:36 -080088 }
89
90 @Override
91 public void onSaveInstanceState(Bundle outState) {
92 super.onSaveInstanceState(outState);
93
linyuh183cb712017-12-27 17:02:37 -080094 outState.putString(STATE_CALL_ID, callId);
95 outState.putString(STATE_POST_CHARS, postDialStr);
Eric Erfanianccca3152017-02-22 16:32:36 -080096 }
97}