Skip to content

Commit

Permalink
Rearrange UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tamo committed Jan 30, 2025
1 parent 395d954 commit 2497042
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 109 deletions.
30 changes: 15 additions & 15 deletions app/src/main/java/jp/deadend/noname/skk/FlickJPKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
a.append(KEYCODE_FLICK_JP_CHAR_TEN_NUM, arrayOf("", "", "", "", "", "", ""))
a.append(KEYCODE_FLICK_JP_CHAR_TEN_NUM_LEFT, arrayOf("", "", "", "", "", "", ""))
a.append(KEYCODE_FLICK_JP_MOJI, arrayOf("カナ", "", "10", "", "", "", ""))
a.append(KEYCODE_FLICK_JP_TOQWERTY, arrayOf("abc", "", "全角", "", "qwe", "", ""))
a.append(KEYCODE_FLICK_JP_TOQWERTY, arrayOf("abc", "", "全角a", "", "qwerty", "", ""))
}

override fun setService(service: SKKService) {
Expand Down Expand Up @@ -160,7 +160,7 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
KEYCODE_FLICK_JP_CHAR_MA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_YA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_RA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_WA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_WA -> key.label = "\nをわー\n"
KEYCODE_FLICK_JP_MOJI -> key.label = "10\n:カナ>\n"
}
} else {
Expand All @@ -174,7 +174,7 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
KEYCODE_FLICK_JP_CHAR_MA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_YA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_RA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_WA -> key.label = ""
KEYCODE_FLICK_JP_CHAR_WA -> key.label = "\nヲワー\n"
KEYCODE_FLICK_JP_MOJI -> key.label = "10\n:かな>\n"
}
}
Expand All @@ -189,14 +189,14 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
private fun onSetShifted(isShifted: Boolean) {
if (isShifted) {
mKutoutenKey.codes[0] = KEYCODE_FLICK_JP_CHAR_TEN_SHIFTED
mKutoutenKey.label = "\n □ \n"
mKutoutenKey.label = "\n\n"
mSpaceKey.label = "設定"
mQwertyKey.label = "abbr"
} else {
mKutoutenKey.codes[0] = KEYCODE_FLICK_JP_CHAR_TEN
mKutoutenKey.label = mKutoutenLabel
mSpaceKey.label = ""
mQwertyKey.label = "ABC\nabc\nqwerty"
mQwertyKey.label = "全角a\nabc\nqwerty"
}
}

