Merge "Moved a functionality of setOverScrollMode to InputMethodServiceCompatWrapper"

main
satok 2011-03-24 22:41:04 -07:00 committed by Android (Google) Code Review
commit 5a41db8814
3 changed files with 27 additions and 4 deletions

View File

@ -96,7 +96,7 @@ public class CompatUtils {
try { try {
return method.invoke(receiver, args); return method.invoke(receiver, args);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "Exception in invoke: IllegalArgmentException"); Log.e(TAG, "Exception in invoke: IllegalArgumentException");
return defaultValue; return defaultValue;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Log.e(TAG, "Exception in invoke: IllegalAccessException"); Log.e(TAG, "Exception in invoke: IllegalAccessException");
@ -112,8 +112,10 @@ public class CompatUtils {
try { try {
return field.get(receiver); return field.get(receiver);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "Exception in getFieldValue: IllegalArgumentException");
return defaultValue; return defaultValue;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Log.e(TAG, "Exception in getFieldValue: IllegalAccessException");
return defaultValue; return defaultValue;
} }
} }
@ -123,9 +125,9 @@ public class CompatUtils {
try { try {
field.set(receiver, value); field.set(receiver, value);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// ignore Log.e(TAG, "Exception in setFieldValue: IllegalArgumentException");
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
// ignore Log.e(TAG, "Exception in setFieldValue: IllegalAccessException");
} }
} }

View File

@ -19,9 +19,20 @@ package com.android.inputmethod.compat;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.view.View;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import android.widget.HorizontalScrollView;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class InputMethodServiceCompatWrapper extends InputMethodService { 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 // 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. // or previous. Note that InputMethodSubtype was added in the API level 11.
// For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged(). // 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 @Override
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
// Do nothing when the API level is 10 or previous // Do nothing when the API level is 10 or previous

View File

@ -530,7 +530,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (container.getPaddingRight() != 0) { if (container.getPaddingRight() != 0) {
HorizontalScrollView scrollView = HorizontalScrollView scrollView =
(HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view); (HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view);
scrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); setOverScrollModeNever(scrollView);
container.setGravity(Gravity.CENTER_HORIZONTAL); container.setGravity(Gravity.CENTER_HORIZONTAL);
} }
mCandidateView = (CandidateView) container.findViewById(R.id.candidates); mCandidateView = (CandidateView) container.findViewById(R.id.candidates);