TouchEventTalker.java
Go to the documentation of this file.
00001 package org.ros.android.android_image_view;
00002 
00003 import org.ros.namespace.GraphName;
00004 import org.ros.node.AbstractNodeMain;
00005 import org.ros.node.ConnectedNode;
00006 import org.ros.node.topic.Publisher;
00007 
00008 import android.view.MotionEvent;
00009 import jsk_gui_msgs.TouchEvent;
00010 
00011 public class TouchEventTalker extends AbstractNodeMain {
00012 
00013         // private boolean publish = false;
00014 
00015         private TouchEvent touchEvent;
00016         private Publisher<TouchEvent> touchEventPublisher;
00017 
00018         synchronized public void publish(float x, float y, float w, float h,
00019                         int state) {
00020                 // this.publish = true;
00021 
00022                 this.touchEvent.setX(x);
00023                 this.touchEvent.setY(y);
00024                 this.touchEvent.setW(w);
00025                 this.touchEvent.setH(h);
00026                 this.touchEvent.setState(stateConverter(state));
00027 
00028                 this.touchEventPublisher.publish(this.touchEvent);
00029         }
00030 
00031         public byte stateConverter(int state){
00032                 switch ( state ){
00033                 case MotionEvent.ACTION_DOWN :
00034                         return TouchEvent.DOWN ;
00035                 case MotionEvent.ACTION_UP :
00036                         return TouchEvent.UP ;
00037                 case MotionEvent.ACTION_MOVE :
00038                         return TouchEvent.MOVE ;
00039                 default :
00040                         return (byte)-1 ;
00041                 }
00042         }
00043 
00044         @Override
00045         public GraphName getDefaultNodeName() {
00046                 return GraphName.of("tap_on_image/talker");
00047         }
00048 
00049         @Override
00050         public void onStart(final ConnectedNode connectedNode) {
00051                 System.out.println(connectedNode.getClass() + "/"
00052                                 + connectedNode.getClass().getName());
00053 
00054                 touchEventPublisher = connectedNode.newPublisher("touchEvent",
00055                                 TouchEvent._TYPE);
00056                 touchEvent = connectedNode.getTopicMessageFactory().newFromType(
00057                                 TouchEvent._TYPE);
00058         }
00059 }


jsk_android_apps
Author(s): Kazuto Murase
autogenerated on Thu Jun 6 2019 18:03:46