Custom Android keyboard without KeyboardView - android

I have seen lots of answers on SO and tutorials on internet on custom keyboard development. However, all of them use KeyboardView for displaying keyboard. It is difficult to manage KeyboardView and KeyboardView does not show custom layouts. Is there any other way to implement custom keyboard app that shows custom layouts?

In your InputMethodService, there's a function onCreateInputView. It returns the main view of your keyboard. You can have it return any view you want, including a custom one. In fact I don't think any serious keyboards actually use KeyboardView- it's too limiting.

Related

UI Automator with custom keyboard. Find exact keyboard button and click it

I'm trying to write UI automation tests for the custom soft keyboard using UI Automator and\or Espresso. Tried different ways but I can't find a proper solution to "find the exact button on the opened keyboard and click it".
Problems:
UIAtomator's UiDevice.findObject(By.text("Q")).click() doesn't find Q button on keyboard.
Espresso's onView(withText("Q")).perform(click()) doesn't find the button either.
For now, it looks like the only way to click button is to measure XY coordinates based on screen height and keyboard height. But this solution is ugly and not persistent.
typeText("text")and uiObject.text = "text" don't work since it bypasses keyboard input.
Was anyone working with custom keyboards? Please help.
Since you're building a custom soft keyboard then I expect you're using a KeyboardView. KeyboardView draws the keys using a canvas therefore it is not possible to get the resource ids of the keys... so no chance to find them through the UiDevice's findObject method.
Considering the KeyboardView class is deprecated since API 29, a possible solution will be to reimplement your own KeyboardView (as suggested here) and use AccessibilityNodeInfo class to build virtual elements (one for each key) that will be included into the view hierarchy.
The best solution in my opinion would be to create your own TCP server to solve this issue. Please refer to this link to find out how: https://ops.tips/blog/a-tcp-server-in-c/

create a android soft keyboard with other views attached to it

I want to develop a custom keyboard where I can add other views above it. how can I achieve this? what will be the main container layout?
I basically want to add banner ads on top of the keyboard. you can provide be a general example to put any view with keyboard view.
like this keyboard
Keyboards must implement an InputMethodService. One of the functions on it is onCreateInputView. That returns the View to display. This can be any View you want, including q layout with ads.
That said- nobody will ever use a keyboard with ads on it. I really don't suggest it.

play video in custom keyboardview background for android

Is there any way to play a video as a background of a custom keyboard view in android?
i need any resource or tutorials or even apps that has this feature
A custom keyboard can have any view it wants to. Which could include a video if you wanted. Just return a layout including a VideoView (or other similar view) from onCreateInputView.
Please note you do NOT have to use KeybaordView. That's a convenience class for if you have a very standard looking keyboard. None of the big keyboard makers use it.

dismiss a view from class extended by InputMethodService

I am created a custom keyboard. The keyboard is NOT an extension of the Keyboard class and does not use the Keyboard View class either. I have successfully created my keyboard so that it popups up. The keyboard is a LinearLayout I created from an xml file. Here is the problem: I can't get rid of it.
If it was an extension of KeyboardView, I would use
keyboard.closing();
but since its a LinearLayout, I don't have that method.
I then tried
keyboard.removeView(keyboard);
I didn't expect this to work, and it didn't.
Finally, I tried
keyboard.removeAllViews();
in hopes that it would sort of leave keyboard on the screen, but no one would no if all the views were removed. This did not work either.
Any suggestions?
Well if keyboard is the View you want to hide, try calling keyboard.setVisibility(View.GONE). If you want to remove it entirely you would have to find the parent view of keyboard and call removeView(keyboard) on that. I think the first approach is simpler though, depending on what you want.

How does an Android app load a keyboard?

I need to bring up a few different keyboards: a 'standard' keyboard with Ctrl and Alt keys; maybe a cursor pad; and so on.
I have found the Keyboard class, which would let me define a keyboard in an XML resource. I have found that the KeyboardView class has a setKeyboard method ... and, so far, I have not found any other class that takes a Keyboard instance.
How am I supposed to use the KeyboardView? I tried adding one to my activity's XML; finding it at runtime with findViewById; and then calling setKeyboard ... but all this did was mess up my layout and not bring up the special keyboard.
This turns out to be very doable, and my initial problems probably had more to do with general Android newbiness (this is my first Android app) and not the KeyboardView. In particular, I'm used to visibility being a simple binary property.
Anyhow:
Declare the KeyboardView in your XML file with android:visibility="gone".
Before you make the view visible, call setKeyboard() to attach a keyboard. This is important, as the KeyboardView gets its size from the keyboard.
To get raw key events, call KeyboardView.setOnKeyboardActionListener(). After refactoring this functionality from a Dialog back to my main View, I put the OnKeyboardActionListener functionality in a stand-alone class, but this is not necessary.
I call keyboardView.setEnabled(true);. This does not seem to be necessary, but I am not sure (yet) under what circumstances it would matter; perhaps only if you call setEnabled(false).
I call keyboardView.setPreviewEnabled(true); - this is especially useful if the user won't be getting visual feedback from an input biox right above the keyboard.
Then, with the keyboard all set, call keyboardView.setVisibility(VISIBLE);.
To hide the keyboard when appropriate, just call keyboardView.setVisibility(GONE);. To change the keyboard (as on a shift key, or a cycle-through-the-symbol-keyboards key, just call setKeyboard again. I use a Map<<Integer, Keyboard> to implement a lazy-create pattern; a weak reference may be desirable, if the program will run for a long time and the keyboard will not be used much.
Keyboard and KeyboardView are for making alternative input method engines (IME). These are then able to be chosen by the user, just as they can install Swype, Graffiti, and other ones from the Android Market.
You, as a developer, can create such an IME, but you cannot force it upon the user.
using the inputType attribute in your editText view will help pick between the different system keyboards (phone, email, etc) Also the APIDemos application that comes with the SDK has an example of how to implement a forced custom keyboard for your app only.

Categories

Resources