Skip to content
Closed
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CandidatesBarController(
candidatesStatusBar.onAddUserWordSubstitutionRequested = value
}

var onSuggestionCommitted: (() -> Unit)? = null
var onSuggestionCommitted: ((String) -> Unit)? = null
set(value) {
field = value
inputStatusBar.onSuggestionCommitted = value
Expand Down Expand Up @@ -253,7 +253,7 @@ class CandidatesBarController(
candidatesStatusBar.getLayout().isActuallyRendered()

private fun View?.isActuallyRendered(): Boolean {
if (this == null || !isAttachedToWindow || windowVisibility != View.VISIBLE || !isShown || width <= 0 || height <= 0) {
if (this == null || !isAttachedToWindow || !isShown || width <= 0 || height <= 0) {
return false
}
val visibleBounds = Rect()
Expand All @@ -262,18 +262,6 @@ class CandidatesBarController(
visibleBounds.height() > 0
}

/** Visible child bounds in IME-window coordinates; absent content owns no input region. */
fun visibleBoundsInWindow(): Rect? {
val view = listOf(inputStatusBar.getLayout(), candidatesStatusBar.getLayout())
.firstOrNull { it.isActuallyRendered() } ?: return null
val bounds = Rect()
if (!view.getLocalVisibleRect(bounds)) return null
val location = IntArray(2)
view.getLocationInWindow(location)
bounds.offset(location[0], location[1])
return bounds
}

fun setPastierinaModeActive(active: Boolean) {
inputStatusBar.setPastierinaModeActive(active)
candidatesStatusBar.setPastierinaModeActive(active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ class PhysicalKeyboardInputMethodService : InputMethodService(), ClicksAccessibi
candidatesBarController.onAddUserWordSubstitutionRequested = { word ->
showAddSubstitutionDialog(word)
}
candidatesBarController.onSuggestionCommitted = {
candidatesBarController.onSuggestionCommitted = { committedWord ->
if (shiftLayerLatched || altModifierLayerLatched) {
shiftLayerLatched = false
altModifierLayerLatched = false
Expand All @@ -1789,7 +1789,7 @@ class PhysicalKeyboardInputMethodService : InputMethodService(), ClicksAccessibi
modifierStateController.consumeShiftOneShot()
}
variationInteractedDuringHold = true
suggestionController.readInitialContext(currentInputConnection)
suggestionController.notifyWordCompletedExternally(committedWord)
updateStatusBarText()
}
candidatesBarController.onHideSuggestion = { suggestion ->
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object SuggestionButtonHandler {
inputConnection: InputConnection?,
listener: VariationButtonHandler.OnVariationSelectedListener? = null,
shouldDisableAutoCapitalize: Boolean,
onSuggestionCommitted: (() -> Unit)? = null
onSuggestionCommitted: ((String) -> Unit)? = null
): View.OnClickListener {
return View.OnClickListener {
Log.d(TAG, "Click on suggestion button: $suggestion")
Expand All @@ -42,7 +42,7 @@ object SuggestionButtonHandler {

val committed = replaceCurrentWord(inputConnection, suggestion, forceLeadingCapital)
if (committed) {
onSuggestionCommitted?.invoke()
onSuggestionCommitted?.invoke(suggestion)
}
listener?.onVariationSelected(suggestion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class FullSuggestionsBar(
pressedColor = it.accent,
iconColor = it.textAndIcons,
cornerRadiusRatio = it.keyCornerRadiusRatio,
borderColor = it.statusButtonBorder,
borderColor = it.divider,
borderWidthPx = dpToPx(1f)
)
}
Expand Down Expand Up @@ -358,7 +358,7 @@ class FullSuggestionsBar(
addWordCandidate: String?,
onAddUserWord: ((String) -> Unit)?,
onAddUserWordSubstitutionRequested: ((String) -> Unit)?,
onSuggestionCommitted: (() -> Unit)?,
onSuggestionCommitted: ((String) -> Unit)?,
onHideSuggestion: ((String) -> Unit)?,
onDeleteUserSuggestion: ((String) -> Unit)?,
canDeleteUserSuggestion: ((String) -> Boolean)?,
Expand Down Expand Up @@ -474,18 +474,6 @@ class FullSuggestionsBar(
}
}

private fun chromeSpacingPx(): Int = dpToPx(3f)

private fun outerButtonExtraPx(): Int =
if (it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)) dpToPx(8f) else 0

private fun minimalButtonWidthPx(): Int {
val size = (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f))
return if (it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)) {
maxOf(dpToPx(56f), (size * 1.6f).toInt())
} else size
}

private fun renderMinimalUiButtons() {
val leftContainer = minimalLeftButtonsContainer ?: return
val rightContainer = minimalRightButtonsContainer ?: return
Expand All @@ -502,25 +490,19 @@ class FullSuggestionsBar(
}

val buttonSize = (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f))
val buttonWidth = minimalButtonWidthPx()
val buttonHeight = if (it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)) {
targetHeightPx
} else buttonSize
val spacing = chromeSpacingPx()
val spacing = dpToPx(3f)
val callbacks = (callbacksProvider?.invoke() ?: StatusBarCallbacks())
.copy(onHamburgerMenuRequested = { toggleHamburgerMenu() })

fun addButton(buttonId: StatusBarButtonId, target: LinearLayout, isLast: Boolean, outerEdge: StatusBarButtonPosition?) {
val actualButtonWidth = buttonWidth + if (outerEdge != null) outerButtonExtraPx() else 0
fun addButton(buttonId: StatusBarButtonId, target: LinearLayout, isLast: Boolean) {
val hosted = host.getOrCreateButton(
id = buttonId,
size = buttonSize,
callbacks = callbacks,
width = actualButtonWidth,
height = buttonHeight
width = buttonSize,
height = buttonSize
) ?: return
host.setOuterEdge(buttonId, outerEdge)
hosted.container.layoutParams = LinearLayout.LayoutParams(actualButtonWidth, buttonHeight).apply {
hosted.container.layoutParams = LinearLayout.LayoutParams(buttonSize, buttonSize).apply {
marginEnd = if (isLast) 0 else spacing
}
target.addView(hosted.container)
Expand All @@ -535,10 +517,10 @@ class FullSuggestionsBar(
.sortedBy { it.order }

leftButtons.forEachIndexed { index, config ->
addButton(config.id, leftContainer, index == leftButtons.lastIndex, if (index == 0) StatusBarButtonPosition.LEFT else null)
addButton(config.id, leftContainer, index == leftButtons.lastIndex)
}
rightButtons.forEachIndexed { index, config ->
addButton(config.id, rightContainer, index == rightButtons.lastIndex, if (index == rightButtons.lastIndex) StatusBarButtonPosition.RIGHT else null)
addButton(config.id, rightContainer, index == rightButtons.lastIndex)
}

leftContainer.visibility = if (leftButtons.isEmpty()) View.GONE else View.VISIBLE
Expand All @@ -548,15 +530,15 @@ class FullSuggestionsBar(

private fun applyContainerInsetsForMinimalButtons() {
val bar = container ?: return
val spacing = chromeSpacingPx()
val spacing = dpToPx(3f)
val indicatorInset = modifierIndicatorsContainer?.takeIf {
showModifierMenuIndicators && it.visibility == View.VISIBLE
}?.let {
modifierIndicatorsWidthPx(it) + spacing
} ?: 0
val minimalLeftInset = if (showMinimalUiButtons) {
minimalLeftButtonsContainer?.takeIf { it.visibility == View.VISIBLE }?.let {
it.childCount * minimalButtonWidthPx() + (if (it.childCount > 0) outerButtonExtraPx() else 0) +
it.childCount * (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f)) +
(it.childCount - 1).coerceAtLeast(0) * spacing +
spacing
} ?: 0
Expand All @@ -576,7 +558,7 @@ class FullSuggestionsBar(
val leftInset = indicatorInset + minimalLeftInset
val rightInset = if (showMinimalUiButtons) {
minimalRightButtonsContainer?.takeIf { it.visibility == View.VISIBLE }?.let {
it.childCount * minimalButtonWidthPx() + (if (it.childCount > 0) outerButtonExtraPx() else 0) +
it.childCount * (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f)) +
(it.childCount - 1).coerceAtLeast(0) * spacing +
spacing
} ?: 0
Expand Down Expand Up @@ -630,7 +612,7 @@ class FullSuggestionsBar(
addWordCandidate: String?,
onAddUserWord: ((String) -> Unit)?,
onAddUserWordSubstitutionRequested: ((String) -> Unit)?,
onSuggestionCommitted: (() -> Unit)?,
onSuggestionCommitted: ((String) -> Unit)?,
onHideSuggestion: ((String) -> Unit)?,
onDeleteUserSuggestion: ((String) -> Unit)?,
canDeleteUserSuggestion: ((String) -> Boolean)?,
Expand Down Expand Up @@ -675,7 +657,7 @@ class FullSuggestionsBar(
).apply {
// Apply margin only if not the last suggestion box
if (index < slotOrder.size - 1) {
marginEnd = chromeSpacingPx()
marginEnd = dpToPx(3f)
}
}
if (suggestion != null && actionCandidate?.equals(suggestion, ignoreCase = true) == true) {
Expand Down Expand Up @@ -811,8 +793,7 @@ class FullSuggestionsBar(
gravity = Gravity.CENTER
layoutParams = weightLayoutParams
background = buildSuggestionBackground()
val padding = dpToPx(4f)
setPadding(padding, padding, padding, padding)
setPadding(dpToPx(4f), dpToPx(4f), dpToPx(4f), dpToPx(4f))

actions.forEachIndexed { index, action ->
val button = ImageView(context).apply {
Expand All @@ -827,7 +808,7 @@ class FullSuggestionsBar(
ViewGroup.LayoutParams.MATCH_PARENT,
1f
).apply {
if (index < actions.lastIndex) marginEnd = chromeSpacingPx()
if (index < actions.lastIndex) marginEnd = dpToPx(3f)
}
isClickable = true
isFocusable = true
Expand Down
Loading