blob: 21c694686ed55133bd721f41d969302dc0b0a409 [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;
pkanward702e542017-02-08 15:44:54 -080021import android.app.Fragment;
22import android.app.FragmentManager;
Salvador Martinez46424972016-10-28 13:28:06 -070023import android.content.Context;
24import android.content.DialogInterface;
25import android.content.DialogInterface.OnClickListener;
26import android.os.Bundle;
27
28/**
29 * A dialog fragment that asks the user if they are sure they want to turn on data roaming
30 * to avoid accidental charges.
31 */
32public class RoamingDialogFragment extends DialogFragment implements OnClickListener {
33
34 /**
35 * The interface we expect a host activity to implement.
36 */
37 public interface RoamingDialogListener {
38 void onPositiveButtonClick(DialogFragment dialog);
39 }
40
41 // the host activity which implements the listening interface
42 private RoamingDialogListener mListener;
43
44
45 @Override
46 public void onAttach(Context context) {
47 super.onAttach(context);
48 // Verify host activity implemented callback interface
pkanward702e542017-02-08 15:44:54 -080049 FragmentManager fragmentManager = getFragmentManager();
50 Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
Salvador Martinez46424972016-10-28 13:28:06 -070051 try {
pkanward702e542017-02-08 15:44:54 -080052 mListener = (RoamingDialogListener) fragment;
Salvador Martinez46424972016-10-28 13:28:06 -070053 } catch (ClassCastException e) {
pkanward702e542017-02-08 15:44:54 -080054 throw new ClassCastException(fragment.toString() +
Salvador Martinez46424972016-10-28 13:28:06 -070055 "must implement RoamingDialogListener");
56 }
57 }
58
59 @Override
60 public Dialog onCreateDialog(Bundle savedInstanceState) {
61 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
62 builder.setMessage(getResources().getString(R.string.roaming_warning))
63 .setTitle(R.string.roaming_alert_title)
64 .setIconAttribute(android.R.attr.alertDialogIcon)
65 .setPositiveButton(android.R.string.yes, this)
66 .setNegativeButton(android.R.string.no, this);
67 return builder.create();
68 }
69
70 @Override
71 public void onClick(DialogInterface dialog, int which) {
72 // let the host know that the positive button has been clicked
73 if (which == dialog.BUTTON_POSITIVE) {
74 mListener.onPositiveButtonClick(this);
75 }
76 }
77}