Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,18 @@ detekt {
}

dependencies {


implementation(libs.fossify.commons)
implementation(libs.androidx.emoji2.bundled)
implementation(libs.androidx.autofill)

implementation(libs.bundles.room)
ksp(libs.androidx.room.compiler)
detektPlugins(libs.compose.detekt)

implementation (project(":emojipicker"))

}


Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen

override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == PICK_EXPORT_CLIPS_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
if (requestCode == PICK_EXPORT_CLIPS_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) {
val outputStream = contentResolver.openOutputStream(resultData.data!!)
exportClipsTo(outputStream)
} else if (requestCode == PICK_IMPORT_CLIPS_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
} else if (requestCode == PICK_IMPORT_CLIPS_SOURCE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) {
val inputStream = contentResolver.openInputStream(resultData.data!!)
parseFile(inputStream)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package org.fossify.keyboard.helpers

import android.os.Bundle
import android.text.Editable
import android.text.Spanned
import android.text.style.SuggestionSpan
import android.util.Log
import android.view.inputmethod.BaseInputConnection
import android.view.inputmethod.CompletionInfo
import android.view.inputmethod.CorrectionInfo
import android.view.inputmethod.ExtractedText
import android.view.inputmethod.ExtractedTextRequest
import android.widget.SearchView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatAutoCompleteTextView

/**
* Source: https://stackoverflow.com/a/39460124
*/
class OtherInputConnection(private val mTextView: AppCompatAutoCompleteTextView?) : BaseInputConnection(
mTextView!!, true
) {
// Keeps track of nested begin/end batch edit to ensure this connection always has a
// balanced impact on its associated TextView.
// A negative value means that this connection has been finished by the InputMethodManager.
private var mBatchEditNesting = 0


override fun getEditable(): Editable? {
val tv = mTextView

return tv?.editableText
}



override fun beginBatchEdit(): Boolean {
synchronized(this) {
if (mBatchEditNesting >= 0) {
mTextView!!.beginBatchEdit()
mBatchEditNesting++
return true
}
}
return false
}

override fun endBatchEdit(): Boolean {
synchronized(this) {
if (mBatchEditNesting > 0) {
// When the connection is reset by the InputMethodManager and reportFinish
// is called, some endBatchEdit calls may still be asynchronously received from the
// IME. Do not take these into account, thus ensuring that this IC's final
// contribution to mTextView's nested batch edit count is zero.
mTextView!!.endBatchEdit()
mBatchEditNesting--
return true
}
}
return false
}

//clear the meta key states means shift, alt, ctrl
override fun clearMetaKeyStates(states: Int): Boolean {
val content = editable ?: return false
val kl = mTextView!!.keyListener //listen keyevents like a, enter, space
if (kl != null) {
try {
kl.clearMetaKeyState(mTextView, content, states)
} catch (e: AbstractMethodError) {
// This is an old listener that doesn't implement the
// new method.
}
}
return true
}

//When a user selects a suggestion from an autocomplete or suggestion list, the input method may call commitCompletion
override fun commitCompletion(text: CompletionInfo): Boolean {
if (DEBUG) Log.v(
TAG,
"commitCompletion $text"
)
mTextView!!.beginBatchEdit()
mTextView.onCommitCompletion(text)
mTextView.endBatchEdit()
return true
}

/**
which is used to commit a correction to a previously entered text.
This correction could be suggested by the input method or obtained through some other means.
*/
override fun commitCorrection(correctionInfo: CorrectionInfo): Boolean {
if (DEBUG) Log.v(
TAG,
"commitCorrection$correctionInfo"
)
mTextView!!.beginBatchEdit()
mTextView.onCommitCorrection(correctionInfo)
mTextView.endBatchEdit()
return true
}

/* It's used to simulate the action associated with an editor action, typically triggered by pressing the "Done" or "Enter" key on the keyboard.*/
override fun performEditorAction(actionCode: Int): Boolean {
if (DEBUG) Log.v(
TAG,
"performEditorAction $actionCode"
)
mTextView!!.onEditorAction(actionCode)
return true
}

/*
handle actions triggered from the context menu associated with the search text.
This menu typically appears when you long-press on the search text field.
*/
override fun performContextMenuAction(id: Int): Boolean {
if (DEBUG) Log.v(
TAG,
"performContextMenuAction $id"
)
mTextView!!.beginBatchEdit()
mTextView.onTextContextMenuItem(id)
mTextView.endBatchEdit()
return true
}

/*It is used to retrieve information about the currently extracted text
* eg- selected text, the start and end offsets, the total number of characters, and more.*/
override fun getExtractedText(request: ExtractedTextRequest, flags: Int): ExtractedText? {
if (mTextView != null) {
val et = ExtractedText()
if (mTextView.extractText(request, et)) {
if (flags and GET_EXTRACTED_TEXT_MONITOR != 0) {
// mTextView.setExtracting(request);
}
return et
}
}
return null
}

// API to send private commands from an input method to its connected editor. This can be used to provide domain-specific features
override fun performPrivateCommand(action: String, data: Bundle): Boolean {
mTextView!!.onPrivateIMECommand(action, data)
return true
}

//send the text to the connected editor from the keyboard pressed
override fun commitText(
text: CharSequence,
newCursorPosition: Int
): Boolean {
if (mTextView == null) {
return super.commitText(text, newCursorPosition)
}
if (text is Spanned) {
text.getSpans(
0, text.length,
SuggestionSpan::class.java
)
// mIMM.registerSuggestionSpansForNotification(spans);
}

// mTextView.resetErrorChangedFlag();
// mTextView.hideErrorIfUnchanged();
return super.commitText(text, newCursorPosition)
}

override fun requestCursorUpdates(cursorUpdateMode: Int): Boolean {
if (DEBUG) Log.v(
TAG,
"requestUpdateCursorAnchorInfo $cursorUpdateMode"
)

// It is possible that any other bit is used as a valid flag in a future release.
// We should reject the entire request in such a case.
val KNOWN_FLAGS_MASK = CURSOR_UPDATE_IMMEDIATE or CURSOR_UPDATE_MONITOR
val unknownFlags = cursorUpdateMode and KNOWN_FLAGS_MASK.inv()
if (unknownFlags != 0) {
if (DEBUG) {
Log.d(
TAG,
"Rejecting requestUpdateCursorAnchorInfo due to unknown flags. cursorUpdateMode=$cursorUpdateMode unknownFlags=$unknownFlags"
)
}
return false
}
return false
}

companion object {
private const val DEBUG = false
private val TAG = "loool"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import android.view.inputmethod.InputMethodSubtype
* The SimpleKeyboardIME class uses this interface to communicate with the input connection
*/
interface OnKeyboardActionListener {
/*

called when focus on the searchview */
fun searchViewFocused(searchView: androidx.appcompat.widget.AppCompatAutoCompleteTextView)

/**
* Called when the user presses a key. This is sent before the [.onKey] is called. For keys that repeat, this is only called once.
* @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key, the value will be zero.
Expand Down Expand Up @@ -48,4 +53,5 @@ interface OnKeyboardActionListener {
* Called when input method is changed in-app.
*/
fun changeInputMethod(id: String, subtype: InputMethodSubtype)
fun updateShiftStateToLowercase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION
import android.view.inputmethod.EditorInfo.IME_MASK_ACTION
import android.widget.inline.InlinePresentationSpec
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.AppCompatAutoCompleteTextView
import androidx.autofill.inline.UiVersions
import androidx.autofill.inline.common.ImageViewStyle
import androidx.autofill.inline.common.TextViewStyle
Expand All @@ -44,6 +45,7 @@ import org.fossify.keyboard.extensions.safeStorageContext
import org.fossify.keyboard.helpers.*
import org.fossify.keyboard.interfaces.OnKeyboardActionListener
import org.fossify.keyboard.views.MyKeyboardView
import org.fossify.keyboard.views.MyKeyboardView.Companion.searching
import java.io.ByteArrayOutputStream
import java.util.Locale

Expand Down Expand Up @@ -72,6 +74,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
private var enterKeyType = IME_ACTION_NONE
private var switchToLetters = false
private var breakIterator: BreakIterator? = null
private var otherInputConnection:OtherInputConnection? = null

private lateinit var binding: KeyboardViewKeyboardBinding

Expand Down Expand Up @@ -101,6 +104,11 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}
}

override fun searchViewFocused(popupToolbarEditText: AppCompatAutoCompleteTextView) {
otherInputConnection = OtherInputConnection(popupToolbarEditText)

}

override fun onPress(primaryCode: Int) {
if (primaryCode != 0) {
keyboardView?.vibrateIfNeeded()
Expand All @@ -126,9 +134,11 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
return
}



val editorInfo = currentInputEditorInfo
if (config.enableSentencesCapitalization && editorInfo != null && editorInfo.inputType != TYPE_NULL) {
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0 && !searching) {
keyboard?.setShifted(ShiftState.ON_ONE_CHAR)
keyboardView?.invalidateAllKeys()
return
Expand Down Expand Up @@ -171,7 +181,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}

override fun onKey(code: Int) {
val inputConnection = currentInputConnection
val inputConnection = getMyCurrentInputConnection()
if (keyboard == null || inputConnection == null) {
return
}
Expand Down Expand Up @@ -305,6 +315,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
else -> {
inputConnection.commitText(codeChar.toString(), 1)
updateShiftKeyState()

}
}
}
Expand Down Expand Up @@ -360,7 +371,9 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}

override fun onText(text: String) {
currentInputConnection?.commitText(text, 1)
getMyCurrentInputConnection().commitText(text, 1)

// currentInputConnection?.commitText(text, 1)
}

override fun reloadKeyboard() {
Expand All @@ -377,6 +390,10 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}
}

override fun updateShiftStateToLowercase() {
updateShiftKeyState()
}

private fun createNewKeyboard(): MyKeyboard {
val keyboardXml = when (inputTypeClass) {
TYPE_CLASS_NUMBER -> {
Expand Down Expand Up @@ -582,4 +599,19 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared

return Icon.createWithData(byteArray, 0, byteArray.size)
}


fun getMyCurrentInputConnection():InputConnection{

if (searching){
if(otherInputConnection==null){
return currentInputConnection
}else{
return otherInputConnection!!
}

}else{
return currentInputConnection
}
}
}
Loading
Loading