Skip to content

Commit

Permalink
add close history view toolbar button (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
codokie authored Apr 6, 2024
1 parent dcddccc commit 38126d2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
// even when state is activated, the not activated color is set
// in suggestionStripView the same thing works correctly, wtf?
// need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key
listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL)
listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL, ToolbarKey.CLOSE_HISTORY)
.forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) }
keyboardAttr.recycle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = when (key) {
FULL_RIGHT -> KeyCode.MOVE_END_OF_LINE
SELECT_WORD -> KeyCode.CLIPBOARD_SELECT_WORD
CLEAR_CLIPBOARD -> null // not managed via code input
CLOSE_HISTORY -> KeyCode.ALPHA
}

private fun getStyleableIconId(key: ToolbarKey) = when (key) {
Expand All @@ -77,6 +78,7 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) {
FULL_LEFT -> R.styleable.Keyboard_iconFullLeft
FULL_RIGHT -> R.styleable.Keyboard_iconFullRight
SELECT_WORD -> R.styleable.Keyboard_iconSelectWord
CLOSE_HISTORY -> R.styleable.Keyboard_iconCloseView
}

fun getToolbarIconByName(name: String, context: Context): Drawable? {
Expand All @@ -91,12 +93,12 @@ fun getToolbarIconByName(name: String, context: Context): Drawable? {
// names need to be aligned with resources strings (using lowercase of key.name)
enum class ToolbarKey {
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN,
FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD
FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY
}

fun toToolbarKeyString(keys: Collection<ToolbarKey>) = keys.joinToString(";") { it.name }

val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD }.joinToString(";") {
val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD || it == CLOSE_HISTORY }.joinToString(";") {
when (it) {
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false"
else -> "${it.name},true"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_close_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24"
android:viewportWidth="24" >
<path android:fillColor="#FFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_close_view_rounded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="960"
android:viewportWidth="960" >
<path android:fillColor="#FFF"
android:pathData="m256,760 l-56,-56 224,-224 -224,-224 56,-56 224,224 224,-224 56,56 -224,224 224,224 -56,56 -224,-224 -224,224Z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
<attr name="iconBin" format="reference" />
<attr name="iconUndo" format="reference" />
<attr name="iconRedo" format="reference" />
<attr name="iconCloseView" format="reference" />
</declare-styleable>

<declare-styleable name="Keyboard_Key">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/keyboard-icons-holo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
<item name="iconFullLeft">@drawable/ic_to_start</item>
<item name="iconFullRight">@drawable/ic_to_end</item>
<item name="iconSelectWord">@drawable/ic_select</item>
<item name="iconCloseView">@drawable/ic_close_view</item>
</style>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/keyboard-icons-lxx-light.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<item name="iconFullLeft">@drawable/ic_to_start</item>
<item name="iconFullRight">@drawable/ic_to_end</item>
<item name="iconSelectWord">@drawable/ic_select</item>
<item name="iconCloseView">@drawable/ic_close_view</item>
</style>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/keyboard-icons-rounded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
<item name="iconFullLeft">@drawable/ic_to_start_rounded</item>
<item name="iconFullRight">@drawable/ic_to_end_rounded</item>
<item name="iconSelectWord">@drawable/ic_select_rounded</item>
<item name="iconCloseView">@drawable/ic_close_view_rounded</item>
</style>
</resources>

0 comments on commit 38126d2

Please sign in to comment.