2 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 package com.google.chip.chiptool.commissioner.thread.internal;
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.widget.EditText;
28 import androidx.fragment.app.DialogFragment;
29 import com.google.chip.chiptool.R;
31 public class InputNetworkPasswordDialogFragment extends DialogFragment
32 implements DialogInterface.OnClickListener {
34 private PasswordDialogListener passwordListener;
35 private EditText passwordText;
37 public interface PasswordDialogListener {
38 public void onPositiveClick(InputNetworkPasswordDialogFragment fragment, String password);
40 public void onNegativeClick(InputNetworkPasswordDialogFragment fragment);
43 public InputNetworkPasswordDialogFragment(PasswordDialogListener passwordListener) {
44 this.passwordListener = passwordListener;
48 public Dialog onCreateDialog(Bundle savedInstanceState) {
49 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
50 LayoutInflater inflater = requireActivity().getLayoutInflater();
51 View view = inflater.inflate(R.layout.commissioner_network_password_dialog, null);
53 passwordText = view.findViewById(R.id.network_password);
55 builder.setTitle("Enter Password");
56 builder.setView(view);
57 builder.setPositiveButton(R.string.commissioner_password_connect, this);
58 builder.setNegativeButton(R.string.commissioner_password_cancel, this);
60 return builder.create();
64 public void onClick(DialogInterface dialogInterface, int which) {
65 if (which == DialogInterface.BUTTON_POSITIVE) {
66 passwordListener.onPositiveClick(this, passwordText.getText().toString());
68 passwordListener.onNegativeClick(this);