diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index cdd3a7244d339de4ba2a3a9e73fe8963c662454c..f4972588702c4e23574c4bb93347b301121db686 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -33,6 +33,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.inputmethodservice.InputMethodService; @@ -51,6 +52,7 @@ import android.view.Display; import android.view.Gravity; import android.view.KeyEvent; import android.view.View; +import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; @@ -218,7 +220,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public final UIHandler mHandler = new UIHandler(this); - private ImageButton floatingButton; + private ImageButton mFloatingButton; + private final Rect mFloatingButtonTouchableBounds = new Rect(); public static final class UIHandler extends LeakGuardHandlerWrapper { private static final int MSG_UPDATE_SHIFT_STATE = 0; @@ -895,8 +898,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggestionStripView.setListener(this, view); } - floatingButton = mInputView.findViewById(R.id.floating_button); - floatingButton.setOnClickListener(new View.OnClickListener() { + mFloatingButton = mInputView.findViewById(R.id.floating_button); + mFloatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switchToSttIme(); @@ -909,9 +912,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final SettingsValues currentSettingsValues = mSettings.getCurrent(); if (shouldShowFloatingButton() && currentSettingsValues.mInputAttributes.mShouldShowSuggestions) { - floatingButton.setVisibility(View.VISIBLE); + mFloatingButton.setVisibility(View.VISIBLE); } else { - floatingButton.setVisibility(View.GONE); + mFloatingButton.setVisibility(View.GONE); } } @@ -935,7 +938,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.onStartInputView(editorInfo, restarting); mStatsUtilsManager.onStartInputView(); - if (floatingButton != null) { + if (mFloatingButton != null) { manageFloatingButtonVisibility(); } } @@ -1336,12 +1339,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int touchBottom = inputHeight; outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION; outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom); + extendTouchableRegionForFloatingButton(outInsets); } outInsets.contentTopInsets = visibleTopY; outInsets.visibleTopInsets = visibleTopY; mInsetsUpdater.setInsets(outInsets); } + private void extendTouchableRegionForFloatingButton(final InputMethodService.Insets outInsets) { + if (mFloatingButton == null || mFloatingButton.getVisibility() != View.VISIBLE) { + return; + } + if (!(mInputView instanceof ViewGroup)) { + return; + } + final int width = mFloatingButton.getWidth(); + final int height = mFloatingButton.getHeight(); + if (width <= 0 || height <= 0) { + return; + } + mFloatingButtonTouchableBounds.set(0, 0, width, height); + ((ViewGroup) mInputView).offsetDescendantRectToMyCoords( + mFloatingButton, mFloatingButtonTouchableBounds); + outInsets.touchableRegion.union(mFloatingButtonTouchableBounds); + } + public void startShowingInputView(final boolean needsToLoadKeyboard) { mIsExecutingStartShowingInputView = true; // This {@link #showWindow(boolean)} will eventually call back