Reputation: 45
Question is related to rotation of the android emulator screen.
I am using DefaultDisplay.getRotation()
to get the rotation angle on the emulator. It returns 0 and 90 only. Even in reverse portrait and reverse landscape. Have not set any specific Screen orientation in the activity XML file. I am a beginner at this so am probably missing something here and could use some help understanding what that might be.
Thanks.
Upvotes: 2
Views: 1543
Reputation: 13520
If you just want to portrait/reverse portrait and landscape/reverse landscape you can use
if (Utils.getDeviceDefaultOrientation(localActivity) == Configuration.ORIENTATION_LANDSCAPE)
{
if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0)
//Landscape Mode
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90)
//Portrait Mode
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_180)
//Reverse Landscape
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270)
//Reverse Portrait
}
else
{
if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0)
//Portrait Mode
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90)
//Landscape Mode
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_180)
//Reverse Portrait Mode
else if (getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270)
//Reverse Landscape Mode
}
We have to check for getDeviceDefaultOrientation
because for tablets the default device orientation is Landscape and it will return getRotation()
0 in that case
Upvotes: 0
Reputation: 24853
Try this..
int rotation = getWindowManager().getDefaultDisplay().getRotation();
Log.v("rotation--", ""+rotation);
switch (rotation) {
case 0:
Toast.makeText(getBaseContext(), "Angle 0", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getBaseContext(), "Angle 90", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getBaseContext(), "Angle 180", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(getBaseContext(), "Angle 270", Toast.LENGTH_SHORT).show();
break;
}
Upvotes: 1
Reputation: 3824
First of all getRotation
method doesn't work in emulator screen. Because according to your thread you can see you are getting only two angles i.e. "0" and "90" because of landscape and potrait mode. So just test it in any real device.
Upvotes: 0