blob: d24967b06c6aa3b313d611703e8cf17eb39df51f [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
Salvador Martinez46424972016-10-28 13:28:06 -070030/**
31 * A dialog fragment that asks the user if they are sure they want to turn on data roaming
32 * to avoid accidental charges.
33 */
34public class RoamingDialogFragment extends DialogFragment implements OnClickListener {
35
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070036 public static final String SUB_ID_KEY = "sub_id_key";
37
38 private int mSubId;
39
Salvador Martinez46424972016-10-28 13:28:06 -070040 /**
41 * The interface we expect a host activity to implement.
42 */
43 public interface RoamingDialogListener {
44 void onPositiveButtonClick(DialogFragment dialog);
45 }
46
47 // the host activity which implements the listening interface
48 private RoamingDialogListener mListener;
49
Salvador Martinez46424972016-10-28 13:28:06 -070050 @Override
51 public void onAttach(Context context) {
52 super.onAttach(context);
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070053 Bundle args = getArguments();
54 mSubId = args.getInt(SUB_ID_KEY);
55
Salvador Martinez46424972016-10-28 13:28:06 -070056 // Verify host activity implemented callback interface
pkanward702e542017-02-08 15:44:54 -080057 FragmentManager fragmentManager = getFragmentManager();
58 Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
Salvador Martinez46424972016-10-28 13:28:06 -070059 try {
pkanward702e542017-02-08 15:44:54 -080060 mListener = (RoamingDialogListener) fragment;
Salvador Martinez46424972016-10-28 13:28:06 -070061 } catch (ClassCastException e) {
pkanward702e542017-02-08 15:44:54 -080062 throw new ClassCastException(fragment.toString() +
Salvador Martinez46424972016-10-28 13:28:06 -070063 "must implement RoamingDialogListener");
64 }
65 }
66
67 @Override
68 public Dialog onCreateDialog(Bundle savedInstanceState) {
69 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
pkanwar7d69db02018-01-01 17:03:42 -080070 int title = R.string.roaming_alert_title;
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070071 PersistableBundle carrierConfig =
72 PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
73 if (carrierConfig != null && carrierConfig.getBoolean(
74 CarrierConfigManager.KEY_CHECK_PRICING_WITH_CARRIER_FOR_DATA_ROAMING_BOOL)) {
75 title = R.string.roaming_check_price_warning;
pkanwar7d69db02018-01-01 17:03:42 -080076 }
Salvador Martinez46424972016-10-28 13:28:06 -070077 builder.setMessage(getResources().getString(R.string.roaming_warning))
pkanwar7d69db02018-01-01 17:03:42 -080078 .setTitle(title)
Salvador Martinez46424972016-10-28 13:28:06 -070079 .setIconAttribute(android.R.attr.alertDialogIcon)
80 .setPositiveButton(android.R.string.yes, this)
81 .setNegativeButton(android.R.string.no, this);
82 return builder.create();
83 }
84
85 @Override
86 public void onClick(DialogInterface dialog, int which) {
87 // let the host know that the positive button has been clicked
88 if (which == dialog.BUTTON_POSITIVE) {
89 mListener.onPositiveButtonClick(this);
90 }
91 }
92}