json:{\\\"id\\\": \\\"#"+getId()+"\\\"}";
if (!act.equals("LongTouch") && !act.equals("Click")) {
float[][] pointer = getXY(event);
result += ", \\\"action\\\" : \\\""+act+"\\\""+
", \\\"count\\\" : "+cnt+
", \\\"X\\\" : "+pointer[0][0]+
", \\\"Y\\\" : "+pointer[0][1]+
", \\\"x\\\" : ["+pointer[0][0]+", "+pointer[1][0]+", "+pointer[2][0]+"], "+
"\\\"y\\\" : ["+pointer[0][1]+", "+pointer[1][1]+", "+pointer[2][1]+"]";
}
result += "}";
main.responseCallback(cb, result);
@Override
public boolean onTouch(View view, MotionEvent event)
{
// Check for clickable state and do nothing if disabled
if(!this.isClickable()) {
this.isSelected = false;
return super.onTouchEvent(event);
}
// Set selected state based on Motion Event
String act = "";
String cb = "";
int index = event.getActionIndex();
int pid = event.getPointerId(index);
int cnt = event.getPointerCount();
switch(event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
PointF p = new PointF();
p.x = event.getX();
p.y = event.getY();
activePointers.put(pid, p);
lastX = event.getX();
lastY = event.getY();
isSelected = true;
ctime = System.currentTimeMillis();
if (touchdown_cb != null) {
act = "Down";
cb = touchdown_cb;
}
else if (touch_cb != null) {
act = "Down";
cb = touch_cb;
}
else
act = "";
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
isSelected = false;
activePointers.remove(pid);
if (touchup_cb != null){
act = "Up";
cb = touchup_cb;
}
else if (touch_cb != null) {
act = "Up";
cb = touch_cb;
}
else act = "";
ctime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_MOVE:
isSelected = true;
if (touchmove_cb != null) {
act = "Move";
cb = touchmove_cb;
}
else if (touch_cb != null) {
act = "Move";
cb = touch_cb;
}
else act = "";
break;
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
//ctime = System.currentTimeMillis();
isSelected = false;
act = "";
break;
}
if ( !cb.equals("") && !act.equals("") ) {
String result = "json:{\"id\":\"#"+pid+"\", \"action\":\""+act+"\"";
if (!act.equals("LongTouch") && !act.equals("Click")) {
result += ",\"count\":"+cnt+
",\"X\":"+event.getX()+
",\"Y\":"+event.getY()+
",\"x\":["+getTouched(0)+"]"+
",\"y\":["+getTouched(1)+"]";
}
result += "}";
//result = "testtt";
main.responseCallback(cb, result);
}
// Redraw image and return super type
this.invalidate();
return super.onTouchEvent(event);
}
private String getTouched(int type) {
String res = "";
if ( activePointers.size() < 1)
return "";
for (int i = 0; i<activePointers.size(); i++) {
int k = activePointers.keyAt(i);
PointF p = activePointers.get(k);
if (type == 0)
res += p.x+", ";
else
res += p.y+", ";
}
res = res.substring(0, res.length()-2);
return res;
}