Merge "Predefined keyboard layouts are configurable via XML resource"
diff --git a/java/res/xml-sw600dp/key_space.xml b/java/res/xml-sw600dp/key_space.xml
index 41f0dbd..4e1e15b 100644
--- a/java/res/xml-sw600dp/key_space.xml
+++ b/java/res/xml-sw600dp/key_space.xml
@@ -24,18 +24,39 @@
     <switch>
         <case
             latin:languageCode="fa"
+            latin:languageSwitchKeyEnabled="true"
+        >
+            <Key
+                latin:keyStyle="languageSwitchKeyStyle" />
+            <Key
+                latin:keyStyle="spaceKeyStyle"
+                latin:keyWidth="21.950%p" />
+            <Key
+                latin:keyStyle="zwnjKeyStyle" />
+        </case>
+        <case
+            latin:languageCode="fa"
+            latin:languageSwitchKeyEnabled="false"
         >
             <Key
                 latin:keyStyle="spaceKeyStyle"
-                latin:keyXPos="30.750%p"
                 latin:keyWidth="30.850%p" />
             <Key
                 latin:keyStyle="zwnjKeyStyle" />
         </case>
+        <case
+            latin:languageSwitchKeyEnabled="true"
+        >
+            <Key
+                latin:keyStyle="languageSwitchKeyStyle" />
+            <Key
+                latin:keyStyle="spaceKeyStyle"
+                latin:keyWidth="30.850%p" />
+        </case>
+        <!-- languageSwitchKeyEnabled="false" -->
         <default>
             <Key
                 latin:keyStyle="spaceKeyStyle"
-                latin:keyXPos="30.750%p"
                 latin:keyWidth="39.750%p" />
         </default>
     </switch>
diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml
index 54ec548..bf392a3 100644
--- a/java/res/xml-sw600dp/key_styles_common.xml
+++ b/java/res/xml-sw600dp/key_styles_common.xml
@@ -101,6 +101,12 @@
         latin:keyActionFlags="noKeyPreview|altCodeWhileTyping"
         latin:backgroundType="functional" />
     <key-style
+        latin:styleName="languageSwitchKeyStyle"
+        latin:code="!code/key_language_switch"
+        latin:keyIcon="!icon/language_switch_key"
+        latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
+        latin:altCode="!code/key_space" />
+    <key-style
         latin:styleName="settingsKeyStyle"
         latin:code="!code/key_settings"
         latin:keyIcon="!icon/settings_key"
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
index e4d081b..a4670da 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
@@ -49,7 +49,10 @@
      */
     private static final int FILE_READ_BUFFER_SIZE = 1024;
     // TODO: make the following data common with the native code
-    private static final byte[] MAGIC_NUMBER = new byte[] { 0x78, (byte)0xB1 };
+    private static final byte[] MAGIC_NUMBER_VERSION_1 =
+            new byte[] { (byte)0x78, (byte)0xB1, (byte)0x00, (byte)0x00 };
+    private static final byte[] MAGIC_NUMBER_VERSION_2 =
+            new byte[] { (byte)0x9B, (byte)0xC1, (byte)0x3A, (byte)0xFE };
 
     private static final String DICTIONARY_PROJECTION[] = { "id" };
 
@@ -268,15 +271,18 @@
     private static void checkMagicAndCopyFileTo(final BufferedInputStream input,
             final FileOutputStream output) throws FileNotFoundException, IOException {
         // Check the magic number
-        final byte[] magicNumberBuffer = new byte[MAGIC_NUMBER.length];
-        final int readMagicNumberSize = input.read(magicNumberBuffer, 0, MAGIC_NUMBER.length);
-        if (readMagicNumberSize < MAGIC_NUMBER.length) {
+        final int length = MAGIC_NUMBER_VERSION_2.length;
+        final byte[] magicNumberBuffer = new byte[length];
+        final int readMagicNumberSize = input.read(magicNumberBuffer, 0, length);
+        if (readMagicNumberSize < length) {
             throw new IOException("Less bytes to read than the magic number length");
         }
-        if (!Arrays.equals(MAGIC_NUMBER, magicNumberBuffer)) {
-            throw new IOException("Wrong magic number for downloaded file");
+        if (!Arrays.equals(MAGIC_NUMBER_VERSION_2, magicNumberBuffer)) {
+            if (!Arrays.equals(MAGIC_NUMBER_VERSION_1, magicNumberBuffer)) {
+                throw new IOException("Wrong magic number for downloaded file");
+            }
         }
-        output.write(MAGIC_NUMBER);
+        output.write(magicNumberBuffer);
 
         // Actually copy the file
         final byte[] buffer = new byte[FILE_READ_BUFFER_SIZE];