Merge "Fix NPE introduced by Change-Id: Ie482167b2ae2804fa1aa43ffb5067af47b7553f1"
diff --git a/java/res/xml-en/dictionary.xml b/java/res/xml-en/dictionary.xml
deleted file mode 100644
index 74af75a..0000000
--- a/java/res/xml-en/dictionary.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, 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.
-*/
--->
-
-<dictionary>
-    <part name = "main0" />
-    <part name = "main1" />
-    <part name = "main2" />
-</dictionary>
\ No newline at end of file
diff --git a/java/res/xml/kbd_alpha_black.xml b/java/res/xml/kbd_alpha_black.xml
new file mode 100644
index 0000000..108e466
--- /dev/null
+++ b/java/res/xml/kbd_alpha_black.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, 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.
+*/
+-->
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+    android:keyWidth="10%p"
+    android:horizontalGap="0px"
+    android:verticalGap="0px"
+    android:keyHeight="@dimen/key_height"
+    >
+
+    <Row>
+        <Key android:keyLabel="a"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_a"
+                android:keyEdgeFlags="left" />
+        <Key android:keyLabel="b" />
+        <Key android:keyLabel="c"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_c" />
+        <Key android:keyLabel="d" />
+        <Key android:keyLabel="e"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_e" />
+        <Key android:keyLabel="f" />
+        <Key android:keyLabel="g" />
+        <Key android:keyLabel="h" />
+        <Key android:keyLabel="i"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_i" />
+        <Key android:keyLabel="j" android:keyEdgeFlags="right" />
+    </Row>
+    <Row>
+        <Key android:keyLabel="k" android:keyEdgeFlags="left" />
+        <Key android:keyLabel="l" />
+        <Key android:keyLabel="m" />
+        <Key android:keyLabel="n"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_n" />
+        <Key android:keyLabel="o"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_o" />
+        <Key android:keyLabel="p" />
+        <Key android:keyLabel="q" />
+        <Key android:keyLabel="r" />
+        <Key android:keyLabel="s"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_s" />
+        <Key android:keyLabel="t" android:keyEdgeFlags="right" />
+    </Row>
+
+    <Row>
+        <Key android:codes="-1" android:keyIcon="@drawable/sym_bkeyboard_shift"
+                android:keyWidth="15%p" android:isModifier="true"
+                android:iconPreview="@drawable/sym_keyboard_feedback_shift"
+                android:isSticky="true" android:keyEdgeFlags="left"/>
+        <Key android:keyLabel="u"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_u" />
+        <Key android:keyLabel="v"/>
+        <Key android:keyLabel="w"/>
+        <Key android:keyLabel="x"/>
+        <Key android:keyLabel="y"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="@string/alternates_for_y"
+        />
+        <Key android:keyLabel="z"/>
+        <Key android:keyLabel=","/>
+        <Key android:codes="-5" android:keyIcon="@drawable/sym_bkeyboard_delete"
+                android:keyWidth="15%p" android:keyEdgeFlags="right"
+                android:iconPreview="@drawable/sym_keyboard_feedback_delete"
+                android:isRepeatable="true"/>
+    </Row>
+
+    <Row android:rowEdgeFlags="bottom">
+        <Key android:codes="-3" android:keyIcon="@drawable/sym_bkeyboard_done"
+                android:iconPreview="@drawable/sym_keyboard_feedback_done"
+                android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+        <Key android:codes="-2" android:keyLabel="123" android:keyWidth="15%p"/>
+        <Key android:codes="32" android:keyIcon="@drawable/sym_bkeyboard_space"
+                android:iconPreview="@drawable/sym_keyboard_feedback_space"
+                android:keyWidth="30%p" android:isRepeatable="true"/>
+        <Key android:codes="46" android:keyLabel="."
+                android:popupKeyboard="@xml/popup_punctuation"
+                android:keyWidth="15%p"/>
+        <Key android:codes="10" android:keyIcon="@drawable/sym_bkeyboard_return"
+                android:iconPreview="@drawable/sym_keyboard_feedback_return"
+                android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+    </Row>
+</Keyboard>
diff --git a/java/res/xml/kbd_phone_black.xml b/java/res/xml/kbd_phone_black.xml
new file mode 100755
index 0000000..b7f9096
--- /dev/null
+++ b/java/res/xml/kbd_phone_black.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, 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.
+*/
+-->
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+    android:keyWidth="26.67%p"
+    android:horizontalGap="0px"
+    android:verticalGap="0px"
+    android:keyHeight="@dimen/key_height"
+    >
+
+    <Row>
+        <Key android:codes="49" android:keyIcon="@drawable/sym_bkeyboard_num1" android:keyEdgeFlags="left"/>
+        <Key android:codes="50" android:keyIcon="@drawable/sym_bkeyboard_num2"/>
+        <Key android:codes="51" android:keyIcon="@drawable/sym_bkeyboard_num3"/>
+        <Key android:keyLabel="-" android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row>
+        <Key android:codes="52" android:keyIcon="@drawable/sym_bkeyboard_num4" android:keyEdgeFlags="left"/>
+        <Key android:codes="53" android:keyIcon="@drawable/sym_bkeyboard_num5"/>
+        <Key android:codes="54" android:keyIcon="@drawable/sym_bkeyboard_num6"/>
+        <Key android:keyLabel="." android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row>
+        <Key android:codes="55" android:keyIcon="@drawable/sym_bkeyboard_num7" android:keyEdgeFlags="left"/>
+        <Key android:codes="56" android:keyIcon="@drawable/sym_bkeyboard_num8"/>
+        <Key android:codes="57" android:keyIcon="@drawable/sym_bkeyboard_num9"/>
+        <Key android:codes="-5" android:keyIcon="@drawable/sym_bkeyboard_delete"
+                android:iconPreview="@drawable/sym_keyboard_feedback_delete"
+                android:keyWidth="20%p"
+                android:isRepeatable="true" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row android:rowEdgeFlags="bottom">
+        <Key android:codes="-2" android:keyIcon="@drawable/sym_bkeyboard_numalt"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="_"
+                android:iconPreview="@drawable/sym_keyboard_feedback_numalt"/>
+
+        <Key android:codes="48" android:keyIcon="@drawable/sym_bkeyboard_num0"/>
+
+        <Key android:codes="32" android:keyIcon="@drawable/sym_bkeyboard_space"
+                android:iconPreview="@drawable/sym_keyboard_feedback_space"
+                android:isRepeatable="true"/>
+        <Key android:codes="10" android:keyIcon="@drawable/sym_bkeyboard_return"
+                android:keyWidth="20%p"
+                android:keyEdgeFlags="right"/>
+    </Row>
+
+</Keyboard>
diff --git a/java/res/xml/kbd_phone_symbols_black.xml b/java/res/xml/kbd_phone_symbols_black.xml
new file mode 100755
index 0000000..c73e5fa
--- /dev/null
+++ b/java/res/xml/kbd_phone_symbols_black.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, 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.
+*/
+-->
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+    android:keyWidth="26.67%p"
+    android:horizontalGap="0px"
+    android:verticalGap="0px"
+    android:keyHeight="@dimen/key_height"
+    >
+
+    <Row>
+        <Key android:keyLabel="(" android:keyEdgeFlags="left"/>
+        <Key android:keyLabel="/"/>
+        <Key android:keyLabel=")"/>
+        <Key android:keyLabel="-" android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row>
+        <Key android:keyLabel="N" android:keyEdgeFlags="left"/>
+        <!-- Pause is a comma.
+                Check PhoneNumberUtils.java to see if this has changed. -->
+        <Key android:codes="44" android:keyLabel="Pause"/>
+        <Key android:keyLabel=","/>
+        <Key android:keyLabel="." android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row>
+        <Key android:codes="42" android:keyIcon="@drawable/sym_bkeyboard_numstar"
+                android:keyEdgeFlags="left"/>
+        <!-- Wait is a semicolon. -->
+        <Key android:codes="59" android:keyLabel="Wait"/>
+        <Key android:codes="35" android:keyIcon="@drawable/sym_bkeyboard_numpound"/>
+        <Key android:codes="-5" android:keyIcon="@drawable/sym_bkeyboard_delete"
+                android:iconPreview="@drawable/sym_keyboard_feedback_delete"
+                android:keyWidth="20%p"
+                android:isRepeatable="true" android:keyEdgeFlags="right"/>
+    </Row>
+
+    <Row android:rowEdgeFlags="bottom">
+        <Key android:codes="-2" android:keyLabel="@string/label_phone_key"
+                android:popupKeyboard="@xml/kbd_popup_template"
+                android:popupCharacters="_"
+                android:keyEdgeFlags="left"/>
+        <Key android:keyLabel="+"/>
+        <Key android:codes="32" android:keyIcon="@drawable/sym_bkeyboard_space"
+                android:iconPreview="@drawable/sym_keyboard_feedback_space"
+                android:isRepeatable="true"/>
+        <Key android:codes="10" android:keyIcon="@drawable/sym_bkeyboard_return"
+                android:keyWidth="20%p"
+                android:keyEdgeFlags="right"/>
+    </Row>
+
+</Keyboard>
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index 95068e6..bcf4902 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -50,10 +50,25 @@
 
     public static final String DEFAULT_LAYOUT_ID = "3";
     public static final String PREF_KEYBOARD_LAYOUT = "keyboard_layout";
