]> rtime.felk.cvut.cz Git - orte.git/commitdiff
Make 'shape4a' compatible with 'shape'.
authorjiri hubacek <jiri.hubacek@gmail.com>
Sat, 27 Sep 2014 19:26:33 +0000 (22:26 +0300)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 9 Feb 2015 16:56:15 +0000 (17:56 +0100)
orte/contrib/shape_android/AndroidManifest.xml
orte/contrib/shape_android/src/org/ocera/orte/shape4a/Box.java [deleted file]
orte/contrib/shape_android/src/org/ocera/orte/shape4a/BoxType.java [new file with mode: 0644]
orte/contrib/shape_android/src/org/ocera/orte/shape4a/PublisherShape.java
orte/contrib/shape_android/src/org/ocera/orte/shape4a/SubscriberElement.java

index e872068ba62b8f25c11cc7d8c039c8cb053d99f3..6b0fcf3868fb172034f64b851c40ec0b3d2aaff7 100644 (file)
@@ -2,7 +2,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.ocera.orte.shape4a"
     android:versionCode="1"
-    android:versionName="1.0" >
+    android:versionName="1.1" >
 
     <uses-sdk
         android:minSdkVersion="8"
diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape4a/Box.java b/orte/contrib/shape_android/src/org/ocera/orte/shape4a/Box.java
deleted file mode 100644 (file)
index f20eab0..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * 
- *     This file is part of shape4a.
- *
- *  shape4a is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  shape4a is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with shape4a.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.ocera.orte.shape4a;
-
-import org.ocera.orte.*;
-import org.ocera.orte.types.*;
-
-import android.util.Log;
-
-/**
- * Object to be send throw ORTE.
- * 
- * @author jiri hubacek <jiri.hubacek@gmail.com>
- * @version %I%, %G%
- * @since 1.0
- */
-public class Box extends MessageData
-{
-       private static final double DESTINATION_WIDTH = 389.0;
-       private static final double DESTINATION_HEIGHT = 256.0;
-       
-       public boolean allowScaling;
-       public int color;
-       // is more shape than strength,
-       // strength is solved throw
-       // publisherProperties or
-       // throw subscriberProperties...
-       public int strength;
-       public BoxRect rectangle;
-       
-       private double scaleWidth;
-       private double scaleHeight;
-       
-       /**
-        * Add topic of new object.
-        * 
-        * @param appDomain
-        * @param newTopic
-        * @since 1.0
-        */
-       public Box(DomainApp appDomain, String newTopic) {
-               super();
-               this.setTopic(newTopic);
-               
-               if (!appDomain.regNewDataType("Box", this.getMaxDataLength())) {
-                       Log.e("Box", "Cannot register data type 'Box'.");
-               }
-               
-               this.rectangle = new BoxRect();
-               this.allowScaling = true;
-               this.scaleWidth = 1;
-               this.scaleHeight = 1;
-       }
-
-       /**
-        * Read data from buffer.
-        * @since 1.0
-        */
-       @Override
-       public void read() {
-               buffer.rewind();
-               if (this.allowScaling) {
-                       this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
-                       this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
-                       this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
-                       this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
-               } else {
-                       this.rectangle.top_left_x = buffer.getShort();
-                       this.rectangle.top_left_y = buffer.getShort();
-                       this.rectangle.bottom_right_x = buffer.getShort();
-                       this.rectangle.bottom_right_y = buffer.getShort();
-               }
-               
-               this.strength = (int) buffer.getShort();
-       }
-
-       /**
-        * Write data to buffer.
-        * @since 1.0
-        */
-       @Override
-       public void write() {
-               buffer.rewind();
-               if (this.allowScaling) {
-                       buffer.putShort((short) (rectangle.top_left_x * this.scaleWidth));
-                       buffer.putShort((short) (rectangle.top_left_y * this.scaleHeight));
-                       buffer.putShort((short) (rectangle.bottom_right_x * this.scaleWidth));
-                       buffer.putShort((short) (rectangle.bottom_right_y * this.scaleHeight));
-               } else {
-                       buffer.putShort(rectangle.top_left_x);
-                       buffer.putShort(rectangle.top_left_y);
-                       buffer.putShort(rectangle.bottom_right_x);
-                       buffer.putShort(rectangle.bottom_right_y);
-               }
-               
-               buffer.putShort((short) this.strength);
-       }
-
-       /**
-        * Get maximum length of data.
-        * @since 1.0
-        */
-       @Override
-       public int getMaxDataLength() {
-               return 5 * ORTEConstant.SHORT_FIELD_SIZE;
-       }
-       
-       /**
-        * Object to be truly send throw ORTE.
-        * 
-        * @since 1.0
-        */
-       public class BoxRect
-       {
-               public short top_left_x;
-               public short top_left_y;
-               public short bottom_right_x;
-               public short bottom_right_y;
-               
-               public BoxRect()
-               {}
-       }
-       
-       /**
-        * When screen rotates, change scale variables to
-        * fit the destination screen.
-        * 
-        * @since 1.0
-        */
-       public void setScale(int currentWidth, int currentHeight)
-       {
-               this.scaleWidth = DESTINATION_WIDTH / currentWidth;
-               this.scaleHeight = DESTINATION_HEIGHT / currentHeight;
-       }
-}
diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape4a/BoxType.java b/orte/contrib/shape_android/src/org/ocera/orte/shape4a/BoxType.java
new file mode 100644 (file)
index 0000000..c8482a5
--- /dev/null
@@ -0,0 +1,180 @@
+/**
+ * 
+ *     This file is part of shape4a.
+ *
+ *  shape4a is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  shape4a is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with shape4a.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.ocera.orte.shape4a;
+
+import org.ocera.orte.DomainApp;
+import org.ocera.orte.types.MessageData;
+import org.ocera.orte.types.ORTEConstant;
+
+import android.util.Log;
+
+/**
+ * Class for object sent and received throw the ORTE middleware.
+ * 
+ * @author jiri hubacek <jiri.hubacek@gmail.com>
+ * @version %I, %G
+ * @since 1.1
+ */
+public class BoxType extends MessageData
+{
+       private static final byte FUZZY = 0;
+       private static final double DESTINATION_WIDTH = 389.0;
+       private static final double DESTINATION_HEIGHT = 331.0;
+       
+       public byte color;
+       public byte shape;
+       public BoxRect rectangle = new BoxRect();
+       
+       public boolean allowScaling;
+       private double scaleWidth;
+       private double scaleHeight;
+       
+       /**
+        * Register new domain type, set default params.
+        * 
+        * @since 1.1
+        */
+       public BoxType(DomainApp appDomain, String newTopic)
+       {
+               super();
+               this.setTopic(newTopic);
+               
+               if (!appDomain.regNewDataType("BoxType", this.getMaxDataLength())) {
+                       Log.e("BoxType", "Cannot register data type 'BoxType'.");
+               }
+               
+               this.allowScaling = true;
+       }
+
+       /* (non-Javadoc)
+        * @see org.ocera.orte.types.MessageData#read()
+        */
+       @Override
+       public void read() 
+       {
+               buffer.rewind();
+               
+               // get color
+               this.color = buffer.get();
+               
+               // skip fuzzy bytes
+               buffer.get();buffer.get();buffer.get();
+               
+               // get shape
+               this.shape = buffer.get();
+               
+               // skip fuzzy bytes
+               buffer.get();buffer.get();buffer.get();
+               
+               // get rect position (with scaling)
+               if (this.allowScaling) {
+                       this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
+                       this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
+                       this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
+                       this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
+               } else {
+                       this.rectangle.top_left_x = buffer.getShort();
+                       this.rectangle.top_left_y = buffer.getShort();
+                       this.rectangle.bottom_right_x = buffer.getShort();
+                       this.rectangle.bottom_right_y = buffer.getShort();
+               }
+               
+               // don't care about last fuzzy byte because of buffer.rewind()
+               
+               //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+",}");
+       }
+
+       /* (non-Javadoc)
+        * @see org.ocera.orte.types.MessageData#write()
+        */
+       @Override
+       public void write()
+       {
+               buffer.rewind();
+               
+               // put color
+               buffer.put(this.color);
+               
+               // put fuzzy bytes
+               buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
+               
+               // put shape
+               buffer.put(this.shape);
+               
+               // put fuzzy bytes
+               buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);buffer.put(BoxType.FUZZY);
+               
+               // put rectange position (with scaling)
+               if (this.allowScaling) {
+                       buffer.putShort((short) (this.rectangle.top_left_x * this.scaleWidth));
+                       buffer.putShort((short) (this.rectangle.top_left_y * this.scaleHeight));
+                       buffer.putShort((short) (this.rectangle.bottom_right_x * this.scaleWidth));
+                       buffer.putShort((short) (this.rectangle.bottom_right_y * this.scaleHeight));
+               } else {
+                       buffer.putShort(this.rectangle.top_left_x);
+                       buffer.putShort(this.rectangle.top_left_y);
+                       buffer.putShort(this.rectangle.bottom_right_x);
+                       buffer.putShort(this.rectangle.bottom_right_y);
+               }
+               
+               // put fuzzy byte
+               buffer.put(BoxType.FUZZY);
+       }
+
+       /* (non-Javadoc)
+        * @see org.ocera.orte.types.MessageData#getMaxDataLength()
+        */
+       @Override
+       public int getMaxDataLength()
+       {
+               return ORTEConstant.BYTE_FIELD_SIZE + ORTEConstant.LONG_FIELD_SIZE + 4*ORTEConstant.SHORT_FIELD_SIZE;
+       }
+       
+       /**
+        * When screen rotates, change scale variables to
+        * fit the destination screen.
+        * 
+        * Method of former Box class.
+        * 
+        * @since 1.0
+        */
+       public void setScale(int currentWidth, int currentHeight)
+       {
+               this.scaleWidth = DESTINATION_WIDTH / currentWidth;
+               this.scaleHeight = DESTINATION_HEIGHT / currentHeight;
+       }
+       
+       /**
+        * Object parameters to be sent throw ORTE.
+        * 
+        * Class from former Box class.
+        * 
+        * @since 1.0
+        */
+       public class BoxRect
+       {
+               public short top_left_x;
+               public short top_left_y;
+               public short bottom_right_x;
+               public short bottom_right_y;
+               
+               public BoxRect()
+               {}
+       }
+}
index 2f90bf304938d20056dfe0eb9d069a6db618654c..d1dde687353aec179fd9f95736870b49678e6136 100644 (file)
@@ -54,7 +54,7 @@ public class PublisherShape extends ShapeDrawable
        private NtpTime persistence;
        
        public Publication publication;
