How to get an event for soft keyboard KEYCODE_DEL? - android

I asked this previously on the Android dev mailing list but got no reply.
In my application, I bring the soft keyboard on from time to time, and
it looks like events for the DEL key are not delivered. The method in
question is at
http://pastebin.com/zZaZWJ4t
and the whole Java class is at
http://squeakvm-tablet.googlecode.com/hg/project/src/org/squeak/android/SqueakView.java
Any alphanumeric key or Enter (Return) tapped on the soft keyboard is
passed to the application except for KEYCODE_DEL. I tried to replace
KEYCODE_DEL in the case clause with anything else (e. g. with code for
for hardware button PAGE_UP), and the clause takes control when that
button is pressed.
I did not subclass the Android Keyboard class, just used the default
input manager.
What can be done in order to receive events for KEYCODE_DEL? Is
deriving a keyboard subclass the only way?
Thanks.

I had a similar issue and I was able to solve it by adding a TextWatcher to EditText using addTextChangedListener.

Your onCreateInputConnection() override is not returning TYPE_NULL as the input type. You must use TYPE_NULL to be assured that key events will be generated. They are in fact generated for some keys and not for others, in some versions of Android but not others, but there is nothing that you can count on about that unless you use TYPE_NULL.
If you do adjust your code to use TYPE_NULL, then please see this description of a workaround for two bugs in certain versions of the default LatinIME Google Keyboard that affect TYPE_NULL processing:
Android - cannot capture backspace/delete press in soft. keyboard

Related

Android Edit Text Cursor Doesn't Appear

in my app I disabled the keyboard (I use now my custom keyboard) using this code:
editText.setInputType(InputType.TYPE_NULL);
Now, my problem is that the text cursor does not appear anymore in the edit text. What should I do? Any suggestion would be very appreciated.
There is an Issue opened in bug tracker Issue opened in bug tracker for this.
One of the users suggests the approach which works on "most" devices.
Briefly, all you have to do is call:
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
for your EditText view (after you called editText.setInputType(InputType.TYPE_NULL);).
You should probably also set:
editText.setTextIsSelectable(true);
in order for text to be selectable (though in does not seem to work properly with Samsung Galaxy SIII). This method is only available starting from HONEYCOMB (api11) so keep that in mind when developing for older Android versions.
Also it is stated that your EditText should not be the first view to receive focus when activity starts (if it is - just requestFocus() from another view). Though I (personally) have not experienced any problems with this.
Rather than just using a custom view for your custom keyboard, why not implement a full-fledged IME? That will solve your cursor problem, and even make your keyboard available outside your app (if you want).
This answer has a couple useful links if you want to do that:
How to develop a soft keyboard for Android?
I really wouldn't suggest this. Writing a good full fledged IME is really hard. In addition, users come to expect functionality from their keyboard (auto-correct, Swyping, next word prediction, the ability to change languages) that you won't have unless you spend months on the keyboard itself. Any app that wouldn't allow me to use Swype would immediately be removed (bias note: I worked on Swype android).
But if you want to integrate fully with the OS as a keyboard, you're going to have to write an InputMethodService. Your keyboard would then be selectable by the user in the keyboard select menu, and usable for any app. That's the only way to get full OS integration, otherwise you'll need to really start from scratch- writing your own EditView. Have fun with that, getting one that looks nice is decidedly non-trivial.
Also, setting input type null won't disable most keyboards. It just puts them into dumb mode and turns off things like prediction.
I tried the below answer and it worked, but take care that
1) EditText must not be focused on initialization
2) when your orientation changes while the user's focus is on the editText, the stock keyboard pops up, which is another "solvable" problem.
This was mentioned in a previous answer but take care that you MUST make sure your editText element do not get focus on instantiation:
https://code.google.com/p/android/issues/detail?id=27609#c7
#7 nyphb...#gmail.com
I have finally found a (for me) working solution to this.
First part (in onCreate):
mText.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11 /*android.os.Build.VERSION_CODES.HONEYCOMB*/) {
// this fakes the TextView (which actually handles cursor drawing)
// into drawing the cursor even though you've disabled soft input
// with TYPE_NULL
mText.setRawInputType(InputType.TYPE_CLASS_TEXT);
}
In addition, android:textIsSelectable needs to be set to true (or set in onCreate) and the EditText must not be focused on initialization. If your EditText is the first focusable View (which it was in my case), you can work around this by putting this just above it:
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
</LinearLayout>

