]> rtime.felk.cvut.cz Git - orte.git/commitdiff
Fix scaling.
authorjiri hubacek <jiri.hubacek@gmail.com>
Sun, 1 Feb 2015 20:43:24 +0000 (21:43 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 9 Feb 2015 16:56:15 +0000 (17:56 +0100)
To be dependent only at destination width and height.

orte/contrib/shape_android/src/org/ocera/orte/shape_android/BoxType.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherView.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java

index 417e4da2e7722c0d8e544eec5c3d511a7c82904f..d9e8d08f96f62a838e97c34edaf5caf91868ef99 100644 (file)
@@ -33,8 +33,8 @@ import android.util.Log;
  */
 public class BoxType extends MessageData
 {
-       private static final double DESTINATION_WIDTH = 367.0; //389.0;
-       private static final double DESTINATION_HEIGHT = 261.0; //331.0;
+       public static final double DESTINATION_WIDTH = 367.0; // empirically, in real it's 389.0;
+       public static final double DESTINATION_HEIGHT = 261.0; // empirically, in real it's 331.0;
        
        public int color;
        public int shape;
index 7725783308e6bb42c44a253fce9ec85990a8a6af..155de07ad953d06030bd8fa0555ed82fd6ab512d 100644 (file)
@@ -18,8 +18,6 @@
  */
 package org.ocera.orte.shape_android;
 
-import java.util.regex.Pattern;
-
 import org.ocera.orte.DomainApp;
 import org.ocera.orte.Manager;
 import org.ocera.orte.types.NtpTime;
@@ -58,6 +56,9 @@ public class PublisherActivity extends Activity {
        private static final int MINSEPARATION_MAX = 5;
        private static final int RESULT_SETTINGS = 1;
        
+       public static int SHAPE_WIDTH = 0;
+       public static int SHAPE_HEIGHT = 0;
+       
        private WifiManager wifiManager;
        private WifiLock wifiLock;
        
@@ -93,6 +94,10 @@ public class PublisherActivity extends Activity {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_publisher);
                
+               // count default shape size
+               SHAPE_WIDTH = (int) (this.getWindowManager().getDefaultDisplay().getWidth() * 25 / BoxType.DESTINATION_WIDTH);
+               SHAPE_HEIGHT = (int) (this.getWindowManager().getDefaultDisplay().getHeight() * 45 / BoxType.DESTINATION_HEIGHT);
+               
                // From Robot_Demo project.
                wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                wifiLock = (WifiLock) wifiManager.createWifiLock((
@@ -178,6 +183,10 @@ public class PublisherActivity extends Activity {
        {
                super.onConfigurationChanged(newConfig);
                
+               // count default shape size
+               SHAPE_WIDTH = (int) (this.getWindowManager().getDefaultDisplay().getWidth() * 25 / BoxType.DESTINATION_WIDTH);
+               SHAPE_HEIGHT = (int) (this.getWindowManager().getDefaultDisplay().getHeight() * 45 / BoxType.DESTINATION_HEIGHT);
+                               
                for (PublisherShape s : this.publisherView.shapes) {
                        s.setScale(this.getWindowManager().getDefaultDisplay().getWidth(), this.getWindowManager().getDefaultDisplay().getHeight());
                }
index 4387302c0dddbd344b8aeb958ddf69e5bb311c28..daf55adb4b988d6e8def4c49403eb16d8d08d06e 100644 (file)
@@ -45,8 +45,6 @@ public class PublisherShape extends ShapeDrawable
        // Prefer at least 48x48 shape size (Full asset), for more
        //  info, please refer to http://developer.android.com/
        
-       private static final int SHAPE_WIDTH = 48;
-       private static final int SHAPE_HEIGHT = 48;
        private boolean manual;
        private int incX, incY;
        
@@ -71,14 +69,14 @@ public class PublisherShape extends ShapeDrawable
                                :((s == 1)
                                        ?new OvalShape()
                                        :((s == 2)
-                                               ?new PathShape(new  Path(), 96, 96)
+                                               ?new PathShape(new  Path(), PublisherActivity.SHAPE_WIDTH, PublisherActivity.SHAPE_HEIGHT)
                                                :new RectShape()
                                        )
                                )
                        );
                
                if (s == 2) { // fix triangle
-                       this.setShape(new PathShape(PublisherShape.returnTrianglePath(), 96, 96));
+                       this.setShape(new PathShape(PublisherShape.returnTrianglePath(), 2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT));
                }
                
                this.manual = false;
@@ -96,7 +94,7 @@ public class PublisherShape extends ShapeDrawable
 
                this.getPaint().setColor(PublisherShape.getColorConstant(c));
                this.setPadding(0, 0, 0, 0);
-               this.setBounds(0, 0, SHAPE_WIDTH, SHAPE_HEIGHT);
+               this.setBounds(0, 0, PublisherActivity.SHAPE_WIDTH, PublisherActivity.SHAPE_HEIGHT);
                
                //Log.d("PublisherShape", "s: "+s+", c: "+c+", left: "+this.getBounds().left+", top: "+this.getBounds().top+", right: "+this.getBounds().right+", bottom: "+this.getBounds().bottom);
        }
@@ -298,10 +296,10 @@ public class PublisherShape extends ShapeDrawable
        {
                Path path = new Path();
                path.setFillType(FillType.EVEN_ODD);
-               path.moveTo(48, 0);
-               path.lineTo(96, 96);
-               path.lineTo(0, 96);
-               path.lineTo(48, 0);
+               path.moveTo(PublisherActivity.SHAPE_WIDTH, 0); // triangle top center
+               path.lineTo(2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT); // triangle right bottom corner
+               path.lineTo(0, 2*PublisherActivity.SHAPE_HEIGHT); // triangle left bottom corner
+               path.lineTo(PublisherActivity.SHAPE_WIDTH, 0); // back to triangle top center
                path.close();
                
                return path;
@@ -327,5 +325,6 @@ public class PublisherShape extends ShapeDrawable
        public void setScale(int currentWidth, int currentHeight)
        {
                this.box.setScale(currentWidth, currentHeight);
+               this.setBounds(this.box.rectangle.top_left_x, this.box.rectangle.top_left_y, this.box.rectangle.top_left_x+PublisherActivity.SHAPE_WIDTH, this.box.rectangle.top_left_y+PublisherActivity.SHAPE_HEIGHT);
        }
 }
index b07f49bb3b823880d9c117e816ef01e0d084c5b0..35fb23eca75ccef4e4b3483e97c8797570749fe0 100644 (file)
@@ -38,6 +38,7 @@ import org.ocera.orte.DomainApp;
  */
 public class PublisherView extends View
 {
+       //TODO maybe different speeds of shapes?
        private static final int STEP_X = 2;
        private static final int STEP_Y = 2;
 
index f88f3280d10921d728bbc46f4180d801270cfcce..a16326ae5bd90a793588c7868a4d3eeec7429a14 100644 (file)
@@ -144,7 +144,7 @@ public class SubscriberElement extends SubscriptionCallback
                        this.shape.setShape(new OvalShape());
                        break;
                case 2:
-                       this.shape.setShape(new PathShape(PublisherShape.returnTrianglePath(), 96, 96));
+                       this.shape.setShape(new PathShape(PublisherShape.returnTrianglePath(), 2*PublisherActivity.SHAPE_WIDTH, 2*PublisherActivity.SHAPE_HEIGHT));
                        break;
                default:
                        this.shape.setShape(new RectShape());
@@ -240,6 +240,7 @@ public class SubscriberElement extends SubscriptionCallback
        public void setScale(int currentWidth, int currentHeight)
        {
                this.box.setScale(currentWidth, currentHeight);
+               this.setShape();
        }
 
 }