-       public Box box;
+       public BoxType box;
        
        /**
         * Set new {@link Shape}, strength and color.
@@ -84,15 +84,15 @@ public class PublisherShape extends ShapeDrawable
                this.manual = false;
                this.persistence = new NtpTime(5);
 
-               this.box = new Box(appDomain, PublisherShape.getColorName(c));
+               this.box = new BoxType(appDomain, PublisherShape.getColorName(c));
                this.publisherProperties = new PublProp(this.box.getTopic(),
-                               "Box",
+                               "BoxType",
                                this.persistence,
                                s+1);
                this.publication = appDomain.createPublication(this.publisherProperties, this.box);
                
-               this.box.strength = s;
-               this.box.color = c;
+               this.box.shape = (byte) s;
+               this.box.color = (byte) c;
 
                this.getPaint().setColor(PublisherShape.getColorConstant(c));
                this.setPadding(0, 0, 0, 0);
@@ -107,7 +107,7 @@ public class PublisherShape extends ShapeDrawable
         * @return Object to send.
         * @since 1.0
         */
-       public Box toSend()
+       public BoxType toSend()
        {
                this.box.rectangle.top_left_x = (short) this.getBounds().left;
                this.box.rectangle.top_left_y = (short) this.getBounds().top;
@@ -202,7 +202,7 @@ public class PublisherShape extends ShapeDrawable
         */
        public String getShapeName()
        {
-               switch (this.box.strength) {
+               switch (this.box.shape) {
                case 0:
                        return "Square";
                case 1:
index 6a635f54f34ba8864b42d11a849b13a565184a37..8dcaec1b477507cb115ba76268375bec8b918878 100644 (file)
@@ -48,7 +48,7 @@ public class SubscriberElement extends SubscriptionCallback
        private NtpTime deadline;
        private NtpTime minSeparation;
        
-       private Box box;
+       private BoxType box;
        private ShapeDrawable shape;
        
        private View parentView;
@@ -67,9 +67,9 @@ public class SubscriberElement extends SubscriptionCallback
                this.deadline = new NtpTime(6);
                this.minSeparation = new NtpTime(0);
                
-               this.box = new Box(appDomain, PublisherShape.getColorName(color));
+               this.box = new BoxType(appDomain, PublisherShape.getColorName(color));
                SubsProp subscriberProperties = new SubsProp(this.box.getTopic(),
-                               "Box",
+                               "BoxType",
                                this.minSeparation,
                                this.deadline,
                                ORTEConstant.IMMEDIATE,
@@ -136,7 +136,7 @@ public class SubscriberElement extends SubscriptionCallback
         */
        public void setShape()
        {
-               switch (this.box.strength) {
+               switch (this.box.shape) {
                case 0:
                        this.shape.setShape(new RectShape());
                        break;