Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>after some investigation I have found a solution:</p> <p>Tablets have LANDSCAPE as default orientation, so screen rotation is 0 or 180 when the orientation is LANDSCAPE, and smartphones have PORTRAIT. I use the next code to difference between tablets and smartphones:</p> <pre><code>Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int orientation = getScreenOrientation(display); int rotation = display.getRotation(); remapCoordinates = (orientation == Configuration.ORIENTATION_LANDSCAPE &amp;&amp; rotation == Surface.ROTATION_0) || (orientation == Configuration.ORIENTATION_LANDSCAPE &amp;&amp; rotation == Surface.ROTATION_180) || (orientation == Configuration.ORIENTATION_PORTRAIT &amp;&amp; rotation == Surface.ROTATION_90) || (orientation == Configuration.ORIENTATION_PORTRAIT &amp;&amp; rotation == Surface.ROTATION_270); </code></pre> <p>where getScreenOrientation method is:</p> <pre><code>public static int getScreenOrientation(Display display){ int orientation; if(display.getWidth()==display.getHeight()){ orientation = Configuration.ORIENTATION_SQUARE; }else{ //if widht is less than height than it is portrait if(display.getWidth() &lt; display.getHeight()){ orientation = Configuration.ORIENTATION_PORTRAIT; }else{ // if it is not any of the above it will defineitly be landscape orientation = Configuration.ORIENTATION_LANDSCAPE; } } return orientation; } </code></pre> <p>Now, I remap the coordinates as before only when the default orientation is LANDSCAPE:</p> <pre><code>if( remapCoordinates){ android.hardware.SensorManager.remapCoordinateSystem(newm, android.hardware.SensorManager.AXIS_MINUS_Y, android.hardware.SensorManager.AXIS_X, newm); } </code></pre> <p>Best regards.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload