From 80380d52dd567ca0425c68ec7fbdeb3cdff1056a Mon Sep 17 00:00:00 2001 From: jiri hubacek Date: Sun, 1 Feb 2015 21:43:24 +0100 Subject: [PATCH] Fix scaling. To be dependent only at destination width and height. --- .../org/ocera/orte/shape_android/BoxType.java | 4 ++-- .../orte/shape_android/PublisherActivity.java | 13 +++++++++++-- .../orte/shape_android/PublisherShape.java | 17 ++++++++--------- .../ocera/orte/shape_android/PublisherView.java | 1 + .../orte/shape_android/SubscriberElement.java | 3 ++- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/BoxType.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/BoxType.java index 417e4da..d9e8d08 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/BoxType.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/BoxType.java @@ -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; diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java index 7725783..155de07 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java @@ -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()); } diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java index 4387302..daf55ad 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java @@ -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); } } diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherView.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherView.java index b07f49b..35fb23e 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherView.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherView.java @@ -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; diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java index f88f328..a16326a 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java @@ -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(); } } -- 2.39.2