Adjust clipboard_value when no autofill suggestions are available
This commit is contained in:
parent
937bedb3eb
commit
b4dc109125
|
@ -312,6 +312,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
clearClipboardContent()
|
clearClipboardContent()
|
||||||
toggleClipboardVisibility(false)
|
toggleClipboardVisibility(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suggestions_holder.addOnLayoutChangeListener(object : OnLayoutChangeListener {
|
||||||
|
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
|
||||||
|
updateSuggestionsToolbarLayout()
|
||||||
|
suggestions_holder.removeOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
val clipboardManager = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
val clipboardManager = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||||
|
@ -1632,18 +1639,32 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
} else {
|
} else {
|
||||||
mToolbarHolder?.autofill_suggestions_holder?.addView(it)
|
mToolbarHolder?.autofill_suggestions_holder?.addView(it)
|
||||||
}
|
}
|
||||||
|
updateSuggestionsToolbarLayout()
|
||||||
// make room on suggestion toolbar for inline views
|
|
||||||
mToolbarHolder?.suggestions_items_holder?.gravity = Gravity.NO_GRAVITY
|
|
||||||
mToolbarHolder?.clipboard_value?.maxWidth = resources.getDimensionPixelSize(R.dimen.suggestion_max_width)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun clearClipboardViews() {
|
fun clearClipboardViews() {
|
||||||
mToolbarHolder?.autofill_suggestions_holder?.removeAllViews()
|
mToolbarHolder?.autofill_suggestions_holder?.removeAllViews()
|
||||||
// restore original clipboard toolbar appearance
|
updateSuggestionsToolbarLayout()
|
||||||
mToolbarHolder?.suggestions_items_holder?.gravity = Gravity.CENTER_HORIZONTAL
|
|
||||||
mToolbarHolder?.clipboard_value?.maxWidth = Integer.MAX_VALUE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateSuggestionsToolbarLayout() {
|
||||||
|
if (hasInlineViews()) {
|
||||||
|
// make room on suggestion toolbar for inline views
|
||||||
|
mToolbarHolder?.suggestions_items_holder?.gravity = Gravity.NO_GRAVITY
|
||||||
|
mToolbarHolder?.clipboard_value?.maxWidth = resources.getDimensionPixelSize(R.dimen.suggestion_max_width)
|
||||||
|
} else {
|
||||||
|
// restore original clipboard toolbar appearance
|
||||||
|
mToolbarHolder?.suggestions_items_holder?.gravity = Gravity.CENTER_HORIZONTAL
|
||||||
|
mToolbarHolder?.suggestions_holder?.measuredWidth?.also { maxWidth ->
|
||||||
|
mToolbarHolder?.clipboard_value?.maxWidth = maxWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if there are [InlineContentView]s in [autofill_suggestions_holder]
|
||||||
|
*/
|
||||||
|
private fun hasInlineViews() = (mToolbarHolder?.autofill_suggestions_holder?.childCount ?: 0) > 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue