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.util.Log;
9 import android.view.LayoutInflater;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.widget.Button;
13 import android.widget.RelativeLayout;
14 import android.widget.TextView;
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 Button dismissButton;
24 static boolean reload=false;
25 static ArrayList<String> esliter=new ArrayList<String>();
26 static ArrayList<Formula> undo=new ArrayList<Formula>();
29 esliter.removeAll(esliter);
34 F = new UndefinedFormula();
37 esliter.addAll(parser.getLiteral(DrawActivity.nomeEs));
41 public Dialog onCreateDialog(final Bundle savedInstanceState) {
42 // Use the Builder class for convenient dialog construction
43 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
44 LayoutInflater inflater=getActivity().getLayoutInflater();
45 View view=inflater.inflate(R.layout.string_layout, null);
46 RelativeLayout litersLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(0)).getChildAt(0);
47 RelativeLayout operatorsLayout=(RelativeLayout)(((ViewGroup)view).getChildAt(1));
48 formulaLayout=(RelativeLayout)((ViewGroup)((ViewGroup)view).getChildAt(2)).getChildAt(0);
49 FView=new TextView(formulaLayout.getContext());
50 FView.setText(F.toString());
51 FView.setTextSize(DrawActivity.textSize);
52 formulaLayout.addView(FView);
54 if(!esliter.isEmpty()) {
55 for (String liter : esliter) {
56 Button lit = new Button(litersLayout.getContext());
57 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
60 lp.addRule(RelativeLayout.RIGHT_OF, leftId);
62 lit.setLayoutParams(lp);
63 lit.setId(DrawActivity.globalId++);
65 litersLayout.addView(lit);
66 lit.setOnClickListener(new touchParserHandler(4, liter.charAt(0)));
69 Button bImpl=new Button(operatorsLayout.getContext());
70 Button bAnd=new Button(operatorsLayout.getContext());
71 Button bOr=new Button(operatorsLayout.getContext());
72 Button bNot=new Button(operatorsLayout.getContext());
73 RelativeLayout.LayoutParams lpImpl=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
74 RelativeLayout.LayoutParams lpAnd=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
75 RelativeLayout.LayoutParams lpNot=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
76 RelativeLayout.LayoutParams lpOr=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
79 bImpl.setLayoutParams(lpImpl);
80 bImpl.setId(DrawActivity.globalId++);
84 lpOr.addRule(RelativeLayout.RIGHT_OF, leftId);
85 bOr.setLayoutParams(lpOr);
86 bOr.setId(DrawActivity.globalId++);
90 lpAnd.addRule(RelativeLayout.RIGHT_OF, leftId);
91 bAnd.setLayoutParams(lpAnd);
92 bAnd.setId(DrawActivity.globalId++);
96 lpNot.addRule(RelativeLayout.RIGHT_OF, leftId);
97 bNot.setLayoutParams(lpNot);
98 bNot.setId(DrawActivity.globalId++);
100 operatorsLayout.addView(bImpl);
101 operatorsLayout.addView(bAnd);
102 operatorsLayout.addView(bNot);
103 operatorsLayout.addView(bOr);
104 bImpl.setOnClickListener(new touchParserHandler(2,' '));
105 bAnd.setOnClickListener(new touchParserHandler(0,' '));
106 bNot.setOnClickListener(new touchParserHandler(3, ' '));
107 bOr.setOnClickListener(new touchParserHandler(1, ' '));
108 builder.setView(view);
109 builder.setTitle("Inserisci una formula").setPositiveButton("Ok", new DialogInterface.OnClickListener() {
110 public void onClick(DialogInterface dialog, int id) {
111 if(!F.toString().contains("_")) {
112 List<EliminationRule> L = F.EliminationRules();
115 touchHPHandler t = new touchHPHandler(L.get(0).createNodes(null, new askFormula()),new Hypothesis(F,true));
124 builder.setNeutralButton("Undo", new DialogInterface.OnClickListener() {
125 public void onClick(DialogInterface dialog, int id) {
127 F = undo.remove(undo.size() - 1);
128 /*for(int i=0;i<undo.size();i++) {
129 Log.e(String.valueOf(i), undo.get(i).toString());
137 builder.setNegativeButton("Annulla", new DialogInterface.OnClickListener() {
138 public void onClick(DialogInterface dialog, int id) {
142 // Create the AlertDialog object and return it
143 return builder.create();
148 parserDialog p=new parserDialog();
150 p.show(DrawActivity.fragmentManager, "CIAO");