From 85b5a03a8db031ac6a7ec8444a8ee192ab54b7c7 Mon Sep 17 00:00:00 2001 From: Frank Preel Date: Wed, 29 Oct 2025 14:04:23 +0000 Subject: [PATCH] fix: show mic icon when suggestions are disabled (cherry picked from commit 558370ba812275a160bb141a18b75b61a992412f) --- .../android/inputmethod/latin/LatinIME.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 09cfb82948..aca24dfa9c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -37,6 +37,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; @@ -55,6 +56,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; @@ -222,7 +224,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; @@ -883,8 +886,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(); @@ -895,10 +898,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void manageFloatingButtonVisibility() { final SettingsValues currentSettingsValues = mSettings.getCurrent(); - if (shouldShowFloatingButton() && currentSettingsValues.mInputAttributes.mShouldShowSuggestions) { - floatingButton.setVisibility(View.VISIBLE); + if (shouldShowFloatingButton() + && currentSettingsValues.mInputAttributes.mShouldShowSuggestions) { + mFloatingButton.setVisibility(View.VISIBLE); } else { - floatingButton.setVisibility(View.GONE); + mFloatingButton.setVisibility(View.GONE); } } @@ -922,7 +926,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.onStartInputView(editorInfo, restarting); mStatsUtilsManager.onStartInputView(); - if (floatingButton != null) { + if (mFloatingButton != null) { manageFloatingButtonVisibility(); } } @@ -1323,12 +1327,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 -- GitLab