3 * This file is part of shape_android.
5 * shape_android is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * shape_android is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with shape_android. If not, see <http://www.gnu.org/licenses/>.
19 package org.ocera.orte.shape_android;
21 import org.ocera.orte.DomainApp;
22 import org.ocera.orte.Publication;
23 import org.ocera.orte.types.NtpTime;
24 import org.ocera.orte.types.PublProp;
26 import android.graphics.Color;
27 import android.graphics.Path;
28 import android.graphics.Path.FillType;
29 import android.graphics.drawable.ShapeDrawable;
30 import android.graphics.drawable.shapes.OvalShape;
31 import android.graphics.drawable.shapes.PathShape;
32 import android.graphics.drawable.shapes.RectShape;
33 import android.graphics.drawable.shapes.Shape;
36 * Some additional parameters for {@link ShapeDrawable}
37 * to make it Publisher-friendly.
39 * @author jiri hubacek <jiri.hubacek@gmail.com>
43 public class PublisherShape extends ShapeDrawable
45 // Prefer at least 48x48 shape size (Full asset), for more
46 // info, please refer to http://developer.android.com/
48 private boolean manual;
49 private int pointerId;
50 private int incX, incY;
52 private PublProp publisherProperties;
53 private NtpTime persistence;
55 public Publication publication;
59 * Set new {@link Shape}, strength and color.
61 * @param s strength, shape
66 public PublisherShape(int s, int c, DomainApp appDomain)
73 ?new PathShape(new Path(), PublisherActivity.SHAPE_WIDTH, PublisherActivity.SHAPE_HEIGHT)
79 if (s == 2) { // fix triangle
80 this.setShape(new PathShape(PublisherShape.returnTrianglePath(), 2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT));
84 this.persistence = new NtpTime(5);
86 this.box = new BoxType(appDomain, PublisherShape.getColorName(c));
87 this.publisherProperties = new PublProp(this.box.getTopic(),
91 this.publication = appDomain.createPublication(this.publisherProperties, this.box);
96 this.getPaint().setColor(PublisherShape.getColorConstant(c));
97 this.setPadding(0, 0, 0, 0);
98 this.setBounds(0, 0, PublisherActivity.SHAPE_WIDTH, PublisherActivity.SHAPE_HEIGHT);
100 //Log.d("PublisherShape", "s: "+s+", c: "+c+", left: "+this.getBounds().left+", top: "+this.getBounds().top+", right: "+this.getBounds().right+", bottom: "+this.getBounds().bottom);
104 * Update parameters of object to send.
106 * @return Object to send.
109 public BoxType toSend()
111 this.box.rectangle.top_left_x = (short) this.getBounds().left;
112 this.box.rectangle.top_left_y = (short) this.getBounds().top;
113 this.box.rectangle.bottom_right_x = (short) this.getBounds().right;
114 this.box.rectangle.bottom_right_y = (short) this.getBounds().bottom;
120 * Revert proprietary color to android color constant.
122 * @param c Proprietary value of color.
123 * @return Android color constant.
126 public static int getColorConstant(int c)
145 * Revert proprietary color to android color constant.
147 * @return Android color constant.
150 public int getColorConstant()
152 return PublisherShape.getColorConstant(this.box.color);
156 * Revert proprietary color to word.
158 * @param c Proprietary value of color.
159 * @return Name of color.
162 public static String getColorName(int c)
164 // should be done better way
165 // texts shouldn't be static
166 // but dynamically mapped to
186 * Revert proprietary color to word.
188 * @return Name of color.
191 public String getColorName()
193 return PublisherShape.getColorName(this.box.color);
197 * Revert strength to shape.
199 * @return Name of shape.
202 public String getShapeName()
204 switch (this.box.shape) {
216 /* getters, setters */
219 * Set value of incX - how much move object
220 * in x-axis direction.
225 public void setIncX(int x) { this.incX = x; }
227 * Get value of incX - how much move object
228 * in x-axis direction.
230 * @return Distance to move in x-axis.
233 public int getIncX() { return this.incX; }
236 * Set value of incY - how much move object
237 * in y-axis direction.
242 public void setIncY(int y) { this.incY = y; }
244 * Get value of incY - how much move object
245 * in y-axis direction.
247 * @return Distance to move in y-axis.
250 public int getIncY() { return this.incY; }
253 * Set strength of publishing.
258 public void setStrength(int s) {
259 PublProp properties = this.publication.getProperties();
260 properties.setStrength(s);
261 this.publication.setProperties(properties);
264 * Get strength of publishing.
266 * @return Strength of publishing.
269 public int getStrength() { return this.publication.getProperties().getStrength(); }
272 * Set if object is moved automatically or by
275 * FALSE - automatically
280 public void setManual(boolean b) { this.manual = b; }
282 * Get if object is moved automatically or by
285 * @return How is object moved.
288 public boolean getManual() { return this.manual; }
291 * Set the touch pointer ID associated with
297 public void setPointerId(int pointerId) { this.pointerId = pointerId; }
300 * Get the touch pointer ID associated with
303 * @return Pointer ID.
306 public int getPointerId() { return this.pointerId; }
309 * Make triangle path for new instance.
311 * @return Triangle path.
314 public static Path returnTrianglePath()
316 Path path = new Path();
317 path.setFillType(FillType.EVEN_ODD);
318 path.moveTo(PublisherActivity.SHAPE_WIDTH, 0); // triangle top center
319 path.lineTo(2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT); // triangle right bottom corner
320 path.lineTo(0, 2*PublisherActivity.SHAPE_HEIGHT); // triangle left bottom corner
321 path.lineTo(PublisherActivity.SHAPE_WIDTH, 0); // back to triangle top center
328 * When publisher is removed, destroy publication.
334 if (this.publication != null) {
335 this.publication.destroy();
336 this.publication = null;
341 * Pass parameters to box.
343 * @param currentWidth
344 * @param currentHeight
347 public void setScale(int currentWidth, int currentHeight)
349 this.box.setScale(currentWidth, currentHeight);
350 this.setBounds(this.box.rectangle.top_left_x, this.box.rectangle.top_left_y, this.box.rectangle.top_left_x+PublisherActivity.SHAPE_WIDTH, this.box.rectangle.top_left_y+PublisherActivity.SHAPE_HEIGHT);