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
// info, please refer to http://developer.android.com/
private boolean manual;
+ private int pointerId;
private int incX, incY;
private PublProp publisherProperties;
*/
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.
*
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
&& 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
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
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.
*
private boolean receiving;
private boolean enabled;
+ public final ReentrantLock lock = new ReentrantLock();
+
/**
* Set default variables of subscriber's object.
*
{
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;
}
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();
+ }
}
}