Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / android / CHIPTool / app / src / main / java / com / google / chip / chiptool / commissioner / thread / internal / InputNetworkPasswordDialogFragment.java
1 /*
2  *   Copyright (c) 2020 Project CHIP Authors
3  *   All rights reserved.
4  *
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
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 package com.google.chip.chiptool.commissioner.thread.internal;
20
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;
30
31 public class InputNetworkPasswordDialogFragment extends DialogFragment
32     implements DialogInterface.OnClickListener {
33
34   private PasswordDialogListener passwordListener;
35   private EditText passwordText;
36
37   public interface PasswordDialogListener {
38     public void onPositiveClick(InputNetworkPasswordDialogFragment fragment, String password);
39
40     public void onNegativeClick(InputNetworkPasswordDialogFragment fragment);
41   }
42
43   public InputNetworkPasswordDialogFragment(PasswordDialogListener passwordListener) {
44     this.passwordListener = passwordListener;
45   }
46
47   @Override
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);
52
53     passwordText = view.findViewById(R.id.network_password);
54
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);
59
60     return builder.create();
61   }
62
63   @Override
64   public void onClick(DialogInterface dialogInterface, int which) {
65     if (which == DialogInterface.BUTTON_POSITIVE) {
66       passwordListener.onPositiveClick(this, passwordText.getText().toString());
67     } else {
68       passwordListener.onNegativeClick(this);
69     }
70   }
71 }