Merge "Fix off by one bug in gesture trail drawing"
diff --git a/java/res/values-ca/strings.xml b/java/res/values-ca/strings.xml
index 273b555..4e1bbd2 100644
--- a/java/res/values-ca/strings.xml
+++ b/java/res/values-ca/strings.xml
@@ -44,10 +44,8 @@
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"Predeterminat"</string>
     <string name="use_contacts_dict" msgid="4435317977804180815">"Suggereix noms de contactes"</string>
     <string name="use_contacts_dict_summary" msgid="6599983334507879959">"Utilitza els noms de contactes per fer suggeriments i correccions"</string>
-    <!-- no translation found for use_double_space_period (8781529969425082860) -->
-    <skip />
-    <!-- no translation found for use_double_space_period_summary (6532892187247952799) -->
-    <skip />
+    <string name="use_double_space_period" msgid="8781529969425082860">"Punt amb doble espai"</string>
+    <string name="use_double_space_period_summary" msgid="6532892187247952799">"Picar dues vegades la barra espaiad. insereix punt i espai blanc"</string>
     <string name="auto_cap" msgid="1719746674854628252">"Majúscules automàtiques"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"Posa en majúscula la primera paraula de cada frase"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"Diccionaris complementaris"</string>
diff --git a/java/res/values-el/strings.xml b/java/res/values-el/strings.xml
index 85ed3df..1ab64f9 100644
--- a/java/res/values-el/strings.xml
+++ b/java/res/values-el/strings.xml
@@ -44,10 +44,8 @@
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"Προεπιλογή"</string>
     <string name="use_contacts_dict" msgid="4435317977804180815">"Πρόταση ονομάτων επαφών"</string>
     <string name="use_contacts_dict_summary" msgid="6599983334507879959">"Χρησιμοποιήστε ονόματα από τις Επαφές για προτάσεις και διορθ."</string>
-    <!-- no translation found for use_double_space_period (8781529969425082860) -->
-    <skip />
-    <!-- no translation found for use_double_space_period_summary (6532892187247952799) -->
-    <skip />
+    <string name="use_double_space_period" msgid="8781529969425082860">"Τελεία με διπλό πάτημα πλήκρου διαστ."</string>
+    <string name="use_double_space_period_summary" msgid="6532892187247952799">"Το διπλό πάτημα του πλήκτρ.διαστ. εισάγει μια τελεία και ένα κενό"</string>
     <string name="auto_cap" msgid="1719746674854628252">"Αυτόματη χρήση κεφαλαίων"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"Χρήση κεφαλαίου στην πρώτη λέξη κάθε πρότασης"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"Πρόσθετα λεξικά"</string>
diff --git a/java/res/values-it/strings.xml b/java/res/values-it/strings.xml
index fd1717f..a3ed5dd 100644
--- a/java/res/values-it/strings.xml
+++ b/java/res/values-it/strings.xml
@@ -44,10 +44,8 @@
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"Predefinito"</string>
     <string name="use_contacts_dict" msgid="4435317977804180815">"Suggerisci nomi di contatti"</string>
     <string name="use_contacts_dict_summary" msgid="6599983334507879959">"Utilizza nomi di Contatti per suggerimenti e correzioni"</string>
-    <!-- no translation found for use_double_space_period (8781529969425082860) -->
-    <skip />
-    <!-- no translation found for use_double_space_period_summary (6532892187247952799) -->
-    <skip />
+    <string name="use_double_space_period" msgid="8781529969425082860">"Doppio spazio per punto"</string>
+    <string name="use_double_space_period_summary" msgid="6532892187247952799">"Tocca due volte barra spaziatr. per inserire punto seguito da spazio"</string>
     <string name="auto_cap" msgid="1719746674854628252">"Maiuscole automatiche"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"Iniziale maiuscola per la prima parola di ogni frase"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"Dizionari aggiuntivi"</string>
diff --git a/java/res/values-iw/strings.xml b/java/res/values-iw/strings.xml
index 90a6032..3c58b9c 100644
--- a/java/res/values-iw/strings.xml
+++ b/java/res/values-iw/strings.xml
@@ -44,10 +44,8 @@
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"ברירת מחדל"</string>
     <string name="use_contacts_dict" msgid="4435317977804180815">"הצע שמות של אנשי קשר"</string>
     <string name="use_contacts_dict_summary" msgid="6599983334507879959">"השתמש בשמות מרשימת אנשי הקשר עבור הצעות ותיקונים"</string>
