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 android.graphics.Canvas;
22 import android.graphics.drawable.ShapeDrawable;
23 import android.graphics.drawable.shapes.OvalShape;
24 import android.graphics.drawable.shapes.PathShape;
25 import android.graphics.drawable.shapes.RectShape;
26 import android.view.View;
28 import org.ocera.orte.DomainApp;
29 import org.ocera.orte.Subscription;
30 import org.ocera.orte.SubscriptionCallback;
31 import org.ocera.orte.types.MessageData;
32 import org.ocera.orte.types.NtpTime;
33 import org.ocera.orte.types.RecvInfo;
34 import org.ocera.orte.types.SubsProp;
35 import org.ocera.orte.types.ORTEConstant;
38 * Subscribing objects are made by this class.
40 * @author jiri hubacek <jiri.hubacek@gmail.com>
44 public class SubscriberElement extends SubscriptionCallback
46 private Subscription subscription;
48 private NtpTime deadline;
49 private NtpTime minSeparation;
52 private ShapeDrawable shape;
54 private View parentView;
56 private boolean receiving;
57 private boolean enabled;
60 * Set default variables of subscriber's object.
63 * @param color Topic is dependent on color.
66 public SubscriberElement(DomainApp appDomain, int color, View v) {
67 this.deadline = new NtpTime(6);
68 this.minSeparation = new NtpTime(0);
70 this.box = new BoxType(appDomain, PublisherShape.getColorName(color));
71 SubsProp subscriberProperties = new SubsProp(this.box.getTopic(),
75 ORTEConstant.IMMEDIATE,
76 ORTEConstant.BEST_EFFORTS,
79 this.subscription = appDomain.createSubscription(subscriberProperties, this.box, this);
81 this.shape = new ShapeDrawable();
82 this.shape.getPaint().setColor(PublisherShape.getColorConstant(color));
92 * What should be done when new data are received.
98 public void callback(RecvInfo info, MessageData msg)
100 switch (info.getRecvStatus()) {
101 case ORTEConstant.NEW_DATA:
102 this.receiving = true;
103 //Log.d("SubscriberElement", "new data: " + (int) ((Box) msg).strength + "(was "+ this.box.strength +"); " + ((Box) msg).rectangle.top_left_x + ", " + ((Box) msg).rectangle.top_left_y + ", " +((Box) msg).rectangle.bottom_right_x + ", " + ((Box) msg).rectangle.bottom_right_y);
105 this.shape.getBounds().left = this.box.rectangle.top_left_x;
106 this.shape.getBounds().top = this.box.rectangle.top_left_y;
107 this.shape.getBounds().right = this.box.rectangle.bottom_right_x;
108 this.shape.getBounds().bottom = this.box.rectangle.bottom_right_y;
112 this.parentView.postInvalidate();
114 case ORTEConstant.DEADLINE:
115 this.receiving = false;
116 this.parentView.postInvalidate();
122 * Draw shape, which is private object.
127 public void drawMe(Canvas canvas)
129 this.shape.draw(canvas);
133 * Set desired shape of object.
137 public void setShape()
139 switch (this.box.shape) {
141 this.shape.setShape(new RectShape());
144 this.shape.setShape(new OvalShape());
147 this.shape.setShape(new PathShape(PublisherShape.returnTrianglePath(), 2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT));
150 this.shape.setShape(new RectShape());
155 * Getter for enabled value. Should be object
161 public boolean getEnabled() { return this.enabled; }
164 * Set value enabled. Should be object
170 public void setEnabled(boolean b) { this.enabled = b; }
173 * Getter for enabled value. Should be object
179 public boolean getAllowScaling() { return this.box.allowScaling; }
182 * Set value enabled. Should be object
188 public void setAllowScaling(boolean b) { this.box.allowScaling = b; }
191 * Getter for receiving value. Should be object
197 public boolean getReceiving() { return this.receiving; }
200 * Set value receiving. Should be object
203 * @param b Receiving?
206 public void setReceiving(boolean b) { this.receiving = b; }
209 * Min. Separation value is used for desired update delay.
211 * @return NtpTime value of Min. Separation.
214 public NtpTime getMinSeparation()
216 return this.subscription.getProperties().getMinSeparation();
220 * Min. Separation value is used for desired update delay,
221 * this is setter for this value.
223 * @param newMinSeparation
226 public void setMinSeparation(NtpTime newMinSeparation)
228 SubsProp properties = this.subscription.getProperties();
229 properties.setMinSeparation(newMinSeparation);
230 this.subscription.setProperties(properties);
234 * Pass parameters to box.
236 * @param currentWidth
237 * @param currentHeight
240 public void setScale(int currentWidth, int currentHeight)
242 this.box.setScale(currentWidth, currentHeight);