public class SampleTouch implements EntryPoint, TouchStartHandler,
TouchMoveHandler, TouchEndHandler {
private HTML html;
private TouchableFocusPanel tfp;
public void onModuleLoad() {
try {
VerticalPanel panel = new VerticalPanel();
html = new HTML();
panel.add(html);
tfp = new TouchableFocusPanel();
tfp.addTouchStartHandler(this);
tfp.addTouchMoveHandler(this);
tfp.addTouchEndHandler(this);
tfp.setSize("1000px", "1000px");
panel.add(tfp);
RootPanel.get().add(panel);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onTouchStart(TouchStartEvent event) {
event.preventDefault();
String msg = "Start: ";
msg += createMessage(event.touches());
html.setHTML(msg);
}
@Override
public void onTouchMove(TouchMoveEvent event) {
event.preventDefault();
String msg = "Move: ";
msg += createMessage(event.touches());
html.setHTML(msg);
}
@Override
public void onTouchEnd(TouchEndEvent event) {
event.preventDefault();
String msg = "End: ";
msg += createMessage(event.touches());
html.setHTML(msg);
}
private String createMessage(JsArray touches) {
String msg = "";
if (touches.length() > 0) {
for (int i = 0; i < touches.length(); i++) {
Touch t = touches.get(i);
int x = t.getRelativeX(tfp.getElement());
int y = t.getRelativeY(tfp.getElement());
msg += i + ":{x:" + x + "," + y + "}, ";
}
}
return msg;
}
}
0 件のコメント:
コメントを投稿