From fefda4e6df5c2f8e2b2730dfe5b88644a1caaa6b Mon Sep 17 00:00:00 2001
From: Ken Wakasa <kwakasa@google.com>
Date: Thu, 20 Jan 2011 23:29:53 +0900
Subject: [PATCH] Refine InputMethodInfo API

bug: 3370297
Change-Id: I16073e6b8b90a06a20e506dac66e3ca25b4712d0
---
 .../inputmethod/latin/SubtypeSwitcher.java    |  4 +--
 .../inputmethod/latin/SubtypeLocaleTests.java | 27 +++++--------------
 2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 99d31d4d2e..da46d26bf7 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -288,9 +288,9 @@ public class SubtypeSwitcher {
             if (subtype != null) {
                 return pm.getDrawable(imiPackageName, subtype.getIconResId(),
                         imi.getServiceInfo().applicationInfo);
-            } else if (imi.getSubtypes().size() > 0 && imi.getSubtypes().get(0) != null) {
+            } else if (imi.getSubtypeCount() > 0 && imi.getSubtypeAt(0) != null) {
                 return pm.getDrawable(imiPackageName,
-                        imi.getSubtypes().get(0).getIconResId(),
+                        imi.getSubtypeAt(0).getIconResId(),
                         imi.getServiceInfo().applicationInfo);
             } else {
                 try {
diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
index 004ddb61a9..e1c3678fdb 100644
--- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
+++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
@@ -33,19 +33,6 @@ public class SubtypeLocaleTests extends AndroidTestCase {
     private Resources mRes;
     private List<InputMethodSubtype> mKeyboardSubtypes;
 
-    public interface Predicator<T> {
-        public boolean evaluate(T object);
-    }
-
-    private static <T> List<T> filter(List<T> source, Predicator<? super T> predicator) {
-        final ArrayList<T> filtered = new ArrayList<T>();
-        for (final T element : source) {
-            if (predicator.evaluate(element))
-                filtered.add(element);
-        }
-        return filtered;
-    }
-
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -59,13 +46,13 @@ public class SubtypeLocaleTests extends AndroidTestCase {
                 Context.INPUT_METHOD_SERVICE);
         for (final InputMethodInfo imi : imm.getInputMethodList()) {
             if (imi.getPackageName().equals(PACKAGE)) {
-                mKeyboardSubtypes = filter(imi.getSubtypes(),
-                        new Predicator<InputMethodSubtype>() {
-                            @Override
-                            public boolean evaluate(InputMethodSubtype ims) {
-                                return ims.getMode().equals("keyboard");
-                            }
-                });
+                final int subtypeCount = imi.getSubtypeCount();
+                for (int i = 0; i < subtypeCount; ++i) {
+                    InputMethodSubtype subtype = imi.getSubtypeAt(i);
+                    if (subtype.getMode().equals("keyboard")) {
+                        mKeyboardSubtypes.add(subtype);
+                    }
+                }
                 break;
             }
         }
-- 
GitLab