Quantcast
Channel: Adobe Community : All Content - AIR Development
Viewing all articles
Browse latest Browse all 2954

Air Native Extension - Java Key Listener

$
0
0

Hello all,

 

Firstly I'd like to thank you for creating an excellent and helpful community. I have an issue I have been stuck on for around 2 weeks now.

 

I am creating an android native extension to listen to key input from a proprietary remote control device. GameInput does not recognise it as a game controller so we have to create a native extension to get the input. I have it working fully except for one issue; if the game loses context (eg the user gets a phone call or the game goes into the background for any other reason) I do not get any other input.

 

The way I am doing it is to attach an onKeyListener to the currently focused View (an AirWindowSurfaceView). This works perfectly, but when the context is lost I'm assuming the AirWindowSurfaceView changes and I cannot find a way to get a reference to the new one. Here is my key listener setup code (from the native Java):

 

public void updateListeners()

{

    if(_view != null)

    {

      _view.setOnKeyListener(null); //remove from the old view

      _view.setOnGenericMotionListener(null);

    }

 

    _context.dispatchStatusEventAsync(_view.toString(), "view"); //send the current view details

    _view = _context.getActivity().getCurrentFocus();  //set the new view

    _context.dispatchStatusEventAsync(_view.toString(), "view");

 

   if(_onKeyListener == null)

   {

       _onKeyListener = new NativeGamepadKeyListener(_context, this); //create new key listener

   }

   if(_onGenericMotionListener == null)

   {

       _onGenericMotionListener = new NativeGamepadMotionListener(_context, this); //create a new motion listener

   }

 

   _view.setOnKeyListener(_onKeyListener);          //set on the new view

   _view.setOnGenericMotionListener(_onGenericMotionListener);

}

 

This updateListeners function is called when I get a focus change event on the current view (attached in a similar way) but this doesn't seem to keep it up to date with the current View.

 

Please note I'm a newbie at making extensions like these and might be going about it totally the wrong way - if I am and you have any suggestions as to the best way to use an onKeyListener in a native extension I'd love to hear it.

 

Thanks in advance for your help!


Viewing all articles
Browse latest Browse all 2954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>