Merge "Revise gesture floating preview design" into jb-mr1-dev
diff --git a/java/res/values-cs/bools.xml b/java/res/values-cs/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-cs/bools.xml
+++ b/java/res/values-cs/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-de/bools.xml b/java/res/values-de/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-de/bools.xml
+++ b/java/res/values-de/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-en/bools.xml b/java/res/values-en/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-en/bools.xml
+++ b/java/res/values-en/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-es/bools.xml b/java/res/values-es/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-es/bools.xml
+++ b/java/res/values-es/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-fr/bools.xml b/java/res/values-fr/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-fr/bools.xml
+++ b/java/res/values-fr/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-nl/bools.xml b/java/res/values-nl/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-nl/bools.xml
+++ b/java/res/values-nl/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-pl/bools.xml b/java/res/values-pl/bools.xml
index 897f4b3..dabfff8 100644
--- a/java/res/values-pl/bools.xml
+++ b/java/res/values-pl/bools.xml
@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values/bools.xml b/java/res/values/bools.xml
index 889d8f7..0069596 100644
--- a/java/res/values/bools.xml
+++ b/java/res/values/bools.xml
@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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.
 */
 -->
diff --git a/java/src/com/android/inputmethod/research/ResearchLog.java b/java/src/com/android/inputmethod/research/ResearchLog.java
index cd9ff85..70c38e9 100644
--- a/java/src/com/android/inputmethod/research/ResearchLog.java
+++ b/java/src/com/android/inputmethod/research/ResearchLog.java
@@ -93,7 +93,7 @@
         mFile = outputFile;
     }
 
-    public synchronized void close() {
+    public synchronized void close(final Runnable onClosed) {
         mExecutor.submit(new Callable<Object>() {
             @Override
             public Object call() throws Exception {
@@ -102,7 +102,14 @@
                         mJsonWriter.endArray();
                         mJsonWriter.flush();
                         mJsonWriter.close();
+                        if (DEBUG) {
+                            Log.d(TAG, "wrote log to " + mFile);
+                        }
                         mHasWrittenData = false;
+                    } else {
+                        if (DEBUG) {
+                            Log.d(TAG, "close() called, but no data, not outputting");
+                        }
                     }
                 } catch (Exception e) {
                     Log.d(TAG, "error when closing ResearchLog:");
@@ -111,6 +118,9 @@
                     if (mFile.exists()) {
                         mFile.setWritable(false, false);
                     }
+                    if (onClosed != null) {
+                        onClosed.run();
+                    }
                 }
                 return null;
             }
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index 5c24871..763fd6e 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -84,6 +84,7 @@
  */
 public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
     private static final String TAG = ResearchLogger.class.getSimpleName();
+    private static final boolean DEBUG = false;
     private static final boolean OUTPUT_ENTIRE_BUFFER = false;  // true may disclose private info
     public static final boolean DEFAULT_USABILITY_STUDY_MODE = false;
     /* package */ static boolean sIsLogging = false;
@@ -344,6 +345,9 @@
     }
 
     private void start() {
+        if (DEBUG) {
+            Log.d(TAG, "start called");
+        }
         maybeShowSplashScreen();
         updateSuspendedState();
         requestIndicatorRedraw();
@@ -371,21 +375,27 @@
     }
 
     /* package */ void stop() {
+        if (DEBUG) {
+            Log.d(TAG, "stop called");
+        }
         logStatistics();
         commitCurrentLogUnit();
 
         if (mMainLogBuffer != null) {
             publishLogBuffer(mMainLogBuffer, mMainResearchLog, false /* isIncludingPrivateData */);
-            mMainResearchLog.close();
+            mMainResearchLog.close(null /* callback */);
             mMainLogBuffer = null;
         }
         if (mFeedbackLogBuffer != null) {
-            mFeedbackLog.close();
+            mFeedbackLog.close(null /* callback */);
             mFeedbackLogBuffer = null;
         }
     }
 
     public boolean abort() {
+        if (DEBUG) {
+            Log.d(TAG, "abort called");
+        }
         boolean didAbortMainLog = false;
         if (mMainLogBuffer != null) {
             mMainLogBuffer.clear();
@@ -549,12 +559,19 @@
                 false /* isPotentiallyPrivate */);
         mFeedbackLogBuffer.shiftIn(feedbackLogUnit);
         publishLogBuffer(mFeedbackLogBuffer, mFeedbackLog, true /* isIncludingPrivateData */);
-        mFeedbackLog.close();
-        uploadNow();
+        mFeedbackLog.close(new Runnable() {
+            @Override
+            public void run() {
+                uploadNow();
+            }
+        });
         mFeedbackLog = new ResearchLog(createLogFile(mFilesDir));
     }
 
     public void uploadNow() {
+        if (DEBUG) {
+            Log.d(TAG, "calling uploadNow()");
+        }
         mInputMethodService.startService(mUploadIntent);
     }
 
@@ -574,6 +591,13 @@
     }
 
     private boolean isAllowedToLog() {
+        if (DEBUG) {
+            Log.d(TAG, "iatl: " +
+                "mipw=" + mIsPasswordView +
+                ", mils=" + mIsLoggingSuspended +
+                ", sil=" + sIsLogging +
+                ", mInFeedbackDialog=" + mInFeedbackDialog);
+        }
         return !mIsPasswordView && !mIsLoggingSuspended && sIsLogging && !mInFeedbackDialog;
     }
 
