From a3ef6cde2158b4a76c70070d790959b03ef0e9d1 Mon Sep 17 00:00:00 2001
From: satok <satok@google.com>
Date: Thu, 24 Mar 2011 21:37:21 -0700
Subject: [PATCH] Moved a functionality of setOverScrollMode to
 InputMethodServiceCompatWrapper

Change-Id: Ie473c9fced9f0a8da5643390b44aa4b86128396d
---
 .../inputmethod/compat/CompatUtils.java       |  8 ++++---
 .../InputMethodServiceCompatWrapper.java      | 21 +++++++++++++++++++
 .../android/inputmethod/latin/LatinIME.java   |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java
index 8bf59091f1..07db4a1bb9 100644
--- a/java/src/com/android/inputmethod/compat/CompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/CompatUtils.java
@@ -96,7 +96,7 @@ public class CompatUtils {
         try {
             return method.invoke(receiver, args);
         } catch (IllegalArgumentException e) {
-            Log.e(TAG, "Exception in invoke: IllegalArgmentException");
+            Log.e(TAG, "Exception in invoke: IllegalArgumentException");
             return defaultValue;
         } catch (IllegalAccessException e) {
             Log.e(TAG, "Exception in invoke: IllegalAccessException");
@@ -112,8 +112,10 @@ public class CompatUtils {
         try {
             return field.get(receiver);
         } catch (IllegalArgumentException e) {
+            Log.e(TAG, "Exception in getFieldValue: IllegalArgumentException");
             return defaultValue;
         } catch (IllegalAccessException e) {
+            Log.e(TAG, "Exception in getFieldValue: IllegalAccessException");
             return defaultValue;
         }
     }
@@ -123,9 +125,9 @@ public class CompatUtils {
         try {
             field.set(receiver, value);
         } catch (IllegalArgumentException e) {
-            // ignore
+            Log.e(TAG, "Exception in setFieldValue: IllegalArgumentException");
         } catch (IllegalAccessException e) {
-            // ignore
+            Log.e(TAG, "Exception in setFieldValue: IllegalAccessException");
         }
     }
 
diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
index 606322af7e..e02aac7045 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
@@ -19,9 +19,20 @@ package com.android.inputmethod.compat;
 import com.android.inputmethod.latin.SubtypeSwitcher;
 
 import android.inputmethodservice.InputMethodService;
+import android.view.View;
 import android.view.inputmethod.InputMethodSubtype;
+import android.widget.HorizontalScrollView;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 public class InputMethodServiceCompatWrapper extends InputMethodService {
+    private static final Method METHOD_HorizontalScrollView_setOverScrollMode =
+            CompatUtils.getMethod(HorizontalScrollView.class, "setOverScrollMode", int.class);
+    private static final Field FIELD_View_OVER_SCROLL_NEVER =
+            CompatUtils.getField(View.class, "OVER_SCROLL_NEVER");
+    private static final Integer View_OVER_SCROLL_NEVER =
+            (Integer)CompatUtils.getFieldValue(null, null, FIELD_View_OVER_SCROLL_NEVER);
     // CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED needs to be false if the API level is 10
     // or previous. Note that InputMethodSubtype was added in the API level 11.
     // For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged().
@@ -55,6 +66,16 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
         }
     }
 
+    protected static void setOverScrollModeNever(HorizontalScrollView scrollView) {
+        if (View_OVER_SCROLL_NEVER != null) {
+            CompatUtils.invoke(scrollView, null, METHOD_HorizontalScrollView_setOverScrollMode,
+                    View_OVER_SCROLL_NEVER);
+        }
+    }
+
+    //////////////////////////////////////
+    // Functions using API v11 or later //
+    //////////////////////////////////////
     @Override
     public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
         // Do nothing when the API level is 10 or previous
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 09a4ead228..4b38e27074 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -530,7 +530,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         if (container.getPaddingRight() != 0) {
             HorizontalScrollView scrollView =
                     (HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view);
-            scrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
+            setOverScrollModeNever(scrollView);
             container.setGravity(Gravity.CENTER_HORIZONTAL);
         }
         mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
-- 
GitLab