Bug 677 - [Android] The softKeyboard should notify when it gets hidden with the Back button
Summary: [Android] The softKeyboard should notify when it gets hidden with the Back bu...
Status: RESOLVED FIXED
Alias: None
Product: Newt
Classification: JogAmp
Component: core (show other bugs)
Version: 1
Hardware: embedded_arm other
: --- normal
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2013-01-28 13:08 CET by Eric Brayet
Modified: 2013-02-28 15:32 CET (History)
0 users

See Also:
Type: ---
SCM Refs:
3a4892c43be4a9dabba73d42175c2cfa39bd6d8d
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Brayet 2013-01-28 13:08:40 CET
On Android devices without keyboard, as the softKeyboard pops up i.e. with GLWindow.setKeyboardVisible(true), the GLWindow must slide up so that the textfield that has the focus remains visible as you type in the text. And when the softKeyboard gets hidden, you must slide the window back.

There are several ways to remove this keyboard. For instance the user can change the focus (then you would call GLWindow.setKeyboardVisible(false). But the user can also press the Back button of the standard tool bar. And that's a problem.

Pressing Back triggers a regular onKey with keyCode=KEYCODE_BACK, but it does not land in the AndroidNewtEventTranslator's onKey(), because it is handled and consumed by the softKeyboard. And then we cannot move the window back to its regular coordinates.

Build 2.0-rc11-post05


Fix suggestion:
---------------
The keyEvent lands in MSurfaceView's dispatchKeyEventPreIme.
We can add a listener mechanism in MSurfaceView
Comment 1 Eric Brayet 2013-01-28 13:50:38 CET
I sent a pull request for this issue:
https://github.com/sgothel/jogl/pull/57
Comment 2 Sven Gothel 2013-01-28 16:20:27 CET
Instead of adding another listener, we shall feed the special menu bar events 
to the translator to generate NEWT key event as follows:

Android.BACK:
  if( soft keyboard is up ) 
    [1] return NEWT.VK_KEYBOARD_INVISIBLE;
  else
    [2] call WindowImpl.windowDestroyNotify(false)

[1] will allow the app to be notified that the soft keyboard got invisible

[2] will allow the user to utilize WindowClosingProtocol to decide whether 
      real destruction is desired. However, the windowDestroyNotified(..)
      will always tell the app that such request has been made.
       <http://jogamp.org/git/?p=jogl.git;a=commit;h=2f63a43fd6ff9964251c43e248c51bc821f3ecbd>
Comment 3 Sven Gothel 2013-01-28 16:22:41 CET
(In reply to comment #2)
> [2] will allow the user to utilize WindowClosingProtocol to decide whether 
>       real destruction is desired. However, the windowDestroyNotified(..)
>       will always tell the app that such request has been made.
Note that  our override of 
   'boolean View::dispatchKeyEventPreIme(KeyEvent event) {..}'
must return TRUE here to ensure we have handled the event..
Comment 4 Sven Gothel 2013-02-28 15:32:07 CET
http://jogamp.org/git/?p=jogl.git;a=commit;h=3a4892c43be4a9dabba73d42175c2cfa39bd6d8d

    Fix Bug 677: NEWT/Android: Add support for Android's KeyEvent.KEYCODE_BACK
    
    Original author: Eric Brayet <ericb@daysofwonder.com>
    Revised by: Sven Gothel <sgothel@jausoft.com>
    
    I took the freedom to cleanup the three original patches
    from https://github.com/Pooouf/jogl.git branch 'bug_677':
      - 7449d4726633d524a3bb79efffd04cfd0ca25e58 (removed by followup patch!)
      - 68c739a4f03e46deecdbb71c125b4586aec08d63 (removes previous patch!)
      - c2813dfc325a1482d18b6fc304e4e483f5633964
    
    Further more I was able to reduce the 'extra' code while utilizing
      - Window's isKeyboardVisible() and using keyboardVisibilityChanged(false)
        to update the hidden keyboard state.
      - Moving the key-handling code to the containing WindowDriver class
        avoiding passing a reference to the inner view.
      - Using AndroidNewtEventFactory for NEWT KeyEvent creation
    
    +++
    
    - Handle KeyEvent.KEYCODE_BACK w/    
      jogamp.newt.driver.android.WindowDriver.MSurfaceView.onKeyPreIme(..):
        if( soft keyboard is up )
          [1] Update keyboard visibility state and return NEWT KeyEvent.VK_KEYBOARD_INVISIBLE;
        else
          [2] call WindowImpl.windowDestroyNotify(true)
    
        [3] then cont. processing, i.e. return false;
    
    - Turns out respecting WindowClosingMode might be
      - too complicated
      - interfere w/ Android UI behavior
    
    - AndroidNewtEventFactory
      - createKeyEvent
        - static
        - adding boolean param 'inclSysKeys', if true, KEYCODE_BACK and KEYCODE_HOME are mapped