Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -242,30 +244,36 @@ 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<View>(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)
}

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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ public static InlineContentClipView createView(final List<InlineSuggestion> 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();
Expand All @@ -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) {
Expand All @@ -179,4 +176,4 @@ private void clipDescendantInlineContentViews(@Nullable View root) {
}
}
}
}
}