• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.DialogInterface;
22 import android.os.Bundle;
23 import android.support.v4.app.DialogFragment;
24 import 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  */
30 public 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 
35   private String callId;
36   private String postDialStr;
37 
PostCharDialogFragment()38   public PostCharDialogFragment() {}
39 
PostCharDialogFragment(String callId, String postDialStr)40   public PostCharDialogFragment(String callId, String postDialStr) {
41     this.callId = callId;
42     this.postDialStr = postDialStr;
43   }
44 
45   @Override
onCreateDialog(Bundle savedInstanceState)46   public Dialog onCreateDialog(Bundle savedInstanceState) {
47     super.onCreateDialog(savedInstanceState);
48 
49     if (postDialStr == null && savedInstanceState != null) {
50       callId = savedInstanceState.getString(STATE_CALL_ID);
51       postDialStr = savedInstanceState.getString(STATE_POST_CHARS);
52     }
53 
54     final StringBuilder buf = new StringBuilder();
55     buf.append(getResources().getText(R.string.wait_prompt_str));
56     buf.append(postDialStr);
57 
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) {
66             TelecomAdapter.getInstance().postDialContinue(callId, true);
67           }
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
onCancel(DialogInterface dialog)83   public void onCancel(DialogInterface dialog) {
84     super.onCancel(dialog);
85 
86     TelecomAdapter.getInstance().postDialContinue(callId, false);
87   }
88 
89   @Override
onSaveInstanceState(Bundle outState)90   public void onSaveInstanceState(Bundle outState) {
91     super.onSaveInstanceState(outState);
92 
93     outState.putString(STATE_CALL_ID, callId);
94     outState.putString(STATE_POST_CHARS, postDialStr);
95   }
96 }
97