-    <!-- no translation found for use_double_space_period (8781529969425082860) -->
-    <skip />
-    <!-- no translation found for use_double_space_period_summary (6532892187247952799) -->
-    <skip />
+    <string name="use_double_space_period" msgid="8781529969425082860">"רווח כפול לנקודה"</string>
+    <string name="use_double_space_period_summary" msgid="6532892187247952799">"הקשה פעמיים על מקש הרווח מזינה נקודה ואחריה רווח"</string>
     <string name="auto_cap" msgid="1719746674854628252">"הפיכת אותיות לרישיות באופן אוטומטי"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"השתמש באות גדולה במילה הראשונה של כל משפט"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"הוספת מילונים"</string>
diff --git a/java/res/values-sw600dp/config.xml b/java/res/values-sw600dp/config.xml
index e296623..b47eacb 100644
--- a/java/res/values-sw600dp/config.xml
+++ b/java/res/values-sw600dp/config.xml
@@ -19,7 +19,7 @@
 -->
 
 <resources>
-    <!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_TABLET7} -->
+    <!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET7} -->
     <integer name="config_device_form_factor">1</integer>
     <bool name="config_enable_show_voice_key_option">false</bool>
     <bool name="config_enable_show_popup_on_keypress_option">false</bool>
diff --git a/java/res/values-sw768dp/config.xml b/java/res/values-sw768dp/config.xml
index 346fa99..5e79541 100644
--- a/java/res/values-sw768dp/config.xml
+++ b/java/res/values-sw768dp/config.xml
@@ -19,7 +19,7 @@
 -->
 
 <resources>
-    <!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_TABLET10} -->
+    <!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET10} -->
     <integer name="config_device_form_factor">2</integer>
     <bool name="config_enable_show_voice_key_option">false</bool>
     <bool name="config_enable_show_popup_on_keypress_option">false</bool>
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index dc5a3d1..dca370a 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -19,7 +19,7 @@
 -->
 
 <resources>
-    <!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_PHONE} -->
+    <!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_PHONE} -->
     <integer name="config_device_form_factor">0</integer>
     <bool name="config_use_fullscreen_mode">false</bool>
     <bool name="config_enable_show_voice_key_option">true</bool>
diff --git a/java/src/com/android/inputmethod/latin/DebugSettings.java b/java/src/com/android/inputmethod/latin/DebugSettings.java
index 989451b..f8aeb4e 100644
--- a/java/src/com/android/inputmethod/latin/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/DebugSettings.java
@@ -16,7 +16,6 @@
 
 package com.android.inputmethod.latin;
 
-import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.pm.PackageInfo;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 179b56b..3935f99 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1085,7 +1085,7 @@
     public boolean onEvaluateFullscreenMode() {
         // Reread resource value here, because this method is called by framework anytime as needed.
         final boolean isFullscreenModeAllowed =
-                mCurrentSettings.isFullscreenModeAllowed(getResources());
+                SettingsValues.isFullscreenModeAllowed(getResources());
         if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
             // TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
             // implies NO_FULLSCREEN. However, the framework mistakenly does.  i.e. NO_EXTRACT_UI
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 23887c4..8612746 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -65,12 +65,6 @@
      * This contains the currently composing text, as LatinIME thinks the TextView is seeing it.
      */
     private StringBuilder mComposingText = new StringBuilder();
-    /**
-     * This is a one-character string containing the character after the cursor. Since LatinIME
-     * never touches it directly, it's never modified by any means other than re-reading from the
-     * TextView when the cursor position is changed by the user.
-     */
-    private CharSequence mCharAfterTheCursor = "";
     // A hint on how many characters to cache from the TextView. A good value of this is given by
     // how many characters we need to be able to almost always find the caps mode.
     private static final int DEFAULT_TEXT_CACHE_SIZE = 100;
@@ -146,7 +140,6 @@
         mCommittedTextBeforeComposingText.setLength(0);
         final CharSequence textBeforeCursor = getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE, 0);
         if (null != textBeforeCursor) mCommittedTextBeforeComposingText.append(textBeforeCursor);
