android app specific soft keyboard - android

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/

Related

Custom Keys to Android default keyboard

I am trying to add some custom keys to the soft keyboard (like a new row of specialized keys on top of the existing keyboard)
I assume the only way would be to get a reference to that keyboard. I know it's possible to get the size of the keyboard (using ViewTreeObserver), but I can't find a way to get the actual keyboard object.
Also, I can add a custom keyboard, but there are a few things that makes everything a bit more complicated, like switching from alphanumeric to special characters and also Shift behaviour. So that's why I'd prefer adding the keys to the existing keyboard, if possible.
Can anyone confirm that's possible? Or that it's not possible?
Thanks a lot!

Create KeyboardView by default keyboard without key definition in xml resource file

I'm creating an object from the android Keyboard class (https://developer.android.com/reference/android/inputmethodservice/Keyboard.html). In my case I just need the default keyboard, no custom keyboard. But the constructors of the Keyboard class requires a xml resource file that contains a definition of rows and keys. It seems it's only for creating a custom keyboard.
I need that object of the Keyboard class to use it in a KeyboardView within a TabLayout:
keyboard123 = (KeyboardView) Tab2View.findViewById(R.id.keyboard123);
Keyboard k1 = new Keyboard(Tab2View.getContext(), R.xml.qwerty_keyboard);
k1 = new Keyboard(Tab2View.getContext(), com.android.internal.R.id.keyboardView);
keyboard123.setKeyboard(k1);
The code above works great, but only if I create an xml file "qwerty_keyboard" with key definition. Is there a way to just get the android default keyboard and display it in one of the tabs in the TabLyout?
You can't do it the way you are trying to do it. You can't make the default keyboard in a View because it's a separate app that runs by itself.
So in order to achieve what you are trying to you'll need to request the inputmanager to pop up when you go to keyboard tab but frankly you'll have so many issues with the sizing (height) that I won't recommend this kind of design :) Just think about it, everyone can make a keyboard and everyone can install one, there is many many many keyboards and they all have different heights, but you might be able to get that height and do some magic...
Another alternative would simply be to make your own embedded keyboard (kinda like what you already did).

android soft keyboard modifications

Is there a way to programmatically remove certain keys from the standard software keyboard. By setting some of the input type flags I am so close to having the keyboard I need. From the calling application is there a way to modify the keyboard directly. I know how to make my own custom keyboard but it seems such a waste to remove one button from the standard one.
////// edit///////
I think I found a way around this if any one has tried this method please let me know if it worked for you.
I have going to grab the softKeyboard service and using the start hook the keyboard uses to grab its view object inflate my own and swap them.
From my research there is no way to implement your own custom keyboard from within a single application. If you want to have a custom keyboard you need to create one from scratch and can not use the IME
soft keyboard comes for edit text. you can modify the softkeyboard for that edit text.
For that you need to set inputType and imeOption property of that edit text.

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 do i add words to the suggestions on top of the soft keyboard

Is there any way to add words to the suggestions in the soft keyboard?
For a specific Edittext field i would like to add a list of names to the suggestions that pops up on top of the soft keyboard in android 2.0.
Does anyone know if this is possible?
Here is the source code of the soft keyboard.
If you go through the code, you will see that it uses a Suggest class which inside has different dictionaries.
If you want to add words for a specific EditText you would need to add and remove or change freq of a certain word from those dictionaries.
Some issues:
I couldn't find a way to get the InputMethodService's instance. (If you can, please answer my question here)
Android allows developers to program their own InputMethodService. I am working on one myself and my implementation doesn't use that dictionaries. So your feature will not work with my IME.
I would suggest using Auto Complete.
You can't add additional words to the ones the IME finds internally, however you can whole-sale supply your own completions via InputMethodManager.displayCompletions():
http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#displayCompletions(android.view.View, android.view.inputmethod.CompletionInfo[])
This is what the auto complete text view uses to show its completions in the IME, when the IME is full screen so it can't be seen. Note that your app is still responsible for showing the completions itself, so they will be available to the user if the IME is not full screen.
(And sorry about the lack of documentation on that method.)

Categories

Resources