-    private static final int[] LAYOUTS = new int [] {
+    private static final int[] THEMES = new int [] {
         R.layout.input_basic, R.layout.input_basic_highcontrast, R.layout.input_stone_normal,
         R.layout.input_stone_bold};
 
+    // Ids for each characters' color in the keyboard
+    private static final int CHAR_THEME_COLOR_WHITE = 0;
+    private static final int CHAR_THEME_COLOR_BLACK = 1;
+
+    // Tables which contains resource ids for each character theme color
+    private static final int[] KBD_ALPHA = new int[] {R.xml.kbd_alpha, R.xml.kbd_alpha_black};
+    private static final int[] KBD_PHONE = new int[] {R.xml.kbd_phone, R.xml.kbd_phone_black};
+    private static final int[] KBD_PHONE_SYMBOLS = new int[] {
+        R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black};
+    private static final int[] KBD_SYMBOLS = new int[] {
+        R.xml.kbd_symbols, R.xml.kbd_symbols_black};
+    private static final int[] KBD_SYMBOLS_SHIFT = new int[] {
+        R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black};
+    private static final int[] KBD_QWERTY = new int[] {R.xml.kbd_qwerty, R.xml.kbd_qwerty_black};
+
     private static final int SYMBOLS_MODE_STATE_NONE = 0;
     private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
     private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
@@ -119,13 +134,11 @@
     }
 
     private KeyboardId makeSymbolsId(boolean hasVoice) {
-        return new KeyboardId(
-                isBlackSym() ? R.xml.kbd_symbols_black : R.xml.kbd_symbols, hasVoice);
+        return new KeyboardId(KBD_SYMBOLS[getCharColorId()], hasVoice);
     }
 
     private KeyboardId makeSymbolsShiftedId(boolean hasVoice) {
-        return new KeyboardId(
-                isBlackSym() ? R.xml.kbd_symbols_shift_black : R.xml.kbd_symbols_shift, hasVoice);
+        return new KeyboardId(KBD_SYMBOLS_SHIFT[getCharColorId()], hasVoice);
     }
 
     void makeKeyboards(boolean forceCreate) {
@@ -270,11 +283,15 @@
 
     private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) {
         boolean hasVoice = hasVoiceButton(isSymbols);
+        int charColorId = getCharColorId();
         // TODO: generalize for any KeyboardId
-        int keyboardRowsResId = isBlackSym() ? R.xml.kbd_qwerty_black : R.xml.kbd_qwerty;
+        int keyboardRowsResId = KBD_QWERTY[charColorId];
         if (isSymbols) {
-            return (mode == MODE_PHONE)
-                ? new KeyboardId(R.xml.kbd_phone_symbols, hasVoice) : makeSymbolsId(hasVoice);
+            if (mode == MODE_PHONE) {
+                return new KeyboardId(KBD_PHONE_SYMBOLS[charColorId], hasVoice);
+            } else {
+                return new KeyboardId(KBD_SYMBOLS[charColorId], hasVoice);
+            }
         }
         switch (mode) {
             case MODE_NONE:
@@ -283,14 +300,15 @@
                 /* fall through */
             case MODE_TEXT:
                 if (mTextMode == MODE_TEXT_ALPHA) {
-                    return new KeyboardId(R.xml.kbd_alpha, KEYBOARDMODE_NORMAL, true, hasVoice);
+                    return new KeyboardId(
+                            KBD_ALPHA[charColorId], KEYBOARDMODE_NORMAL, true, hasVoice);
                 }
                 // Normally mTextMode should be MODE_TEXT_QWERTY.
                 return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_NORMAL, true, hasVoice);
             case MODE_SYMBOLS:
-                return makeSymbolsId(hasVoice);
+                return new KeyboardId(KBD_SYMBOLS[charColorId], hasVoice);
             case MODE_PHONE:
-                return new KeyboardId(R.xml.kbd_phone, hasVoice);
+                return new KeyboardId(KBD_PHONE[charColorId], hasVoice);
             case MODE_URL:
                 return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_URL, true, hasVoice);
             case MODE_EMAIL:
@@ -387,7 +405,7 @@
             if (mInputView != null) {
                 mInputView.closing();
             }
-            if (LAYOUTS.length <= newLayout) {
+            if (THEMES.length <= newLayout) {
                 newLayout = Integer.valueOf(DEFAULT_LAYOUT_ID);
             }
 
@@ -396,7 +414,7 @@
             for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
                 try {
                     mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater(
-                            ).inflate(LAYOUTS[newLayout], null);
+                            ).inflate(THEMES[newLayout], null);
                     tryGC = false;
                 } catch (OutOfMemoryError e) {
                     tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
@@ -406,7 +424,7 @@
                             mLayoutId + "," + newLayout, e);
                 }
             }
-            mInputView.setExtentionLayoutResId(LAYOUTS[newLayout]);
+            mInputView.setExtentionLayoutResId(THEMES[newLayout]);
             mInputView.setOnKeyboardActionListener(mInputMethodService);
             mLayoutId = newLayout;
         }
@@ -432,4 +450,13 @@
         }
         return false;
     }
+
+    private int getCharColorId () {
+        if (isBlackSym()) {
+            return CHAR_THEME_COLOR_BLACK;
+        } else {
+            return CHAR_THEME_COLOR_WHITE;
+        }
+    }
+
 }