Skip to content
Merged
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.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,35 @@ class StatusBarButtonHost(
}

private fun applyTheme(view: View, fallbackHeight: Int? = null, state: ButtonState? = null) {
(view.getTag(it.palsoftware.pastiera.R.id.tag_badge_view) as? TextView)?.let { badge ->
val params = view.layoutParams
val enlargedPastierinaButton = params != null && params.height > 0 &&
params.width > params.height * 1.2f &&
it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)
badge.setTextSize(TypedValue.COMPLEX_UNIT_SP, if (enlargedPastierinaButton) 14f else 10f)
(badge.layoutParams as? FrameLayout.LayoutParams)?.let { badgeParams ->
val rightMargin = dpToPx(if (enlargedPastierinaButton) 12f else 2f)
if (badgeParams.rightMargin != rightMargin) {
badgeParams.rightMargin = rightMargin
badge.layoutParams = badgeParams
}
}
}
val theme = themeOverride ?: return
(view.getTag(it.palsoftware.pastiera.R.id.tag_badge_view) as? TextView)?.setTextColor(theme.iconColor)
val height = view.layoutParams?.height?.takeIf { it > 0 }
?: view.height.takeIf { it > 0 }
?: fallbackHeight?.takeIf { it > 0 }
if (height != null) {
val active = state is ButtonState.MinimalUiState && state.isActive
val gapless = it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)
view.background = StatusBarButtonStyles.createButtonDrawable(
heightPx = height,
normalColor = if (active) theme.pressedColor else theme.normalColor,
pressedColor = theme.pressedColor,
cornerRadiusRatio = theme.cornerRadiusRatio,
cornerRadiusRatio = if (gapless) 0f else theme.cornerRadiusRatio,
borderColor = theme.borderColor,
borderWidthPx = theme.borderWidthPx
borderWidthPx = if (gapless) 0 else theme.borderWidthPx
)
}
when (view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ class FullSuggestionsBar(
}
}

private fun gaplessChrome(): Boolean =
it.palsoftware.pastiera.SettingsManager.getTitan2EliteRoundedCornerInsetsEnabled(context)

private fun chromeSpacingPx(): Int = if (gaplessChrome()) 0 else dpToPx(3f)

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 @@ -490,7 +502,11 @@ class FullSuggestionsBar(
}

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

