1 /* 2 * Copyright (C) 2020 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.settings.network.telephony; 18 19 import android.app.Dialog; 20 import android.content.DialogInterface; 21 import android.os.Bundle; 22 import android.text.TextUtils; 23 24 import androidx.appcompat.app.AlertDialog; 25 import androidx.fragment.app.FragmentActivity; 26 27 /** Fragment to show an alert dialog which only has the positive button. */ 28 public class AlertDialogFragment extends BaseDialogFragment 29 implements DialogInterface.OnClickListener { 30 private static final String TAG = "AlertDialogFragment"; 31 32 // Arguments 33 private static final String ARG_TITLE = "title"; 34 private static final String ARG_MSG = "msg"; 35 36 /** 37 * @param activity 38 * @param title 39 * @param msg 40 */ show(FragmentActivity activity, String title, String msg)41 public static void show(FragmentActivity activity, String title, String msg) { 42 AlertDialogFragment fragment = new AlertDialogFragment(); 43 Bundle arguments = new Bundle(); 44 arguments.putString(ARG_TITLE, title); 45 arguments.putString(ARG_MSG, msg); 46 fragment.setArguments(arguments); 47 fragment.show(activity.getSupportFragmentManager(), TAG); 48 } 49 50 @Override onCreateDialog(Bundle savedInstanceState)51 public Dialog onCreateDialog(Bundle savedInstanceState) { 52 AlertDialog.Builder builder = 53 new AlertDialog.Builder(getContext()) 54 .setTitle(getArguments().getString(ARG_TITLE)) 55 .setPositiveButton(android.R.string.ok, this); 56 if (!TextUtils.isEmpty(getArguments().getString(ARG_MSG))) { 57 builder.setMessage(getArguments().getString(ARG_MSG)); 58 } 59 return builder.create(); 60 } 61 62 @Override onClick(DialogInterface dialog, int which)63 public void onClick(DialogInterface dialog, int which) { 64 if (getActivity() != null) { 65 getActivity().finish(); 66 } 67 super.dismiss(); 68 } 69 } 70