Skip to content
Merged
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 @@ -9,6 +9,7 @@ import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.InsetDrawable
import android.graphics.drawable.RippleDrawable
import android.util.AttributeSet
import android.util.TypedValue
Expand Down Expand Up @@ -90,21 +91,32 @@ class StylePreviewStripView @JvmOverloads constructor(
lp.gravity = Gravity.CENTER_VERTICAL
closeButton.layoutParams = lp

closeButton.setPadding(expandPadding, expandPadding, expandPadding, expandPadding)
closeButton.scaleType = ImageView.ScaleType.CENTER_INSIDE

// Themed close icon matching the active keyboard theme (e.g. ic_close_rounded on rounded themes)
val closeDrawable = KeyboardIconsSet.instance.getNewDrawable(ToolbarKey.CLOSE_HISTORY.name, context)
?: ContextCompat.getDrawable(context, R.drawable.ic_close)
closeButton.setImageDrawable(closeDrawable)
closeButton.setBackgroundResource(R.drawable.toolbar_key_background)
val inset = ((keyDimension - chipHeightPx()) / 2).coerceAtLeast(0)
closeButton.background = InsetDrawable(
createChipDrawable(chipColor(colors), keyboardCornerRadiusPx(resources), colors.get(ColorType.KEY_TEXT)),
inset
)
// after the background, an InsetDrawable would otherwise replace the padding
closeButton.setPadding(expandPadding, expandPadding, expandPadding, expandPadding)
colors.setColor(closeButton, ColorType.TOOL_BAR_KEY)
colors.setColor(closeButton.background, ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND)
}

/**
* Populates style chips previewing the target text or sample word.
*/
private fun chipHeightPx() = (30 * resources.displayMetrics.density).toInt()

// without key borders the key color can equal the strip, so keep the toolbar button color there
private fun chipColor(colors: Colors) = colors.get(
if (colors.hasKeyBorders) ColorType.KEY_BACKGROUND else ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND
)

fun setTargetText(
targetText: String,
onApply: (String) -> Unit,
Expand All @@ -116,7 +128,7 @@ class StylePreviewStripView @JvmOverloads constructor(
scrollView.scrollTo(0, 0)
chipsContainer.removeAllViews()
val density = resources.displayMetrics.density
val chipHeight = (30 * density).toInt()
val chipHeight = chipHeightPx()
val cornerRadius = keyboardCornerRadiusPx(resources)
val marginH = (4 * density).toInt()
val padH = (14 * density).toInt()
Expand Down Expand Up @@ -154,7 +166,7 @@ class StylePreviewStripView @JvmOverloads constructor(
setTypeface(null, Typeface.NORMAL)
setTextColor(colors.get(ColorType.KEY_TEXT))
background = createChipDrawable(
bgColor = colors.get(ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND),
bgColor = chipColor(colors),
cornerRadiusPx = cornerRadius,
rippleColor = colors.get(ColorType.KEY_TEXT)
)
Expand Down Expand Up @@ -211,7 +223,7 @@ class StylePreviewStripView @JvmOverloads constructor(
setTypeface(null, Typeface.NORMAL)
setTextColor(colors.get(ColorType.KEY_TEXT))
background = createChipDrawable(
bgColor = colors.get(ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND),
bgColor = chipColor(colors),
cornerRadiusPx = cornerRadius,
rippleColor = colors.get(ColorType.KEY_TEXT)
)
Expand Down
Loading