--- /dev/null
+package com.example.furt.myapplication;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class parserDialog extends DialogFragment {
+ static Formula F=null; //formula che sto costruendo
+ static RelativeLayout formulaLayout;
+ static TextView FView; //View contenente la formula che sto visualizzando
+ static boolean reload=false;
+ static ArrayList<String> esliter=new ArrayList<String>();
+ static ArrayList<Formula> undo=new ArrayList<Formula>();
+ public parserDialog()
+ {
+ esliter.removeAll(esliter);
+ if(!reload)
+ undo.removeAll(undo);
+ reload=false;
+ if(F==null) {
+ F = new UndefinedFormula();
+ F.setCursor();
+ }
+ esliter.addAll(parser.getLiteral(DrawActivity.nomeEs));
+ }
+ @Override
+ public Dialog onCreateDialog(final Bundle savedInstanceState) {
+ // Use the Builder class for convenient dialog construction
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ LayoutInflater inflater=getActivity().getLayoutInflater();
+ View view=inflater.inflate(R.layout.string_layout, null);
+ RelativeLayout litersLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(0)).getChildAt(0);
+ RelativeLayout operatorsLayout=(RelativeLayout)(((ViewGroup)view).getChildAt(1));
+ formulaLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(2)).getChildAt(0);
+ FView=new TextView(formulaLayout.getContext());
+ FView.setText(F.toString());
+ FView.setTextSize(DrawActivity.textSize);
+ formulaLayout.addView(FView);
+ int leftId=0;
+ if(!esliter.isEmpty()) {
+ for (String liter : esliter) {
+ Button lit = new Button(litersLayout.getContext());
+ RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ lit.setText(liter);
+ if (leftId != 0) {
+ lp.addRule(RelativeLayout.RIGHT_OF, leftId);
+ }
+ lit.setLayoutParams(lp);
+ lit.setId(DrawActivity.globalId++);
+ leftId = lit.getId();
+ litersLayout.addView(lit);
+ lit.setOnClickListener(new touchParserHandler(4, liter.charAt(0)));
+ }
+ }
+ Button bImpl=new Button(operatorsLayout.getContext());
+ Button bAnd=new Button(operatorsLayout.getContext());
+ Button bOr=new Button(operatorsLayout.getContext());
+ Button bNot=new Button(operatorsLayout.getContext());
+ RelativeLayout.LayoutParams lpImpl=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ RelativeLayout.LayoutParams lpAnd=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ RelativeLayout.LayoutParams lpNot=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ RelativeLayout.LayoutParams lpOr=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+
+ bImpl.setText("⇒");
+ bImpl.setLayoutParams(lpImpl);
+ bImpl.setId(DrawActivity.globalId++);
+ leftId=bImpl.getId();
+
+ bOr.setText("∨");
+ lpOr.addRule(RelativeLayout.RIGHT_OF, leftId);
+ bOr.setLayoutParams(lpOr);
+ bOr.setId(DrawActivity.globalId++);
+ leftId=bOr.getId();
+
+ bAnd.setText("∧");
+ lpAnd.addRule(RelativeLayout.RIGHT_OF, leftId);
+ bAnd.setLayoutParams(lpAnd);
+ bAnd.setId(DrawActivity.globalId++);
+ leftId=bAnd.getId();
+
+ bNot.setText("¬");
+ lpNot.addRule(RelativeLayout.RIGHT_OF, leftId);
+ bNot.setLayoutParams(lpNot);
+ bNot.setId(DrawActivity.globalId++);
+
+ operatorsLayout.addView(bImpl);
+ operatorsLayout.addView(bAnd);
+ operatorsLayout.addView(bNot);
+ operatorsLayout.addView(bOr);
+ bImpl.setOnClickListener(new touchParserHandler(2,' '));
+ bAnd.setOnClickListener(new touchParserHandler(0,' '));
+ bNot.setOnClickListener(new touchParserHandler(3, ' '));
+ bOr.setOnClickListener(new touchParserHandler(1, ' '));
+ builder.setView(view);
+ builder.setTitle("Inserisci una formula").setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ if(!F.toString().contains("_")) {
+ List<EliminationRule> L = F.EliminationRules();
+ if (L.size()==0){
+ F=null;
+ Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare questa ipotesi ora",Toast.LENGTH_LONG).show();
+ return;
+ }
+ if (F.toString().equals(DrawActivity.selectedNode.F.toString())) //sto provando a scaricare il nodo selezionato
+ {
+ Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare un nodo aperto senza dimostrarlo",Toast.LENGTH_LONG).show();
+ F=null;
+ return;
+ }
+ touchHPHandler t = new touchHPHandler(L.get(0).createNodes(null, new askFormula()),new Hypothesis(F,true));
+ F = null;
+ t.discard=false;
+ t.onClick(null);
+ }
+ else{
+ Toast.makeText(DrawActivity.rootNode.view.getContext(),"Completa l'inserimento!",Toast.LENGTH_SHORT).show();
+ reboot();
+ }
+ }
+ });
+ builder.setNeutralButton("Undo", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ if(undo.size()>1) {
+ F = undo.remove(undo.size() - 1);
+ }
+ else
+ F=null;
+ reboot();
+ }
+ });
+ builder.setNegativeButton("Annulla", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ F=null;
+ }
+ });
+ // Create the AlertDialog object and return it
+ return builder.create();
+ }
+ static void reboot()
+ {
+ reload=true;
+ parserDialog p=new parserDialog();
+ p.F=F;
+ p.show(DrawActivity.fragmentManager, "CIAO");
+ }
+
+}