From 85154e36e0676862a5a73d64c5670027d61006c1 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 26 Jul 2023 22:00:23 +0200 Subject: [PATCH] use new input_layout dialog --- .../foucry/pilldroid/DrugListActivity.java | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index e30689e..c2742ae 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -7,6 +7,7 @@ import android.annotation.SuppressLint; import android.app.Dialog; import android.app.NotificationManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -344,7 +345,7 @@ public class DrugListActivity extends AppCompatActivity { // final EditText editText = promptView.findViewById(R.id.edittext); // setup a dialog window - final Dialog dlg = new Dialog(this); + /*final Dialog dlg = new Dialog(this); dlg.requestWindowFeature(Window.FEATURE_NO_TITLE); dlg.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dlg.setContentView(R.layout.input_dialog); @@ -360,7 +361,7 @@ public class DrugListActivity extends AppCompatActivity { prompt.setText(R.string.enter_cip_13_here); ok.setEnabled(false); String cip13 = "34009" + editText.getText().toString(); - icon.setImageResource(R.drawable.pilldroid_icon); + //icon.setImageResource(R.drawable.pilldroid_icon); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -393,7 +394,59 @@ public class DrugListActivity extends AppCompatActivity { dlg.dismiss(); finish(); } + });*/ + final Dialog dialog = new Dialog(this); + Window window = dialog.getWindow(); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + + dialog.setCancelable(true); + dialog.setCanceledOnTouchOutside(true); + dialog.setContentView(R.layout.input_dialog); + + Button ok = (Button) dialog.findViewById(R.id.agreed); + Button cancel = (Button) dialog.findViewById(R.id.notagreed); + ok.setEnabled(false); + //TextView title = (TextView ) dialog.findViewById(R.id.title); + final EditText editText=(EditText)dialog.findViewById(R.id.editcip13); + String cip13 = String.valueOf(editText.getText()); + //title.setText(R.string.enter_cip_13); + //alert_title.setTextSize(20); + ok.setText(R.string.button_ok); + cancel.setText(R.string.button_cancel); + editText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + //alert.getButton(alert.BUTTON_POSITIVE).setEnabled(s.length() == 8); + ok.setEnabled(s.length() == 8); + } }); + ok.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + dialog.cancel(); + Log.i("EditText Value",editText.getEditableText().toString()); + MedicinesDAO medicinesDAO = medicines.getMedicinesDAO(); + Medicine aMedicine = medicinesDAO.getMedicineByCIP13(cip13); + askToAddInDB(aMedicine); + } + }); + cancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.cancel(); + Log.i(TAG, "dismiss dialog"); + } + }); + + dialog.show(); } /**