]> matita.cs.unibo.it Git - logicplayer.git/blob - mainActivity/src/com/example/furt/myapplication/touchParserHandler.java
New version (to be tested).
[logicplayer.git] / mainActivity / src / com / example / furt / myapplication / touchParserHandler.java
1 package com.example.furt.myapplication;
2
3 import android.view.View;
4 import android.widget.TextView;
5 import android.widget.Toast;
6
7 public class touchParserHandler implements View.OnClickListener
8 {
9     int type; //0=and 1=or 2=impl 3=not 4=literal
10     char l; //for literals
11     touchParserHandler(int t,char l)
12     {
13         type=t;
14         this.l=l;
15     }
16     public void onClick(View view)
17     {
18         if(!parserDialog.F.toString().contains("_"))
19         {
20             Toast.makeText(DrawActivity.rootNode.view.getContext(),"Formula completa! Premere \"Undo\" per modificare", Toast.LENGTH_SHORT).show();
21             return;
22         }
23         parserDialog.undo.add(parserDialog.F.duplicate());
24         parserDialog.formulaLayout.removeAllViews();
25         if(type==0)
26         {
27             UndefinedFormula newCursor=new UndefinedFormula();
28             newCursor.currentF=true;
29             Formula newF=new FormulaAnd(newCursor,new UndefinedFormula());
30             if ((parserDialog.F).toString().equals("_"))
31             {
32                 parserDialog.F=newF;
33             }
34             else {
35                 parserDialog.F.Fill(newF);
36                 parserDialog.F.setCursor();
37             }
38         }
39         else if(type==1)
40         {
41             UndefinedFormula newCursor=new UndefinedFormula();
42             newCursor.currentF=true;
43             Formula newF=new FormulaOr(newCursor,new UndefinedFormula());
44             if ((parserDialog.F).toString().equals("_"))
45             {
46                 parserDialog.F=newF;
47             }
48             else
49                 parserDialog.F.Fill(newF);
50         }
51         else if(type==2)
52         {
53             UndefinedFormula newCursor=new UndefinedFormula();
54             newCursor.currentF=true;
55             Formula newF=new FormulaImpl(newCursor,new UndefinedFormula());
56             if ((parserDialog.F).toString().equals("_"))
57             {
58                 parserDialog.F=newF;
59             }
60             else {
61                 parserDialog.F.Fill(newF);
62                 parserDialog.F.setCursor();
63             }
64         }
65         else if(type==3)
66         {
67             UndefinedFormula newCursor=new UndefinedFormula();
68             newCursor.currentF=true;
69             Formula newF=new FormulaNot(newCursor);
70             if ((parserDialog.F).toString().equals("_"))
71             {
72                 parserDialog.F=newF;
73             }
74             else {
75                 parserDialog.F.Fill(newF);
76                 parserDialog.F.setCursor();
77             }
78         }
79         else if(type==4)
80         {
81             Formula newF;
82             if(l=='⊥')
83                 newF=new FormulaBOT();
84             else if(l=='T')
85                 newF=new FormulaTOP();
86             else
87                 newF=new Literal(l);
88             if ((parserDialog.F).toString().equals("_"))
89             {
90                 parserDialog.F=newF;
91             }
92             else {
93                 parserDialog.F.Fill(newF);
94                 parserDialog.F.setCursor();
95             }
96         }
97         TextView FView=new TextView(parserDialog.formulaLayout.getContext());
98         FView.setText(parserDialog.F.toString());
99         FView.setTextSize(DrawActivity.textSize);
100         parserDialog.formulaLayout.addView(FView);
101     }
102 }