Merge "Put the LoggingEvents class in sync with latest - adds some VoiceSearch events which won't be used by LatinIME."
diff --git a/Android.mk b/Android.mk
index 4c842c5..fd6c97e 100755
--- a/Android.mk
+++ b/Android.mk
@@ -11,7 +11,7 @@
 
 LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime
 
-LOCAL_AAPT_FLAGS := -0 .dict
+#LOCAL_AAPT_FLAGS := -0 .dict
 
 include $(BUILD_PACKAGE)
 include $(LOCAL_PATH)/dictionary/Android.mk
diff --git a/res/values/donottranslate.xml b/res/values/donottranslate.xml
index d9649f3..b9cfbd1 100644
--- a/res/values/donottranslate.xml
+++ b/res/values/donottranslate.xml
@@ -21,7 +21,7 @@
     <!-- Symbols that are commonly considered word separators in this language -->
     <string name="word_separators">.\u0020,;:!?\n()[]*&amp;@{}/&lt;&gt;_+=|\u0022</string>
     <!-- Symbols that are sentence separators, for purposes of making it hug the last sentence. -->
-    <string name="sentence_separators">.,;:!?</string>
+    <string name="sentence_separators">.,!?</string>
     <!-- Accented characters related to "d" -->
     <string name="alternates_for_d"></string>
     <!-- Accented characters related to "r" -->
diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java
index 762f292..a9a61c3 100644
--- a/src/com/android/inputmethod/latin/LatinIME.java
+++ b/src/com/android/inputmethod/latin/LatinIME.java
@@ -815,15 +815,19 @@
         InputConnection ic = getCurrentInputConnection();
         if (attr != null && mInputView != null && mKeyboardSwitcher.isAlphabetMode()
                 && ic != null) {
-            int caps = 0;
-            EditorInfo ei = getCurrentInputEditorInfo();
-            if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
-                caps = ic.getCursorCapsMode(attr.inputType);
-            }
-            mInputView.setShifted(mCapsLock || caps != 0);
+            mInputView.setShifted(mCapsLock || getCursorCapsMode(ic, attr) != 0);
         }
     }
-    
+
+    private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
+        int caps = 0;
+        EditorInfo ei = getCurrentInputEditorInfo();
+        if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
+            caps = ic.getCursorCapsMode(attr.inputType);
+        }
+        return caps;
+    }
+
     private void swapPunctuationAndSpace() {
         final InputConnection ic = getCurrentInputConnection();
         if (ic == null) return;
@@ -837,7 +841,7 @@
             updateShiftKeyState(getCurrentInputEditorInfo());
         }
     }
