2323/**
2424 * Created by Ajay on 9/25/2016.
2525 */
26- public class TeleopPage extends Fragment implements View .OnClickListener {
26+ public class FieldUIPage extends Fragment implements View .OnClickListener {
2727
2828 SurfaceView surface ;
2929 Field field ;
@@ -46,22 +46,21 @@ public class TeleopPage extends Fragment implements View.OnClickListener {
4646 boolean hasVibrator ;
4747
4848 @ Override
49- public void onCreate (Bundle savedInstanceState ){
49+ public void onCreate (Bundle savedInstanceState ) {
5050 super .onCreate (savedInstanceState );
5151 }
5252
5353 @ Override
54- public View onCreateView (LayoutInflater inflator , ViewGroup container , Bundle savedInstanceState ){
54+ public View onCreateView (LayoutInflater inflator , ViewGroup container , Bundle savedInstanceState ) {
5555
56- View view = inflator .inflate (R .layout .teleoppage , container , false );
56+ View view = inflator .inflate (R .layout .field_ui_page , container , false );
5757
5858 surface = view .findViewById (R .id .fieldCanvas );
5959 Bitmap fieldRed = BitmapFactory .decodeResource (getResources (), R .drawable .fieldred );
6060 Bitmap fieldBlue = BitmapFactory .decodeResource (getResources (), R .drawable .fieldblue );
6161 field = new Field (surface , fieldRed , fieldBlue );
6262 surface .setOnTouchListener (field );
6363
64-
6564 pickupHatch = view .findViewById (R .id .pickupHatch );
6665 pickupHatch .setOnClickListener (this );
6766
@@ -89,9 +88,6 @@ public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle sa
8988 failDropCargo = view .findViewById (R .id .failDropCargo );
9089 failDropCargo .setOnClickListener (this );
9190
92-
93- view .setTag ("page2" );
94-
9591 vibrator = (Vibrator ) getContext ().getSystemService (Context .VIBRATOR_SERVICE );
9692
9793 hasVibrator = vibrator .hasVibrator ();
@@ -101,20 +97,15 @@ public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle sa
10197
10298 @ Override
10399 public void onClick (View v ) {
104-
105-
106-
107- if (v == undo ){
108-
109- if (events .size () > 0 ){
110-
111- Event event = events .get (events .size ()-1 );
100+ if (v == undo ) {
101+ if (events .size () > 0 ) {
102+ Event event = events .get (events .size () - 1 );
112103
113104 String location = "" ;
114105
115- if (field .selected != -1 ) {
106+ if (field .selected != -1 ) {
116107 location += "location " + field .selected ;
117- } else {
108+ } else {
118109 location += "the field" ;
119110 }
120111
@@ -123,7 +114,7 @@ public void onClick(View v) {
123114 .setMessage ("Are you sure you would like to undo the action that said " + getActionText (event .eventType ) + location + "?" )
124115 .setPositiveButton ("Yes" , new DialogInterface .OnClickListener () {
125116 public void onClick (DialogInterface dialog , int which ) {
126- events .remove (events .size ()- 1 );
117+ events .remove (events .size () - 1 );
127118 }
128119 })
129120 .setNegativeButton ("No" , null )
@@ -136,75 +127,70 @@ public void onClick(DialogInterface dialog, int which) {
136127 return ; //only have to undo, not add an event
137128 }
138129
139-
140130 //Vibrate the vibrator to notify scout
141- if (hasVibrator ) vibrator .vibrate (new long [] {0 , 100 , 25 , 100 }, -1 );
131+ if (hasVibrator ) vibrator .vibrate (new long []{0 , 100 , 25 , 100 }, -1 );
142132
143133 final Event event ;
144134 int eventType = -1 ;
145135
146136 String action = "" ;
147137
148138 //hatch eventTypes are from 0-3, cargo eventTypes are from 4-7
149- if (v == pickupHatch ) {
139+ if (v == pickupHatch ) {
150140 eventType = 0 ;
151- } else if (v == failPickupHatch ) {
141+ } else if (v == failPickupHatch ) {
152142 eventType = 1 ;
153- } else if (v == dropHatch ){
143+ } else if (v == dropHatch ) {
154144 eventType = 2 ;
155- } else if (v == failDropHatch ) {
145+ } else if (v == failDropHatch ) {
156146 eventType = 3 ;
157- } else if (v == pickupCargo ) {
147+ } else if (v == pickupCargo ) {
158148 eventType = 4 ;
159- } else if (v == failPickupCargo ) {
149+ } else if (v == failPickupCargo ) {
160150 eventType = 5 ;
161- } else if (v == dropCargo ) {
151+ } else if (v == dropCargo ) {
162152 eventType = 6 ;
163- } else if (v == failDropCargo ) {
153+ } else if (v == failDropCargo ) {
164154 eventType = 7 ;
165155 }
166156
167-
168-
169157 action = getActionText (eventType );
170158
171- if (field .selected != -1 ) {
159+ if (field .selected != -1 ) {
172160 action += "location " + field .selected ;
173- } else {
161+ } else {
174162 action += "the field" ;
175163 }
176164
177- if (eventType != -1 ) {
165+ if (eventType != -1 ) {
178166 final String a = action ;
179167 event = new Event (eventType , field .selected , System .currentTimeMillis (), 0 );
180168 if (hasVibrator ) {
181169 addEvent (event , action , true );
182- }
183- else {
170+ } else {
184171 addEvent (event , a , false );
185172 }
186173 }
187174 }
188175
189- private void addEvent (Event e , String action , boolean makeToast ){
176+ private void addEvent (Event e , String action , boolean makeToast ) {
190177 events .add (e );
191178
192- if (makeToast ){
193- Toast .makeText (getContext (), "Event " + action + " recorded" , Toast .LENGTH_SHORT ).show ();
179+ if (makeToast ) {
180+ Toast .makeText (getContext (), "Event " + action + " recorded" , Toast .LENGTH_SHORT ).show ();
194181 }
195182 }
196183
197-
198- public String getActionText (int eventType ){
184+ public String getActionText (int eventType ) {
199185 String item = "hatch" ;
200- if (eventType > 3 ){
186+ if (eventType > 3 ) {
201187 //this converts it to as if it was a hatch event, as they have the same
202188 // messages other than the different item
203189 eventType -= 4 ;
204190 item = "cargo" ;
205191 }
206192
207- switch (eventType ){
193+ switch (eventType ) {
208194 case 0 :
209195 return "that the robot picked up a " + item + " from " ;
210196 case 1 :
@@ -217,11 +203,11 @@ public String getActionText(int eventType){
217203 return "invalid event" ;
218204 }
219205
220- public void reset (){
206+ public void reset () {
221207 events .clear ();
222208 }
223209
224- public String [] getData (){
210+ public String [] getData () {
225211 StringBuilder labels = new StringBuilder ();
226212 StringBuilder data = new StringBuilder ();
227213
@@ -239,58 +225,58 @@ public String[] getData(){
239225
240226 String [] labelActions = {"Hatch Hit" , "Hatch Miss" , "Cargo Hit" , "Cargo Miss" };
241227
242- for (Event e : events ){
228+ for (Event e : events ) {
243229 int location = e .location ;
244230
245231 int id = 0 ;
246- switch (e .eventType ){
232+ switch (e .eventType ) {
247233 case 2 :
248234 //eventType 2: dropHatch
249- id = 0 ;
235+ id = 0 ;
250236 System .out .println ("2" );
251237 break ;
252238
253239 case 3 :
254240 //eventType 3: failDropHatch
255- id = 1 ;
241+ id = 1 ;
256242 System .out .println ("3" );
257243 break ;
258244
259245 case 6 :
260246 //eventType 6: dropCargo
261247 System .out .println ("6" );
262- id = 2 ;
248+ id = 2 ;
263249 break ;
264250
265251 case 7 :
266252 //eventType 7: failDropCargo
267253 System .out .println ("7" );
268- id = 3 ;
254+ id = 3 ;
269255 break ;
270256
271257 default :
272258 System .out .println (e .eventType );
273259 break ;
274260 }
275261
276- if (MainActivity .arrayContains (cargoShipLocations , location )){
277- cargoShip [id ] ++;
262+ if (MainActivity .arrayContains (cargoShipLocations , location )) {
263+ cargoShip [id ]++;
278264 }
279- if (MainActivity .arrayContains (levelOneRocketLocations , location )){
280- levelOneRocket [id ] ++;
281- fullRocket [id ] ++;
265+ if (MainActivity .arrayContains (levelOneRocketLocations , location )) {
266+ levelOneRocket [id ]++;
267+ fullRocket [id ]++;
282268 }
283- if (MainActivity .arrayContains (levelTwoRocketLocations , location )){
284- levelTwoRocket [id ] ++;
285- fullRocket [id ] ++;
269+ if (MainActivity .arrayContains (levelTwoRocketLocations , location )) {
270+ levelTwoRocket [id ]++;
271+ fullRocket [id ]++;
286272 }
287- if (MainActivity .arrayContains (levelThreeRocketLocations , location )){
288- levelThreeRocket [id ] ++;
289- fullRocket [id ] ++;
273+ if (MainActivity .arrayContains (levelThreeRocketLocations , location )) {
274+ levelThreeRocket [id ]++;
275+ fullRocket [id ]++;
290276 }
291277 }
292278
293- for (int i = 0 ; i < labelActions .length ; i ++){
279+ for (int i = 0 ; i < labelActions .length ; i ++) {
294280 labels .append ("Cargo ship " + labelActions [i ] + "," );
295281 data .append (cargoShip [i ] + "," );
296282 labels .append ("Level 1 rocket " + labelActions [i ] + "," );
@@ -301,10 +287,9 @@ public String[] getData(){
301287 data .append (levelThreeRocket [i ] + "," );
302288 labels .append ("Full rocket " + labelActions [i ] + "," );
303289 data .append (fullRocket [i ] + "," );
304-
305290 }
306291
307- return (new String [] {labels .toString (), data .toString ()});
292+ return (new String []{labels .toString (), data .toString ()});
308293
309294 }
310295
0 commit comments