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