3 * This file is part of shape4a.
5 * shape4a 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 * shape4a 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 shape4a. If not, see <http://www.gnu.org/licenses/>.
19 package org.ocera.orte.shape4a;
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 static final int SHAPE_WIDTH = 48;
49 private static final int SHAPE_HEIGHT = 48;
50 private boolean manual;
51 private int incX, incY;
53 private PublProp publisherProperties;
54 private NtpTime persistence;
56 public Publication publication;
60 * Set new {@link Shape}, strength and color.
62 * @param s strength, shape
67 public PublisherShape(int s, int c, DomainApp appDomain)
74 ?new PathShape(new Path(), 96, 96)
80 if (s == 2) { // fix triangle
81 this.setShape(new PathShape(PublisherShape.returnTrianglePath(), 96, 96));
85 this.persistence = new NtpTime(5);
87 this.box = new Box(appDomain, PublisherShape.getColorName(c));
88 this.publisherProperties = new PublProp(this.box.getTopic(),
92 this.publication = appDomain.createPublication(this.publisherProperties, this.box);
94 this.box.strength = s;
97 this.getPaint().setColor(PublisherShape.getColorConstant(c));
98 this.setPadding(0, 0, 0, 0);
99 this.setBounds(0, 0, SHAPE_WIDTH, SHAPE_HEIGHT);
101 //Log.d("PublisherShape", "s: "+s+", c: "+c+", left: "+this.getBounds().left+", top: "+this.getBounds().top+", right: "+this.getBounds().right+", bottom: "+this.getBounds().bottom);
105 * Update parameters of object to send.
107 * @return Object to send.
112 this.box.rectangle.top_left_x = (short) this.getBounds().left;
113 this.box.rectangle.top_left_y = (short) this.getBounds().top;
114 this.box.rectangle.bottom_right_x = (short) this.getBounds().right;
115 this.box.rectangle.bottom_right_y = (short) this.getBounds().bottom;
121 * Revert proprietary color to android color constant.
123 * @param c Proprietary value of color.
124 * @return Android color constant.
127 public static int getColorConstant(int c)
146 * Revert proprietary color to android color constant.
148 * @return Android color constant.
151 public int getColorConstant()
153 return PublisherShape.getColorConstant(this.box.color);
157 * Revert proprietary color to word.
159 * @param c Proprietary value of color.
160 * @return Name of color.
163 public static String getColorName(int c)
165 // should be done better way
166 // texts shouldn't be static
167 // but dynamically mapped to
187 * Revert proprietary color to word.
189 * @return Name of color.
192 public String getColorName()
194 return PublisherShape.getColorName(this.box.color);
198 * Revert strength to shape.
200 * @return Name of shape.
203 public String getShapeName()
205 switch (this.box.strength) {
217 /* getters, setters */
220 * Set value of incX - how much move object
221 * in x-axis direction.
226 public void setIncX(int x) { this.incX = x; }
228 * Get value of incX - how much move object
229 * in x-axis direction.
231 * @return Distance to move in x-axis.
234 public int getIncX() { return this.incX; }
237 * Set value of incY - how much move object
238 * in y-axis direction.
243 public void setIncY(int y) { this.incY = y; }
245 * Get value of incY - how much move object
246 * in y-axis direction.
248 * @return Distance to move in y-axis.
251 public int getIncY() { return this.incY; }
254 * Set strength of publishing.
259 public void setStrength(int s) {
260 PublProp properties = this.publication.getProperties();
261 properties.setStrength(s);
262 this.publication.setProperties(properties);
265 * Get strength of publishing.
267 * @return Strength of publishing.
270 public int getStrength() { return this.publication.getProperties().getStrength(); }
273 * Set if object is moved automatically or by
276 * FALSE - automatically
281 public void setManual(boolean b) { this.manual = b; }
283 * Get if object is moved automatically or by
286 * @return How is object moved.
289 public boolean getManual() { return this.manual; }
292 * Make triangle path for new instance.
294 * @return Triangle path.
297 public static Path returnTrianglePath()
299 Path path = new Path();
300 path.setFillType(FillType.EVEN_ODD);
311 * When publisher is removed, destroy publication.
317 this.publication.destroy();
321 * Pass parameters to box.
323 * @param currentWidth
324 * @param currentHeight
327 public void setScale(int currentWidth, int currentHeight)
329 this.box.setScale(currentWidth, currentHeight);