What are the classes that implement the default Android soft keyboards? - android

What are the classes that implement the default Android soft keyboards, the ones you get when you define EditText with android:inputType="text" or other possible values of android:inputType?
(I want to see how these classes work, to introduce some additional functionality into them.)
I have found that the keyboard is not part of my Activity, and moreover, the OnTouch events of keyboard do not go through Activity.dispatchTouchEvent(..).
This agrees with the documentation that says that the keyboard runs in a service, apparently meaning that it is run in a different thread and is not part of the Activity containing the EditText element, among other things.
It also says that this service is implemented by InputMethodService.
I hoped to find these classes by setting breakpoints in InputMethodService in various places, including its onCreate(..) method. None of these breakpoints was hit.
So I found no way to get to these classes.
Any help?
Thanks

InputMethodService is the base class of all soft keyboard. However there is no default soft keyboard. Each one is its own completely separate app. Every OEM decides independently which app to use.
That's why your breakpoints failed- because the breakpoint would need to have been put in a different app (the keyboard app). You'd have more luck putting breakpoints in EditableInputConnection, which is the implementation of the communication bridge between the two apps for TextView and EditView.
IF you're interested in seeing the code, look at https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/refs/heads/master That's Google's basic keyboard. It can show you how things work, but IIRC it isn't written for readability. Of course its been 8 years since I've written a keyboard, maybe its gotten better. The direct link to the InputMethodService is https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/refs/heads/master/java/src/com/android/inputmethod/latin/LatinIME.java

Related

Creating custom android keyboard NOT from scratch (modify system keyboard)

What I need is to add a custom key to android keyboard. I know I can implement my own keyboard but implementing all the functionalities (dictionary, swipe, microphone button etc) sounds like a lot of work. I see two solutions:
modify system keyboard (I expect it not to be possible, but it's
sometimes good to ask :))
create my own keyboard but somehow deriving it from existing one
Is any of these possible? Any other ideas?
After an investigation, answers are:
not possible
not possible
:)

IME and catching (touch) events

Im currently trying to get my diploma in psychology and i want to write about different types of keyboards for smartphones. To research this area i need a tool that measures times. As Im new to Android programming, my friend is helping me, but we got stuck.
Here is what we need, and what we tried. Id really appreciate any help =)
We need a way to call a function before user input in IME begins and after user input in IME ends. (We need this only for timelogging, we dont need the actual input.)
We also need to call a function before user input for chosing autocorrection starts/ends.
We need to do this for all kinds of IMEs especially keyboards
like Swype, Swiftkey etc (though one of them working is enough)
We tried:
TextWatcher via addTextChangedListener
- seems to be unreliable to get the times beforeTextChanged/afterTextChanged is randomly called, even within a gesture
or multiple times within a gesture
subclassing EditText implementing OnTouchListener,
using onTouch()
- didnt seem to get called at all when using swype, so either we did it wrong or ime/swpye consumes those events,
also tried it with onKeyPreIme, wasnt called either
Ideal would be:
a way of catching the "touch" events before they are passed to the IME to log the current time via System.currentTimeMillis()
the same "after" the gesture ends i.e. when the finger is released from display
we dont need actual code, a link to the right command/documentation/widget would be sweet.
You get bonus cookies if you are ever in berlin and need a place to ... get cookies :)
Not sure if this is much of an answer, but...
Is your plan to write this in an Android application that you can distribute and run on anybody's device?
Sounds like whatever you do on the EditText or your application may not be enough because the IME is a separate module in Android, so you would not be able to get any information about auto correct or prediction or things like that (different IME have different of such features). You would only be able to get the text entered (or removed) from the text entry.
The best I can think of is for you to develop your own IME, then you can log anything you like in there.
To go about that, I would suggest, you first checkout this article from Android Developer:
http://developer.android.com/guide/topics/text/creating-input-method.html
And then you can check out the source code for the default Latin IME there:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/inputmethod/latin/LatinIME.java
Although this one has probably much more than you need and has (I think) some links into the Android framework itself, so you cannot really build it as a separate module the way it is now.
Hope that helps

custom android softkeyboard for a particular application

