Skip to content

Commit

Permalink
Merge branch 'main' into clipboard-clear
Browse files Browse the repository at this point in the history
  • Loading branch information
codokie authored Apr 12, 2024
2 parents 5d4b5fa + 28bc9a4 commit 4d9f904
Show file tree
Hide file tree
Showing 32 changed files with 1,016 additions and 206 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "helium314.keyboard"
minSdkVersion 21
targetSdkVersion 34
versionCode 1002
versionName '1.2'
versionCode 1003
versionName '1.3-beta1'
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/dictionaries_in_dict_repo.csv
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ main,ur,
main,af,exp
main,ar,exp
main,bn,exp
main,bn_BD,exp
main,bg,exp
main,cs,exp
main,en_GB,exp
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/assets/language_key_texts/cv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[popup_keys]
" « » „ “ ”
у у́ ү ӯ
к қ
е е́ ә
н ң
г ғ
х ҳ
ы ы́
а а́
о о́ ө
ж җ
э э́ є
я я́
ч ҷ
и и́ і ӣ
ю ю́

[labels]
alphabet: АБВ
44 changes: 44 additions & 0 deletions app/src/main/assets/layouts/chuvash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ё
ӑ
ӗ
ҫ
ӳ
ъ
-
!
?
"

й
ц
у
к
е
н
г
ш
щ
з
х

ф
ы
в
а
п
р
о
л
д
ж
э

