]> rtime.felk.cvut.cz Git - orte.git/commitdiff
Merge branch 'shape_android_features' of https://github.com/Vajnar/orte
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 12 Nov 2018 11:20:24 +0000 (12:20 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 12 Nov 2018 11:20:24 +0000 (12:20 +0100)
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/SettingsActivity.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java
orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberView.java

index 557482de86fc4dcffbc4b5b7430902d090eee2d8..8a13a3904faa08e90df40ecf27feba7df9ebc40b 100644 (file)
@@ -104,7 +104,7 @@ public class PublisherActivity extends Activity {
                SHAPE_HEIGHT = (int) (this.getWindowManager().getDefaultDisplay().getHeight() * 45 / BoxType.DESTINATION_HEIGHT);
                
                // From Robot_Demo project.
-               wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+               wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
                wifiLock = (WifiLock) wifiManager.createWifiLock((
                                        (android.os.Build.VERSION.SDK_INT >= 12)
                                        ? WifiManager.WIFI_MODE_FULL_HIGH_PERF
index 212be3f016208255eb5f19ce51e4d76cecb9e81e..9cf0b267e8e96e735f2716b03009dd64f48f8511 100644 (file)
@@ -46,6 +46,7 @@ public class PublisherShape extends ShapeDrawable
        //  info, please refer to http://developer.android.com/
        
        private boolean manual;
+       private int pointerId;
        private int incX, incY;
        
        private PublProp publisherProperties;
@@ -286,6 +287,24 @@ public class PublisherShape extends ShapeDrawable
         */
        public boolean getManual() { return this.manual; }
 
+       /**
+        * Set the touch pointer ID associated with
+        * this shape.
+        *
+        * @param pointerId
+        * @since 1.0
+        */
+       public void setPointerId(int pointerId) { this.pointerId = pointerId; }
+
+       /**
+        * Get the touch pointer ID associated with
+        * this shape.
+        *
+        * @return Pointer ID.
+        * @since 1.0
+        */
+       public int getPointerId() { return this.pointerId; }
+
        /**
         * Make triangle path for new instance.
         * 
index 35fb23eca75ccef4e4b3483e97c8797570749fe0..d1a0536225e53cc09b1a90ad4743cc36f7d8ad40 100644 (file)
@@ -115,8 +115,9 @@ public class PublisherView extends View
                
                switch (event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
-                       myX = (int) event.getX();
-                       myY = (int) event.getY();
+               case MotionEvent.ACTION_POINTER_DOWN:
+                       myX = (int) event.getX(event.getActionIndex());
+                       myY = (int) event.getY(event.getActionIndex());
                        
                        for (PublisherShape shape : shapes) {
                                if (myX <= shape.getBounds().right
@@ -124,26 +125,27 @@ public class PublisherView extends View
                                                && myY >= shape.getBounds().top
                                                && myY <= shape.getBounds().bottom) {
                                        shape.setManual(true);
+                                       shape.setPointerId(event.getPointerId(event.getActionIndex()));
                                        break;
                                }
                        }
                        
                        return true;
                case MotionEvent.ACTION_MOVE:
-                       myX = (int) event.getX();
-                       myY = (int) event.getY();
-                       
                        for (PublisherShape shape : shapes) {
                                if (shape.getManual()) {
+                                       myX = (int) event.getX(event.findPointerIndex(shape.getPointerId()));
+                                       myY = (int) event.getY(event.findPointerIndex(shape.getPointerId()));
+
                                        shape.setBounds((int) (myX - shape.getShape().getWidth()/2), (int) (myY - shape.getShape().getHeight()/2), (int) (myX + shape.getShape().getWidth()/2), (int) (myY + shape.getShape().getHeight()/2));
-                                       break;
                                }
                        }
                        
                        return true;
                case MotionEvent.ACTION_UP:
-                       myX = (int) event.getX();
-                       myY = (int) event.getY();
+               case MotionEvent.ACTION_POINTER_UP:
+                       myX = (int) event.getX(event.getActionIndex());
+                       myY = (int) event.getY(event.getActionIndex());
                        
                        for (PublisherShape shape : shapes) {
                                if (myX <= shape.getBounds().right
index 0478f4d852ead0bbc8ddb8ac275453e2691d333d..adf735c95027b78673181038cad0545e18c07fe6 100644 (file)
@@ -45,7 +45,7 @@ public class SettingsActivity extends PreferenceActivity
                super.onCreate(savedInstanceState);
                addPreferencesFromResource(R.layout.activity_settings);
                
-               WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+               WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
                EditTextPreference pref = (EditTextPreference) findPreference("prefManagers");
 
                //TODO should be done in respect to @strings
index 6b74f63fc900cd2f72437e95f0ff5dca108fdd40..4d65efc638ac3924311dcf176a78d1a7ac25013e 100644 (file)
@@ -34,6 +34,8 @@ import org.ocera.orte.types.RecvInfo;
 import org.ocera.orte.types.SubsProp;
 import org.ocera.orte.types.ORTEConstant;
 
+import java.util.concurrent.locks.ReentrantLock;
+
 /**
  * Subscribing objects are made by this class.
  * 
@@ -56,6 +58,8 @@ public class SubscriberElement extends SubscriptionCallback
        private boolean receiving;
        private boolean enabled;
 
+       public final ReentrantLock lock = new ReentrantLock();
+
        /**
         * Set default variables of subscriber's object.
         * 
@@ -99,20 +103,31 @@ public class SubscriberElement extends SubscriptionCallback
        {
                switch (info.getRecvStatus()) {
                case ORTEConstant.NEW_DATA:
-                       this.receiving = true;
-                       //Log.d("SubscriberElement", "new data: " + (int) ((Box) msg).strength + "(was "+ this.box.strength +"); " + ((Box) msg).rectangle.top_left_x + ", " + ((Box) msg).rectangle.top_left_y + ", "  +((Box) msg).rectangle.bottom_right_x + ", " + ((Box) msg).rectangle.bottom_right_y);
-                       
-                       this.shape.getBounds().left = this.box.rectangle.top_left_x;
-                       this.shape.getBounds().top = this.box.rectangle.top_left_y;
-                       this.shape.getBounds().right = this.box.rectangle.bottom_right_x;
-                       this.shape.getBounds().bottom = this.box.rectangle.bottom_right_y;
-                       
-                       this.setShape();
+
+                       lock.lock();
+                       try {
+                               this.receiving = true;
+                               //Log.d("SubscriberElement", "new data: " + (int) ((Box) msg).strength + "(was "+ this.box.strength +"); " + ((Box) msg).rectangle.top_left_x + ", " + ((Box) msg).rectangle.top_left_y + ", "  +((Box) msg).rectangle.bottom_right_x + ", " + ((Box) msg).rectangle.bottom_right_y);
+
+                               this.shape.setBounds(this.box.rectangle.top_left_x,
+                                               this.box.rectangle.top_left_y,
+                                               this.box.rectangle.bottom_right_x,
+                                               this.box.rectangle.bottom_right_y);
+
+                               this.setShape();
+                       } finally {
+                               lock.unlock();
+                       }
 
                        this.parentView.postInvalidate();
                        break;
                case ORTEConstant.DEADLINE:
-                       this.receiving = false;
+                       lock.lock();
+                       try {
+                               this.receiving = false;
+                       } finally {
+                               lock.unlock();
+                       }
                        this.parentView.postInvalidate();
                        break;
                }
index 31f84d66c757f467878a0d843226ee0b8bc14c04..343a8c9e1be86cf9cd3744807d21176d62b09992 100644 (file)
@@ -56,7 +56,12 @@ public class SubscriberView extends View {
        protected void onDraw(Canvas canvas)
        {
                for (SubscriberElement element : elements) {
-                       if (element.getReceiving() && element.getEnabled()) element.drawMe(canvas);
+                       element.lock.lock();
+                       try {
+                               if (element.getReceiving() && element.getEnabled()) element.drawMe(canvas);
+                       } finally {
+                               element.lock.unlock();
+                       }
                }
        }