Closed Bug 877659 Opened 11 years ago Closed 11 years ago

Robocop: Find a way to check if the vkb is opened and close it without using a BACK action

Categories

(Firefox for Android Graveyard :: General, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 24

People

(Reporter: AdrianT, Assigned: AdrianT)

References

Details

Attachments

(1 file, 1 obsolete file)

This is a follow-up to https://bugzilla.mozilla.org/show_bug.cgi?id=875363#c6

In some cases when a pop-up with a focused text field is displayed the vkb is opened and sending a BACK event (mActions.sendSpecialKey(Actions.SpecialKey.BACK)) the app will be minimized instead of the vkb being dismissed.

We need a reliable way to check if the vkb is opened and close it if it is using android code. This will eliminate the need to always check the device type/version with popups (for e.g. testAddSearchEngine, the checkBookmarkEdit method from BaseTest used in testBookmarksTab)
Blocks: 875363
I don't think you have to check if the vkb is open: if the vkb is already hidden, hiding it again will not do anything.
Here are my findings so far after testing on the LG Optimus 2X (Android 2.2) and the Asus Transfrmer TF101 (Android 4.0.4):

1) On the LG Optimus the vkb is not opened when the pop-up is displayed. On the Asus it is.
2) I am unable to use the setFlags method listed below since i get a security exception - only the generating activity can set those:
  getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
3) Using the InputMethodManager hideSoftInputFromWindow does not work on the Asus. 
  imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
4) I can use the toggleSoftInput method to hide the vkb on the Asus but unfortunately this displays the vkb on the LG where initially it was not displayed:
  imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
5) I tried tapping in the input field to bring up the vkb regardless of the device used and then toggle it but it seems that mSolo.clickOnEditText(0); closes the pop-up completely on the Asus TF101 for some reason.
Attached patch proof of concept patch (obsolete) — Splinter Review
Looking into this and seeing that there are issues with getting the keyboard closed on all devices I found a bypass to that.
The attached patch clicks the buttons of the pop-up regardless if they are "obstructed" by a vkb or not. This is just a proof of concept and I need to check this on existing patches but worked for me on a few local tests on both the LG Optimus 2X (Android 2.2) and the Asus Transformer TF1 (Android 4.0.4). Will look into this and submit a complete patch and a tryserver run as soon as possible.
Try run: https://tbpl.mozilla.org/?tree=Try&rev=83f88ac3db33

From all the research I done on this it seems that there actually is no way to check if the keyboard is up or not so we still have to use the device test to just close the keyboard for tablets. The only way I found to make this work was using toggle since hide does not seem to work on all devices.

I created 2 new methods in BaseTest:
 * toggleVKB() to toggle the kbd to be hidden or shown - this will hide the vkb without the risk of minimizing the app when using a BACK action
 * clickOnButton(String label) which will perform the click on the button even if the view is blocked by the vkb and so removing the need to check if the vkb is up and to close it
Attachment #757473 - Attachment is obsolete: true
Attachment #757951 - Flags: review?(jmaher)
Comment on attachment 757951 [details] [diff] [review]
vkb toggle and pop-up buttons click patch

Review of attachment 757951 [details] [diff] [review]:
-----------------------------------------------------------------

this looks good and the try run is solid as well, thanks!

::: mobile/android/base/tests/BaseTest.java.in
@@ +491,5 @@
> +
> +    // Used to hide/show the virtual keyboard
> +    public void toggleVKB() {
> +        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
> +        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

I wonder if this will work with custom keyboards.  I suspect it will work great with all system keyboards.
Attachment #757951 - Flags: review?(jmaher) → review+
> ::: mobile/android/base/tests/BaseTest.java.in
> @@ +491,5 @@
> > +
> > +    // Used to hide/show the virtual keyboard
> > +    public void toggleVKB() {
> > +        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
> > +        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
> 
> I wonder if this will work with custom keyboards.  I suspect it will work
> great with all system keyboards.

This should work with any keyboard. From what I have seen the InputMethodManager can be used to get a list of the active IMEs and can also change the default one. To bad that for some reason the hideSoftInputFromWindow does not work since that would have always kept the keyboard hidden and we would not need 2 different methods here.
https://hg.mozilla.org/integration/mozilla-inbound/rev/d7b6013ae60f

Please include patches with real commit messages, not Try syntax, when requesting checkin.
Assignee: nobody → adrian.tamas
Flags: in-testsuite+
Keywords: checkin-needed
Blocks: 879767
https://hg.mozilla.org/mozilla-central/rev/d7b6013ae60f
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 24
Bug 880650 mentions that 23 is affected and Jim mentioned that this bug needs uplift first.
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: