1 /*
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 
17 package com.android.incallui;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.app.DialogFragment;
22 import android.content.DialogInterface;
23 import android.os.Bundle;
24 import android.view.WindowManager;
25 
26 import com.android.dialer.R;
27 
28 /**
29  * Pop up an alert dialog with OK and Cancel buttons to allow user to Accept or Reject the WAIT
30  * inserted as part of the Dial string.
31  */
32 public class PostCharDialogFragment extends DialogFragment {
33 
34     private static final String STATE_CALL_ID = "CALL_ID";
35     private static final String STATE_POST_CHARS = "POST_CHARS";
36 
37     private String mCallId;
38     private String mPostDialStr;
39 
PostCharDialogFragment()40     public PostCharDialogFragment() {
41     }
42 
PostCharDialogFragment(String callId, String postDialStr)43     public PostCharDialogFragment(String callId, String postDialStr) {
44         mCallId = callId;
45         mPostDialStr = postDialStr;
46     }
47 
48     @Override
onCreateDialog(Bundle savedInstanceState)49     public Dialog onCreateDialog(Bundle savedInstanceState) {
50         super.onCreateDialog(savedInstanceState);
51 
52         if (mPostDialStr == null && savedInstanceState != null) {
53             mCallId = savedInstanceState.getString(STATE_CALL_ID);
54             mPostDialStr = savedInstanceState.getString(STATE_POST_CHARS);
55         }
56 
57         final StringBuilder buf = new StringBuilder();
58         buf.append(getResources().getText(R.string.wait_prompt_str));
59         buf.append(mPostDialStr);
60 
61         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
62         builder.setMessage(buf.toString());
63 
64         builder.setPositiveButton(R.string.pause_prompt_yes, new DialogInterface.OnClickListener() {
65             @Override
66             public void onClick(DialogInterface dialog, int whichButton) {
67                 TelecomAdapter.getInstance().postDialContinue(mCallId, true);
68             }
69         });
70         builder.setNegativeButton(R.string.pause_prompt_no, new DialogInterface.OnClickListener() {
71             @Override
72             public void onClick(DialogInterface dialog, int whichButton) {
73                 dialog.cancel();
74             }
75         });
76 
77         final AlertDialog dialog = builder.create();
78         return dialog;
79     }
80 
81     @Override
onCancel(DialogInterface dialog)82     public void onCancel(DialogInterface dialog) {
83         super.onCancel(dialog);
84 
85         TelecomAdapter.getInstance().postDialContinue(mCallId, false);
86     }
87 
88     @Override
onSaveInstanceState(Bundle outState)89     public void onSaveInstanceState(Bundle outState) {
90         super.onSaveInstanceState(outState);
91 
92         outState.putString(STATE_CALL_ID, mCallId);
93         outState.putString(STATE_POST_CHARS, mPostDialStr);
94     }
95 }
96