From 10f18f5fb7b601f7778d179b9c30b1e781c1efc2 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Tue, 10 Apr 2012 19:06:03 +0900
Subject: [PATCH] Use system locale for labels on no language keyboard

Bug: 6010147
Change-Id: I9a6ce1bf82ca13359f715f4d1fc5f2bf15d4ee6e
---
 .../inputmethod/keyboard/Keyboard.java        | 15 +++++++++-
 .../keyboard/KeyboardLayoutSet.java           | 28 ++++---------------
 2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 4018d65d46..58225e95d6 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -32,7 +32,9 @@ import com.android.inputmethod.keyboard.internal.KeyboardCodesSet;
 import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
 import com.android.inputmethod.keyboard.internal.KeyboardLabelsSet;
 import com.android.inputmethod.latin.LatinImeLogger;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
 import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.SubtypeLocale;
 import com.android.inputmethod.latin.Utils;
 import com.android.inputmethod.latin.XmlParseUtils;
 
@@ -44,6 +46,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Locale;
 
 /**
  * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard
@@ -782,7 +785,17 @@ public class Keyboard {
                 final String language = params.mId.mLocale.getLanguage();
                 params.mCodesSet.setLanguage(language);
                 params.mLabelsSet.setLanguage(language);
-                params.mLabelsSet.loadStringResources(mContext);
+                final RunInLocale<Void> job = new RunInLocale<Void>() {
+                    @Override
+                    protected Void job(Resources res) {
+                        params.mLabelsSet.loadStringResources(mContext);
+                        return null;
+                    }
+                };
+                // Null means the current system locale.
+                final Locale locale = language.equals(SubtypeLocale.NO_LANGUAGE)
+                        ? null : params.mId.mLocale;
+                job.runInLocale(mResources, locale);
 
                 final int resourceId = keyboardAttr.getResourceId(
                         R.styleable.Keyboard_touchPositionCorrectionData, 0);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index c8ec3a4dd5..803a2948eb 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -29,12 +29,10 @@ import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.compat.EditorInfoCompatUtils;
 import com.android.inputmethod.keyboard.KeyboardLayoutSet.Params.ElementParams;
-import com.android.inputmethod.keyboard.internal.KeySpecParser;
 import com.android.inputmethod.latin.InputTypeUtils;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
 import com.android.inputmethod.latin.LocaleUtils;
-import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.StringUtils;
 import com.android.inputmethod.latin.SubtypeLocale;
@@ -183,14 +181,7 @@ public class KeyboardLayoutSet {
                 builder.setAutoGenerate(sKeysCache);
             }
             final int keyboardXmlId = elementParams.mKeyboardXmlId;
-            final RunInLocale<Void> job = new RunInLocale<Void>() {
-                @Override
-                protected Void job(Resources res) {
-                    builder.load(keyboardXmlId, id);
-                    return null;
-                }
-            };
-            job.runInLocale(context.getResources(), id.mLocale);
+            builder.load(keyboardXmlId, id);
             builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled);
             builder.setProximityCharsCorrectionEnabled(
                     elementParams.mProximityCharsCorrectionEnabled);
@@ -321,18 +312,11 @@ public class KeyboardLayoutSet {
                     R.xml.keyboard_layout_set_qwerty);
             final String keyboardLayoutSetName = mParams.mKeyboardLayoutSetName;
             final int xmlId = mResources.getIdentifier(keyboardLayoutSetName, "xml", packageName);
-            final RunInLocale<Void> job = new RunInLocale<Void>() {
-                @Override
-                protected Void job(Resources res) {
-                    try {
-                        parseKeyboardLayoutSet(res, xmlId);
-                    } catch (Exception e) {
-                        throw new RuntimeException(e.getMessage() + " in " + keyboardLayoutSetName);
-                    }
-                    return null;
-                }
-            };
-            job.runInLocale(mResources, mParams.mLocale);
+            try {
+                parseKeyboardLayoutSet(mResources, xmlId);
+            } catch (Exception e) {
+                throw new RuntimeException(e.getMessage() + " in " + keyboardLayoutSetName);
+            }
             return new KeyboardLayoutSet(mContext, mParams);
         }
 
-- 
GitLab