Android webView touchEvents - android

I have a webapp I am trying to interface with android. It is very easy to get a webview to display the page, however the page uses an on screen keyboard. If only one input was on a page, it would be easy to set
android:focusableInTouchMode="false"
in the webview, however there are a few places where multiple inputs are present, and this disables the ability to select any them (the first one on the page is automatically selected).
Would it work to maybe extend and override a webView to be able to select an input but not open the softKeyboard?
I have also looked at
this example, however I don't think that will work with a webview.
EDIT:
To help clarify, i can just override with myWebView.setOnTouchListener(...), and have done so in test, this is great as it does not allow the softKeyboard to show, however it also does not let anything else happen ie. input selection. Ideally there would be a happy medium where everything happens except the softKeyboard appearing. (yes I have tried other methods such as
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

I feel that my question was somewhat vague as I was at my wits end after several hours of looking into this.
My end goal was to be able to display a web page with an on screen keyboard with multiple input fields. The problem was that the android softKeyboard would be shown whenever focus was on an input field.
I tried multiple workarounds, one listed in the question did not work because I could not select any inputs as touch commands were not registered.
I tried overriding onTouch, however the keyboard is shown after an 'up' touch and so it was impossible to have default behavior and still intercept and disable the keyboard.
The solution that worked for my problem was to extend the WebView class, and then override 'onCreateInputConnection'. This is where android interprets the 'type' of the html input field. The problem is that html does not have a 'null' type for this, so android will always display some sort of keyboard based on the input type. Android does however have a null input type which tells the keyboard there is no need for input here.
#Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
BaseInputConnection fic = new BaseInputConnection(this, true);
outAttrs.actionLabel = null;
outAttrs.inputType = InputType.TYPE_NULL;
return fic;
}
This overriden method is all that was needed for my webview to completely disable inputs on all of my text fields.
NOTE: This does also disable attached hardware keyboard input...not a problem in my case, however I would be interested in learning about a work around there.

Related

How do I disable text composition in an html textarea when on android?

I am using the input event on a textarea to apply some logic that mutates the value of the textarea. This works as expected in local dev environment in a browser.
However, my target platform is android. On this platform, I'm noticing that instead of event.inputType being insertText, sometimes it is insertCompositionText. Android is apparently trying to be efficient by not actually mutating the textarea's value until you press space. How can I disable this behavior?
I found someone in a similar situation here who tried to use blur and focus events quickly. I can't use this because (1) it's hacky, hope there is a better solution (2) it resets the cursor position and degrades the user experience.
For reference, using ionic vue, but this is just an html <textarea>:
<textarea v-model="input" #input="onInput" />
onInput(event) {
console.log("onInput", event);
//more logic
}
You can't. That behavior comes from the keyboard, which is a separate app on Android. Not implementing the composing text functionality correctly will likely screw it up, breaking autocomplete, tap to correct, and the delete key, which all behave much differently due to composing text. It might even break normal typing- the idea of composing text is that it's temporary until you make it permanent. If so, when it does autocorrect on space it would assume the old stuff is deleted and recommit the entire word, causing duplication.
I was able to handle this issue by adding a hidden password input and route all the focus, events and value of my text input to the password input
The browsers will not show any predictive for password inputs and no insertCompositionText anymore

Is there anyway using html5 to force android/ios virtual keyboard to be shown

I have some html forms that when they get rendered I would like the keyboard to appear without the user having to touch the field first. I have tried using click and focus neither brings up the keyboard.
For what its worth I am using angular.
I do not believe this is possible with out a very kludgy work around. You might be able to have a hidden text field that it set to focus, which would bring up the keyboard and then manually set focus on other items in the view when needed. However this might cause some issues and you might be able to see the cursor in the hidden text field, among other issues. Why do you need the keyboard to be displayed without a focus on some field?

Android soft keyboard will hide for no reason

I'm having the following issue - I have placed
android:windowSoftInputMode = "stateAlwaysVisible"
in my manifest which works relatively fine since the software keyboard is almost always visible. I have a webview in which I have an editable div in which the user can enter text. However when the user have entered some text and taps somewhere else on the webview(on a position different from the current cursor position) the software keyboard will hide for a moment and afterwards reappear. I'm at my wits end and can't find an explanation for this. Using InputMethodManager to make the keyboard always visible also didn't help.
Any help will be greatly appereciated. Thanks!
The issue was that the keyboard is hiding due to the fact that we were passing all the touch events down to javascript we are having via loadUrl("javascript : bar(event.getX(), event.getY()));".
Turns out the loadUrl method internally hides the software keyboard. I worked this around by not passing the touch events to the javascript, but instead by using window.onmousemove

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.

android app specific soft keyboard

Is there a way to create an app specific soft keyboard on Android? After reading about InputMethodService docs and checking out alternative keyboard apps out there, I figure the alternate keyboard can only be configured for system wide usage (through Settings -> Locale and Text).
If the answer to above question is no, then is there at least a way to load a custom dictionary and override the default dictionary of the system keyboard (only when my app is in use)? That will help in giving very relevant suggestions to the user when he has only tapped couple of keys.
If you just want a View that looks and acts like a soft keyboard, I did that in my SmallKeyboard class. You just need to extend android.inputmethodservice.KeyboardView and decide on layout. See the onKey and onText methods at the end of that file for the action taken when keys are pressed.
Instead of my keyboard model inner class, you could load it from XML if your key set is fairly constant.
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/

Categories

Resources