diff options
author | 2013-02-01 15:05:57 +0000 | |
---|---|---|
committer | 2013-02-01 15:05:58 +0000 | |
commit | 5bdd7bab11cee1be86d8ab3e2167059eb9d682e2 (patch) | |
tree | d9a27ef20001608ddbec372bf9962777a11a1658 /java/src/com/android/inputmethod/research/Replayer.java | |
parent | ee456af9d4c7ce4fe2dc0513a8b2cf08c21b5f21 (diff) | |
parent | 588d9b5c8df2bea421f66a4f4306c93c2e4fc485 (diff) | |
download | latinime-5bdd7bab11cee1be86d8ab3e2167059eb9d682e2.tar.gz latinime-5bdd7bab11cee1be86d8ab3e2167059eb9d682e2.tar.xz latinime-5bdd7bab11cee1be86d8ab3e2167059eb9d682e2.zip |
Merge "[Rlog47] Replayer service, inspect-researchLog.py"
Diffstat (limited to 'java/src/com/android/inputmethod/research/Replayer.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/Replayer.java | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/research/Replayer.java b/java/src/com/android/inputmethod/research/Replayer.java index 4cc2a5814..611abb288 100644 --- a/java/src/com/android/inputmethod/research/Replayer.java +++ b/java/src/com/android/inputmethod/research/Replayer.java @@ -1,22 +1,23 @@ /* * Copyright (C) 2012 The Android Open Source Project * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.android.inputmethod.research; import android.os.Handler; +import android.os.Looper; import android.os.Message; import android.os.SystemClock; import android.util.Log; @@ -40,6 +41,14 @@ public class Replayer { private boolean mIsReplaying = false; private KeyboardSwitcher mKeyboardSwitcher; + private Replayer() { + } + + private static final Replayer sInstance = new Replayer(); + public static Replayer getInstance() { + return sInstance; + } + public void setKeyboardSwitcher(final KeyboardSwitcher keyboardSwitcher) { mKeyboardSwitcher = keyboardSwitcher; } @@ -49,7 +58,7 @@ public class Replayer { private static final int COMPLETION_TIME_MS = 500; // TODO: Support historical events and multi-touch. - public void replay(final ReplayData replayData) { + public void replay(final ReplayData replayData, final Runnable callback) { if (mIsReplaying) { return; } @@ -72,7 +81,7 @@ public class Replayer { // The adjustment needed to translate times from the original recorded time to the current // time. final long timeAdjustment = currentStartTime - origStartTime; - final Handler handler = new Handler() { + final Handler handler = new Handler(Looper.getMainLooper()) { // Track the time of the most recent DOWN event, to be passed as a parameter when // constructing a MotionEvent. It's initialized here to the origStartTime, but this is // only a precaution. The value should be overwritten by the first ACTION_DOWN event @@ -113,8 +122,12 @@ public class Replayer { Log.d(TAG, "queuing event at " + msgTime); } } + final long presentDoneTime = replayData.mTimes.get(numActions - 1) + timeAdjustment + COMPLETION_TIME_MS; handler.sendMessageAtTime(Message.obtain(handler, MSG_DONE), presentDoneTime); + if (callback != null) { + handler.postAtTime(callback, presentDoneTime + 1); + } } } |