Merge "Remove alt-code-while-typing from tablet"
diff --git a/java/res/xml-sw600dp/row_hebrew4.xml b/java/res/xml-sw600dp/row_hebrew4.xml
new file mode 100644
index 0000000..e44d7d2
--- /dev/null
+++ b/java/res/xml-sw600dp/row_hebrew4.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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
+**
+**     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.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:keyWidth="8.9%p"
+    >
+        <Key
+            latin:keyStyle="toSymbolKeyStyle"
+            latin:keyWidth="13.0%p" />
+        <Key
+            latin:keyStyle="tabKeyStyle" />
+        <include
+            latin:keyboardLayout="@xml/key_f1" />
+        <include
+            latin:keyboardLayout="@xml/key_space" />
+        <include
+            latin:keyboardLayout="@xml/keys_comma_period" />
+        <Spacer
+            latin:keyXPos="-10.00%p"
+            latin:keyWidth="0%p" />
+        <include
+            latin:keyboardLayout="@xml/key_shortcut" />
+    </Row>
+</merge>
diff --git a/java/res/xml-sw600dp/row_qwerty4.xml b/java/res/xml-sw600dp/row_qwerty4.xml
index 95b328b..58610ae 100644
--- a/java/res/xml-sw600dp/row_qwerty4.xml
+++ b/java/res/xml-sw600dp/row_qwerty4.xml
@@ -33,21 +33,10 @@
             latin:keyboardLayout="@xml/key_f1" />
         <include
             latin:keyboardLayout="@xml/key_space" />
-        <switch>
-            <case
-                latin:languageCode="iw"
-            >
-                <include
-                    latin:keyboardLayout="@xml/keys_comma_period" />
-            </case>
-            <!-- not languageCode="iw" -->
-            <default>
-                <include
-                    latin:keyboardLayout="@xml/key_apostrophe" />
-                <include
-                    latin:keyboardLayout="@xml/key_dash" />
-            </default>
-        </switch>
+        <include
+            latin:keyboardLayout="@xml/key_apostrophe" />
+        <include
+            latin:keyboardLayout="@xml/key_dash" />
         <Spacer
             latin:keyXPos="-10.00%p"
             latin:keyWidth="0%p" />
diff --git a/java/res/xml-sw600dp/rows_hebrew.xml b/java/res/xml-sw600dp/rows_hebrew.xml
index d6861e8..521473f 100644
--- a/java/res/xml-sw600dp/rows_hebrew.xml
+++ b/java/res/xml-sw600dp/rows_hebrew.xml
@@ -58,5 +58,5 @@
             latin:keyWidth="fillRight" />
     </Row>
     <include
-        latin:keyboardLayout="@xml/row_qwerty4" />
+        latin:keyboardLayout="@xml/row_hebrew4" />
 </merge>
diff --git a/java/res/xml-sw768dp/row_hebrew4.xml b/java/res/xml-sw768dp/row_hebrew4.xml
new file mode 100644
index 0000000..e95d5fb
--- /dev/null
+++ b/java/res/xml-sw768dp/row_hebrew4.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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
+**
+**     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.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:keyWidth="8.047%p"
+    >
+        <include
+            latin:keyboardLayout="@xml/key_settings" />
+        <Spacer
+            latin:keyXPos="15.157%p"
+            latin:keyWidth="0%p" />
+        <include
+            latin:keyboardLayout="@xml/keys_f1f2" />
+        <include
+            latin:keyboardLayout="@xml/key_space" />
+        <include
+            latin:keyboardLayout="@xml/keys_comma_period" />
+        <include
+            latin:keyboardLayout="@xml/key_shortcut" />
+    </Row>
+</merge>
diff --git a/java/res/xml-sw768dp/row_qwerty4.xml b/java/res/xml-sw768dp/row_qwerty4.xml
index a1011c8..b902d03 100644
--- a/java/res/xml-sw768dp/row_qwerty4.xml
+++ b/java/res/xml-sw768dp/row_qwerty4.xml
@@ -33,20 +33,10 @@
             latin:keyboardLayout="@xml/keys_f1f2" />
         <include
             latin:keyboardLayout="@xml/key_space" />
-        <switch>
-            <case
-                latin:languageCode="iw"
-            >
-                <include
-                    latin:keyboardLayout="@xml/keys_comma_period" />
-            </case>
-            <default>
-                <include
-                    latin:keyboardLayout="@xml/key_apostrophe" />
-                <include
-                    latin:keyboardLayout="@xml/key_dash" />
-            </default>
-        </switch>
+        <include
+            latin:keyboardLayout="@xml/key_apostrophe" />
+        <include
+            latin:keyboardLayout="@xml/key_dash" />
         <include
             latin:keyboardLayout="@xml/key_shortcut" />
     </Row>
diff --git a/java/res/xml-sw768dp/rows_hebrew.xml b/java/res/xml-sw768dp/rows_hebrew.xml
index e70f450..beb59b4 100644
--- a/java/res/xml-sw768dp/rows_hebrew.xml
+++ b/java/res/xml-sw768dp/rows_hebrew.xml
@@ -61,5 +61,5 @@
             latin:keyXPos="13.829%p" />
     </Row>
     <include
