title: SCREEN_ORIENTATION_LANDSCAPE upside down - Why?
body: <p>I am using the following code to set orientation locking per user preference:</p>
  
  <pre><code> private void doLock(boolean locked) {
       if (locked) {
         int o = getResources().getConfiguration().orientation;
         if (o == Configuration.ORIENTATION_LANDSCAPE)
           setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);       
         else if (o == Configuration.ORIENTATION_PORTRAIT)
           setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);       
       } 
       else {
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
       }
   }
  </code></pre>
  
  <p>It works, except for the case in which I am in unlocked mode (<code>SCREEN_ORIENTATION_SENSOR</code>) with the screen showing <code>LANDSCAPE</code> correctly (!), then invoke <code>doLock(true)</code> and...</p>
  
  <p>instead of the screen locking to <code>LANDSCAPE</code> in its current (correct) landscape view, it locks to an <strong>upside down</strong> landscape view. i.e. same exact but flip vertically (<code>y</code> becomes <code>-y</code>).</p>
  
  <p>Why is that and how do I approach this problem in order to fix it?</p>
  
  <p>My initial inquiry reveals that there are <a href="http://developer.android.com/reference/android/R.attr.html#screenOrientation" rel="noreferrer">quite a few</a> possibilities other than the common two (<code>portrait</code>, <code>landscape</code>), including <code>reverseLandscape</code>, but my hunch tells me that this problem may be <a href="http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html" rel="noreferrer">device-dependent</a> and so by using it I might be fixing the problem only for my phone but not for all other devices.</p>
  
  <p>Is there a way to force correct <code>landscape</code> orientation (when switched from <code>sensor</code>) in all devices?</p>
  
  <p>To make this clearer and easier to reproduce, here are the steps that exhibit the problem:</p>
  
  <ol>
  <li>Start with phone rotated to the right (<strong>clockwise</strong>), in unlocked mode (<code>SCREEN_ORIENTATION_SENSOR</code>) with the screen showing <code>LANDSCAPE</code> correctly (!), </li>
  <li>Then invoke <code>doLock(true)</code></li>
  <li>Instead of the screen locking to <code>LANDSCAPE</code> in its current (correct) landscape view, it locks to an <strong>upside down</strong> landscape view. i.e. same exact but flip vertically (<code>y</code> becomes <code>-y</code>).</li>
  </ol>