AI2 Component  (Version nb184)
Ev3UI.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2016 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime;
7 
17 
27 @DesignerComponent(version = YaVersion.EV3_UI_COMPONENT_VERSION,
28  description = "A component that provides a high-level interface to a LEGO MINDSTORMS EV3 " +
29  "robot, with functions to draw graphs on EV3 screen.",
30  category = ComponentCategory.LEGOMINDSTORMS,
31  nonVisible = true,
32  iconName = "images/legoMindstormsEv3.png")
33 @SimpleObject
34 @UsesPermissions(permissionNames = "android.permission.INTERNET," +
35  "android.permission.WRITE_EXTERNAL_STORAGE," +
36  "android.permission.READ_EXTERNAL_STORAGE")
37 public class Ev3UI extends LegoMindstormsEv3Base {
38 
42  public Ev3UI(ComponentContainer container) {
43  super(container, "Ev3UI");
44  }
45 
49  @SimpleFunction(description = "Draw a point on the screen.")
50  public void DrawPoint(int color, int x, int y) {
51  String functionName = "DrawPoint";
52 
53  if (color != 0 && color != 1) {
54  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
55  return;
56  }
57 
58  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
59  false,
60  0,
61  0,
62  "cccc",
64  (byte) color,
65  (short) x,
66  (short) y);
67  sendCommand(functionName, command, false);
68 
70  false,
71  0,
72  0,
73  "c",
75  sendCommand(functionName, command, false);
76  }
77 
81  @SimpleFunction(description = "Draw a built-in icon on screen.")
82  public void DrawIcon(int color, int x, int y, int type, int no) {
83  String functionName = "DrawIcon";
84 
85  if (color != 0 && color != 1) {
86  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
87  return;
88  }
89 
90  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
91  false,
92  0,
93  0,
94  "cccccc",
96  (byte) color,
97  (short) x,
98  (short) y,
99  type,
100  no);
101  sendCommand(functionName, command, false);
102 
104  false,
105  0,
106  0,
107  "c",
108  Ev3Constants.UIDrawSubcode.UPDATE);
109  sendCommand(functionName, command, false);
110  }
111 
115  @SimpleFunction(description = "Draw a line on the screen.")
116  public void DrawLine(int color, int x1, int y1, int x2, int y2) {
117  String functionName = "DrawLine";
118 
119  if (color != 0 && color != 1) {
120  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
121  return;
122  }
123 
124  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
125  false,
126  0,
127  0,
128  "cccccc",
130  (byte) color,
131  (short) x1,
132  (short) y1,
133  (short) x2,
134  (short) y2);
135  sendCommand(functionName, command, false);
136 
138  false,
139  0,
140  0,
141  "c",
142  Ev3Constants.UIDrawSubcode.UPDATE);
143  sendCommand(functionName, command, false);
144  }
145 
149  @SimpleFunction(description = "Draw a rectangle on the screen.")
150  public void DrawRect(int color, int x, int y, int width, int height, boolean fill) {
151  String functionName = "DrawRect";
152 
153  if (color != 0 && color != 1) {
154  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
155  return;
156  }
157 
158  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
159  false,
160  0,
161  0,
162  "cccccc",
163  fill ? Ev3Constants.UIDrawSubcode.FILLRECT : Ev3Constants.UIDrawSubcode.RECT,
164  (byte) color,
165  (short) x,
166  (short) y,
167  (short) width,
168  (short) height);
169  sendCommand(functionName, command, false);
170 
172  false,
173  0,
174  0,
175  "c",
176  Ev3Constants.UIDrawSubcode.UPDATE);
177  sendCommand(functionName, command, false);
178  }
179 
183  @SimpleFunction(description = "Draw a circle on the screen.")
184  public void DrawCircle(int color, int x, int y, int radius, boolean fill) {
185  String functionName = "DrawCircle";
186 
187  if (color != 0 && color != 1 || radius < 0) {
188  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
189  return;
190  }
191 
192  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
193  false,
194  0,
195  0,
196  "ccccc",
197  fill ? Ev3Constants.UIDrawSubcode.FILLCIRCLE : Ev3Constants.UIDrawSubcode.CIRCLE,
198  (byte) color,
199  (short) x,
200  (short) y,
201  (short) radius);
202  sendCommand(functionName, command, false);
203 
205  false,
206  0,
207  0,
208  "c",
209  Ev3Constants.UIDrawSubcode.UPDATE);
210  sendCommand(functionName, command, false);
211  }
212 
216  @SimpleFunction(description = "Fill the screen with a color.")
217  public void FillScreen(int color) {
218  String functionName = "FillScreen";
219 
220  if (color != 0 && color != 1) {
221  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
222  return;
223  }
224 
225  byte[] command = Ev3BinaryParser.encodeDirectCommand(Ev3Constants.Opcode.UI_DRAW,
226  false,
227  0,
228  0,
229  "cccc",
230  Ev3Constants.UIDrawSubcode.FILLWINDOW,
231  (byte) color,
232  (short) 0,
233  (short) 0);
234  sendCommand(functionName, command, false);
235 
237  false,
238  0,
239  0,
240  "c",
241  Ev3Constants.UIDrawSubcode.UPDATE);
242  sendCommand(functionName, command, false);
243  }
244 }
com.google.appinventor.components.annotations.SimpleFunction
Definition: SimpleFunction.java:23
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.runtime.util.Ev3Constants.UIDrawSubcode
Definition: Ev3Constants.java:376
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components
com.google.appinventor.components.runtime.util.Ev3BinaryParser
Definition: Ev3BinaryParser.java:21
com.google.appinventor.components.runtime.util.Ev3Constants.Opcode
Definition: Ev3Constants.java:15
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.runtime.util.Ev3BinaryParser.encodeDirectCommand
static byte[] encodeDirectCommand(byte opcode, boolean needReply, int globalAllocation, int localAllocation, String paramFormat, Object... parameters)
Definition: Ev3BinaryParser.java:506
com.google.appinventor.components.annotations.UsesPermissions
Definition: UsesPermissions.java:21
com.google.appinventor.components.runtime.Ev3UI.Ev3UI
Ev3UI(ComponentContainer container)
Definition: Ev3UI.java:42
com.google.appinventor.components.runtime.Ev3UI
Definition: Ev3UI.java:37
com.google.appinventor.components.runtime.LegoMindstormsEv3Base
Definition: LegoMindstormsEv3Base.java:24
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google
com
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT
static final int ERROR_EV3_ILLEGAL_ARGUMENT
Definition: ErrorMessages.java:216
com.google.appinventor.components.runtime.util.Ev3Constants
Definition: Ev3Constants.java:14
com.google.appinventor.components.annotations
com.google.appinventor