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.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 double DESTINATION_WIDTH = 367.0; //389.0;
37 private static final double DESTINATION_HEIGHT = 261.0; //331.0;
41 public BoxRect rectangle = new BoxRect();
43 public boolean allowScaling;
44 private double scaleWidth;
45 private double scaleHeight;
48 * Register new domain type, set default params.
52 public BoxType(DomainApp appDomain, String newTopic)
55 this.setTopic(newTopic);
57 if (!appDomain.regNewDataType("BoxType", this.getMaxDataLength())) {
58 Log.e("BoxType", "Cannot register data type 'BoxType'.");
61 this.allowScaling = true;
62 this.buffer.order(null); // set buffer to Little endian (Shape uses this)
66 * @see org.ocera.orte.types.MessageData#read()
74 this.color = buffer.getInt();
77 this.shape = buffer.getInt();
79 // get rect position (with scaling)
80 if (this.allowScaling) {
81 this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
82 this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
83 this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
84 this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
86 this.rectangle.top_left_x = buffer.getShort();
87 this.rectangle.top_left_y = buffer.getShort();
88 this.rectangle.bottom_right_x = buffer.getShort();
89 this.rectangle.bottom_right_y = buffer.getShort();
92 //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+",}");
96 * @see org.ocera.orte.types.MessageData#write()
104 buffer.putInt(this.color);
107 buffer.putInt(this.shape);
109 // put rectange position (with scaling)
110 if (this.allowScaling) {
111 buffer.putShort((short) (this.rectangle.top_left_x * this.scaleWidth));
112 buffer.putShort((short) (this.rectangle.top_left_y * this.scaleHeight));
113 buffer.putShort((short) (this.rectangle.bottom_right_x * this.scaleWidth));
114 buffer.putShort((short) (this.rectangle.bottom_right_y * this.scaleHeight));
116 buffer.putShort(this.rectangle.top_left_x);
117 buffer.putShort(this.rectangle.top_left_y);
118 buffer.putShort(this.rectangle.bottom_right_x);
119 buffer.putShort(this.rectangle.bottom_right_y);
124 * @see org.ocera.orte.types.MessageData#getMaxDataLength()
127 public int getMaxDataLength()
129 return 2*ORTEConstant.INT_FIELD_SIZE + 4*ORTEConstant.SHORT_FIELD_SIZE;
133 * When screen rotates, change scale variables to
134 * fit the destination screen.
136 * Method of former Box class.
140 public void setScale(int currentWidth, int currentHeight)
142 this.scaleWidth = DESTINATION_WIDTH / currentWidth;
143 this.scaleHeight = DESTINATION_HEIGHT / currentHeight;
147 * Object parameters to be sent throw ORTE.
149 * Class from former Box class.
155 public short top_left_x;
156 public short top_left_y;
157 public short bottom_right_x;
158 public short bottom_right_y;