FileDocCategorySizeDatePackage
GestureRecorder.javaAPI DocAndroid 5.1 API8476Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar

GestureRecorder

public class GestureRecorder extends Object
Convenience class for capturing gestures for later analysis.

Fields Summary
public static final boolean
DEBUG
public static final String
TAG
static final long
SAVE_DELAY
static final int
SAVE_MESSAGE
private LinkedList
mGestures
private Gesture
mCurrentGesture
private int
mLastSaveLen
private String
mLogfile
private android.os.Handler
mHandler
Constructors Summary
public GestureRecorder(String filename)


       
        mLogfile = filename;
        mGestures = new LinkedList<Gesture>();
        mCurrentGesture = null;
    
Methods Summary
public voidadd(android.view.MotionEvent ev)

        synchronized (mGestures) {
            if (mCurrentGesture == null || mCurrentGesture.isComplete()) {
                mCurrentGesture = new Gesture();
                mGestures.add(mCurrentGesture);
            }
            mCurrentGesture.add(ev);
        }
        saveLater();
    
public voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        save();
        if (mLastSaveLen >= 0) {
            pw.println(String.valueOf(mLastSaveLen) + " gestures written to " + mLogfile);
        } else {
            pw.println("error writing gestures");
        }
    
public voidsave()

        synchronized (mGestures) {
            try {
                BufferedWriter w = new BufferedWriter(new FileWriter(mLogfile, /*append=*/ true));
                w.append(toJsonLocked() + "\n");
                w.close();
                mGestures.clear();
                // If we have a pending gesture, push it back
                if (mCurrentGesture != null && !mCurrentGesture.isComplete()) {
                    mGestures.add(mCurrentGesture);
                }
                if (DEBUG) {
                    Log.v(TAG, String.format("Wrote %d complete gestures to %s", mLastSaveLen, mLogfile));
                }
            } catch (IOException e) {
                Log.e(TAG, String.format("Couldn't write gestures to %s", mLogfile), e);
                mLastSaveLen = -1;
            }
        }
    
public voidsaveLater()

        mHandler.removeMessages(SAVE_MESSAGE);
        mHandler.sendEmptyMessageDelayed(SAVE_MESSAGE, SAVE_DELAY);
    
public voidtag(long when, java.lang.String tag, java.lang.String info)

        synchronized (mGestures) {
            if (mCurrentGesture == null) {
                mCurrentGesture = new Gesture();
                mGestures.add(mCurrentGesture);
            }
            mCurrentGesture.tag(when, tag, info);
        }
        saveLater();
    
public voidtag(long when, java.lang.String tag)

        tag(when, tag, null);
    
public voidtag(java.lang.String tag)

        tag(SystemClock.uptimeMillis(), tag, null);
    
public voidtag(java.lang.String tag, java.lang.String info)

        tag(SystemClock.uptimeMillis(), tag, info);
    
public java.lang.StringtoJson()

        String s;
        synchronized (mGestures) {
            s = toJsonLocked();
        }
        return s;
    
public java.lang.StringtoJsonLocked()
Generates a JSON string capturing all completed gestures. Not threadsafe; call with a lock.

        StringBuilder sb = new StringBuilder();
        boolean first = true;
        sb.append("[");
        int count = 0;
        for (Gesture g : mGestures) {
            if (!g.isComplete()) continue;
            if (!first) sb.append("," );
            first = false;
            sb.append(g.toJson());
            count++;
        }
        mLastSaveLen = count;
        sb.append("]");
        return sb.toString();