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,7 @@ fun FlickMapping.toFlickAction(): FlickAction {
"ForceHalfWidthSpace" -> KeyAction.ForceHalfWidthSpace
"ForceFullWidthSpace" -> KeyAction.ForceFullWidthSpace
"ShowEmojiKeyboard" -> KeyAction.ShowEmojiKeyboard
"SwitchToKana" -> KeyAction.SwitchToKanaLayout
"SwitchToEnglish" -> KeyAction.SwitchToEnglishLayout
"SwitchToNumber" -> KeyAction.SwitchToNumberLayout
"DeleteUntilSymbol" -> KeyAction.DeleteUntilSymbol
Expand Down Expand Up @@ -223,6 +224,7 @@ fun FlickAction.toDbStrings(): Pair<String, String?> {
KeyAction.ForceHalfWidthSpace -> "ForceHalfWidthSpace" to null
KeyAction.ForceFullWidthSpace -> "ForceFullWidthSpace" to null
KeyAction.ShowEmojiKeyboard -> "ShowEmojiKeyboard" to CircularFlickSlotActionMapper.EMOJI_KEYBOARD_LABEL
KeyAction.SwitchToKanaLayout -> "SwitchToKana" to null
KeyAction.SwitchToEnglishLayout -> "SwitchToEnglish" to null
KeyAction.SwitchToNumberLayout -> "SwitchToNumber" to null
KeyAction.DeleteUntilSymbol -> "DeleteUntilSymbol" to null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ class EditableFlickKeyboardView @JvmOverloads constructor(
}
} else {
AutoSizeButton(context).apply {
val label = KeyIconResolver.resolvedLabelForRendering(keyData)
val label = KeyIconResolver.resolvedLabelForRendering(keyData, context)
isFocusable = false; isClickable = true
isAllCaps = false
minimumHeight = 0
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.kazumaproject.markdownhelperkeyboard.custom_keyboard.ui

import android.os.Bundle
import androidx.core.os.bundleOf
import com.kazumaproject.custom_keyboard.data.FlickAction
import com.kazumaproject.custom_keyboard.data.FlickDirection
import com.kazumaproject.custom_keyboard.data.KeyAction
import com.kazumaproject.custom_keyboard.data.KeyActionMapper
import com.kazumaproject.custom_keyboard.data.KeyData

internal val specialFlickDirections = listOf(
FlickDirection.TAP,
FlickDirection.UP,
FlickDirection.DOWN,
FlickDirection.UP_LEFT,
FlickDirection.UP_RIGHT
)

internal sealed interface MixedFlickSlot {
data object Unassigned : MixedFlickSlot
data class Text(val output: String = "") : MixedFlickSlot
data class Action(val action: KeyAction? = null) : MixedFlickSlot

fun toFlickAction(): FlickAction? = when (this) {
Unassigned -> null
is Text -> output.takeIf(String::isNotEmpty)?.let { FlickAction.Input(it) }
is Action -> action?.let { FlickAction.Action(it) }
}

companion object {
fun fromFlickAction(action: FlickAction?): MixedFlickSlot = when (action) {
is FlickAction.Input -> if (action.char.isEmpty()) Unassigned else Text(action.char)
is FlickAction.Action -> when (val keyAction = action.action) {
is KeyAction.Text -> Text(keyAction.text)
is KeyAction.InputText -> Text(keyAction.text)
else -> Action(keyAction)
}
null -> Unassigned
}
}
}

internal class MixedFlickEditorState(
val slots: MutableMap<FlickDirection, MixedFlickSlot>,
var label: String,
var selectedDirection: FlickDirection = FlickDirection.TAP
) {
fun canSave(validTargetIds: Set<String>): Boolean =
slots[FlickDirection.TAP]?.toFlickAction() != null &&
slots.values.all { (it as? MixedFlickSlot.Action)?.action.isValidMoveToCustomKeyboardTarget(validTargetIds) }

fun toBundle(): Bundle = bundleOf(
"label" to label,
"selectedDirection" to selectedDirection.name,
"slots" to Bundle().apply {
slots.forEach { (direction, slot) ->
val value = when (slot) {
MixedFlickSlot.Unassigned -> null
is MixedFlickSlot.Text -> bundleOf("text" to slot.output)
is MixedFlickSlot.Action -> bundleOf(
"action" to KeyActionMapper.fromKeyAction(slot.action),
"pendingTarget" to (slot.action == KeyAction.MoveToCustomKeyboard(""))
)
}
putBundle(direction.name, value)
}
}
)

companion object {
fun fromKey(key: KeyData, flickMap: Map<FlickDirection, FlickAction>): MixedFlickEditorState {
val slots = specialFlickDirections.associateWith { direction ->
val alternate = when (direction) {
FlickDirection.UP_LEFT -> flickMap[FlickDirection.UP_LEFT_FAR]
FlickDirection.UP_RIGHT -> flickMap[FlickDirection.UP_RIGHT_FAR]
else -> null
}
val fallback = key.action?.takeIf { direction == FlickDirection.TAP }
?.let { FlickAction.Action(it) }
val saved = flickMap[direction] ?: alternate
MixedFlickSlot.fromFlickAction(
saved?.takeUnless { it is FlickAction.Input && it.char.isEmpty() } ?: fallback
)
}.toMutableMap()
return MixedFlickEditorState(slots, key.label.takeUnless { key.isSpecialKey }.orEmpty())
}

fun fromBundle(bundle: Bundle): MixedFlickEditorState {
val savedSlots = bundle.getBundle("slots")
return MixedFlickEditorState(
slots = specialFlickDirections.associateWith { direction ->
val slot = savedSlots?.getBundle(direction.name)
when {
slot == null -> MixedFlickSlot.Unassigned
slot.containsKey("text") -> MixedFlickSlot.Text(slot.getString("text").orEmpty())
slot.getBoolean("pendingTarget") -> MixedFlickSlot.Action(KeyAction.MoveToCustomKeyboard(""))
else -> MixedFlickSlot.Action(KeyActionMapper.toKeyAction(slot.getString("action")))
}
}.toMutableMap(),
label = bundle.getString("label").orEmpty(),
selectedDirection = specialFlickDirections.firstOrNull {
it.name == bundle.getString("selectedDirection")
} ?: FlickDirection.TAP
)
}
}
}
77 changes: 77 additions & 0 deletions app/src/main/res/layout/fragment_key_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
android:id="@+id/key_type_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:selectionRequired="true"
app:singleSelection="true">

<com.google.android.material.chip.Chip
Expand All @@ -42,6 +43,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/special_key" />

<com.google.android.material.chip.Chip
android:id="@+id/chip_mixed"
style="@style/Widget.Material3.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:text="@string/mixed_key" />
</com.google.android.material.chip.ChipGroup>

<!-- NEW: Special category selector -->
Expand Down Expand Up @@ -326,6 +335,23 @@
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mixed_key_label_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/key_label"
android:visibility="gone">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/mixed_key_label_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:saveEnabled="false" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/key_action_layout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
Expand Down Expand Up @@ -545,6 +571,40 @@
tools:text="右フリック時の挙動"
tools:visibility="visible" />

<com.google.android.material.chip.ChipGroup
android:id="@+id/mixed_flick_slot_type_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="gone"
app:selectionRequired="true"
app:singleSelection="true">

<com.google.android.material.chip.Chip
android:id="@+id/chip_mixed_unassigned"
style="@style/Widget.Material3.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:text="@string/mixed_flick_unassigned" />

<com.google.android.material.chip.Chip
android:id="@+id/chip_mixed_text"
style="@style/Widget.Material3.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:text="@string/mixed_flick_text" />

<com.google.android.material.chip.Chip
android:id="@+id/chip_mixed_action"
style="@style/Widget.Material3.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:text="@string/mixed_flick_action" />
</com.google.android.material.chip.ChipGroup>

<!-- 文字入力欄(ペタル・2段フリックのテキスト入力用) -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_char_input_layout"
Expand Down Expand Up @@ -581,6 +641,23 @@
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mixed_flick_target_layout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/custom_keyboard_target_hint"
android:visibility="gone">

<AutoCompleteTextView
android:id="@+id/mixed_flick_target_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:saveEnabled="false" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/long_press_action_layout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@
<string name="editor_cycle_target">挿入方向切替</string>
<string name="normal_key">通常キー</string>
<string name="special_key">特別なキー</string>
<string name="mixed_key">混在キー</string>
<string name="mixed_flick_unassigned">未設定</string>
<string name="mixed_flick_text">文字入力</string>
<string name="mixed_flick_action">特殊アクション</string>
<string name="key_label">キーの表示ラベル</string>
<string name="key_action">キーのアクション</string>
<string name="double_tap_action">ダブルタップのアクション</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,10 @@
<string name="editor_cycle_target">Cycle target</string>
<string name="normal_key">Normal Key</string>
<string name="special_key">Special Key</string>
<string name="mixed_key">Mixed Key</string>
<string name="mixed_flick_unassigned">Unassigned</string>
<string name="mixed_flick_text">Text Input</string>
<string name="mixed_flick_action">Special Action</string>
<string name="key_label">Label for Key Display</string>
<string name="key_action">Action for Key</string>
<string name="double_tap_action">Double-tap action</string>
Expand Down
Loading
Loading