Expand All @@ -210,7 +210,7 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
key = findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_RIGHT)
if (key != null) {
key.codes[0] = KEYCODE_FLICK_JP_GOOGLE
key.label = "Google\n変換"
key.label = "Google"
}
} else {
var key = findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_PASTE)
Expand Down Expand Up @@ -251,19 +251,19 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
// 句読点
when (skkPrefs.kutoutenType) {
"en" -> {
mKutoutenLabel = "\n ,!\n"
mKutoutenLabel = "\n.,!\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_CHAR_TEN, arrayOf("", "", "", "", "", "", "")
)
}
"jp_en" -> {
mKutoutenLabel = "\n ,!\n"
mKutoutenLabel = "\n。,!\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_CHAR_TEN, arrayOf("", "", "", "", "", "", "")
)
}
else -> {
mKutoutenLabel = "\n 、!\n"
mKutoutenLabel = "\n。、!\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_CHAR_TEN, arrayOf("", "", "", "", "", "", "")
)
Expand All @@ -272,21 +272,21 @@ class FlickJPKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView
mKutoutenKey.label = mKutoutenLabel
when {
skkPrefs.useSoftCancelKey -> {
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "\n └゛CXL └゜\n"
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "\n◻゙CXL◻゚\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_KOMOJI, arrayOf("CXL", "", "", "", "", "", "")
KEYCODE_FLICK_JP_KOMOJI, arrayOf("CXL", "◻゙", "", "◻゚", "", "", "")
)
}
skkPrefs.useSoftTransKey -> {
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "CXL\n└゛└゜\n"
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "CXL\n◻゙□゚\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_KOMOJI, arrayOf("└゛└゜", "", "CXL", "", "", "", "")
KEYCODE_FLICK_JP_KOMOJI, arrayOf("◻゙□゚", "◻゙", "CXL", "◻゚", "", "", "")
)
}
else -> {
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "CXL\n └゛小 └゜\n"
findKeyByCode(mJPKeyboard, KEYCODE_FLICK_JP_KOMOJI)?.label = "CXL\n◻゙小◻゚\n"
mFlickGuideLabelList.put(
KEYCODE_FLICK_JP_KOMOJI, arrayOf("", "", "CXL", "", "", "", "")
KEYCODE_FLICK_JP_KOMOJI, arrayOf("", "◻゙", "CXL", "◻゚", "", "", "")
)
}
}
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/jp/deadend/noname/skk/GodanKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class GodanKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView(c

cancelKey.codes[0] = KEYCODE_GODAN_CANCEL
cancelKey.codes[1] = KEYCODE_GODAN_NONE
cancelKey.label = "cxl"
cancelKey.label = /* if (!mIsASCII && skkPrefs.simpleGodan) "cxl" else */ "貼付\ncxl\ngoogle"
cancelKey.icon = null

keyboard.reloadShiftKeys()
Expand All @@ -122,10 +122,10 @@ class GodanKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView(c
}

cancelKey.codes[0] = KEYCODE_GODAN_CANCEL
cancelKey.label = "cxl"
cancelKey.label = /* if (!mIsASCII && skkPrefs.simpleGodan) "cxl" else */ "貼付\ncxl\ngoogle"

qKey.codes[0] = KEYCODE_GODAN_CHAR_Q
qKey.label = "Q"
qKey.label = /* if (!mIsASCII && skkPrefs.simpleGodan) "Q" else */ "かな\nQ\n半カナ"
}

