diff options
author | 2012-12-23 15:40:37 -0800 | |
---|---|---|
committer | 2013-01-08 08:50:06 -0800 | |
commit | e9c6455881060c9f43a15a499582118b2ac2fa65 (patch) | |
tree | 525c3e57d42c0401109df633050fb025c4559329 /java/src/com/android/inputmethod/research/JsonUtils.java | |
parent | 9bad176ebe4f6520db188b5498efbbf7e5fc2c4f (diff) | |
download | latinime-e9c6455881060c9f43a15a499582118b2ac2fa65.tar.gz latinime-e9c6455881060c9f43a15a499582118b2ac2fa65.tar.xz latinime-e9c6455881060c9f43a15a499582118b2ac2fa65.zip |
[Rlog48] Better logging of MotionEvents
- Now includes all historical data stored in a motionEvent
- Simpler API, refactored to move extraction code to JsonUtils
Change-Id: I52d9756ddbeaa14d1704787da59bf1aad18f0335
Diffstat (limited to 'java/src/com/android/inputmethod/research/JsonUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/JsonUtils.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/research/JsonUtils.java b/java/src/com/android/inputmethod/research/JsonUtils.java index cb331d7f9..1dfd01c69 100644 --- a/java/src/com/android/inputmethod/research/JsonUtils.java +++ b/java/src/com/android/inputmethod/research/JsonUtils.java @@ -18,6 +18,7 @@ package com.android.inputmethod.research; import android.content.SharedPreferences; import android.util.JsonWriter; +import android.view.MotionEvent; import android.view.inputmethod.CompletionInfo; import com.android.inputmethod.keyboard.Key; @@ -27,6 +28,9 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.io.IOException; import java.util.Map; +/** + * Routines for mapping classes and variables to JSON representations for logging. + */ /* package */ class JsonUtils { private JsonUtils() { // This utility class is not publicly instantiable. @@ -100,4 +104,54 @@ import java.util.Map; jsonWriter.endArray(); jsonWriter.endObject(); } + + /* package */ static void writeJson(final MotionEvent me, final JsonWriter jsonWriter) + throws IOException { + jsonWriter.beginObject(); + jsonWriter.name("pointerIds"); + jsonWriter.beginArray(); + final int pointerCount = me.getPointerCount(); + for (int index = 0; index < pointerCount; index++) { + jsonWriter.value(me.getPointerId(index)); + } + jsonWriter.endArray(); + + jsonWriter.name("xyt"); + jsonWriter.beginArray(); + final int historicalSize = me.getHistorySize(); + for (int index = 0; index < historicalSize; index++) { + jsonWriter.beginObject(); + jsonWriter.name("t"); + jsonWriter.value(me.getHistoricalEventTime(index)); + jsonWriter.name("d"); + jsonWriter.beginArray(); + for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { + jsonWriter.beginObject(); + jsonWriter.name("x"); + jsonWriter.value(me.getHistoricalX(pointerIndex, index)); + jsonWriter.name("y"); + jsonWriter.value(me.getHistoricalY(pointerIndex, index)); + jsonWriter.endObject(); + } + jsonWriter.endArray(); + jsonWriter.endObject(); + } + jsonWriter.beginObject(); + jsonWriter.name("t"); + jsonWriter.value(me.getEventTime()); + jsonWriter.name("d"); + jsonWriter.beginArray(); + for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { + jsonWriter.beginObject(); + jsonWriter.name("x"); + jsonWriter.value(me.getX(pointerIndex)); + jsonWriter.name("y"); + jsonWriter.value(me.getY(pointerIndex)); + jsonWriter.endObject(); + } + jsonWriter.endArray(); + jsonWriter.endObject(); + jsonWriter.endArray(); + jsonWriter.endObject(); + } } |