@@ -662,6 +686,9 @@
     }
 
     /* package for test */ void commitCurrentLogUnit() {
+        if (DEBUG) {
+            Log.d(TAG, "commitCurrentLogUnit");
+        }
         if (!mCurrentLogUnit.isEmpty()) {
             if (mMainLogBuffer != null) {
                 mMainLogBuffer.shiftIn(mCurrentLogUnit);
@@ -1014,26 +1041,26 @@
             final boolean isPasswordView = kid.passwordInput();
             getInstance().setIsPasswordView(isPasswordView);
             final Object[] values = {
-                    KeyboardId.elementIdToName(kid.mElementId),
-                    kid.mLocale + ":" + kid.mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
-                    kid.mOrientation,
-                    kid.mWidth,
-                    KeyboardId.modeName(kid.mMode),
-                    kid.imeAction(),
-                    kid.navigateNext(),
-                    kid.navigatePrevious(),
-                    kid.mClobberSettingsKey,
-                    isPasswordView,
-                    kid.mShortcutKeyEnabled,
-                    kid.mHasShortcutKey,
-                    kid.mLanguageSwitchKeyEnabled,
-                    kid.isMultiLine(),
-                    keyboard.mOccupiedWidth,
-                    keyboard.mOccupiedHeight,
-                    keyboard.mKeys
-                };
-            getInstance().enqueueEvent(EVENTKEYS_MAINKEYBOARDVIEW_SETKEYBOARD, values);
+                KeyboardId.elementIdToName(kid.mElementId),
+                kid.mLocale + ":" + kid.mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
+                kid.mOrientation,
+                kid.mWidth,
+                KeyboardId.modeName(kid.mMode),
+                kid.imeAction(),
+                kid.navigateNext(),
+                kid.navigatePrevious(),
+                kid.mClobberSettingsKey,
+                isPasswordView,
+                kid.mShortcutKeyEnabled,
+                kid.mHasShortcutKey,
+                kid.mLanguageSwitchKeyEnabled,
+                kid.isMultiLine(),
+                keyboard.mOccupiedWidth,
+                keyboard.mOccupiedHeight,
+                keyboard.mKeys
+            };
             getInstance().setIsPasswordView(isPasswordView);
+            getInstance().enqueueEvent(EVENTKEYS_MAINKEYBOARDVIEW_SETKEYBOARD, values);
         }
     }