From 5c490e5da5a1a403c307eb3660fe74158434a0dc Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 17 Apr 2014 16:59:19 +0900 Subject: [PATCH] Refactor RunInLocale a bit Change-Id: If60877b29bb1263161ec85c99320ad07b7dd4245 --- .../inputmethod/latin/utils/RunInLocale.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/utils/RunInLocale.java b/java/src/com/android/inputmethod/latin/utils/RunInLocale.java index 2c9e3b191..3c632bbc3 100644 --- a/java/src/com/android/inputmethod/latin/utils/RunInLocale.java +++ b/java/src/com/android/inputmethod/latin/utils/RunInLocale.java @@ -30,25 +30,23 @@ public abstract class RunInLocale { * Execute {@link #job(Resources)} method in specified system locale exclusively. * * @param res the resources to use. - * @param newLocale the locale to change to. + * @param newLocale the locale to change to. Run in system locale if null. * @return the value returned from {@link #job(Resources)}. */ public T runInLocale(final Resources res, final Locale newLocale) { synchronized (sLockForRunInLocale) { - final Configuration conf = res.getConfiguration(); - final Locale oldLocale = conf.locale; - final boolean needsChange = (newLocale != null && !newLocale.equals(oldLocale)); + final Configuration savedConf = res.getConfiguration(); + if (newLocale == null || newLocale.equals(savedConf.locale)) { + return job(res); + } + final Configuration newConf = new Configuration(); + newConf.setTo(savedConf); + newConf.setLocale(newLocale); try { - if (needsChange) { - conf.locale = newLocale; - res.updateConfiguration(conf, null); - } + res.updateConfiguration(newConf, null); return job(res); } finally { - if (needsChange) { - conf.locale = oldLocale; - res.updateConfiguration(conf, null); - } + res.updateConfiguration(savedConf, null); } } }