Avoid potential negative array index access to cached text.
[LibreOffice.git] / android / source / src / java / org / libreoffice / PasswordDialogFragment.java
blob08bc7f596894c1160187ec291fa07c4f5fac3b89
1 package org.libreoffice;
3 import android.app.AlertDialog;
4 import android.app.Dialog;
5 import android.content.DialogInterface;
6 import android.os.Bundle;
7 import androidx.annotation.NonNull;
8 import androidx.annotation.Nullable;
9 import androidx.fragment.app.DialogFragment;
10 import android.view.LayoutInflater;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.widget.EditText;
15 public class PasswordDialogFragment extends DialogFragment {
17 private LibreOfficeMainActivity mContext;
19 @NonNull
20 @Override
21 public Dialog onCreateDialog(Bundle savedInstanceState) {
22 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
23 LayoutInflater inflater = getActivity().getLayoutInflater();
25 final View dialogView = inflater.inflate(R.layout.password_dialog, null);
27 builder.setView(dialogView)
28 .setPositiveButton(R.string.action_pwd_dialog_OK, new DialogInterface.OnClickListener() {
29 @Override
30 public void onClick(DialogInterface dialog, int which) {
31 String pwd = ((EditText)dialogView.findViewById(R.id.password)).getText().toString();
32 mContext.savePassword(pwd);
35 .setNegativeButton(R.string.action_pwd_dialog_cancel, new DialogInterface.OnClickListener() {
36 @Override
37 public void onClick(DialogInterface dialog, int which) {
38 mContext.savePassword(null);
40 }).setTitle(R.string.action_pwd_dialog_title);
42 return builder.create();
45 @Nullable
46 @Override
47 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
48 getDialog().setCanceledOnTouchOutside(false);
49 setCancelable(false);
50 return super.onCreateView(inflater, container, savedInstanceState);
53 public void setLOMainActivity(LibreOfficeMainActivity context) {
54 mContext = context;