How to make softkeyboard candidate view not block application view? - android

I am playing with the Demo SoftKeyboard the comes with the Android SDK.
In portrait mode when the candidate view is shown, it doesn't move the app up as the default android keyboard does. Hence it covers part of the application view.
What should be changed in order to make the candidate view in the demo softkeyboard behave as the default android keyboard does?
I've also looked at the source of the android keyboard from git but found nothing related to this behavior.

I know this is old but here is an answer anyway.
#Override public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
if (!isFullscreenMode()) {
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
}

Related

How to detect the keyboard on the android window - Titanium Appcelerator

I need something to verify the existence of the keyboard in the window of an android app ... The problem is I can not test the focus / blur the input, and need that check for keyboard ... I see the official documentation Appcelerator and this functionality is only for iOS ... does anyone have a solution?
KeyboardVisible property for iOS:
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-property-keyboardVisible
As you can see in the official docs there is no native way to detect if the keyboard is visible; if you need to show the keyboard when the user open the window, add a listener to 'open' and 'resume' (this one is from the activity, not the window, and is triggered also when your app go from the background to the foreground) for a function that focus your field, if you need to know when the keyboard is open to change the layout, android already try to fit it for you (in this case, place everything inside of a scrollview).
On iOS you can listen to the keyboardframechanged event. For Android, you might be able to use one of these modules.
There is no any direct way to do this. but some trick may be work. try this.
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});

Qt Android: Pressing "Done" does not hide the keyboard

When I write into a line edit using the Android keyboard, and I press the "Done" button (screenshot below), the keyboard does not disappear. This happens even in a newly created project with just a line edit (I tested it).
How can I make "Done" to hide the keyboard?
Please note that I am looking for a developer solution (i.e. programming, not user oriented) and a native way (i.e. C++/Qt, not Java).
I'm using Qt 5.2.0.
You have to call the QInputMethod::hide() slot.
C++ Solution
connect(ui->lineEdit, SIGNAL(editingFinished()), QGuiApplication::inputMethod(), SLOT(hide()));
QML Solution
TextInput {
Keys.onEnterPressed: {
//...
Qt.inputMethod.hide()
}
Keys.onReturnPressed: {
//...
Qt.inputMethod.hide()
}
}

Show soft keyboard even though a hardware keyboard is connected

Is there any way to show software keyboard with USB keyboard connected (in my case RFID reader)?
I tried to force show it using InputManager (with these or similar parameters), but with no luck
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Important notice - I know that there is a button in status/system bar to show it, but this button is not visible to user (Kiosk app).
You need to override the InputMethodService method onEvaluateInputViewShown() to evaluate to true even when there is a hard keyboard. See onEvaluateInputShown() and the Soft Input View section of InputMethodService. Try creating your own custom InputMethodService class to override this method.
EDIT: The source for onEvaluateInputShown() should help. The solution should be as simple as creating your own class that extends InputMethodService and overriding this one method, which is only a couple of lines long. Make sure to add your custom service to your manifest as well.
From Source:
"Override this to control when the soft input area should be shown to the user. The default implementation only shows the input view when there is no hard keyboard or the keyboard is hidden. If you change what this returns, you will need to call updateInputViewShown() yourself whenever the returned value may have changed to have it re-evalauted and applied."
public boolean onEvaluateInputViewShown() {
Configuration config = getResources().getConfiguration();
return config.keyboard == Configuration.KEYBOARD_NOKEYS
|| config.hardKeyboardHidden == Configuration.KEYBOARDHIDDEN_YES;
}
Here are the possible configurations you can check for. Configuration.KEYBOARD_NOKEYS corresponds to no hardware keyboard. This method returns true (soft keyboard should be shown) if there is no hardware keyboard or if the hardware keyboard is hidden. Removing both of these checks and simply returning true should make the software keyboard visible even if a hardware keyboard is attached.
Try (not tested):
public boolean onEvaluateInputViewShown() {
return true;
}
Since this return value will not change, you won't need to call updateInputViewShown() yourself. If you modify this method differently, be sure to remember this detail.
The soft keyboard can have unpredictable behaviour on different platforms. First in your code, ensure you have an editable input control. Eg, if you have an EditText, you could use:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
However, you can just show and hide it whenever you want using:
//show keyboard:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//hide keyboard :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You could also add any of these events inside OnCreate or some other method of the controls.
If however for some reason any of the above fails, your best option might be to use an alternative keyboard, e.g. Compass Keyboard,
OR
You could even build yours:
See an example of a keyboard implementing the inputmethodservice.KeyboardView
You might also want to take a look at the GingerBread Keyboard source.
If your app has the WRITE_SECURE_SETTINGS permission (available to system apps or Android Things apps) it can set the show_ime_with_hard_keyboard system setting which will enable soft keyboard even if a hard keyboard is plugged:
Settings.Secure.putInt(getContentResolver(), "show_ime_with_hard_keyboard", 1);
This worked in my app, interestingly, also an kiosk app.
This is a bit stripped, I did some checks beforehand, whether IMM is null and such.
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInputFromWindow(someInputView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
according to this https://stackoverflow.com/a/24287780/2233069, I made working solution for Kiosk mode.
boolean hardwareKeyboardPlugged=false;
....
mEditText.setOnFocusChangeListener(this);//in onCreate()
....
#Override
public void onResume() {
//protect from barcode scanner overriding keys
hardwareKeyboardPlugged=(getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO);
super.onResume();
}
....
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
if (hardwareKeyboardPlugged){
//protect from barcode scanner overriding keys
hardwareKeyboardPlugged=false;
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
Toast.makeText(this, "USB device detected. Turn OFF hardware keyboard to enable soft keyboard!", Toast.LENGTH_LONG).show();
}
}