я
ч
с
м
и
т
ь
б
ю
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, ToolbarKey.CLOSE_HISTORY)
listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CUT, 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 @@ -52,6 +52,7 @@ public final class KeyboardIconsSet {
public static final String NAME_CLIPBOARD_ACTION_KEY = "clipboard_action_key";
public static final String NAME_CLIPBOARD_NORMAL_KEY = "clipboard_normal_key";
public static final String NAME_CLEAR_CLIPBOARD_KEY = "clear_clipboard_key";
public static final String NAME_CUT_KEY = "cut_key";
public static final String NAME_NUMPAD_KEY = "numpad_key";
public static final String NAME_START_ONEHANDED_KEY = "start_onehanded_mode_key";
public static final String NAME_STOP_ONEHANDED_KEY = "stop_onehanded_mode_key";
Expand Down Expand Up @@ -89,6 +90,7 @@ public final class KeyboardIconsSet {
NAME_CLIPBOARD_ACTION_KEY, R.styleable.Keyboard_iconClipboardActionKey,
NAME_CLIPBOARD_NORMAL_KEY, R.styleable.Keyboard_iconClipboardNormalKey,
NAME_CLEAR_CLIPBOARD_KEY, R.styleable.Keyboard_iconClearClipboardKey,
NAME_CUT_KEY, R.styleable.Keyboard_iconCutKey,
NAME_NUMPAD_KEY, R.styleable.Keyboard_iconNumpadKey,
NAME_START_ONEHANDED_KEY, R.styleable.Keyboard_iconStartOneHandedMode,
NAME_STOP_ONEHANDED_KEY, R.styleable.Keyboard_iconStopOneHandedMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.SharedPreferences
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import androidx.preference.PreferenceManager
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import helium314.keyboard.compat.ClipboardManagerCompat
Expand Down Expand Up @@ -110,19 +109,18 @@ class ClipboardHistoryManager(
// Copies a CharSequence to internal clipboard.
// If there is already an entry with the same text,
// then only its timestamp and position is updated.
fun copyTextToInternalClipboard(text: CharSequence) {
if (TextUtils.isEmpty(text)) return
val timeStamp = System.currentTimeMillis()
val from = historyEntries.indexOfFirst { it.content.toString() == text.toString() }
if (from != -1) {
val historyEntry = historyEntries[from]
historyEntry.timeStamp = timeStamp
fun copyTextToInternalClipboard(content: CharSequence, timeStamp: Long = System.currentTimeMillis()) {
if (TextUtils.isEmpty(content)) return
val duplicateEntryIndex = historyEntries.indexOfFirst { it.content.toString() == content.toString() }
if (duplicateEntryIndex != -1) {
val existingEntry = historyEntries[duplicateEntryIndex]
existingEntry.timeStamp = timeStamp
sortHistoryEntries()
val to = historyEntries.indexOf(historyEntry)
onHistoryChangeListener?.onClipboardHistoryEntryMoved(from, to)
val newIndex = historyEntries.indexOf(existingEntry)
onHistoryChangeListener?.onClipboardHistoryEntryMoved(duplicateEntryIndex, newIndex)
return
}
val entry = ClipboardHistoryEntry(timeStamp, text)
val entry = ClipboardHistoryEntry(timeStamp, content)
historyEntries.add(entry)
sortHistoryEntries()
val at = historyEntries.indexOf(entry)
Expand Down Expand Up @@ -223,4 +221,4 @@ class ClipboardHistoryManager(
private const val ONE_MINUTE_MILLIS = 60 * 1000L
private const val DEFAULT_RETENTION_TIME_MIN = 10
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,16 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp
inputTransaction.getMSettingsValues().mClipboardHistoryEnabled
&& inputTransaction.getMSettingsValues().mCopyToInternalClipboard);
break;
case KeyCode.CLIPBOARD_CUT:
if (mConnection.hasSelection()) {
mConnection.copyText();
// fake delete keypress to remove the text
final Event backspaceEvent = LatinIME.createSoftwareKeypressEvent(KeyCode.DELETE,
event.getMX(), event.getMY(), event.isKeyRepeat());
handleBackspaceEvent(backspaceEvent, inputTransaction, currentKeyboardScript);
inputTransaction.setDidAffectContents();
}
break;
case KeyCode.ARROW_LEFT:
sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object ScriptUtils {
"ar", "ur", "fa" -> SCRIPT_ARABIC
"hy" -> SCRIPT_ARMENIAN
"bn" -> SCRIPT_BENGALI
"sr", "mk", "ru", "uk", "mn", "be", "kk", "ky", "bg", "xdq" -> SCRIPT_CYRILLIC
"sr", "mk", "ru", "uk", "mn", "be", "kk", "ky", "bg", "xdq", "cv" -> SCRIPT_CYRILLIC
"ka" -> SCRIPT_GEORGIAN
"el" -> SCRIPT_GREEK
"iw" -> SCRIPT_HEBREW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = when (key) {
CLIPBOARD -> KeyCode.CLIPBOARD
SELECT_ALL -> KeyCode.CLIPBOARD_SELECT_ALL
COPY -> KeyCode.CLIPBOARD_COPY
CUT -> KeyCode.CLIPBOARD_CUT
ONE_HANDED -> if (Settings.getInstance().current.mOneHandedModeEnabled) KeyCode.STOP_ONE_HANDED_MODE else KeyCode.START_ONE_HANDED_MODE
LEFT -> KeyCode.ARROW_LEFT
RIGHT -> KeyCode.ARROW_RIGHT
Expand All @@ -65,6 +66,7 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) {
CLIPBOARD -> R.styleable.Keyboard_iconClipboardNormalKey
SELECT_ALL -> R.styleable.Keyboard_iconSelectAll
COPY -> R.styleable.Keyboard_iconCopyKey
CUT -> R.styleable.Keyboard_iconCutKey
ONE_HANDED -> R.styleable.Keyboard_iconStartOneHandedMode
LEFT -> R.styleable.Keyboard_iconArrowLeft
RIGHT -> R.styleable.Keyboard_iconArrowRight
Expand Down Expand Up @@ -92,15 +94,15 @@ 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,
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, ONE_HANDED, LEFT, RIGHT, UP, DOWN,
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 || it == CLOSE_HISTORY }.joinToString(";") {
when (it) {
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false"
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT, CUT -> "${it.name},false"
else -> "${it.name},true"
}
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/sym_keyboard_cut.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="M9.64,7.64c0.23,-0.5 0.36,-1.05 0.36,-1.64 0,-2.21 -1.79,-4 -4,-4S2,3.79 2,6s1.79,4 4,4c0.59,0 1.14,-0.13 1.64,-0.36L10,12l-2.36,2.36C7.14,14.13 6.59,14 6,14c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4c0,-0.59 -0.13,-1.14 -0.36,-1.64L12,14l7,7h3v-1L9.64,7.64zM6,8c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM6,20c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM12,12.5c-0.28,0 -0.5,-0.22 -0.5,-0.5s0.22,-0.5 0.5,-0.5 0.5,0.22 0.5,0.5 -0.22,0.5 -0.5,0.5zM19,3l-6,6 2,2 7,-7L22,3z"/>
</vector>
Loading

0 comments on commit 4d9f904

Please sign in to comment.