Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added emoji picker with the features to search emoji and get recent used emoji #280

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ dependencies {

implementation(libs.bundles.room)
ksp(libs.androidx.room.compiler)

implementation (project(":emojipicker"))


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package com.simplemobiletools.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

/**
* Source: https://stackoverflow.com/a/39460124
*/
class OtherInputConnection(private val mTextView: androidx.appcompat.widget.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
Log.i("heregotEditTEZT", tv!!.text.toString())
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) {
val spans = 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 @@ -41,4 +41,9 @@ interface OnKeyboardActionListener {
* Called to force the KeyboardView to reload the keyboard
*/
fun reloadKeyboard()

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.os.Build
import android.os.Bundle
import android.text.InputType.*
import android.text.TextUtils
import android.util.Log
import android.util.Size
import android.view.KeyEvent
import android.view.View
Expand All @@ -23,6 +24,8 @@ 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.appcompat.widget.SearchView
import androidx.autofill.inline.UiVersions
import androidx.autofill.inline.common.ImageViewStyle
import androidx.autofill.inline.common.TextViewStyle
Expand Down Expand Up @@ -60,9 +63,17 @@ 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

companion object{
/*true and false define the inputconnection where is input is send like
* if true-> send to emoji searchview
* if false -> send to currentinputconnection*/
var searching=false
}

override fun onInitializeInterface() {
super.onInitializeInterface()
safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
Expand Down Expand Up @@ -106,7 +117,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared

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 @@ -149,7 +160,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 @@ -216,7 +227,10 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}

MyKeyboard.KEYCODE_EMOJI -> {
keyboardView?.openEmojiPalette()
if(!searching){
keyboardView?.openEmojiPalette()
}

}

else -> {
Expand Down Expand Up @@ -324,7 +338,8 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}

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

}

override fun reloadKeyboard() {
Expand All @@ -333,6 +348,10 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
keyboardView?.setKeyboard(keyboard)
}

override fun searchViewFocused(searchView: AppCompatAutoCompleteTextView) {
otherInputConnection = OtherInputConnection(searchView)
}

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

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

fun getMyCurrentInputConnection():InputConnection{
if (searching){
if(otherInputConnection==null){
Log.i("thisISrunn", "yes2")
return currentInputConnection
}else{
Log.i("thisISrunn", "yes")
return otherInputConnection!!
}

}else{
Log.i("thisISrunn", "yes3")
return currentInputConnection
}
}
}
Loading