-        latin:keyboardLayout="@xml/row_qwerty4" />
+        latin:keyboardLayout="@xml/row_hebrew4" />
 </merge>
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 38e6d5a..d5bd7fd 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -880,18 +880,19 @@
         final KeyPreviewDrawParams params = mKeyPreviewDrawParams;
         final int keyDrawX = key.mX + key.mVisualInsetsLeft;
         final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
+        final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel;
         // What we show as preview should match what we show on a key top in onBufferDraw().
-        if (key.mLabel != null) {
+        if (label != null) {
             // TODO Should take care of temporaryShiftLabel here.
             previewText.setCompoundDrawables(null, null, null, null);
-            if (StringUtils.codePointCount(key.mLabel) > 1) {
+            if (StringUtils.codePointCount(label) > 1) {
                 previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize);
                 previewText.setTypeface(Typeface.DEFAULT_BOLD);
             } else {
                 previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mPreviewTextSize);
                 previewText.setTypeface(params.mKeyTextStyle);
             }
-            previewText.setText(key.mLabel);
+            previewText.setText(label);
         } else {
             previewText.setCompoundDrawables(null, null, null,
                     key.getPreviewIcon(mKeyboard.mIconsSet));
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java
index 160581c..a43b905 100644
--- a/java/src/com/android/inputmethod/latin/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/StringUtils.java
@@ -123,6 +123,23 @@
     }
 
     /**
+     * Returns true if cs contains any upper case characters.
+     *
+     * @param cs the CharSequence to check
+     * @return {@code true} if cs contains any upper case characters, {@code false} otherwise.
+     */
+    public static boolean hasUpperCase(final CharSequence cs) {
+        final int length = cs.length();
+        for (int i = 0, cp = 0; i < length; i += Character.charCount(cp)) {
+            cp = Character.codePointAt(cs, i);
+            if (Character.isUpperCase(cp)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
      * Remove duplicates from an array of strings.
      *
      * This method will always keep the first occurrence of all strings at their position
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 86753e2..7cbee4f 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -242,13 +242,8 @@
 
         mBigramSuggestions = new ArrayList<SuggestedWordInfo>(PREF_MAX_BIGRAMS);
 
-        CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase();
-        if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) {
-            prevWordForBigram = lowerPrevWord;
-        }
-        for (final Dictionary dictionary : mBigramDictionaries.values()) {
-            dictionary.getBigrams(sEmptyWordComposer, prevWordForBigram, this);
-        }
+        getAllBigrams(prevWordForBigram, sEmptyWordComposer);
+
         // Nothing entered: return all bigrams for the previous word
         int insertCount = Math.min(mBigramSuggestions.size(), mPrefMaxSuggestions);
         for (int i = 0; i < insertCount; ++i) {
@@ -290,13 +285,7 @@
             mBigramSuggestions = new ArrayList<SuggestedWordInfo>(PREF_MAX_BIGRAMS);
 
             if (!TextUtils.isEmpty(prevWordForBigram)) {
-                CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase();
-                if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) {
-                    prevWordForBigram = lowerPrevWord;
-                }
-                for (final Dictionary dictionary : mBigramDictionaries.values()) {
-                    dictionary.getBigrams(wordComposer, prevWordForBigram, this);
-                }
+                getAllBigrams(prevWordForBigram, wordComposer);
                 if (TextUtils.isEmpty(consideredWord)) {
                     // Nothing entered: return all bigrams for the previous word
                     int insertCount = Math.min(mBigramSuggestions.size(), mPrefMaxSuggestions);
@@ -409,6 +398,23 @@
                 false /* isObsoleteSuggestions */);
     }
 
+    /**
+     * Adds all bigram predictions for prevWord. Also checks the lower case version of prevWord if
+     * it contains any upper case characters.
+     */
+    private void getAllBigrams(final CharSequence prevWord, final WordComposer wordComposer) {
+        if (StringUtils.hasUpperCase(prevWord)) {
+            // TODO: Must pay attention to locale when changing case.
+            final CharSequence lowerPrevWord = prevWord.toString().toLowerCase();
+            for (final Dictionary dictionary : mBigramDictionaries.values()) {
+                dictionary.getBigrams(wordComposer, lowerPrevWord, this);
+            }
+        }
+        for (final Dictionary dictionary : mBigramDictionaries.values()) {
+            dictionary.getBigrams(wordComposer, prevWord, this);
+        }
+    }
+
     private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo(
             final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) {
         final SuggestedWordInfo typedWordInfo = suggestions.get(0);
diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
index 8a5a822..5db06ef 100644
--- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
@@ -88,4 +88,15 @@
         assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
                 StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5"));
     }
+
+    public void testHasUpperCase() {
+        assertTrue("single upper-case string", StringUtils.hasUpperCase("String"));
+        assertTrue("multi upper-case string", StringUtils.hasUpperCase("stRInG"));
+        assertTrue("all upper-case string", StringUtils.hasUpperCase("STRING"));
+        assertTrue("upper-case string with non-letters", StringUtils.hasUpperCase("He's"));
+
+        assertFalse("empty string", StringUtils.hasUpperCase(""));
+        assertFalse("lower-case string", StringUtils.hasUpperCase("string"));
+        assertFalse("lower-case string with non-letters", StringUtils.hasUpperCase("he's"));
+    }
 }