3 Replies Latest reply on Mar 5, 2013 2:18 PM by francoland

    Flex 4.6 Mobile- soft keyboard and andorid back button

    frank_aq Level 1

      Forgive me as I posted this question in another thread but it doesn't seem to be getting much attention.

       

      When using Flex 4.6 on Android I've noticed an undesired behavior related to the soft keyboard.

       

      When the soft keyboard is open and you press the hardware back button two things happen:

      First, the keyboard closes.

      Then, if you're on a secondary view you get a pop view or if you're on the home view the app closes.

       

      I've been trying to solve this by overriding the hardware back button but have yet to come up with anything that works. It seems most of the posted solutions are for older versions of Flex and don't seem to work in 4.6

       

      Both of my phones I'm testing this on are HTC's incase this is hardware specific.

        • 1. Re: Flex 4.6 Mobile- soft keyboard and andorid back button
          frank_aq Level 1

          Looks like I've been able to fix this (at least on my phone (HTC Evo Shift 4G)

           

          Here is one of my views with the fix. Basically, I'm checking to see if a text field has focus and only popping if it doesn't. It should be easy enough to write a custom text field class an use a static var that all views could check off of.

           

          I will admit I am a bit worried that this issue may be related to my hardware (my phone has a physical keyboard) or the sense ui. If anyone has a different phone to test this on; I've included a link to my FXP and I'm looking forward to your feedback!

           

          <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                  xmlns:s="library://ns.adobe.com/flex/spark" title="TestView" backKeyPressed="onBackKeyPressed( event )" >

           

          ////

          ////

           

          import mx.events.FlexEvent;

                      private var kb:Boolean = false

                      private function onBackKeyPressed( e:FlexEvent ):void {

                          trace(kb);

                          e.preventDefault();

                          if(!kb){

           

                              navigator.popView();

                          } else {

                              stage.focus = null;

                          }

                      }

           

          ///////

          //////

           

           

          <s:TextInput focusIn="kb = true" focusOut="kb = false" />

           

          FXP project with my fix can be found here: http://francisaltomare.com/_etc/TestBackKey.fxp

          • 2. Re: Flex 4.6 Mobile- soft keyboard and andorid back button
            GEG_man

            Hi, frank! I have likely the same issue.It's in your project too.

            Way to reproduce:

            1) Activate keyboard at the second view in textInput.

            2) Press back. (Keyboard will disapper.)

            3) Press back. App will exit, but it' will not return to the previous view, as it should be.

             

            I've tested it on Galaxy Nexus and Xperia Ray and Air 3.1/3,2.

            • 3. Re: Flex 4.6 Mobile- soft keyboard and andorid back button
              francoland

              Hi GEG_man and frank,

              try to do as shown in the code below works for me, I tried to simplify the code to SoftKeyboard to prevent the application exits on pressing the back button:

               

               

              <?xml version="1.0" encoding="utf-8"?>

              <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                      xmlns:s="library://ns.adobe.com/flex/spark"

                      title="Test SoftKeyBoard" viewActivate="view1_viewActivateHandler(event)" backKeyPressed="backKeyPressedHandler(event)"

                      destructionPolicy="never">

                  <fx:Script>

                      <![CDATA[

                          import mx.events.FlexEvent;

                          import spark.events.IndexChangeEvent;

                          import spark.events.TextOperationEvent;

                          import spark.events.ViewNavigatorEvent;

               

                          private var focusInOut:Boolean = false;

                         

                          protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void

                          {

                              message.text = data.description;

                              message.setFocus();

                          }

               

                          protected function backKeyPressedHandler( event:FlexEvent ):void {

                              //trace("Trigger: "+event.type);

                              //trace("USER_TRIGGERED: "+SoftKeyboardTrigger.USER_TRIGGERED.length);

                              if(SoftKeyboardTrigger.USER_TRIGGERED.length == 13 && focusInOut==true){

                                  event.preventDefault();

                                  stage.focus = stage;

                              } else {

                                   stage.focus = null;

                              }

                          }       

                     

                          protected function recipient_softKeyboardActivateHandler(event:SoftKeyboardEvent):void

                          {

                              trace("Activate: "+event.type);

                              event.preventDefault();

                              stage.focus = null;

                              setFocus()==true;               

                          }

                         

                          protected function recipient_softKeyboardDeactivateHandler(event:SoftKeyboardEvent):void

                          {

                              //trace("Deactivate: "+event.type);

                              event.preventDefault();

                              stage.focus = stage;

                              setFocus()==false;

                          }

                         

                      ]]>

                  </fx:Script>

               

                  <s:TextArea id="message" width="100%" height="300" change="message_changeHandler(event)" text="{data.description}"

                              softKeyboardActivate="recipient_softKeyboardActivateHandler(event)" softKeyboardDeactivate="recipient_softKeyboardDeactivateHandler(event)"

                              focusIn="focusInOut=true" focusOut="focusInOut=false"/>

                 

              </s:View>

               

              I've tested it on Galaxy S3 and LG P990 and Air 3.4/3,5/3.6.

               

              enjoy

              Franco