1 package com.android.settings.wifi; 2 3 import android.app.Dialog; 4 import android.content.Context; 5 import android.os.Bundle; 6 import android.view.LayoutInflater; 7 import android.view.View; 8 import android.widget.ProgressBar; 9 import android.widget.TextView; 10 11 import androidx.appcompat.app.AlertDialog; 12 13 import com.android.settings.R; 14 15 /** 16 * This is similar fragment with {@link NetworkRequestDialogFragment} but only for single SSID mode. 17 */ 18 public class NetworkRequestSingleSsidDialogFragment extends 19 NetworkRequestDialogBaseFragment { 20 public static final String EXTRA_SSID = "DIALOG_REQUEST_SSID"; 21 public static final String EXTRA_TRYAGAIN = "DIALOG_IS_TRYAGAIN"; 22 23 @Override onCreateDialog(Bundle savedInstanceState)24 public Dialog onCreateDialog(Bundle savedInstanceState) { 25 boolean isTryAgain = false; 26 String requestSsid = ""; 27 if (getArguments() != null) { 28 isTryAgain = getArguments().getBoolean(EXTRA_TRYAGAIN, true); 29 requestSsid = getArguments().getString(EXTRA_SSID, ""); 30 } 31 32 final Context context = getContext(); 33 final LayoutInflater inflater = LayoutInflater.from(context); 34 35 final View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null); 36 final TextView title = customTitle.findViewById(R.id.network_request_title_text); 37 title.setText(getTitle()); 38 final TextView summary = customTitle.findViewById(R.id.network_request_summary_text); 39 summary.setText(getSummary()); 40 final ProgressBar progressBar = customTitle 41 .findViewById(R.id.network_request_title_progress); 42 progressBar.setVisibility(View.GONE); 43 44 final AlertDialog.Builder builder = new AlertDialog.Builder(context) 45 .setCustomTitle(customTitle) 46 .setMessage(requestSsid) 47 .setPositiveButton(isTryAgain ? R.string.network_connection_timeout_dialog_ok 48 : R.string.wifi_connect, (dialog, which) -> onUserClickConnectButton()) 49 .setNeutralButton(R.string.cancel, (dialog, which) -> onCancel(dialog)); 50 51 // Don't dismiss dialog when touching outside. User reports it is easy to touch outside. 52 // This causes dialog to close. 53 setCancelable(false); 54 55 return builder.create(); 56 } 57 onUserClickConnectButton()58 private void onUserClickConnectButton() { 59 if (mActivity != null) { 60 mActivity.onClickConnectButton(); 61 } 62 } 63 } 64