blob: ec2967fe140958d5b7ca2077b42375a031d61b35 [file] [log] [blame]
Salvador Martinez46424972016-10-28 13:28:06 -07001/*
2 * Copyright (C) 2016 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 */
16package com.android.phone;
17
18import android.app.AlertDialog;
19import android.app.Dialog;
20import android.app.DialogFragment;
21import android.content.Context;
22import android.content.DialogInterface;
23import android.content.DialogInterface.OnClickListener;
24import android.os.Bundle;
25
26/**
27 * A dialog fragment that asks the user if they are sure they want to turn on data roaming
28 * to avoid accidental charges.
29 */
30public class RoamingDialogFragment extends DialogFragment implements OnClickListener {
31
32 /**
33 * The interface we expect a host activity to implement.
34 */
35 public interface RoamingDialogListener {
36 void onPositiveButtonClick(DialogFragment dialog);
37 }
38
39 // the host activity which implements the listening interface
40 private RoamingDialogListener mListener;
41
42
43 @Override
44 public void onAttach(Context context) {
45 super.onAttach(context);
46 // Verify host activity implemented callback interface
47 try {
48 mListener = (RoamingDialogListener) getActivity();
49 } catch (ClassCastException e) {
50 throw new ClassCastException(getActivity().toString() +
51 "must implement RoamingDialogListener");
52 }
53 }
54
55 @Override
56 public Dialog onCreateDialog(Bundle savedInstanceState) {
57 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
58 builder.setMessage(getResources().getString(R.string.roaming_warning))
59 .setTitle(R.string.roaming_alert_title)
60 .setIconAttribute(android.R.attr.alertDialogIcon)
61 .setPositiveButton(android.R.string.yes, this)
62 .setNegativeButton(android.R.string.no, this);
63 return builder.create();
64 }
65
66 @Override
67 public void onClick(DialogInterface dialog, int which) {
68 // let the host know that the positive button has been clicked
69 if (which == dialog.BUTTON_POSITIVE) {
70 mListener.onPositiveButtonClick(this);
71 }
72 }
73}