THEAccess/compose-keyboard-ime

Keyboard clicking not response

liweijian opened this issue · 9 comments

Hi, I want to say that this project is awesome! It help me a lot to understand Jetpack Compose API and IME.

I tried to compile and install this app in Android 10 and Android 11 phone, but it sounds a lot like it didn't work as expected, just wondering if anything that I had missed?

bqbs commented

@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for AndroidKeyboardView like this.
class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )

val view = AndroidKeyboardView(this) { txt ->
  currentInputConnection.commitText(txt, txt.length)
  return@AndroidKeyboardView
}

And pass it layer by layer until KeyboardKey. Finally, call it inside Box's clickable. May it help.

bqbs commented

@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for AndroidKeyboardView like this. class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )

val view = AndroidKeyboardView(this) { txt ->
  currentInputConnection.commitText(txt, txt.length)
  return@AndroidKeyboardView
}

And pass it layer by layer until KeyboardKey. Finally, call it inside Box's clickable. May it help.

😕 Sorry guys. There is a easy way the do it.Just using LocalContext.curent inside KeyboardKey method. You can get the context that is an instance of ImeService.

@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for AndroidKeyboardView like this. class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )

val view = AndroidKeyboardView(this) { txt ->
  currentInputConnection.commitText(txt, txt.length)
  return@AndroidKeyboardView
}

And pass it layer by layer until KeyboardKey. Finally, call it inside Box's clickable. May it help.

😕 Sorry guys. There is a easy way the do it.Just using LocalContext.curent inside KeyboardKey method. You can get the context that is an instance of ImeService.

Can you show me how to do it?
If I use your method by passing callback, android studio gives warning regarding ViewConstructor and the char result is flaky

bqbs commented

@frengky-sinaga Sorry for late reply. LocalContext.curent is an instance of InputMethodService. You can get the currentInputConnection directly. No need callback.

@frengky-sinaga Sorry for late reply. LocalContext.curent is an instance of InputMethodService. You can get the currentInputConnection directly. No need callback.

Can you show the sample code? Still cannot input the key from the keyboard

bqbs commented

@frengky-sinaga Sorry for late reply. LocalContext.curent is an instance of InputMethodService. You can get the currentInputConnection directly. No need callback.

Can you show the sample code? Still cannot input the key from the keyboard

Check the fun KeyboardKey and the lines with comment.

@Composable
fun KeyboardKey(
    keyboardKey: String,
    modifier: Modifier,
) {
    val context = LocalContext.current     // An instance of IMEService
    val interactionSource = remember { MutableInteractionSource() }
    val pressed = interactionSource.collectIsPressedAsState()
    Box(modifier = modifier) {
        Text(keyboardKey, Modifier
            .fillMaxWidth()
            .padding(2.dp)
            .border(1.dp, Color.Black)
            .clickable(interactionSource = interactionSource, indication = null) {
                (context as IMEService).currentInputConnection.commitText(keyboardKey, keyboardKey.length)    //  call commitText
            }
            .background(Color.White)
            .padding(
                start = 12.dp,
                end = 12.dp,
                top = 16.dp,
                bottom = 16.dp
            )

        )
            // ...
    }
}

And if you can't get the context, check this link # How to get Context in Jetpack Compose.Good luck.

Can we directly implement IMEService to specific application without using these

  1.         ctx.startActivity(Intent(Settings.ACTION_INPUT_METHOD_SETTINGS))
    
  2.         inputMethodManager.showInputMethodPicker()
    
bqbs commented

@bagoriya You can try it. Then enable the IME from "Settings > System > Language & input". But, usually the IME apk will provids a setup interface like this demo shown.

Fixed in #3