Transparent InputMethod for Android

Trying to make an Android InputMethod that is transparent - i.e. the underlying content shows through to the keyboard that I am developing.
I've been able to make the View that I pass to the system transparent - I think - but there seems to be something underneath my view that is solid white - and obfuscating the underlying content.
It is definitely possible, these guys do it:
https://play.google.com/store/apps/details?id=com.aitype.android.tablet.p&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5haXR5cGUuYW5kcm9pZC50YWJsZXQucCJd
I figured it out! Not sure if this is how the guys in your play store link did it, but this is what worked for me. Also, I realize this post is over a year old, but I'm still answering it just in case someone else out there discovers this when trying to create a transparent keyboard.
The "something" under your view is actually nothing - it's empty space. Your keyboard pushed the entire view up and out of the way to make room for its height, leaving empty white space behind. Your transparent keyboard let this white space show through.
Here's the solution: instead of returning your view in onCreateInputView, return it in onCreateCandidatesView. That's the view that normally lives above the keyboard and lists the autocorrect suggestions. But you're going to use this to house your actual keyboard.
The reason you want to have your keyboard be a candidates view is because the input view most often pushes the underlying view up. Individual apps can decide how they want to behave when a keyboard is shown via android:windowSoftInputMode and the input view respects their preference, but the candidates view always uses adjustPan.
From the docs: "Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus." http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html
So, return your transparent view from onCreateCandidatesView, return null from onCreateInputView and make sure to call setCandidatesViewShown(true) so your candidates view shows up (I call it in onWindowShown).
Normally InputMethodServices uses background color which is same with current binding application's background color. If you want to make this transparent, I think you should make it as popup-window structure, not an inputmethod window I think.
It may such easy to make the full screen keyboard layout extra area transparent via java reflection only if you're quite familiar with InputMethodService.
the extra area has an id name fullscreenArea, you can fetch the area's id, then findViewById() then set its background.
the keyboard look as this before I done my practice :
a giant blank cover the below page.
so after is :
you can see the below page which contained an EditText and others displayed.
here is my code :
public static void makeKeyboardTransparent(InputMethodService service) {
try {
View decorView = service.getWindow().getWindow().getDecorView();
final int viewId = fetchInternalRId("fullscreenArea");
View fullscreenArea = decorView.findViewById(viewId);
if (fullscreenArea != null) {
modifyView(fullscreenArea);
return;
}
} catch (Exception e) {
}
try {
Class<?> superClass = service.getClass().getSuperclass();
Field fullscreenAreaField = superClass.getDeclaredField("mFullscreenArea");
fullscreenAreaField.setAccessible(true);
View fullscreenArea = (View) fullscreenAreaField.get(service);
if (fullscreenArea != null) {
modifyView(fullscreenArea);
}
} catch (Exception e) {
}
}
private static void modifyView(View fullscreenArea) {
fullscreenArea.setBackgroundColor(Color.TRANSPARENT);
}
private static int fetchInternalRId(String name) throws Exception {
Class<?> rIdClass = Class.forName("com.android.internal.R$id");
return rIdClass.getDeclaredField(name).getInt(rIdClass);
}
I provided two approach to make the blank area transparent, both of them worked fine in my test, all you need is pass your InputMethodService into makeKeyboardTransparent() and see what it can do.

Flex 4.6 hide/dismiss softkeyboard

I'm having some issues with the softkeyboard behaviour in flex 4.6 and air 3.1
I have a list with a search bar on top. When a user selects the TextInput component the softkeyboard pops up like it should.
Now when the user is done typing his text and presses the return (or the done/search/...) key I want the softkeyboard to disappear.
What I've tried so far:
I've set the returnKeyLabel property to "done" and the button shows
up accordingly. However it only dismisses the keyboard on Android, on
IOS the keyboard just stays up.
I then tried by not setting the returnKeyLabel and manually
catching the Return key and setting the focus to another element that
does not require a softkeyboard but that didn't work either.
I also tried by dispatching my own "faked" click events when the Return key was pressed but this also didn't work.
As part of searching about this problem I found this Dismiss SoftKeyboard in Flex Mobile but that didn't work either. Or at least not in flex 4.6
Now does anyone know of a good way to hide the softkeyboard or make the returnKeyLabel "done" work on IOS that will work with flex 4.6/air 3.1?
Have you tried something like this?
<s:TextInput prompt="First Name" returnKeyLabel="done" enter="handlerFunction()"/>
private function handlerFunction():void{
stage.focus = null
}
For flex mobile android apps I have mimicked the intuitive ios way of tapping on the background to remove the softkeyboard as follows:
import spark.components.supportClasses.*
protected function application1_clickHandler(event:MouseEvent):void
{
if(event.target is StyleableTextField || event.target is StyleableStageText){
// ignore because came from a textInput
}else{
stage.focus = null
// to remove the softkeyboard
}
}
<s:TextInput prompt="First Name" returnKeyLabel="done" enter="{stage.focus = null}"/>
This is the same as Francis' answer, but it saves having to make a new function

Categories

Resources