-        mCharAfterTheCursor = getTextAfterCursor(1, 0);
         if (null != mIC) {
             mIC.finishComposingText();
             if (ProductionFlag.IS_EXPERIMENTAL) {
@@ -398,6 +391,7 @@
         if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
     }
 
+    @SuppressWarnings("unused")
     public String getNthPreviousWord(final String sentenceSeperators, final int n) {
         mIC = mParent.getCurrentInputConnection();
         if (null == mIC) return null;
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
index 7871977..100e377 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
@@ -63,7 +63,7 @@
 
         @Override
         public int readUnsignedByte() {
-            return ((int)mBuffer[mPosition++]) & 0xFF;
+            return mBuffer[mPosition++] & 0xFF;
         }
 
         @Override
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
index 4fd9bfa..f30a60a 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java
@@ -376,10 +376,10 @@
                     final byte fc = fcp.getFc();
                     final boolean isValid = fcp.isValid();
                     if (prevFc > 0 && prevFc == fc) {
-                        freq = ((int)fc) & 0xFF;
+                        freq = fc & 0xFF;
                     } else if (UserHistoryForgettingCurveUtils.
                             needsToSave(fc, isValid, mAddLevel0Bigrams)) {
-                        freq = ((int)fc) & 0xFF;
+                        freq = fc & 0xFF;
                     } else {
                         // Delete this entry
                         freq = -1;
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 876bc8e..3eac6a2 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -41,6 +41,7 @@
 import java.nio.channels.FileChannel;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
 
 public final class Utils {
     private Utils() {
@@ -193,7 +194,7 @@
 
         private UsabilityStudyLogUtils() {
             mDate = new Date();
-            mDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss.SSSZ");
+            mDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss.SSSZ", Locale.US);
 
             HandlerThread handlerThread = new HandlerThread("UsabilityStudyLogUtils logging task",
                     Process.THREAD_PRIORITY_BACKGROUND);
@@ -255,7 +256,7 @@
                     final long currentTime = System.currentTimeMillis();
                     mDate.setTime(currentTime);
 
-                    final String printString = String.format("%s\t%d\t%s\n",
+                    final String printString = String.format(Locale.US, "%s\t%d\t%s\n",
                             mDateFormat.format(mDate), currentTime, log);
                     if (LatinImeLogger.sDBG) {
                         Log.d(USABILITY_TAG, "Write: " + log);
@@ -297,7 +298,7 @@
                     final Date date = new Date();
                     date.setTime(System.currentTimeMillis());
                     final String currentDateTimeString =
-                            new SimpleDateFormat("yyyyMMdd-HHmmssZ").format(date);
+                            new SimpleDateFormat("yyyyMMdd-HHmmssZ", Locale.US).format(date);
                     if (mFile == null) {
                         Log.w(USABILITY_TAG, "No internal log file found.");
                         return;
@@ -313,11 +314,15 @@
                             + "/research-" + currentDateTimeString + ".log";
                     final File destFile = new File(destPath);
                     try {
-                        final FileChannel src = (new FileInputStream(mFile)).getChannel();
-                        final FileChannel dest = (new FileOutputStream(destFile)).getChannel();
+                        final FileInputStream srcStream = new FileInputStream(mFile);
+                        final FileOutputStream destStream = new FileOutputStream(destFile);
+                        final FileChannel src = srcStream.getChannel();
+                        final FileChannel dest = destStream.getChannel();
                         src.transferTo(0, src.size(), dest);
                         src.close();
+                        srcStream.close();
                         dest.close();
+                        destStream.close();
                     } catch (FileNotFoundException e1) {
                         Log.w(USABILITY_TAG, e1);
                         return;
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index d1a3c7b..fb1eb27 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -921,6 +921,7 @@
      * @param formatOptions file format options.
      * @return the address of the END of the node.
      */
+    @SuppressWarnings("unused")
     private static int writePlacedNode(final FusionDictionary dict, byte[] buffer,
             final Node node, final FormatOptions formatOptions) {
         // TODO: Make the code in common with BinaryDictIOUtils#writeCharGroup
@@ -1407,6 +1408,7 @@
     // TODO: static!? This will behave erratically when used in multi-threaded code.
     // We need to fix this
     private static int[] sGetWordBuffer = new int[FormatSpec.MAX_WORD_LENGTH];
+    @SuppressWarnings("unused")
     private static WeightedString getWordAtAddressWithParentAddress(
             final FusionDictionaryBufferInterface buffer, final int headerSize, final int address,
             final FormatOptions options) {
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index b0b3777..ee647ab 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -617,6 +617,7 @@
     /**
      * Helper method to find a word in a given branch.
      */
+    @SuppressWarnings("unused")
     public static CharGroup findWordInTree(Node node, final String s) {
         int index = 0;
         final StringBuilder checker = DBG ? new StringBuilder() : null;
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index 3443b7a..982d104 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -57,7 +57,6 @@
 import com.android.inputmethod.keyboard.KeyboardId;
 import com.android.inputmethod.keyboard.KeyboardView;
 import com.android.inputmethod.keyboard.MainKeyboardView;
-import com.android.inputmethod.latin.CollectionUtils;
 import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.Dictionary;
 import com.android.inputmethod.latin.InputTypeUtils;
@@ -144,7 +143,6 @@
     private final Statistics mStatistics;
 
     private Intent mUploadIntent;
-    private PendingIntent mUploadPendingIntent;
 
     private LogUnit mCurrentLogUnit = new LogUnit();
 
@@ -189,7 +187,6 @@
         mInputMethodService = ims;
         mPrefs = prefs;
         mUploadIntent = new Intent(mInputMethodService, UploaderService.class);
-        mUploadPendingIntent = PendingIntent.getService(mInputMethodService, 0, mUploadIntent, 0);
 
         if (ProductionFlag.IS_EXPERIMENTAL) {
             scheduleUploadingService(mInputMethodService);
@@ -428,21 +425,6 @@
     }
 
     private long mResumeTime = 0L;
-    private void suspendLoggingUntil(long time) {
-        mIsLoggingSuspended = true;
-        mResumeTime = time;
-        requestIndicatorRedraw();
-    }
-
-    private void resumeLogging() {
-        mResumeTime = 0L;
-        updateSuspendedState();
-        requestIndicatorRedraw();
-        if (isAllowedToLog()) {
-            restart();
-        }
-    }
-
     private void updateSuspendedState() {
         final long time = System.currentTimeMillis();
         if (time > mResumeTime) {
@@ -840,10 +822,6 @@
         stop();
     }
 
-    private static final String[] EVENTKEYS_USER_FEEDBACK = {
-        "UserFeedback", "FeedbackContents"
-    };
-
     private static final String[] EVENTKEYS_PREFS_CHANGED = {
         "PrefsChanged", "prefs"
     };
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 3809027..631b31f 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -208,9 +208,9 @@
 #define DEBUG_CORRECTION false
 #define DEBUG_CORRECTION_FREQ false
 #define DEBUG_WORDS_PRIORITY_QUEUE false
-#define DEBUG_SAMPLING_POINTS true
-#define DEBUG_POINTS_PROBABILITY true
-#define DEBUG_DOUBLE_LETTER true
+#define DEBUG_SAMPLING_POINTS false
+#define DEBUG_POINTS_PROBABILITY false
+#define DEBUG_DOUBLE_LETTER false
 
 #ifdef FLAG_FULL_DBG
 #define DEBUG_GEO_FULL true
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index a1e20cf..7879175 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -1143,9 +1143,9 @@
     return true;
 }
 
-// Get a word that is detected by tracing highest probability sequence into codePointBuf and
+// Get a word that is detected by tracing the most probable char sequence into codePointBuf and
 // returns probability of generating the word.
-float ProximityInfoState::getHighestProbabilitySequence(int *const codePointBuf) const {
+float ProximityInfoState::getMostProbableCharSequence(int *const codePointBuf) const {
     static const float DEMOTION_LOG_PROBABILITY = 0.3f;
     int index = 0;
     float sumLogProbability = 0.0f;
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index 5f968e1..a986e20 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -196,7 +196,7 @@
     // Returns angle of three points. x, y, and z are indices.
     float getPointsAngle(const int index0, const int index1, const int index2) const;
 
-    float getHighestProbabilitySequence(int *const codePointBuf) const;
+    float getMostProbableCharSequence(int *const codePointBuf) const;
 
     float getProbability(const int index, const int charCode) const;