]> matita.cs.unibo.it Git - logicplayer.git/blob - mainActivity/src/com/example/furt/myapplication/touchnodeHandler.java
The applet.
[logicplayer.git] / mainActivity / src / com / example / furt / myapplication / touchnodeHandler.java
1 package com.example.furt.myapplication;
2
3 import android.graphics.Color;
4 import android.util.TypedValue;
5 import android.view.View;
6 import android.view.ViewGroup;
7 import android.widget.Button;
8 import android.widget.RelativeLayout;
9 import android.widget.TextView;
10 import android.util.Log;
11 import android.graphics.Paint;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 public class touchnodeHandler implements View.OnClickListener {
17
18     Node n;
19     touchnodeHandler(Node node) {
20         n=node;
21     }
22     @Override
23     public void onClick(View view) {
24         TextView v=(TextView)view;
25         v.setTextColor(Color.RED);
26         if (DrawActivity.selectedNode!=null)
27             if (DrawActivity.selectedNode.view==view) {
28                 if (DrawActivity.selectedNode.Children.size()==0){
29                     List<IntroductionRule> L=new ArrayList<IntroductionRule>();
30
31                     for (IntroductionRule r: DrawActivity.selectedNode.F.introductionRules())
32                     {
33                         if (r.getPriority()!=0)
34                             L.add(r);
35                     }
36                     if (L.size()==1)
37                     {
38                         Node selectedRule=L.get(0).createNodes(new askFormula());
39                         for (Node n : selectedRule.Children) {
40                             for (Hypothesis hp : n.NodeHP)
41                                 hp.fromNode = DrawActivity.selectedNode; //le ipotesi dei nuovi figli provengono dal nodo in cui stanno per essere inserite
42                             n.addHPList(DrawActivity.selectedNode.NodeHP);
43                             n.handler = null;
44                             DrawActivity.selectedNode.addChild(n);
45                         }
46                         DrawActivity.selectedNode.hasFocus = false;
47                         DrawActivity.selectedNode.ruleName = selectedRule.Children.get(0).ruleName;
48                         DrawActivity.selectedNode.Children.get(0).hasFocus = true;
49                         DrawActivity.nmoves++;
50                         DrawActivity.rootNode.Clean();
51                         DrawActivity.startDraw();
52                     }
53                     else {
54                         RuleDialog ruleDialog = new RuleDialog(DrawActivity.selectedNode.F.introductionRules());
55                         ruleDialog.show(DrawActivity.fragmentManager, "CIAO");
56                     }
57                 }
58                 else
59                 {
60                     CopyPasteDialog copyPasteDialog=new CopyPasteDialog(DrawActivity.selectedNode);
61                     copyPasteDialog.show(DrawActivity.fragmentManager,"");
62                 }
63                 return;
64             }
65         int i,size;
66         if (DrawActivity.selectedNode!=null) {
67             if(DrawActivity.selectedNode.status==Node.OPEN || DrawActivity.selectedNode.status==Node.FAKE)
68                 DrawActivity.selectedNode.view.setTextColor(Color.BLACK);
69             else
70                 DrawActivity.selectedNode.view.setTextColor(Color.GRAY);
71         }
72         DrawActivity.selectedNode = n;
73         DrawActivity.globalHP.removeAllViews();
74         size = n.NodeHP.size();
75         int leftID=0;
76         int headID=0;
77         float sum=0;
78         final Button elim=new Button(view.getContext());
79         String newText = "Nuova";
80         elim.setText(newText);
81         elim.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
82         elim.setId(DrawActivity.globalId++);
83         RelativeLayout.LayoutParams myP2=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
84         elim.setLayoutParams(myP2);
85         elim.setOnClickListener(new View.OnClickListener() {
86             @Override
87             public void onClick(View v) {
88                 parserDialog p=new parserDialog();
89                 p.show(DrawActivity.fragmentManager, ""); //parte l'editor per inserire nuove formule
90             }
91         });
92         DrawActivity.globalHP.addView(elim);
93         Paint p = new Paint();
94         p.setTextSize(DrawActivity.textSize);
95         float newSize=p.measureText(newText)+(float)(p.measureText(newText)*0.20) + 200;
96         sum+=newSize;
97         leftID=elim.getId();
98         for (i = 0; i<size; i++) //fa apparire le ipotesi cancellate
99         {
100             final TextView newT=new TextView(view.getContext());
101             RelativeLayout.LayoutParams myP=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
102             newT.setText(n.NodeHP.get(i).HP.toString());
103             newT.setTextSize(TypedValue.COMPLEX_UNIT_SP,30);
104             newT.setId(DrawActivity.globalId++);
105             myP.setMargins(50,0,0,0);
106             sum+=n.NodeHP.get(i).HP.size();
107             if (sum>(DrawActivity.v.widthPixels/1.5)) //ho superato la larghezza dello schermo: devo andare a capo
108             {
109                 sum=n.NodeHP.get(i).HP.size();
110                 headID=leftID;
111             }
112             else
113                 myP.addRule(RelativeLayout.RIGHT_OF,leftID);
114             if (headID!=0)
115                 myP.addRule(RelativeLayout.BELOW,headID);
116             newT.setLayoutParams(myP);
117             List<EliminationRule> R=n.NodeHP.get(i).HP.EliminationRules();
118             if (R.size()!=0) {
119                 Node L= R.get(0).createNodes(null,new askFormula());
120                 newT.setOnClickListener(new touchHPHandler(L,n.NodeHP.get(i)));
121             }
122             else
123                 newT.setOnClickListener(new touchHPHandler(null,n.NodeHP.get(i)));
124             newT.setOnLongClickListener(new LongHPClick(n.NodeHP.get(i).fromNode));
125             leftID=newT.getId();
126             DrawActivity.globalHP.addView(newT);
127         }
128 /*
129         final Button elim=new Button(view.getContext());
130         RelativeLayout.LayoutParams myP=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
131         elim.setText("Nuova");
132         elim.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
133         elim.setId(DrawActivity.globalId++);
134         myP.setMargins(50,0,0,0);
135         sum+=elim.getWidth();
136         if (sum>(DrawActivity.v.widthPixels/1.5)) //ho superato la larghezza dello schermo: devo andare a capo
137         {
138             sum=n.NodeHP.get(i).HP.size();
139             headID=leftID;
140         }
141         else
142             myP.addRule(RelativeLayout.RIGHT_OF,leftID);
143         if (headID!=0)
144             myP.addRule(RelativeLayout.BELOW, headID);
145         elim.setLayoutParams(myP);
146         elim.setOnClickListener(new View.OnClickListener() {
147             @Override
148             public void onClick(View v) {
149                 parserDialog p=new parserDialog();
150                 p.show(DrawActivity.fragmentManager, ""); //parte l'editor per inserire nuove formule
151             }
152         });
153         DrawActivity.globalHP.addView(elim);
154 */
155
156     }
157 }