is it possible to detect/modify input from softkeyboard - android

I'm currently working on android service. One of its task is to read the input data entered by user (and also modify it) .
The only possible way that till now, I've figured out is to make a custom keyboard and write methods in that custom keyboard. I don't want this .
Is their any other method for it?
Thanks
Edit: I need this to work across multiple applications. So I don't think TextWatcher can help here.

It can surely be observed by using an Accessibilityservice.
Check
http://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html
specially typeViewTextChanged and typeWindowContentChanged
This will not completly check all key hooks but you can check for changedtext in the focused window. With a little workaround you will be able to do what you want to do.

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

Notification for keyboard fires

Is there anyway to get a know when a keyboard (dis)appears?
Actually I'm trying to implement this
I haven't found anything which answers my question. I think I wasn't clear enough.
This
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/nRaBoB8F54I
is a pretty old thread but it explains my problem pretty well.
I was wondering if there's any solution available to this now.
Please help. Thanks. :)
I'm not sure if this will work, you can try it and let me know. But if you put
android:configChange="keyboardHidden"
in your manifest for the activity, that will make it call onConfigChange of your activity passing it in a Configuration object where you can query the keyboardHidden member variable and see if its the same as it was last time or not. Note you will also have to check hardKeyboardHidden to tell if it was a slideout keyboard that went away or the software keyboard.
The problem is I know this works for pulling out the hardware keyboard. I don't know if it also calls you for displaying the software keyboard. Worth a try though.

Show suggestions of AutoCompleteTextView

Is it possible to have the AutoCompleteTextView show the suggestions above the keyboard just like when using the default dictionary? (If yes, how:))
Or can I use my own database to show suggestion when using EditText?
Hope you understand what I mean:)
Thank you
Bastaixen
I don't think this is possible. The suggestions shown above the keyboard are actually part of the IME, so completely unrelated to your application / activity.
The only way to do this would be for you to build-in your own IME and then you can customize what suggestions would be there. You can base it on latinIME, but there are still a couple of things you would need to figure out:
You would need to figure out how to tell Android to use your custom IME in your app. Or, like this answer say, just build in the keyboard in your app.
if your user is using a different keyboard (for different language, or swype or something like that), they would probably not like it much...

changing sound/click on soft keyboard - android

I need some help with a project i'm doing. Hopefully someone can help me :)
I need to change the sound or click the keyboard makes whenever i'm typing in an editText. I need the sound/click to be whatever sound i may prefer (in wave-, mp3- or whatever format).
So, a couple of questions:
Can i change this in the already implemented keyboard?
Or should i make my own keyboard?
if the latter is the case, how do i do that? Can i find the source code somewhere?
I have been looking at other questions regarding how to make your own keyboard. e.g. How do I make my own keyboard for an app in android?
And if i have to make my own keyboard i want to look like this. But how to do it?
Can i change this in the already implemented keyboard?
You can't... it's already built and some manufactures provide their own keyboard implementations.
Or should i make my own keyboard?
Yes, you must.
If the latter is the case, how do i do that? Can i find the source code somewhere?
There are some open source projects of Keyboard implementations... for instance:
https://github.com/g1011999/Gingerbread-Keyboard/
http://code.google.com/p/softkeyboard/
There you can learn how to write your own keyboard, which is completely different from writing a conventional app.
My suggestion is to create a new fork of the Gingerbread-Keyboard (this supports Android 2.2 or higher only)... and then implement that specific change you want. For one of my apps I did so, and it's far easier than implementing the keyboard from scratch.

Categories

Resources