I have created a custom softkeyboard. It works for all the application throughout.
Is it possible to create a softkeyboard so that it can work for a particular application not for all the application.
Any ideas.
Thanks in advance
Here is good explanation of different ways to achieve this.
The Android Nethack application has a complete and clear source code example of how to create a custom keyboard for an application, how to display it on screen and how to define multiple keyboard layouts. It contains pretty much everything you need to know.
It is by far the best example I have seen.
http://code.google.com/p/nethack-android/
Umm, I guess you could integrate your own soft keyboard within your application - and never show the real one. Much work though, but I guess it could be done.
However you cannot force a certain soft keyboard to a certain application, but lots of keyboards support different styles using this in the XML:
android:inputType=""
Perhaps one of those would suit you?
For example if you'd like a keyboard fit for input in the form of email-addresses:
android:inputType="textWebEmailAddress"

Custom Application specific Keyboard in Android

I want to create a custom keyboard for my application. ie. consider a simple text input and when I click on that, I want a custom keyboard to appear. For ex : a dialler like keyboard, having keys 0-9 and then some custom buttons for my application. Is it possible to do that in android?
Yes, this is possible. There are two ways to approach this:
Create your own input method (keyboard) - here's an example on google of how this can be done: http://developer.android.com/resources/samples/SoftKeyboard/index.html - you'll then need to set this keyboard as an IME in your app.
Create your own view with a bunch of buttons to handle your own stuff. This won't be a "keyboard" in a true android way, but it would do everything you need for your app. I have seen apps that contain their own "keyboards" designed in this way.
In addition, keep in mind that even the basic android keyboard has several "versions" available: alpha, keypad, symbols, etc.
Which way you prefer to go depends on your specific needs, your development abilities and time constraints.
Create your own view with a bunch of buttons to handle your own stuff. This won't be a "keyboard" in a true android way, but it would do everything you need for your app. I have seen apps that contain their own "keyboards" designed in this way.
In addition, keep in mind that even the basic android keyboard has several "versions" available: alpha, keypad, symbols, etc.
Which way you prefer to go depends on your specific needs, your development abilities and time constraints.

Custom 'Keyboard' built in an application on Android

I've been looking to create a custom keyboard for my application. At first, I started to look at the SoftKeyboard for the SDK examples, but reading the Android Developer Group led me to this post:
This is really not how the input
method framework is supposed to work.
An IME should be a generic input
facility, not for a particular
application. If you need some
app-specific input, you should build
it into your UI rather than pushing
it out to a generic IME.
How do I build an app-specific input within the UI? I mean, is there a way to extend the Keyboard app or something and use it only in my application?
Features needed for the keyboard:
Shift key to display some other keys
Special keys like square root or PI
etc.
PS: an ugly solution could be to make a table of ImageButton for example, but I wanted to make something clean.
I'm not really sure if there's a straight-forward solution to this (to that extent that it is even possible to understand the real reason behind the original question).
As is quoted in the original question:
If you need some app-specific input, you should build it into your UI
rather than pushing it out to a generic IME.
What is meant by that, is not that you within your app should try to build in such input features by extending or modifying the soft keyboard on the phone. There are so many different soft keyboards (and basically, the soft keyboard is just another app), since most phone manufacturers create their own version, and people download 3rd party keyboards (such as Swype or SwiftKey etc.), and I can't picture there being a way for you to "hack" into those to add a few buttons or whatever it is you want (which could also be a major security hole, another reason why it probably isn't possible).
What instead the above quote suggests, is that you have to create some other form of input besides the keyboard. One such example, and a very good one if I might add, is how the RealCalc Scientific Calculator looks:
Now this isn't open source, so I can only guess how the code looks like (but it shouldn't be too hard a guess either): in its simplest form, this is just a grid with lots of buttons. Each button handles the onClick event, which would mean performing some kind of action (changing the label on some other buttons, showing a menu, displaying some text in the upper label or whatever), and that's probably pretty much what's to it. And of course, the phone's soft keyboard is never displayed (since you don't need a keyboard with all those buttons (and also there aren't any input fields to write anything in)).
It all boils down to the already mentioned quote: If you need some app-specific input, you should build it into your UI. Or in other words: create buttons (and don't display the soft keyboard if you don't need it) and make things happen when you click them.
And just to have mentioned it: if you do want to create your own IME (which I strongly believe is not the case here), you should have a look at the following resources:
Onscreen Input Methods
Creating an Input Method
Soft Keyboard sample
In my humble opinion you should take a look at the beginning of reference about keyboard and keyboard view http://developer.android.com/reference/android/inputmethodservice/Keyboard.html and http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html.
There you can see an example of defining keyboard using XML file. I think that this is what you are looking for.
As mentioned by #sebap123
Keyboard and KeyboardView class are the one you need to use,
Further, for Implementation, here is a quick detailed guide.

Categories

Resources