Java tutorial
//package com.java2s; import org.json.JSONException; import org.json.JSONObject; import android.view.MotionEvent; import android.view.MotionEvent.PointerCoords; import android.view.MotionEvent.PointerProperties; public class Main { public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException { JSONObject jObj = new JSONObject(); jObj.put("downTime", e.getDownTime()); jObj.put("eventTime", e.getEventTime()); jObj.put("action", e.getAction()); jObj.put("pointerCount", e.getPointerCount()); jObj.put("metaState", e.getMetaState()); jObj.put("buttonState", e.getButtonState()); jObj.put("xPrecision", e.getXPrecision()); jObj.put("yPrecision", e.getYPrecision()); jObj.put("deviceId", e.getDeviceId()); jObj.put("edgeFlags", e.getEdgeFlags()); jObj.put("source", e.getSource()); jObj.put("flags", e.getFlags()); for (int i = 0; i < e.getPointerCount(); i++) { PointerProperties prop = new PointerProperties(); e.getPointerProperties(i, prop); PointerCoords coords = new PointerCoords(); e.getPointerCoords(i, coords); JSONObject pointer = JObjFromPointer(prop, coords); jObj.accumulate("pointers", pointer); } return jObj; } public static JSONObject JObjFromPointer(PointerProperties prop, PointerCoords coords) throws JSONException { JSONObject pointer = new JSONObject(); pointer.put("id", prop.id); pointer.put("toolType", prop.toolType); pointer.put("orientation", coords.orientation); pointer.put("pressure", coords.pressure); pointer.put("size", coords.size); pointer.put("toolMajor", coords.toolMajor); pointer.put("toolMinor", coords.toolMinor); pointer.put("touchMajor", coords.touchMajor); pointer.put("touchMinor", coords.touchMinor); pointer.put("x", coords.x); pointer.put("y", coords.y); return pointer; } }