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.content.SharedPreferences;
26 import android.preference.PreferenceManager;
27 import android.util.Log;
30 * Class for object sent and received throw the ORTE middleware.
32 * @author jiri hubacek <jiri.hubacek@gmail.com>
36 public class BoxType extends MessageData
38 private static final byte FUZZY = 0;
39 private static final double DESTINATION_WIDTH = 367.0; //389.0;
40 private static final double DESTINATION_HEIGHT = 261.0; //331.0;
44 public BoxRect rectangle = new BoxRect();
46 public boolean allowScaling;
47 private double scaleWidth;
48 private double scaleHeight;
51 * Register new domain type, set default params.
55 public BoxType(DomainApp appDomain, String newTopic)
58 this.setTopic(newTopic);
60 if (!appDomain.regNewDataType("BoxType", this.getMaxDataLength())) {
61 Log.e("BoxType", "Cannot register data type 'BoxType'.");
64 this.allowScaling = true;
68 * @see org.ocera.orte.types.MessageData#read()
76 this.color = buffer.get();
79 buffer.get();buffer.get();buffer.get();
82 this.shape = buffer.get();
85 buffer.get();buffer.get();buffer.get();
87 // get rect position (with scaling)
88 if (this.allowScaling) {
89 this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
90 this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
91 this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
92 this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
94 this.rectangle.top_left_x = buffer.getShort();
95 this.rectangle.top_left_y = buffer.getShort();
96 this.rectangle.bottom_right_x = buffer.getShort();
97 this.rectangle.bottom_right_y = buffer.getShort();
100 // don't care about last fuzzy byte because of buffer.rewind()
102 //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+",}");
106 * @see org.ocera.orte.types.MessageData#write()
114 buffer.put(this.color);
117 buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
120 buffer.put(this.shape);
123 buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
125 // put rectange position (with scaling)
126 if (this.allowScaling) {
127 buffer.putShort((short) (this.rectangle.top_left_x * this.scaleWidth));
128 buffer.putShort((short) (this.rectangle.top_left_y * this.scaleHeight));
129 buffer.putShort((short) (this.rectangle.bottom_right_x * this.scaleWidth));
130 buffer.putShort((short) (this.rectangle.bottom_right_y * this.scaleHeight));
132 buffer.putShort(this.rectangle.top_left_x);
133 buffer.putShort(this.rectangle.top_left_y);
134 buffer.putShort(this.rectangle.bottom_right_x);
135 buffer.putShort(this.rectangle.bottom_right_y);
139 buffer.put(BoxType.FUZZY);
143 * @see org.ocera.orte.types.MessageData#getMaxDataLength()
146 public int getMaxDataLength()
148 return ORTEConstant.BYTE_FIELD_SIZE + ORTEConstant.LONG_FIELD_SIZE + 4*ORTEConstant.SHORT_FIELD_SIZE;
152 * When screen rotates, change scale variables to
153 * fit the destination screen.
155 * Method of former Box class.
159 public void setScale(int currentWidth, int currentHeight)
161 this.scaleWidth = DESTINATION_WIDTH / currentWidth;
162 this.scaleHeight = DESTINATION_HEIGHT / currentHeight;
166 * Object parameters to be sent throw ORTE.
168 * Class from former Box class.
174 public short top_left_x;
175 public short top_left_y;
176 public short bottom_right_x;
177 public short bottom_right_y;