1 package com.example.furt.myapplication;
3 import android.app.AlertDialog;
4 import android.app.Dialog;
5 import android.app.DialogFragment;
6 import android.content.DialogInterface;
7 import android.os.Bundle;
8 import android.view.LayoutInflater;
9 import android.view.View;
10 import android.view.ViewGroup;
11 import android.widget.Button;
12 import android.widget.RelativeLayout;
13 import android.widget.TextView;
14 import android.widget.Toast;
16 import java.util.ArrayList;
17 import java.util.List;
19 public class parserDialog extends DialogFragment {
20 static Formula F=null; //formula che sto costruendo
21 static RelativeLayout formulaLayout;
22 static TextView FView; //View contenente la formula che sto visualizzando
23 static boolean reload=false;
24 static ArrayList<String> esliter=new ArrayList<String>();
25 static ArrayList<Formula> undo=new ArrayList<Formula>();
28 esliter.removeAll(esliter);
33 F = new UndefinedFormula();
36 esliter.addAll(parser.getLiteral(DrawActivity.nomeEs));
39 public Dialog onCreateDialog(final Bundle savedInstanceState) {
40 // Use the Builder class for convenient dialog construction
41 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
42 LayoutInflater inflater=getActivity().getLayoutInflater();
43 View view=inflater.inflate(R.layout.string_layout, null);
44 RelativeLayout litersLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(0)).getChildAt(0);
45 RelativeLayout operatorsLayout=(RelativeLayout)(((ViewGroup)view).getChildAt(1));
46 formulaLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(2)).getChildAt(0);
47 FView=new TextView(formulaLayout.getContext());
48 FView.setText(F.toString());
49 FView.setTextSize(DrawActivity.textSize);
50 formulaLayout.addView(FView);
52 if(!esliter.isEmpty()) {
53 for (String liter : esliter) {
54 Button lit = new Button(litersLayout.getContext());
55 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
58 lp.addRule(RelativeLayout.RIGHT_OF, leftId);
60 lit.setLayoutParams(lp);
61 lit.setId(DrawActivity.globalId++);
63 litersLayout.addView(lit);
64 lit.setOnClickListener(new touchParserHandler(4, liter.charAt(0)));
67 Button bImpl=new Button(operatorsLayout.getContext());
68 Button bAnd=new Button(operatorsLayout.getContext());
69 Button bOr=new Button(operatorsLayout.getContext());
70 Button bNot=new Button(operatorsLayout.getContext());
71 RelativeLayout.LayoutParams lpImpl=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
72 RelativeLayout.LayoutParams lpAnd=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
73 RelativeLayout.LayoutParams lpNot=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
74 RelativeLayout.LayoutParams lpOr=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
77 bImpl.setLayoutParams(lpImpl);
78 bImpl.setId(DrawActivity.globalId++);
82 lpOr.addRule(RelativeLayout.RIGHT_OF, leftId);
83 bOr.setLayoutParams(lpOr);
84 bOr.setId(DrawActivity.globalId++);
88 lpAnd.addRule(RelativeLayout.RIGHT_OF, leftId);
89 bAnd.setLayoutParams(lpAnd);
90 bAnd.setId(DrawActivity.globalId++);
94 lpNot.addRule(RelativeLayout.RIGHT_OF, leftId);
95 bNot.setLayoutParams(lpNot);
96 bNot.setId(DrawActivity.globalId++);
98 operatorsLayout.addView(bImpl);
99 operatorsLayout.addView(bAnd);
100 operatorsLayout.addView(bNot);
101 operatorsLayout.addView(bOr);
102 bImpl.setOnClickListener(new touchParserHandler(2,' '));
103 bAnd.setOnClickListener(new touchParserHandler(0,' '));
104 bNot.setOnClickListener(new touchParserHandler(3, ' '));
105 bOr.setOnClickListener(new touchParserHandler(1, ' '));
106 builder.setView(view);
107 builder.setTitle("Inserisci una formula").setPositiveButton("Ok", new DialogInterface.OnClickListener() {
108 public void onClick(DialogInterface dialog, int id) {
109 if(!F.toString().contains("_")) {
110 List<EliminationRule> L = F.EliminationRules();
113 Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare questa ipotesi ora",Toast.LENGTH_LONG).show();
116 if (F.toString().equals(DrawActivity.selectedNode.F.toString())) //sto provando a scaricare il nodo selezionato
118 Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare un nodo aperto senza dimostrarlo",Toast.LENGTH_LONG).show();
122 touchHPHandler t = new touchHPHandler(L.get(0).createNodes(null, new askFormula()),new Hypothesis(F,true));
128 Toast.makeText(DrawActivity.rootNode.view.getContext(),"Completa l'inserimento!",Toast.LENGTH_SHORT).show();
133 builder.setNeutralButton("Undo", new DialogInterface.OnClickListener() {
134 public void onClick(DialogInterface dialog, int id) {
136 F = undo.remove(undo.size() - 1);
143 builder.setNegativeButton("Annulla", new DialogInterface.OnClickListener() {
144 public void onClick(DialogInterface dialog, int id) {
148 // Create the AlertDialog object and return it
149 return builder.create();
154 parserDialog p=new parserDialog();
156 p.show(DrawActivity.fragmentManager, "CIAO");