[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
main
Kurt Partridge 2012-12-23 15:40:37 -08:00
parent 9bad176ebe
commit e9c6455881
3 changed files with 59 additions and 6 deletions

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.research;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.JsonWriter; import android.util.JsonWriter;
import android.view.MotionEvent;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
@ -27,6 +28,9 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
/**
* Routines for mapping classes and variables to JSON representations for logging.
*/
/* package */ class JsonUtils { /* package */ class JsonUtils {
private JsonUtils() { private JsonUtils() {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
@ -100,4 +104,54 @@ import java.util.Map;
jsonWriter.endArray(); jsonWriter.endArray();
jsonWriter.endObject(); 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();
}
} }

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.research;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.JsonWriter; import android.util.JsonWriter;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
@ -189,6 +190,8 @@ import java.util.Map;
JsonUtils.writeJson((Key[]) value, jsonWriter); JsonUtils.writeJson((Key[]) value, jsonWriter);
} else if (value instanceof SuggestedWords) { } else if (value instanceof SuggestedWords) {
JsonUtils.writeJson((SuggestedWords) value, jsonWriter); JsonUtils.writeJson((SuggestedWords) value, jsonWriter);
} else if (value instanceof MotionEvent) {
JsonUtils.writeJson((MotionEvent) value, jsonWriter);
} else if (value == null) { } else if (value == null) {
jsonWriter.nullValue(); jsonWriter.nullValue();
} else { } else {

View File

@ -643,7 +643,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mMainKeyboardView.invalidateAllKeys(); mMainKeyboardView.invalidateAllKeys();
} }
public void paintIndicator(KeyboardView view, Paint paint, Canvas canvas, int width, public void paintIndicator(KeyboardView view, Paint paint, Canvas canvas, int width,
int height) { int height) {
// TODO: Reimplement using a keyboard background image specific to the ResearchLogger // TODO: Reimplement using a keyboard background image specific to the ResearchLogger
@ -896,8 +895,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
* *
*/ */
private static final LogStatement LOGSTATEMENT_MAIN_KEYBOARD_VIEW_PROCESS_MOTION_EVENT = private static final LogStatement LOGSTATEMENT_MAIN_KEYBOARD_VIEW_PROCESS_MOTION_EVENT =
new LogStatement("MainKeyboardViewProcessMotionEvent", true, false, "action", new LogStatement("MotionEvent", true, false, "action", "MotionEvent");
"eventTime", "id", "x", "y", "size", "pressure");
public static void mainKeyboardView_processMotionEvent(final MotionEvent me, final int action, public static void mainKeyboardView_processMotionEvent(final MotionEvent me, final int action,
final long eventTime, final int index, final int id, final int x, final int y) { final long eventTime, final int index, final int id, final int x, final int y) {
if (me != null) { if (me != null) {
@ -912,11 +910,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
case MotionEvent.ACTION_OUTSIDE: actionString = "OUTSIDE"; break; case MotionEvent.ACTION_OUTSIDE: actionString = "OUTSIDE"; break;
default: actionString = "ACTION_" + action; break; default: actionString = "ACTION_" + action; break;
} }
final float size = me.getSize(index);
final float pressure = me.getPressure(index);
final ResearchLogger researchLogger = getInstance(); final ResearchLogger researchLogger = getInstance();
researchLogger.enqueueEvent(LOGSTATEMENT_MAIN_KEYBOARD_VIEW_PROCESS_MOTION_EVENT, researchLogger.enqueueEvent(LOGSTATEMENT_MAIN_KEYBOARD_VIEW_PROCESS_MOTION_EVENT,
actionString, eventTime, id, x, y, size, pressure); actionString, MotionEvent.obtain(me));
if (action == MotionEvent.ACTION_DOWN) { if (action == MotionEvent.ACTION_DOWN) {
// Subtract 1 from eventTime so the down event is included in the later // Subtract 1 from eventTime so the down event is included in the later
// LogUnit, not the earlier (the test is for inequality). // LogUnit, not the earlier (the test is for inequality).