-    
+
     private void doubleSpace() {
         //if (!mAutoPunctuate) return;
         if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
@@ -893,7 +897,7 @@
             case LatinKeyboardView.KEYCODE_OPTIONS:
                 showOptionsMenu();
                 break;
-            case LatinKeyboardView.KEYCODE_F1:
+            case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE:
                 toggleLanguage(false);
                 break;
             case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS:
@@ -1014,6 +1018,11 @@
             mWord.add(primaryCode, keyCodes);
             InputConnection ic = getCurrentInputConnection();
             if (ic != null) {
+                // If it's the first letter, make note of auto-caps state
+                if (mWord.size() == 1) {
+                    mWord.setAutoCapitalized(
+                            getCursorCapsMode(ic, getCurrentInputEditorInfo()) != 0);
+                }
                 ic.setComposingText(mComposing, 1);
             }
             postUpdateSuggestions();
@@ -1847,6 +1856,11 @@
             final int length = word.length();
             // Don't add very short or very long words.
             if (length < 2 || length > getMaxWordLength()) return;
+            if (mWord.isAutoCapitalized()) {
+                // Remove caps before adding
+                word = Character.toLowerCase(word.charAt(0))
+                        + word.substring(1);
+            }
             int freq = getWordFrequency(word);
             freq = freq < 0 ? addFrequency : freq + addFrequency;
             super.addWord(word, freq);
diff --git a/src/com/android/inputmethod/latin/LatinKeyboard.java b/src/com/android/inputmethod/latin/LatinKeyboard.java
index 0591312..f5748f4 100644
--- a/src/com/android/inputmethod/latin/LatinKeyboard.java
+++ b/src/com/android/inputmethod/latin/LatinKeyboard.java
@@ -42,7 +42,7 @@
     private Key mEnterKey;
     private Key mF1Key;
     private Key mSpaceKey;
-    private Locale mLocale;
+    /* package */ Locale mLocale;
     private Resources mRes;
     private int mMode;
 
@@ -227,17 +227,40 @@
     }
 
     private void setF1Key() {
-        if (mF1Key == null) return; // No function key on this keyboard
+        // TODO
+//        else {
+//            mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
+//            switch (mMode) {
+//            case KeyboardSwitcher.KEYBOARDMODE_NORMAL:
+//            case KeyboardSwitcher.KEYBOARDMODE_IM:
+//                mF1Key.label = ",";
+//                mF1Key.codes = new int[] { ',' };
+//                mF1Key.icon = null;
+//                mF1Key.iconPreview = null;
+//                break;
+//            case KeyboardSwitcher.KEYBOARDMODE_EMAIL:
+//            case KeyboardSwitcher.KEYBOARDMODE_URL:
+//                mF1Key.label = mRes.getString(R.string.popular_domain_0);
+//                mF1Key.codes = new int[] { '.' };
+//                mF1Key.text = mF1Key.label;
+//                mF1Key.icon = null;
+//                mF1Key.iconPreview = null;
+//                mF1Key.popupResId = R.xml.popup_domains;
+//                break;
+//            }
+//        }
+    }
+
+    private void updateSpaceBarForLocale() {
         if (mLocale != null) {
             // Create the graphic for spacebar
-            mF1Key.label = null;
-            mF1Key.icon = mRes.getDrawable(R.drawable.sym_keyboard_globe);
             Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
                     Bitmap.Config.ARGB_8888);
             Canvas canvas = new Canvas(buffer);
             canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
             Paint paint = new Paint();
             paint.setAntiAlias(true);
+            // TODO: Make the text size a customizable attribute
             paint.setTextSize(22);
             paint.setTextAlign(Align.CENTER);
             // Draw a drop shadow for the text
@@ -250,36 +273,18 @@
             mSpaceIcon.setBounds(x, y, 
                     x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight());
             mSpaceIcon.draw(canvas);
-            mSpaceKey.icon = new BitmapDrawable(mRes, buffer);            
+            mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
+            mSpaceKey.repeatable = false;
         } else {
             mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
-            switch (mMode) {
-            case KeyboardSwitcher.KEYBOARDMODE_NORMAL:
-            case KeyboardSwitcher.KEYBOARDMODE_IM:
-                mF1Key.label = ",";
-                mF1Key.codes = new int[] { ',' };
-                mF1Key.icon = null;
-                mF1Key.iconPreview = null;
-                break;
-            case KeyboardSwitcher.KEYBOARDMODE_EMAIL:
-            case KeyboardSwitcher.KEYBOARDMODE_URL:
-                mF1Key.label = mRes.getString(R.string.popular_domain_0);
-                mF1Key.codes = new int[] { '.' };
-                mF1Key.text = mF1Key.label;
-                mF1Key.icon = null;
-                mF1Key.iconPreview = null;
-                mF1Key.popupResId = R.xml.popup_domains;
-                break;
-            }
+            mSpaceKey.repeatable = true;
         }
     }
 
     public void setLanguage(Locale locale) {
         if (mLocale != null && mLocale.equals(locale)) return;
         mLocale = locale;
-        setF1Key();
-        if (mF1Key != null) {
-        }
+        updateSpaceBarForLocale();
     }
 
     static class LatinKey extends Keyboard.Key {
diff --git a/src/com/android/inputmethod/latin/LatinKeyboardView.java b/src/com/android/inputmethod/latin/LatinKeyboardView.java
index ea9ccf0..a88c181 100644
--- a/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -37,6 +37,8 @@
     static final int KEYCODE_SHIFT_LONGPRESS = -101;
     static final int KEYCODE_VOICE = -102;
     static final int KEYCODE_F1 = -103;
+    static final int KEYCODE_NEXT_LANGUAGE = -104;
+
     private Keyboard mPhoneKeyboard;
 
     public LatinKeyboardView(Context context, AttributeSet attrs) {
@@ -64,6 +66,9 @@
             // Long pressing on 0 in phone number keypad gives you a '+'.
             getOnKeyboardActionListener().onKey('+', null);
             return true;
+        } else if (key.codes[0] == ' ' && ((LatinKeyboard)getKeyboard()).mLocale != null) {
+            getOnKeyboardActionListener().onKey(KEYCODE_NEXT_LANGUAGE, null);
+            return true;
         } else {
             return super.onLongPress(key);
         }
diff --git a/src/com/android/inputmethod/latin/WordComposer.java b/src/com/android/inputmethod/latin/WordComposer.java
index 50725d4..e97cb24 100644
--- a/src/com/android/inputmethod/latin/WordComposer.java
+++ b/src/com/android/inputmethod/latin/WordComposer.java
@@ -36,6 +36,8 @@
     private StringBuilder mTypedWord;
 
     private int mCapsCount;
+
+    private boolean mAutoCapitalized;
     
     /**
      * Whether the user chose to capitalize the word.
@@ -152,4 +154,21 @@
     public boolean isMostlyCaps() {
         return mCapsCount > 1;
     }
+
+    /** 
+     * Saves the reason why the word is capitalized - whether it was automatic or
+     * due to the user hitting shift in the middle of a sentence.
+     * @param auto whether it was an automatic capitalization due to start of sentence
+     */
+    public void setAutoCapitalized(boolean auto) {
+        mAutoCapitalized = auto;
+    }
+
+    /**
+     * Returns whether the word was automatically capitalized.
+     * @return whether the word was automatically capitalized
+     */
+    public boolean isAutoCapitalized() {
+        return mAutoCapitalized;
+    }
 }