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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class ThemePrefs(sharedPreferences: SharedPreferences) :

val keyRadius = int(R.string.key_radius, "key_radius", 4, 0, 48, "dp")

val textEditingButtonRadius =
int(R.string.text_editing_button_radius, "text_editing_button_radius", 8, 0, 48, "dp")

val clipboardEntryRadius =
int(R.string.clipboard_entry_radius, "clipboard_entry_radius", 2, 0, 48, "dp")

enum class PunctuationPosition {
Bottom,
TopRight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlin.math.min

abstract class ClipboardAdapter(
private val theme: Theme,
private val entryRadius: Float,
private val maskSensitive: Boolean
) : PagingDataAdapter<ClipboardEntry, ClipboardAdapter.ViewHolder>(diffCallback) {

Expand Down Expand Up @@ -87,7 +88,7 @@ abstract class ClipboardAdapter(
class ViewHolder(val entryUi: ClipboardEntryUi) : RecyclerView.ViewHolder(entryUi.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(ClipboardEntryUi(parent.context, theme))
ViewHolder(ClipboardEntryUi(parent.context, theme, entryRadius))

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val entry = getItem(position) ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import splitties.views.dsl.core.wrapContent
import splitties.views.imageDrawable
import splitties.views.setPaddingDp

class ClipboardEntryUi(override val ctx: Context, private val theme: Theme) : Ui {
class ClipboardEntryUi(override val ctx: Context, private val theme: Theme, radius: Float) : Ui {

val textView = textView {
minLines = 1
Expand Down Expand Up @@ -62,7 +62,6 @@ class ClipboardEntryUi(override val ctx: Context, private val theme: Theme) : Ui
override val root = CustomGestureView(ctx).apply {
isClickable = true
minimumHeight = dp(30)
val radius = dp(2f)
foreground = RippleDrawable(
ColorStateList.valueOf(theme.keyPressHighlightColor), null,
GradientDrawable().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.fcitx.fcitx5.android.data.clipboard.ClipboardManager
import org.fcitx.fcitx5.android.data.clipboard.db.ClipboardEntry
import org.fcitx.fcitx5.android.data.prefs.AppPrefs
import org.fcitx.fcitx5.android.data.prefs.ManagedPreference
import org.fcitx.fcitx5.android.data.theme.ThemeManager
import org.fcitx.fcitx5.android.input.FcitxInputMethodService
import org.fcitx.fcitx5.android.input.clipboard.ClipboardStateMachine.BooleanKey.ClipboardDbEmpty
import org.fcitx.fcitx5.android.input.clipboard.ClipboardStateMachine.BooleanKey.ClipboardListeningEnabled
Expand Down Expand Up @@ -74,13 +75,19 @@ class ClipboardWindow : InputWindow.ExtendedInputWindow<ClipboardWindow>() {
private val clipboardReturnAfterPaste by prefs.clipboardReturnAfterPaste
private val clipboardMaskSensitive by prefs.clipboardMaskSensitive

private val clipboardEntryRadius by ThemeManager.prefs.clipboardEntryRadius

private val clipboardEntriesPager by lazy {
Pager(PagingConfig(pageSize = 16)) { ClipboardManager.allEntries() }
}
private var adapterSubmitJob: Job? = null

private val adapter: ClipboardAdapter by lazy {
object : ClipboardAdapter(this@ClipboardWindow.theme, clipboardMaskSensitive) {
object : ClipboardAdapter(
theme,
context.dp(clipboardEntryRadius.toFloat()),
clipboardMaskSensitive
) {
override fun onPin(id: Int) {
service.lifecycleScope.launch { ClipboardManager.pin(id) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2024 Fcitx5 for Android Contributors
*/

package org.fcitx.fcitx5.android.input.editing

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.InsetDrawable
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.RippleDrawable
import android.graphics.drawable.StateListDrawable
import androidx.annotation.DrawableRes
import org.fcitx.fcitx5.android.data.theme.Theme
import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView
import org.fcitx.fcitx5.android.utils.borderDrawable
import org.fcitx.fcitx5.android.utils.pressHighlightDrawable
import org.fcitx.fcitx5.android.utils.rippleDrawable
import splitties.dimensions.dp
import splitties.views.dsl.core.add
import splitties.views.dsl.core.imageView
import splitties.views.dsl.core.lParams
import splitties.views.dsl.core.textView
import splitties.views.dsl.core.wrapContent
import splitties.views.gravityCenter
import splitties.views.imageResource
import kotlin.math.max

@SuppressLint("ViewConstructor")
class TextEditingButton(
ctx: Context,
private val theme: Theme,
private val rippled: Boolean,
private val bordered: Boolean,
private val radius: Float,
private val altStyle: Boolean = false
) : CustomGestureView(ctx) {

// bordered
private val shadowWidth = dp(1)
private val hMargin = dp(4)
private val vMargin = dp(4)

// !bordered
private val lineWidth = max(1, dp(1) / 2)

init {
if (bordered) {
background = LayerDrawable(
arrayOf(
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.keyShadowColor)
},
GradientDrawable().apply {
cornerRadius = radius
setColor(if (altStyle) theme.altKeyBackgroundColor else theme.keyBackgroundColor)
}
)
).apply {
setLayerInset(0, hMargin, vMargin, hMargin, vMargin - shadowWidth)
setLayerInset(1, hMargin, vMargin, hMargin, vMargin)
}
if (rippled) {
foreground = RippleDrawable(
ColorStateList.valueOf(theme.keyPressHighlightColor), null,
// ripple should be masked with an opaque color
InsetDrawable(
GradientDrawable().apply {
cornerRadius = radius
setColor(Color.WHITE)
},
hMargin, vMargin, hMargin, vMargin
)
)
} else {
foreground = StateListDrawable().apply {
addState(
intArrayOf(android.R.attr.state_pressed),
// use mask drawable as highlight directly
InsetDrawable(
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.keyPressHighlightColor)
},
hMargin, vMargin, hMargin, vMargin
)
)
}
}
} else {
background = borderDrawable(lineWidth, theme.dividerColor)
foreground =
if (rippled) rippleDrawable(theme.keyPressHighlightColor)
else pressHighlightDrawable(theme.keyPressHighlightColor)
}
}

val textView = textView {
isClickable = false
isFocusable = false
background = null
setTextColor(if (altStyle) theme.altKeyTextColor else theme.keyTextColor)
}

val imageView = imageView {
isClickable = false
isFocusable = false
imageTintList = ColorStateList.valueOf(theme.altKeyTextColor)
}

fun setText(id: Int) {
textView.setText(id)
removeView(imageView)
add(textView, lParams(wrapContent, wrapContent, gravityCenter))
}

fun setIcon(@DrawableRes icon: Int) {
imageView.imageResource = icon
removeView(textView)
add(imageView, lParams(wrapContent, wrapContent, gravityCenter))
}

fun enableActivatedState() {
textView.setTextColor(
ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_activated),
intArrayOf(android.R.attr.state_enabled)
),
intArrayOf(
theme.genericActiveForegroundColor,
if (altStyle) theme.altKeyTextColor else theme.keyTextColor
)
)
)
imageView.imageTintList = ColorStateList(
arrayOf(
intArrayOf(android.R.attr.state_activated),
intArrayOf(android.R.attr.state_enabled)
),
intArrayOf(
theme.genericActiveForegroundColor,
theme.altKeyTextColor
)
)
if (bordered) {
background = StateListDrawable().apply {
addState(
intArrayOf(android.R.attr.state_activated),
LayerDrawable(
arrayOf(
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.keyShadowColor)
},
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.genericActiveBackgroundColor)
}
)
).apply {
setLayerInset(0, hMargin, vMargin, hMargin, vMargin - shadowWidth)
setLayerInset(1, hMargin, vMargin, hMargin, vMargin)
}
)
addState(
intArrayOf(android.R.attr.state_enabled),
LayerDrawable(
arrayOf(
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.keyShadowColor)
},
GradientDrawable().apply {
cornerRadius = radius
setColor(theme.keyBackgroundColor)
}
)
).apply {
setLayerInset(0, hMargin, vMargin, hMargin, vMargin - shadowWidth)
setLayerInset(1, hMargin, vMargin, hMargin, vMargin)
}
)
}
} else {
background = StateListDrawable().apply {
addState(
intArrayOf(android.R.attr.state_activated),
borderDrawable(
lineWidth,
theme.dividerColor,
theme.genericActiveBackgroundColor
)
)
addState(
intArrayOf(android.R.attr.state_enabled),
borderDrawable(lineWidth, theme.dividerColor)
)
}
}
}
}
Loading