diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.kt b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.kt index cff038f758..0499d8f7b3 100644 --- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.kt +++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.kt @@ -22,11 +22,13 @@ import android.view.MotionEvent import android.view.View import android.view.View.OnLongClickListener import android.view.ViewGroup +import android.view.WindowManager import android.view.accessibility.AccessibilityEvent import android.widget.ImageButton import android.widget.LinearLayout import android.widget.RelativeLayout import android.widget.TextView +import androidx.core.view.doOnNextLayout import androidx.core.view.isVisible import helium314.keyboard.compat.isDeviceLocked import helium314.keyboard.event.HapticEvent @@ -242,23 +244,26 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int) updateKeys() } - fun setExternalSuggestionView(view: View?, addCloseButton: Boolean) { + fun setExternalSuggestionView(view: View, addCloseButton: Boolean) { clear() + updateKeys() isExternalSuggestionVisible = true - if (addCloseButton) { - val wrapper = LinearLayout(context) - wrapper.layoutParams = LinearLayout.LayoutParams(suggestionsStrip.width - 30.dpToPx(resources), LayoutParams.MATCH_PARENT) - wrapper.addView(view) - suggestionsStrip.addView(wrapper) + Log.d(TAG, "Display width: ${context.getSystemService(WindowManager::class.java).defaultDisplay.width}, " + + "suggestion strip view width: $width, " + + "suggestions strip wrapper width: ${findViewById(R.id.suggestions_strip_wrapper).width}, " + + "toolbarExpandKey width: ${toolbarExpandKey.width}, pinnedKeys width: ${pinnedKeys.width}, " + + "suggestionsStrip width: ${suggestionsStrip.width}, toolbarKeyLayoutParams.width: ${toolbarKeyLayoutParams.width}") + if (addCloseButton) { + view.layoutParams = getExternalSuggestionsLayoutParams() + suggestionsStrip.addView(view) val closeButton = createToolbarKey(context, ToolbarKey.CLOSE_HISTORY) closeButton.layoutParams = toolbarKeyLayoutParams setupKey(closeButton, Settings.getValues().mColors) - closeButton.setOnClickListener { - listener.removeExternalSuggestions() - } + closeButton.setOnClickListener { listener.removeExternalSuggestions() } suggestionsStrip.addView(closeButton) + doOnNextLayout { view.layoutParams = getExternalSuggestionsLayoutParams() } } else { suggestionsStrip.addView(view) } @@ -266,6 +271,9 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int) if (Settings.getValues().mAutoHideToolbar) setToolbarVisibility(false) } + private fun getExternalSuggestionsLayoutParams(): LinearLayout.LayoutParams = + LinearLayout.LayoutParams(suggestionsStrip.width - toolbarKeyLayoutParams.width, LayoutParams.MATCH_PARENT) + fun setMoreSuggestionsHeight(remainingHeight: Int) { layoutHelper.setMoreSuggestionsHeight(remainingHeight) } diff --git a/app/src/main/java/helium314/keyboard/latin/utils/InlineAutofillUtils.java b/app/src/main/java/helium314/keyboard/latin/utils/InlineAutofillUtils.java index e59a752754..cdfd963d78 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/InlineAutofillUtils.java +++ b/app/src/main/java/helium314/keyboard/latin/utils/InlineAutofillUtils.java @@ -130,9 +130,6 @@ public static InlineContentClipView createView(final List inli */ public static class InlineContentClipView extends FrameLayout { @NonNull - private final ViewTreeObserver.OnDrawListener mOnDrawListener = - this::clipDescendantInlineContentViews; - @NonNull private final Rect mParentBounds = new Rect(); @NonNull private final Rect mContentBounds = new Rect(); @@ -147,19 +144,19 @@ public InlineContentClipView(@NonNull Context context, @Nullable AttributeSet at mBackgroundView.getHolder().setFormat(PixelFormat.TRANSPARENT); addView(mBackgroundView); } + @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - getViewTreeObserver().addOnDrawListener(mOnDrawListener); - } - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - getViewTreeObserver().removeOnDrawListener(mOnDrawListener); + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + if (changed) { + clipDescendantInlineContentViews(); + } } + private void clipDescendantInlineContentViews() { mParentBounds.right = getWidth(); mParentBounds.bottom = getHeight(); + Log.d(InlineContentClipView.class.getSimpleName(), "Clipping to " + mParentBounds); clipDescendantInlineContentViews(this); } private void clipDescendantInlineContentViews(@Nullable View root) { @@ -179,4 +176,4 @@ private void clipDescendantInlineContentViews(@Nullable View root) { } } } -} \ No newline at end of file +}