Android: input field does not fire event when hitting 'next' on keyboard

I have multiple input fields on a html page optimized for Android.
The problem is that the event "onchange" is not always triggered when 'next' is clicked on the virtual keyboard.
To me this seems to be a similar to issue 7459 of the Android browser:
http://code.google.com/p/android/issues/detail?id=7459
How can I circumvent or compensate this issue? I need to calculate and refresh another input field in the function calc() after the value of any of the fields has been changed. If available even Android specific events or behaviours can be used.
Thanks, Holger

android add buttons on top of softkeyboard

I want to add some buttons on top of the soft keyboard (Enter and Cancel). Is there a nice way to do this or do I have to detect the keyboard being shown and add the buttons into my view?
I can't see the logic your trying to apply here.
if you add buttons above your keyboard then you lose some areas in your keyboard (for example you cant press on q w s a).
I think you should look into creating your own custom keyboard.
maybe this will help
android app specific soft keyboard
Jason
You won't be able to do this, and with good reason. If apps could modify an existing input method like this, they could trivially log all keystrokes on your device without you knowing. If you've ever installed a custom input method, you'll see a big warning that using it means trusting it not to log your keystrokes, and the functionality you're after would totally circumvent that protection.

How to use OnKeyboardActionListener?

Simply say, is there any example about 'OnKeyboardActionListener'?
I want to call my method, whenever user type any character on keyboard.
OnKeyListener or OnKeyDown is not called when the word is composing. <- it's a problem.
So, I'm trying to use 'OnKeyboardActionListener' to solve the problem above.
Simply say, is there any example about
'OnKeyboardActionListener'?
This interface is used in the creation of input method editors ("soft keyboards"). The SoftKeyboard sample that shipped with your SDK uses this interface.
I want to call my method, whenever
user type any character on keyboard.
If this is your own keyboard, follow the SoftKeyboard example.
OnKeyboardActionListener is for implementing software keyboards.
OnKeyListener and OnKeyDown do not get called, as you have discovered, when using a software keyboard. They only get called when using a hardware keyboard, which many Android devices don't even have.
I assume what you are trying to do is capture key events as they are occurring in an EditText area. Your best bet in this case, in order to handle both software keyboard input and hardware keyboard input, is to register a TextWatcher via the addTextChangedListener() method.
Note that on phones with Android 2.1 and later, such as the Nexus One, people have the option of using speech recognition to input text into your EditText instead of typing the text. When they do that you may get full words, or even full sentences, entered all at once. So you need to check the entire contents of the EditText field when there is a change to the contents.

how to hook key event

I'd like to limit the text length of EditText widget,
And if user type more charactes than the limited length,
I want to show a kind of warning popup, however I can't show popup.
The problem is that we can't show popup while typing,
Probably, many people think a way of utilizing OnKeyListener or OnKeyDown.
But, when the word is composing, nothing come into OnKeyListener or OnKeyDown,
So, we can't show popup when we want to.
Is there anyone who have smart idea to solve this problem?
You should be able to remove focus from the widget, and show your message.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
OnKeyboardActionListener is for implementing software keyboards.
OnKeyListener and OnKeyDown do not get called, as you have discovered, when using a software keyboard. They only get called when using a hardware keyboard, which many Android devices don't even have.
I assume what you are trying to do is capture key events as they are occurring in an EditText area. Your best bet in this case, in order to handle both software keyboard input and hardware keyboard input, is to register a TextWatcher via the addTextChangedListener() method.
Note that on phones with Android 2.1 and later, such as the Nexus One, people have the option of using speech recognition to input text into your EditText instead of typing the text. When they do that you may get full words, or even full sentences, entered all at once. So you need to check the entire contents of the EditText field when there is a change to the contents.

Categories

Resources