Empty EditText when turning screen on and Screen lock set to None - android

I'm having a problem where an EditText in landscape/full screen mode becomes empty after turning the screen off and then on when the system Screen lock is set to None. The keyboard remains active, but it doesn't appear to have focus and no text updates are displayed on the screen. If I tap the Done button or rotate to portrait, then the full screen editor is removed and I can see the previously entered text in the normal EditText view.
I'm reproducing this on JB in both the emulator and a device. The EditText has an android:id and I've found this problem with a variety of EditText and AutoCompleteTextView configurations, but only when the system Screen lock setting is set to None. Everything works fine when it's set to Slide or Pattern, so I suspect that the lack of a screen lock is the source of this problem.
I found the same problem in Calendar, but not in Messaging. When editing an SMS message in landscape/full screen mode and then turning the screen off/on, at first the message appears to be empty, but then it returns after a second. I reviewed the source code below, but I didn't see anything special in onResume() that appeared to be addressing this issue.
https://github.com/android/platform_packages_apps_mms/blob/master/src/com/android/mms/ui/ComposeMessageActivity.java
Does anyone know how to properly fix this, so that when Screen lock is None you can edit text in landscape/full screen mode, turn the screen off and then back on, and the text is displayed just as you left it?

As a (hopefully) temporary fix, I have included the following line in onResume() and it appears to do the trick. Initially I tried to only run this when the IME isFullscreenMode(), but this returns false in onResume() (after returning true in onPause()). I would guess that this is part of the root of the problem. When system Screen lock is None and the screen is turned on, the IME doesn't know that it's in full screen mode when it actually is.
View view = getCurrentFocus();
if (view != null) {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.restartInput(view);
}

Related

Why is onStartInputView() called when the device is locked?

I am writing a custom IME and there's something I don't understand in its lifecycle.
onStartInputView() and onFinishInputView() are supposed to be called when the keyboard view is displayed and destroyed, respectively. They're also called if the user changes app or text field while the soft keyboard is up. That's fine.
They weird case is that:
Given the soft keyboard is currently shown and I'm typing text (for instance, in my SMS app)
When I lock my device (turn the screen off)
Then I see a weird successions of calls:
onFinishInputView(finishingInput=true)
onStartInputView(editorInfo, restarting=false)
onFinishInputView(finishingInput=true)
onStartInputView(editorInfo, restarting=false)
onStartInputView() is the last call, so from the IME perspective the keyboard view is "visible" even though my device is locked (screen off).
My custom IME needs to know precisely when the keyboard is not displayed anymore (for instance to stop some background processing, or send a session close event): how can I do that since it seems I can't rely on onStartInputView()?
Thanks!

Android InputMethodService Inconsistent State in Fullscreen Mode

I am developing a soft keyboard. I have a class MyIME that extends InputMethodService.
I override onKey(int, int) to handle keypresses. My keyboard is able to insert and delete text the way I defined it just fine in portrait modes, I am just running into a problem in landscape when the keyboard is set to full screen.
In full screen mode, the framework's default ExtractEditLayout is used which contains an ExtractEditText instance. As I type in full screen mode, the following weird behavior happens:
I can type normal characters just fine. I insert these using getCurrentInputConnection().commitText(String.valueOf(code), 1);
When I press backspace to delete a character, the cursor moves back and the preceding character is removed. This behaves fine. Subsequent key strokes from this point on are no longer functioning as they are supposed to:
If I press backspace after the first one, the cursor moves backwards however the character does not get deleted. When backspace is pressed, getCurrentInputConnection().deleteSurroundingText(1, 0); is executed.
Similarly, if I add more characters after pressing backspace once, the cursor will move forward but the characters will not appear on the screen.
When I exit full screen mode by rotating my device back into portrait orientation, all of the characters that I typed or deleted are there. It appears as if the ExtractEditLayout used for composing fullscreen messages becomes out of sync with my InputMethodService subclass and it appears that they only become out of sync after I initially attempt to delete a character.
The bug was related to an expensive ExtractedTextRequest I was making each time I pressed backspace. The request was being used to determine if the text field was empty so I could determine whether or not to set the keyboard into a shifted state.
I got rid of the ExtractedTextRequest and now determine if the textfield is empty by a two (largish) calls to InputConnection's getTextBeforeCursor() and getTextAfterCursor() and the undesired behavior I described in the question component of this post no longer occurs.

prevent activity from receiving touch events when screen display is off

I'm setting my screen to be always awake in order to preventing it from going into sleep mode at all.
hence, when the screen display is turned off, the user has to touch the screen in order to bring it on again, but the problem is that this touch is received by the foreground activity and it reacts according to it, and the user is for sure just trying to turn the screen display on.
I tried to set the following flags but didn't work:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
&&
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
To resolve your issue you have to do one of the below things which prevents screen to turn off automatically.
Add android:keepScreenOn="true" to some widget in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.
OR
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to disable the screen timeout and
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to re-enable it.

PhoneGap + Android page doesn't refresh after soft keyboard closes

Most of the time (but not always), when I finish typing in a or and the soft keyboard hides, the view area is left raised with a black space on the bottom. Clicking, tilting or otherwise engaging the phone corrects the screen. However, user's first motion is usually pressing , but if you click submit it jumps down and you actually just click on the text area again. How do you stop this and get the screen to reset after the keyboard closes.
Take a look at you AndroidManifest.xml
http://developer.android.com/guide/topics/manifest/activity-element.html
I think you need to change android:configChanges.
I have the exact same problem what i did was handle hidekeyboard even in javascript and do something like window.scrollTo(0,0) or $("input[type=text],textarea").blur();
This will cause the the screen to get back to normal position
But there is just one problem when click from input field of type = text to a input field password it internally hide the keyboard which causes the hidekeyboard event to fire and scrolls the screen to top. This is the only side effect of this
Let me know if you find the solution for this

IME Resize Options for Horizontal Orientation

I've created a custom IME for Android tablets and I'm having trouble resizing when the screen is in horizontal orientation. Whenever an EditText is clicked while the screen is horizontal, the IME takes over the entire screen with the standard EditText and Button combo with my custom IME at the bottom of the screen. However, I'd like for the IME to simply pop up without that and type directly into the field that was originally clicked, as it does in horizontal orientation. I've looked at the SoftKeyboard example, which accomplishes this (at least on honeycomb) and can't find exactly where they are setting that effect.
Sorry if this is a duplicate, I've tried searching but couldn't find this exact question.
If anyone else is having this issue, you can prevent your IME from entering fullscreen mode by overriding the onEvaluateFullscreenMode() method, which is what determines whether or not your IME will display in full screen.
Now I'm having different issues but that's for a different thread!

Categories

Resources