1

My android application uses the Y Axis accelerometer to control the character in the game.

This is working fine on most mobile phones, however on my Galaxy Tab 2 10.1, the axis seems to be reversed and I have to manualy change the input for it work.

I would like to write a simple conditional statement that would swap based on device type, however I am unsure what the best practice for this would be. As I am sure someone would have come accross this issue before I ask the question.

How can I determine if the device is a table or a mobile in order to change Accelerometer axis?

Rhys
  • 2,807
  • 8
  • 46
  • 68
  • Never used android before so I don't know if this would be a viable solution, but what you could do is have a small "setup" before the user starts playing. By setup I just mean have the user tilt their device right/left/forward/back so that you can bind each tilt direction/axis to the correct in-game direction/axis. – Supericy May 18 '13 at 07:02
  • Hi, Thanks for the suggestions. But, I would like to avoid the user have to do this is possible. I was hoping there was a way to check axis configuration and the set based on that. – Rhys May 18 '13 at 07:05

2 Answers2

3

I think this relates to the default orientation of the device, which tends to be portrait for phones, or landscape for tablets. There's a question here about exactly that: How to check device natural (default) orientation on Android (i.e. get landscape for e.g., Motorola Charm or Flipout) , and based on my experiences I'd say that this is the best answer . An important point to understand is that whatever the display is doing (landscape, portrait, etc), the x-y-z axes used by the sensors don't change.

Community
  • 1
  • 1
Stochastically
  • 7,616
  • 5
  • 30
  • 58
0

I found out the best way to do this is to check the screen size on the device and base a boolean conditional to device on which axis to use. This is tested and working great.

// Check the screen layout to determine if the device is a tablet.

public boolean isTablet(Context context) {
    boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
    boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    return (xlarge || large);
}

// Changle Accelx or Accely input based on the above (Im using OpenGLES 1.1)

if (isTablet(glGame)) {
    world.update(deltaTime, game.getInput().getAccelX());
}
if (!isTablet(glGame)) {
    world.update(deltaTime, game.getInput().getAccelY());
}
Rhys
  • 2,807
  • 8
  • 46
  • 68