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.types.MessageData;
23 import org.ocera.orte.types.ORTEConstant;
25 import android.util.Log;
28 * Class for object sent and received throw the ORTE middleware.
30 * @author jiri hubacek <jiri.hubacek@gmail.com>
34 public class BoxType extends MessageData
36 private static final byte FUZZY = 0;
37 private static final double DESTINATION_WIDTH = 389.0;
38 private static final double DESTINATION_HEIGHT = 331.0;
42 public BoxRect rectangle = new BoxRect();
44 public boolean allowScaling;
45 private double scaleWidth;
46 private double scaleHeight;
49 * Register new domain type, set default params.
53 public BoxType(DomainApp appDomain, String newTopic)
56 this.setTopic(newTopic);
58 if (!appDomain.regNewDataType("BoxType", this.getMaxDataLength())) {
59 Log.e("BoxType", "Cannot register data type 'BoxType'.");
62 this.allowScaling = true;
66 * @see org.ocera.orte.types.MessageData#read()
74 this.color = buffer.get();
77 buffer.get();buffer.get();buffer.get();
80 this.shape = buffer.get();
83 buffer.get();buffer.get();buffer.get();
85 // get rect position (with scaling)
86 if (this.allowScaling) {
87 this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
88 this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
89 this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
90 this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
92 this.rectangle.top_left_x = buffer.getShort();
93 this.rectangle.top_left_y = buffer.getShort();
94 this.rectangle.bottom_right_x = buffer.getShort();
95 this.rectangle.bottom_right_y = buffer.getShort();
98 // don't care about last fuzzy byte because of buffer.rewind()
100 //Log.d("BoxType", "receiving - color: "+this.color+", shape: "+this.shape+ ", rectangle:{"+this.rectangle.top_left_x+","+this.rectangle.top_left_y+","+this.rectangle.bottom_right_x+","+this.rectangle.bottom_right_y+",}");
104 * @see org.ocera.orte.types.MessageData#write()
112 buffer.put(this.color);
115 buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
118 buffer.put(this.shape);
121 buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
123 // put rectange position (with scaling)
124 if (this.allowScaling) {
125 buffer.putShort((short) (this.rectangle.top_left_x * this.scaleWidth));
126 buffer.putShort((short) (this.rectangle.top_left_y * this.scaleHeight));
127 buffer.putShort((short) (this.rectangle.bottom_right_x * this.scaleWidth));
128 buffer.putShort((short) (this.rectangle.bottom_right_y * this.scaleHeight));
130 buffer.putShort(this.rectangle.top_left_x);
131 buffer.putShort(this.rectangle.top_left_y);
132 buffer.putShort(this.rectangle.bottom_right_x);
133 buffer.putShort(this.rectangle.bottom_right_y);
137 buffer.put(BoxType.FUZZY);
141 * @see org.ocera.orte.types.MessageData#getMaxDataLength()
144 public int getMaxDataLength()
146 return ORTEConstant.BYTE_FIELD_SIZE + ORTEConstant.LONG_FIELD_SIZE + 4*ORTEConstant.SHORT_FIELD_SIZE;
150 * When screen rotates, change scale variables to
151 * fit the destination screen.
153 * Method of former Box class.
157 public void setScale(int currentWidth, int currentHeight)
159 this.scaleWidth = DESTINATION_WIDTH / currentWidth;
160 this.scaleHeight = DESTINATION_HEIGHT / currentHeight;
164 * Object parameters to be sent throw ORTE.
166 * Class from former Box class.
172 public short top_left_x;
173 public short top_left_y;
174 public short bottom_right_x;
175 public short bottom_right_y;