Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Xperia Play Keycodes in Unity?

Discussion in 'Android' started by jashan, Apr 7, 2011.

  1. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hi there,

    I noticed that question is also on Unity Answers:

    what are the input codes for Sony Xperia Play keys?

    ... but without any proper answer, yet. I did answer with what I know so far and tried so far - but any official help would be greatly appreciated; especially since Unity 3.3 officially supports the Sony Ericsson Xperia play; and I also wasn't able to find any real info in the docs, either.
     
  2. colargol

    colargol

    Joined:
    Mar 31, 2010
    Posts:
    65
  3. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Wow, thanks - that tutorial really answers all my Xperia play questions :) thanks for sharing the link!
     
  4. ZeroStride

    ZeroStride

    Joined:
    Mar 9, 2011
    Posts:
    34
    It's worth noting that their method for detecting if navigation is hidden or not will fail on phones like the GalaxyS which report that navigation is shown, however when asked, will claim that no navigation is present. My code for this functionality:

    Code (csharp):
    1.  
    2.     private AndroidJavaObject _currentConfig = null;
    3.     protected void initAndroidConfigLink()
    4.     {
    5.         using(AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    6.         {
    7.             AndroidJavaObject activity = player.GetStatic<AndroidJavaObject>("currentActivity");
    8.             _currentConfig = activity.Call<AndroidJavaObject>("getResources").Call<AndroidJavaObject>("getConfiguration");
    9.         }
    10.        
    11.         StartCoroutine(CheckPhoneControllerStatus());
    12.     }
    13.    
    14.     private bool _phoneControllerEnabled = false;
    15.     public bool PhoneControllerEnabled
    16.     {
    17.         get
    18.         {
    19.             return _phoneControllerEnabled;
    20.         }
    21.     }
    22.    
    23.     private IEnumerator CheckPhoneControllerStatus()
    24.     {
    25.         const int NAVIGATIONHIDDEN_UNDEFINED = 0;
    26.         const int NAVIGATIONHIDDEN_YES = 2;
    27.        
    28.         const int NAVIGATION_DPAD = 2;
    29.        
    30.         int navCapabilities = _currentConfig.Get<int>("navigation");
    31.         int nav;
    32.         while((navCapabilities  NAVIGATION_DPAD) > 0)
    33.         {
    34.             nav = _currentConfig.Get<int>("navigationHidden");
    35.             if(nav == NAVIGATIONHIDDEN_YES || nav == NAVIGATIONHIDDEN_UNDEFINED)
    36.             {
    37.                 // The phone is either not an Xperia, or it is closed
    38.                 //if(_phoneControllerEnabled) Debug.Log("### Phone controller was open, it is now closed.");
    39.                 _phoneControllerEnabled = false;
    40.                
    41.                 // TODO: Some kind of on-screen indicator that touch controls are now active
    42.                 allowTouch2 = false;
    43.                 allowGamepad = false;
    44.                
    45.                 allowTouch = true;
    46.                 allowAccelerometer = true;
    47.             }
    48.             else
    49.             {
    50.                 // The phone is slid open so that the PlayStation-ish controller is exposed
    51.                 //if(!_phoneControllerEnabled) Debug.Log("### Phone controller was closed, it is now open.");
    52.                 _phoneControllerEnabled = true;
    53.                
    54.                 // TODO: Some kind of on-screen indicator that touch controls are no longer active
    55.                 allowTouch2 = true;
    56.                 allowGamepad = true;
    57.                
    58.                 allowTouch = false;
    59.                 allowAccelerometer = false;
    60.                
    61.                 // Reset the camera tilt
    62.                 ((GRacerInputHuman)(this)).ResetAccelYWindow();
    63.                 Camera.main.gameObject.GetComponent<LumaCarCamera>().avgAccelYValue = 0.0f;
    64.             }
    65.             yield return new WaitForSeconds(2.0f);
    66.         }
    67.     }
    68.  
    I do not have a list of all phones which report to have NAVIGATION_DPAD, however.
     
  5. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hm ... on my Xperia Play, I always get NAVIGATIONHIDDEN_NO (1), no matter whether the keypad is slided in or out. I do get log messages when the keypad is slid in or out, though - so it doesn't seem like it's a problem with the device.

    Also, I get 3 as navCapabilities from my Google Nexus One, and again: NAVIGATIONHIDDEN_NO (1). So it seems this really isn't working at all :-(
     
  6. colargol

    colargol

    Joined:
    Mar 31, 2010
    Posts:
    65
    jashan:
    Do you have "Use NativeActivity" checked in Player settings?
     
  7. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Ah, thanks - no, I missed that. However, it turned out NativeActivity only works with Gingerbread. My Google Nexus One is still on Froyo so I have a testing device that is more representative of the general market (currently around 63% with 2.2, and around 2.5% with 2.3 and 2.3.3 combined). Hm ... I start to dislike Android a little ;-) ... so, it seems I'll have to do 2 builds: one 2.2 build and another build for 2.3.

    However, the really bad news is: Having NativeActivity enabled doesn't seem to make a difference with NAVIGATIONHIDDEN_NO. I still get it all the time. So, I created a Gingerbread build and deployed to my Xperia Play (which is on 2.3.2 which seems to be "the version" on that device even though there's also 2.3.3 for other devices already).

    The device is "closed", but I get:

    Code (csharp):
    1. 04-10 17:07:38.444: INFO/Unity(2278): Keypad available: 1 => True; navCapabilities: 2
    I slide out the keypad and get:

    Code (csharp):
    1. 04-10 17:09:09.364: DEBUG/lidswitchd(128): enabling touchpad
    still the same as before (only that now it would be "correct"). Slide the keypad back in, and get:

    Code (csharp):
    1. 04-10 17:09:45.094: DEBUG/lidswitchd(128): disabling touchpad
    and also:

    Code (csharp):
    1. 04-10 17:09:45.294: DEBUG/Unity(2278): onConfigurationChanged
    ... so, Unity "gets" it ... but still:

    Code (csharp):
    1. 04-10 17:10:05.364: INFO/Unity(2278): Keypad available: 1 => True; navCapabilities: 2
    Hmmmmm ... this sucks :-( ... so just to be sure I'm not overheated by the sun or something like that, here's the code that's generating that logging statement:

    Code (csharp):
    1.         while ((navCapabilities  NAVIGATION_DPAD) > 0) {
    2.             nav = currentConfig.Get<int>("navigationHidden");
    3.             if (nav == NAVIGATIONHIDDEN_YES || nav == NAVIGATIONHIDDEN_UNDEFINED) {
    4.                 keypadAvailable = false;
    5.             } else {
    6.                 keypadAvailable = true;
    7.             }
    8.             log.DebugFormat("Keypad available: {0} => {1}; navCapabilities: {2}", nav, keypadAvailable, navCapabilities);
    9.             yield return new WaitForSeconds(slideReactionTime);
    10.         }
    The member variable currentConfig was created as in the tutorial, the code for that is executed in Start(), looks like this:

    Code (csharp):
    1.     private void InitAndroidConfigLink() {
    2.         using (AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
    3.             AndroidJavaObject activity = player.GetStatic<AndroidJavaObject>("currentActivity");
    4.             currentConfig = activity.Call<AndroidJavaObject>("getResources").Call<AndroidJavaObject>("getConfiguration");
    5.         }
    6.     }
    Any ideas?
     
  8. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
  9. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    My Nexus One does ;-) ... it reports "3", so that would be NONAV + DPAD ... which doesn't seem very logical to me but ... it seems that's the case for many Android-things ;-) ... Xperia Play reports 2, so that's "only DPAD" ... so maybe one could instead check for "NONAV not present"?
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    did you consider the possibility that the optical track thingy reports to be a dpad too?

    will test it on my htc desire which has one as well on wednesday and report back, but it would make sense

    I think what should be checked is if the additional buttons are present (given thats possible) as they are granted to be missing on all others :D
     
  11. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Ah, I guess that's it ...

    That might be a possibility - but I wouldn't know how to check for those. I guess for now I'll stay with the other checks which includes checking for the device name.
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    device name is likely the easiest indeed cause there is 1 xperia play, point ;)

    checking for buttons potentially would involve some java or plugin usage to grab it from "deeper in", not checked it either as I don't have the play and don't intend to get it due to the "once again we give no damned that < 4GB internal free is not adequate for 2011" attitude of sony
     
  13. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    You would think so ... but ... it's actually R800i. No wait, in some areas it's R800a ... or R800at ... or R800x ... so, one might guess it's simply "R800-something" ... but no, Sony Ericsson is being creative: There's also a Z1i which is also an "Xperia Play". This really reminds me of the mess that J2ME was ;-)
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    thats a joke, right? sony live ... ^^

    their way to ensure you can not target it without buying it
     
  15. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hehe, yeah ...

    Or maybe they're trying to make you develop exclusively for their devices because developing for just one of their devices (or ... um ... is the Xperia Play already 5 devices??? ;-) ) is already so complicated that you'd rather not add the complexity of also supporting other Android devices, let alone iOS and the rest of the world ;-)

    Or maybe it's just cool among the mobile manufacturers to have as many device names under their belt as possible. I stopped counting but I'm pretty sure that by now, Nokia has many hundreds of devices and it wouldn't surprise me if they even were beyond 1,000.
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The various R800? are normal though (different continent gets different ending due to language limitation or network)
    Is the Z thingy potentially the CDMA or a China only (would make sense as they for there sometimes get different model numbers so leaks for china don't give out any information in the end as the model mentioned in PR for US / EU is different to it) version?
     
  17. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Yeah, I think the Z-thingie is for China.
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Test this code on my HTC Desire with its stick thingy:
    allowTouch and allowAccelerometer are false, allowtouch2 and allowGamepad are true -> missassumed to be an xperia play

    when combining with the code you posted on the other side, it ends on the right side, as expected due to the model check :)

    Thanks for sharing jashan
     
    Last edited: Apr 21, 2011
  19. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    That sounds like what happened on my Nexus One. It doesn't only assume it's an xperia play, it assumes it's an xperia play with keypad slid out (I hope this is correct English ... not sure, might also be "slided out", correct me if I'm wrong).
     
  20. flim

    flim

    Joined:
    Mar 22, 2008
    Posts:
    326
    Is there a complete example project available like those on Unity Resources page?
     
  21. flim

    flim

    Joined:
    Mar 22, 2008
    Posts:
    326
    When I copy the code from the page http://blogs.sonyericsson.com/wp/2011/02/28/xperiaplaytipsbyangrymobgames/

    I got error in the following portion of code
    Code (csharp):
    1. leftStickDown = (lDiff.sqrMagnitude < secondaryPadRadiusInPixels * secondaryPadRadiusInPixels);
    2. rightStickDown = (rDiff.sqrMagnitude 0.01F)
    3. {
    4. playerControllerOne.LookingDirection = rDiff;
    5. }
    Could someone advise how to fix that? Thanks in advance.
     
  22. flim

    flim

    Joined:
    Mar 22, 2008
    Posts:
    326