blob: 4d3bd47d34f95e3e73301217eab72fdb0828db6b [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;
pkanwar7d69db02018-01-01 17:03:42 -080027import android.os.PersistableBundle;
28import android.telephony.CarrierConfigManager;
29
30import com.android.internal.telephony.Phone;
Salvador Martinez46424972016-10-28 13:28:06 -070031
32/**
33 * A dialog fragment that asks the user if they are sure they want to turn on data roaming
34 * to avoid accidental charges.
35 */
36public class RoamingDialogFragment extends DialogFragment implements OnClickListener {
37
38 /**
39 * The interface we expect a host activity to implement.
40 */
41 public interface RoamingDialogListener {
42 void onPositiveButtonClick(DialogFragment dialog);
43 }
44
45 // the host activity which implements the listening interface
46 private RoamingDialogListener mListener;
47
pkanwar7d69db02018-01-01 17:03:42 -080048 private Phone mPhone;
49
50 public void setPhone(Phone phone) {
51 mPhone = phone;
52 }
Salvador Martinez46424972016-10-28 13:28:06 -070053
54 @Override
55 public void onAttach(Context context) {
56 super.onAttach(context);
57 // Verify host activity implemented callback interface
pkanward702e542017-02-08 15:44:54 -080058 FragmentManager fragmentManager = getFragmentManager();
59 Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
Salvador Martinez46424972016-10-28 13:28:06 -070060 try {
pkanward702e542017-02-08 15:44:54 -080061 mListener = (RoamingDialogListener) fragment;
Salvador Martinez46424972016-10-28 13:28:06 -070062 } catch (ClassCastException e) {
pkanward702e542017-02-08 15:44:54 -080063 throw new ClassCastException(fragment.toString() +
Salvador Martinez46424972016-10-28 13:28:06 -070064 "must implement RoamingDialogListener");
65 }
66 }
67
68 @Override
69 public Dialog onCreateDialog(Bundle savedInstanceState) {
70 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
pkanwar7d69db02018-01-01 17:03:42 -080071 int title = R.string.roaming_alert_title;
72 if (mPhone != null) {
73 PersistableBundle carrierConfig =
74 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
75 if (carrierConfig != null && carrierConfig.getBoolean(
76 CarrierConfigManager.KEY_CHECK_PRICING_WITH_CARRIER_FOR_DATA_ROAMING_BOOL)) {
77 title = R.string.roaming_check_price_warning;
78 }
79 }
Salvador Martinez46424972016-10-28 13:28:06 -070080 builder.setMessage(getResources().getString(R.string.roaming_warning))
pkanwar7d69db02018-01-01 17:03:42 -080081 .setTitle(title)
Salvador Martinez46424972016-10-28 13:28:06 -070082 .setIconAttribute(android.R.attr.alertDialogIcon)
83 .setPositiveButton(android.R.string.yes, this)
84 .setNegativeButton(android.R.string.no, this);
85 return builder.create();
86 }
87
88 @Override
89 public void onClick(DialogInterface dialog, int which) {
90 // let the host know that the positive button has been clicked
91 if (which == dialog.BUTTON_POSITIVE) {
92 mListener.onPositiveButtonClick(this);
93 }
94 }
95}