Expand All @@ -499,10 +515,10 @@ class FullSuggestionsBar(
id = buttonId,
size = buttonSize,
callbacks = callbacks,
width = buttonSize,
height = buttonSize
width = buttonWidth,
height = buttonHeight
) ?: return
hosted.container.layoutParams = LinearLayout.LayoutParams(buttonSize, buttonSize).apply {
hosted.container.layoutParams = LinearLayout.LayoutParams(buttonWidth, buttonHeight).apply {
marginEnd = if (isLast) 0 else spacing
}
target.addView(hosted.container)
Expand Down Expand Up @@ -530,15 +546,15 @@ class FullSuggestionsBar(

private fun applyContainerInsetsForMinimalButtons() {
val bar = container ?: return
val spacing = dpToPx(3f)
val spacing = chromeSpacingPx()
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 * (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f)) +
it.childCount * minimalButtonWidthPx() +
(it.childCount - 1).coerceAtLeast(0) * spacing +
spacing
} ?: 0
Expand All @@ -558,7 +574,7 @@ class FullSuggestionsBar(
val leftInset = indicatorInset + minimalLeftInset
val rightInset = if (showMinimalUiButtons) {
minimalRightButtonsContainer?.takeIf { it.visibility == View.VISIBLE }?.let {
it.childCount * (targetHeightPx - dpToPx(4f)).coerceAtLeast(dpToPx(24f)) +
it.childCount * minimalButtonWidthPx() +
(it.childCount - 1).coerceAtLeast(0) * spacing +
spacing
} ?: 0
Expand Down Expand Up @@ -657,7 +673,7 @@ class FullSuggestionsBar(
).apply {
// Apply margin only if not the last suggestion box
if (index < slotOrder.size - 1) {
marginEnd = dpToPx(3f)
marginEnd = chromeSpacingPx()
}
}
if (suggestion != null && actionCandidate?.equals(suggestion, ignoreCase = true) == true) {
Expand Down Expand Up @@ -793,7 +809,8 @@ class FullSuggestionsBar(
gravity = Gravity.CENTER
layoutParams = weightLayoutParams
background = buildSuggestionBackground()
setPadding(dpToPx(4f), dpToPx(4f), dpToPx(4f), dpToPx(4f))
val padding = if (gaplessChrome()) 0 else dpToPx(4f)
setPadding(padding, padding, padding, padding)

actions.forEachIndexed { index, action ->
val button = ImageView(context).apply {
Expand All @@ -808,7 +825,7 @@ class FullSuggestionsBar(
ViewGroup.LayoutParams.MATCH_PARENT,
1f
).apply {
if (index < actions.lastIndex) marginEnd = dpToPx(3f)
if (index < actions.lastIndex) marginEnd = chromeSpacingPx()
}
isClickable = true
isFocusable = true
Expand All @@ -829,12 +846,12 @@ class FullSuggestionsBar(
private fun buildActionBackground(color: Int): StateListDrawable {
val normal = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
cornerRadius = dpToPx(7f).toFloat()
cornerRadius = if (gaplessChrome()) 0f else dpToPx(7f).toFloat()
setColor(color)
}
val pressed = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
cornerRadius = dpToPx(7f).toFloat()
cornerRadius = if (gaplessChrome()) 0f else dpToPx(7f).toFloat()
setColor(themeOverride?.accent ?: PRESSED_BLUE)
}
return StateListDrawable().apply {
Expand Down Expand Up @@ -938,18 +955,18 @@ class FullSuggestionsBar(
}

private fun buildSuggestionBackground(): StateListDrawable {
val radiusRatio = themeOverride?.chromeCornerRadiusRatio ?: 0f
val radiusRatio = if (gaplessChrome()) 0f else themeOverride?.chromeCornerRadiusRatio ?: 0f
val radius = (targetHeightPx * radiusRatio).coerceAtLeast(0f)
val normalDrawable = GradientDrawable().apply {
setColor(themeOverride?.suggestion ?: DEFAULT_SUGGESTION_COLOR)
cornerRadius = radius
alpha = 255 // placeholders look identical; they stay non-clickable
themeOverride?.let { setStroke(dpToPx(1f), it.divider) }
if (!gaplessChrome()) themeOverride?.let { setStroke(dpToPx(1f), it.divider) }
}
val pressedDrawable = GradientDrawable().apply {
setColor(themeOverride?.accent ?: PRESSED_BLUE)
cornerRadius = radius
themeOverride?.let { setStroke(dpToPx(1f), it.divider) }
if (!gaplessChrome()) themeOverride?.let { setStroke(dpToPx(1f), it.divider) }
}
return StateListDrawable().apply {
addState(intArrayOf(android.R.attr.state_pressed), pressedDrawable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ class ClipboardHistoryView(
currentInputConnection = connection
}

/** The chrome owns the shared, screen-contoured close button in rounded mode. */
fun configureRoundedLayout(enabled: Boolean) {
closeButton?.visibility = if (enabled) View.GONE else View.VISIBLE
}

fun configureSoftwareKeyboardMode(heightPx: Int?) {
val targetHeight = heightPx?.takeIf { it > 0 } ?: dpToPx(177f)
updateHeight(targetHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.palsoftware.pastiera.inputmethod.ui

import android.content.Context
import android.graphics.Color
import android.graphics.Matrix
import android.graphics.Rect
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.ColorDrawable
Expand Down Expand Up @@ -69,6 +70,9 @@ class EmojiPickerView(
private val searchPanel: FrameLayout
private val searchToggleButton: ImageView
private val closeButton: ImageView
private var roundedControls = false
private var roundedIconSize = 0f
val edgeControls: Pair<View, View> get() = searchToggleButton to closeButton

private var coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
private var loadingJob: Job? = null
Expand Down Expand Up @@ -375,6 +379,66 @@ class EmojiPickerView(
currentInputConnection = connection
}

fun configureRoundedControls(enabled: Boolean, rowHeight: Int, iconSize: Float) {
roundedControls = enabled
roundedIconSize = iconSize
// Reserve the slot; rounded mode uses the chrome's shared SYM close control.
closeButton.visibility = if (enabled) View.INVISIBLE else View.VISIBLE
val height = if (enabled) rowHeight else dpToPx(32f)
val bar = closeButton.parent as LinearLayout
bar.layoutParams = bar.layoutParams.apply { this.height = height }
tabScrollView.layoutParams = tabScrollView.layoutParams.apply { this.height = height }
tabRow.layoutParams = tabRow.layoutParams.apply { this.height = height }
tabRow.setPadding(if (enabled) 0 else smallPadding / 2, 0, if (enabled) 0 else smallPadding / 2, 0)
for (index in 0 until tabRow.childCount) {
val category = tabRow.getChildAt(index)
category.layoutParams = category.layoutParams.apply {
this.height = if (enabled) ViewGroup.LayoutParams.MATCH_PARENT else dpToPx(32f)
}
(category as? ImageView)?.scaleType = ImageView.ScaleType.CENTER_INSIDE
}
fun sizeControls(width: Int) {
listOf(searchToggleButton, closeButton).forEach { button ->
button.layoutParams = (button.layoutParams as LinearLayout.LayoutParams).apply {
this.width = if (enabled) {
if (button === closeButton) width - (width / 10) * 9 else width / 10
} else dpToPx(if (button === closeButton) 36f else 32f)
this.height = height
marginEnd = if (!enabled && button === searchToggleButton) spacing else 0
}
}
applyEdgeControlAppearance()
}
sizeControls(width.takeIf { it > 0 } ?: resources.displayMetrics.widthPixels)
requestLayout()
}

private fun applyEdgeControlAppearance() {
listOf(searchToggleButton, closeButton).forEach { button ->
if (roundedControls) {
button.background = ColorDrawable(themeOverride?.statusBarButton ?: Color.TRANSPARENT)
button.setPadding(0, 0, 0, 0)
button.scaleType = ImageView.ScaleType.MATRIX
button.drawable?.let { icon ->
val scale = roundedIconSize / icon.intrinsicHeight.coerceAtLeast(1)
button.imageMatrix = Matrix().apply {
setScale(scale, scale)
postTranslate(
(button.layoutParams.width - icon.intrinsicWidth * scale) / 2f +
dpToPx(4f) * if (button === searchToggleButton) 1 else -1,
(button.layoutParams.height - icon.intrinsicHeight * scale) / 2f - dpToPx(2f)
)
}
}
} else {
val pad = dpToPx(4f)
button.setPadding(pad, pad, pad, pad)
button.scaleType = ImageView.ScaleType.CENTER_INSIDE
button.background = if (button === closeButton) createCloseButtonBackground() else createTabBackground(isSearchPanelVisible)
}
}
}

fun configureSoftwareKeyboardMode(heightPx: Int?, onKeyboardLayoutRequested: (() -> Unit)?) {
val configuredHeight = configuredHeightPx(context)
val targetHeight = heightPx?.takeIf { it > 0 } ?: configuredHeight
Expand Down Expand Up @@ -807,6 +871,7 @@ class EmojiPickerView(
isSearchPanelVisible = visible
searchPanel.visibility = if (visible) View.VISIBLE else View.GONE
searchToggleButton.background = createTabBackground(visible)
applyEdgeControlAppearance()
setSearchInputCaptureEnabled(visible)
if (visible) {
searchField.requestFocus()
Expand Down Expand Up @@ -920,7 +985,7 @@ class EmojiPickerView(
isFocusable = true
layoutParams = LinearLayout.LayoutParams(
0, // Use weight
tabHeight,
if (roundedControls) ViewGroup.LayoutParams.MATCH_PARENT else tabHeight,
1f // Equal weight for all tabs
)
setOnClickListener {
Expand Down Expand Up @@ -1159,6 +1224,7 @@ class EmojiPickerView(
searchToggleButton.background = createTabBackground(isSearchPanelVisible)
keyboardSwitcherButton.setColorFilter(theme?.textAndIcons ?: Color.WHITE)
keyboardSwitcherButton.background = createTabBackground(false)
applyEdgeControlAppearance()
emptyView.setTextColor(colorWithAlpha(theme?.textAndIcons ?: Color.WHITE, 128))
updateTabsSelection()
sectionAdapter.notifyDataSetChanged()
Expand Down
Loading
Loading