From 706fce9bb0e044f281bf12742c406964b18e9190 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 9 Feb 2016 01:03:52 -0800 Subject: [PATCH] Follow API removal of LocaleList#getPrimary(). This follows up to a recent CL [1] that removed #getPrimary() method from LocaleList class. [1] I75f77aea6b75e38793ed8477e5e5a4420d5e6d85 fee44846376c212114223fc4259382921e6dca7a Bug: 26984092 Change-Id: Ied4678d35c4dcb380ce24e9bce9336dbbf6c16b8 --- .../inputmethod/compat/EditorInfoCompatUtils.java | 5 ++++- .../inputmethod/compat/LocaleListCompatUtils.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index 43714829a..56ce8f5e6 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -90,6 +90,9 @@ public final class EditorInfoCompatUtils { if (localeList == null) { return null; } - return LocaleListCompatUtils.getPrimary(localeList); + if (LocaleListCompatUtils.isEmpty(localeList)) { + return null; + } + return LocaleListCompatUtils.get(localeList, 0); } } diff --git a/java/src/com/android/inputmethod/compat/LocaleListCompatUtils.java b/java/src/com/android/inputmethod/compat/LocaleListCompatUtils.java index 01030aedd..1c49cd4d2 100644 --- a/java/src/com/android/inputmethod/compat/LocaleListCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/LocaleListCompatUtils.java @@ -21,14 +21,20 @@ import java.util.Locale; public final class LocaleListCompatUtils { private static final Class CLASS_LocaleList = CompatUtils.getClass("android.util.LocaleList"); - private static final Method METHOD_getPrimary = - CompatUtils.getMethod(CLASS_LocaleList, "getPrimary"); + private static final Method METHOD_get = + CompatUtils.getMethod(CLASS_LocaleList, "get", int.class); + private static final Method METHOD_isEmpty = + CompatUtils.getMethod(CLASS_LocaleList, "isEmpty"); private LocaleListCompatUtils() { // This utility class is not publicly instantiable. } - public static Locale getPrimary(final Object localeList) { - return (Locale) CompatUtils.invoke(localeList, null, METHOD_getPrimary); + public static boolean isEmpty(final Object localeList) { + return (Boolean) CompatUtils.invoke(localeList, Boolean.FALSE, METHOD_isEmpty); + } + + public static Locale get(final Object localeList, final int index) { + return (Locale) CompatUtils.invoke(localeList, null, METHOD_get, index); } }