fun setKeyState(state: SKKState): GodanKeyboardView {
Expand Down Expand Up @@ -165,7 +165,7 @@ class GodanKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView(c
key = findKeyByCode(keyboard, KEYCODE_GODAN_RIGHT)
if (key != null) {
key.codes[0] = KEYCODE_GODAN_GOOGLE
key.label = "Google\n変換"
key.label = "Google"
}
} else {
var key = findKeyByCode(keyboard, KEYCODE_GODAN_PASTE)
Expand Down Expand Up @@ -214,21 +214,21 @@ class GodanKeyboardView(context: Context, attrs: AttributeSet?) : KeyboardView(c

when {
skkPrefs.useSoftCancelKey -> {
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "\n └゛cxl └゜\n"
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "\n◻゙cxl◻゚\n"
mFlickGuideLabelList.put(
KEYCODE_GODAN_KOMOJI, arrayOf("CXL", "", "", "", "", "", "")
KEYCODE_GODAN_KOMOJI, arrayOf("CXL", "◻゙", "", "◻゚", "", "", "")
)
}
skkPrefs.useSoftTransKey -> {
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "cxl\n└゛└゜\n"
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "cxl\n◻゙□゚\n"
mFlickGuideLabelList.put(
KEYCODE_GODAN_KOMOJI, arrayOf("└゛└゜", "", "CXL", "", "", "", "")
KEYCODE_GODAN_KOMOJI, arrayOf("◻゙□゚", "◻゙", "CXL", "◻゚", "", "", "")
)
}
else -> {
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "cxl\n └゛小 └゜\n"
findKeyByCode(keyboard, KEYCODE_GODAN_KOMOJI)?.label = "cxl\n◻゙小◻゚\n"
mFlickGuideLabelList.put(
KEYCODE_GODAN_KOMOJI, arrayOf("", "", "CXL", "", "", "", "")
KEYCODE_GODAN_KOMOJI, arrayOf("", "◻゙", "CXL", "◻゚", "", "", "")
)
}
}
Expand Down
75 changes: 56 additions & 19 deletions app/src/main/java/jp/deadend/noname/skk/KeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ open class KeyboardView @JvmOverloads constructor(
R.styleable.KeyboardView_keyTextColor ->
mKeyTextColor = a.getColor(attr, -0x1000000)
R.styleable.KeyboardView_labelTextSize ->
mLabelTextSize = a.getDimensionPixelSize(attr, 14)
mLabelTextSize = a.getDimensionPixelSize(attr, 16)
R.styleable.KeyboardView_popupLayout ->
mPopupLayout = a.getResourceId(attr, 0)
}
Expand Down Expand Up @@ -398,53 +398,90 @@ open class KeyboardView @JvmOverloads constructor(
keyBackground?.draw(canvas)
if (label != null) {
// For characters, use large font. For labels like "Done", use small font.
if (label.length > 1 && key.codes.size < 2) {
if (label.length > 1 && !label.contains('\n') && key.codes.size < 2) {
mPaint.textSize = mLabelTextSize.toFloat()
mPaint.typeface = Typeface.DEFAULT_BOLD
mPaint.textScaleX = 1.0f
} else {
mPaint.textSize = mKeyTextSize.toFloat()
mPaint.typeface = Typeface.DEFAULT
mPaint.textScaleX = if (isZenkaku) 1.4f else 1.0f
}
val lines = label.split("\n")
val numLines = lines.size
val isGodanKey = numLines == 3 &&
lines[0].length == 1 &&
lines[1].length == 3 &&
lines[2].length == 1
val sizeFactors = if (numLines == 3) {
listOf(.4f, .8f, .4f) // Godan以外でも中央の行を大きくする (「わ」「abc」等)
} else {
listOf(1f, 1f, 1f)
}
val sizeDefault = mPaint.textSize
val lineScale = 1.5f
lines.forEachIndexed { i, line ->
// Draw the text
canvas.drawText(
line,
(key.width - mPadding.left - mPadding.right) / 2f + mPadding.left,
(key.height - mPadding.top - mPadding.bottom) / 2f + mPadding.top
- mPaint.descent() + lineScale * (
(mPaint.textSize * numLines - mPaint.descent()) / 2f
- mPaint.textSize * (numLines - 1 - i)),
mPaint
)
fun drawText(t: String, descent: Float) {
canvas.drawText(
t,
(key.width + mPadding.left - mPadding.right) / 2f,
(key.height + mPadding.top - mPadding.bottom) / 2f
+ lineScale * (((0..<numLines).fold(0f) { s, j ->
s + sizeDefault * sizeFactors[j]
}) - descent) / 2f
- lineScale * ((0..<numLines - 1 - i).fold(0f) { s, j ->
s + sizeDefault * sizeFactors[j]
}) - descent,
mPaint
)
}

mPaint.textSize = sizeDefault * sizeFactors[i]
mPaint.typeface = if (i.toFloat() == (numLines - 1) / 2f) {
Typeface.DEFAULT_BOLD // 中央の行 (1行だけならその行)
} else {
Typeface.DEFAULT
}

if (isGodanKey && i == 1) {
val descent = mPaint.descent()
drawText(line[1].toString(), descent)

// 左右フリックのキー
mPaint.typeface = Typeface.DEFAULT
mPaint.textSize *= .8f
drawText("${line[0]}  ${line[2]}", descent)
} else {
drawText(line, mPaint.descent())
}
}

// 英数キーボードの上下フリックやシフトを上下に小さく表示
val savedAlign = mPaint.textAlign
if (!shiftedLabel.isNullOrEmpty()
&& shiftedLabel != label.uppercase()
&& shiftedLabel != label.lowercase()
) {
mPaint.textSize = mKeyTextSize / 2f
mPaint.textAlign = Align.LEFT
mPaint.textSize = mKeyTextSize * .6f
mPaint.typeface = Typeface.DEFAULT
canvas.drawText(
shiftedLabel,
key.width - mPadding.right - mPaint.textSize,
mPadding.top + mPaint.textSize,
mPadding.left + mPaint.textSize,
mPadding.top + mPaint.textSize * 1.5f,
mPaint
)
}
if (key.downLabel.isNotEmpty()) {
mPaint.textSize = mKeyTextSize / 2f
mPaint.textAlign = Align.RIGHT
mPaint.textSize = mKeyTextSize * .6f
mPaint.typeface = Typeface.DEFAULT
canvas.drawText(
key.downLabel.toString(),
key.width - mPadding.right - mPaint.textSize,
key.height - mPadding.bottom - mPaint.textSize,
key.height - mPadding.bottom - mPaint.textSize * .5f,
mPaint
)
}
mPaint.textAlign = savedAlign
} else if (icon != null) {
val drawableX =
(key.width - mPadding.left - mPadding.right - icon.intrinsicWidth) / 2 + mPadding.left
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/keyboard_key_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="80sp"
android:maxLines="1"
android:textSize="40sp"
android:autoSizeMaxTextSize="40sp"
android:autoSizeTextType="uniform"
android:textColor="@color/key_char_color"
android:minWidth="32dip"
android:gravity="center"
Expand Down
45 changes: 25 additions & 20 deletions app/src/main/res/layout/popup_flickguide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
android:includeFontPadding="false"
android:textColor="@color/key_char_color"
android:textSize="22sp"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="8sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
android:maxLines="1"
android:autoSizeMaxTextSize="22sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform" />

<TextView
android:id="@+id/labelI"
Expand All @@ -34,10 +35,11 @@
android:includeFontPadding="false"
android:textColor="@color/key_char_color"
android:textSize="22sp"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="8sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
android:maxLines="1"
android:autoSizeMaxTextSize="22sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform" />

<TextView
android:id="@+id/labelU"
Expand All @@ -51,10 +53,11 @@
android:includeFontPadding="false"
android:textColor="@color/key_char_color"
android:textSize="22sp"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="8sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
android:maxLines="1"
android:autoSizeMaxTextSize="22sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform" />

<TextView
android:id="@+id/labelE"
Expand All @@ -68,10 +71,11 @@
android:includeFontPadding="false"
android:textColor="@color/key_char_color"
android:textSize="22sp"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="8sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
android:maxLines="1"
android:autoSizeMaxTextSize="22sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform" />

<TextView
android:id="@+id/labelO"
Expand All @@ -85,10 +89,11 @@
android:includeFontPadding="false"
android:textColor="@color/key_char_color"
android:textSize="22sp"
app:autoSizeMaxTextSize="22sp"
app:autoSizeMinTextSize="8sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
android:maxLines="1"
android:autoSizeMaxTextSize="22sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform" />

<TextView
android:id="@+id/labelLeftA"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<item>off</item>
</string-array>
<string-array name="sensitivity_entries">
<item>高</item>
<item>高 (小さいキーに最適)</item>
<item>中</item>
<item>低</item>
<item>低 (大きいキーに最適)</item>
</string-array>
<string-array name="sensitivity_values">
<item>high</item>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/keys_flick_jp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<Row app:rowEdgeFlags="bottom">
<Key app:codes="-1003" app:keyLabel="ABC\nabc\nqwerty" />
<Key app:codes="-1006" app:keyLabel="CXL\n ゛小 ゜\n▽" />
<Key app:codes="-210" app:keyLabel="" />
<Key app:codes="-211" app:keyLabel="?\n。 、!\n…" />
<Key app:codes="-210" app:keyLabel="ん\nをわー\n〜" />
<Key app:codes="-211" app:keyLabel="?\n。、!\n…" />
<Key app:codes="-1007" app:keyIcon="@drawable/ic_keyboard_return" />
</Row>
</Keyboard>
Loading

0 comments on commit 2497042

Please sign in to comment.