Merge "Moved a functionality of setOverScrollMode to InputMethodServiceCompatWrapper"
This commit is contained in:
commit
5a41db8814
3 changed files with 27 additions and 4 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue