7 package com.google.appinventor.components.runtime;
21 import android.graphics.Canvas;
22 import android.graphics.Paint;
39 @DesignerComponent(version = YaVersion.BALL_COMPONENT_VERSION,
40 description =
"<p>A round 'sprite' that can be placed on a " +
41 "<code>Canvas</code>, where it can react to touches and drags, " +
42 "interact with other sprites (<code>ImageSprite</code>s and other " +
43 "<code>Ball</code>s) and the edge of the Canvas, and move according " +
44 "to its property values.</p>" +
45 "<p>For example, to have a <code>Ball</code> move 4 pixels toward the " +
46 "top of a <code>Canvas</code> every 500 milliseconds (half second), " +
47 "you would set the <code>Speed</code> property to 4 [pixels], the " +
48 "<code>Interval</code> property to 500 [milliseconds], the " +
49 "<code>Heading</code> property to 90 [degrees], and the " +
50 "<code>Enabled</code> property to <code>True</code>.</p>" +
51 "<p>The difference between a <code>Ball</code> and an <code>ImageSprite</code> is " +
52 "that the latter can get its appearance from an image file, while a " +
53 "<code>Ball</code>'s appearance can be changed only by varying its " +
54 "<code>PaintColor</code> and <code>Radius</code> properties.</p>",
55 category = ComponentCategory.ANIMATION)
59 private int paintColor;
61 static final int DEFAULT_RADIUS = 5;
77 float correctedXLeft = (float)(
xLeft *
form.deviceDensity());
78 float correctedYTop = (float)(
yTop *
form.deviceDensity());
79 float correctedRadius = radius *
form.deviceDensity();
80 canvas.drawCircle(correctedXLeft + correctedRadius, correctedYTop +
81 correctedRadius, correctedRadius, paint);
129 @
SimpleProperty(description =
"The distance from the edge of the Ball to its center.")
131 int dr = radius - this.radius;
137 this.radius = radius;
155 description =
"The color of the Ball.",
191 description =
"Whether the x- and y-coordinates should represent the center of the Ball " +
192 "(true) or its left and top edges (false).")
194 super.OriginAtCenter(b);
203 description =
"The horizontal coordinate of the Ball, increasing as the Ball moves right. " +
204 "If the property OriginAtCenter is true, the coordinate is for the center of the Ball; " +
205 "otherwise, it is for the leftmost point of the Ball.")
217 description =
"The vertical coordinate of the Ball, increasing as the Ball moves " +
218 "down. If the property OriginAtCenter is true, the coordinate is for the center of the Ball; " +
219 "otherwise, it is for the uppermost point of the Ball.")
233 description =
"Sets the x and y coordinates of the Ball. If CenterAtOrigin is " +
234 "true, the center of the Ball will be placed here. Otherwise, the top left edge of the Ball " +
235 "will be placed at the specified coordinates.")