diff options
| author | 2011-04-22 11:37:25 -0700 | |
|---|---|---|
| committer | 2011-04-22 11:37:25 -0700 | |
| commit | b035072dcb1b36ea7e3723d910f8a429a214709d (patch) | |
| tree | aa2c36f1686614671dfe3270b140b35d59a9dcc0 | |
| parent | b440b90358bd83c753d81623c889bdd66d0c14ac (diff) | |
| parent | dacea8ce503369e7b82ff1c0e1a5a8a48863a25a (diff) | |
Merge "Start work on simulating landscape/portrait when orientation is locked."
4 files changed, 181 insertions, 61 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 980239b52983..8e839c09b1d2 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -200,8 +200,27 @@ public class Display { * @param outMetrics */ public void getMetrics(DisplayMetrics outMetrics) { - outMetrics.widthPixels = getWidth(); - outMetrics.heightPixels = getHeight(); + synchronized (mTmpPoint) { + getSize(mTmpPoint); + outMetrics.widthPixels = mTmpPoint.x; + outMetrics.heightPixels = mTmpPoint.y; + } + getNonSizeMetrics(outMetrics); + } + + /** + * Initialize a DisplayMetrics object from this display's data. + * + * @param outMetrics + * @hide + */ + public void getRealMetrics(DisplayMetrics outMetrics) { + outMetrics.widthPixels = getRealWidth(); + outMetrics.heightPixels = getRealHeight(); + getNonSizeMetrics(outMetrics); + } + + private void getNonSizeMetrics(DisplayMetrics outMetrics) { outMetrics.density = mDensity; outMetrics.densityDpi = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f); outMetrics.scaledDensity= outMetrics.density; diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 8f7bb8cc43b7..3d19380d5959 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -400,7 +400,7 @@ public interface WindowManagerPolicy { * display dimensions. */ public void setInitialDisplaySize(int width, int height); - + /** * Check permissions when adding a window. * @@ -816,6 +816,13 @@ public interface WindowManagerPolicy { boolean displayEnabled); /** + * Return the currently locked screen rotation, if any. Return + * Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, or + * Surface.ROTATION_270 if locked; return -1 if not locked. + */ + public int getLockedRotationLw(); + + /** * Called when the system is mostly done booting to determine whether * the system should go into safe mode. */ diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 65321b72cce0..a37ccc7d0a7e 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -2615,6 +2615,26 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + public int getLockedRotationLw() { + synchronized (mLock) { + if (false) { + // Not yet working. + if (mHdmiPlugged) { + return Surface.ROTATION_0; + } else if (mLidOpen == LID_OPEN) { + return mLidOpenRotation; + } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { + return mCarDockRotation; + } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { + return mDeskDockRotation; + } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { + return mUserRotation; + } + } + return -1; + } + } + private int getCurrentLandscapeRotation(int lastRotation) { // if the user has locked rotation, we ignore the sensor if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index 538e38cc4b99..8b739a43b6c7 100644 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -398,6 +398,7 @@ public class WindowManagerService extends IWindowManager.Stub int mRotation = 0; int mRequestedRotation = 0; int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + boolean mAltOrientation = false; int mLastRotationFlags; ArrayList<IRotationWatcher> mRotationWatchers = new ArrayList<IRotationWatcher>(); @@ -585,7 +586,6 @@ public class WindowManagerService extends IWindowManager.Stub } final Configuration mTempConfiguration = new Configuration(); - int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; // The frame use to limit the size of the app running in compatibility mode. Rect mCompatibleScreenFrame = new Rect(); @@ -4954,7 +4954,52 @@ public class WindowManagerService extends IWindowManager.Stub rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation, mDisplayEnabled); if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); + + int desiredRotation = rotation; + int lockedRotation = mPolicy.getLockedRotationLw(); + if (lockedRotation >= 0 && rotation != lockedRotation) { + // We are locked in a rotation but something is requesting + // a different rotation... we will either keep the locked + // rotation if it results in the same orientation, or have to + // switch into an emulated orientation mode. + + // First, we know that our rotation is actually going to be + // the locked rotation. + rotation = lockedRotation; + + // Now the difference between the desired and lockedRotation + // may mean that the orientation is different... if that is + // not the case, we can just make the desired rotation be the + // same as the new locked rotation. + switch (lockedRotation) { + case Surface.ROTATION_0: + if (rotation == Surface.ROTATION_180) { + desiredRotation = lockedRotation; + } + break; + case Surface.ROTATION_90: + if (rotation == Surface.ROTATION_270) { + desiredRotation = lockedRotation; + } + break; + case Surface.ROTATION_180: + if (rotation == Surface.ROTATION_0) { + desiredRotation = lockedRotation; + } + break; + case Surface.ROTATION_270: + if (rotation == Surface.ROTATION_90) { + desiredRotation = lockedRotation; + } + break; + } + } + changed = mDisplayEnabled && mRotation != rotation; + if (mAltOrientation != (rotation != desiredRotation)) { + changed = true; + mAltOrientation = rotation != desiredRotation; + } if (changed) { if (DEBUG_ORIENTATION) Slog.v(TAG, @@ -5000,6 +5045,7 @@ public class WindowManagerService extends IWindowManager.Stub Surface.setOrientation(0, rotation, animFlags); } } + for (int i=mWindows.size()-1; i>=0; i--) { WindowState w = mWindows.get(i); if (w.mSurface != null) { @@ -5440,8 +5486,32 @@ public class WindowManagerService extends IWindowManager.Stub // Use the effective "visual" dimensions based on current rotation final boolean rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270); - final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; - final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; + final int realdw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; + final int realdh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; + + if (mAltOrientation) { + mCurDisplayWidth = realdw; + mCurDisplayHeight = realdh; + if (realdw > realdh) { + // Turn landscape into portrait. + int maxw = (int)(realdh/1.3f); + if (maxw < realdw) { + mCurDisplayWidth = maxw; + } + } else { + // Turn portrait into landscape. + int maxh = (int)(realdw/1.3f); + if (maxh < realdh) { + mCurDisplayHeight = maxh; + } + } + } else { + mCurDisplayWidth = realdw; + mCurDisplayHeight = realdh; + } + + final int dw = mCurDisplayWidth; + final int dh = mCurDisplayHeight; int orientation = Configuration.ORIENTATION_SQUARE; if (dw < dh) { @@ -5452,66 +5522,69 @@ public class WindowManagerService extends IWindowManager.Stub config.orientation = orientation; DisplayMetrics dm = new DisplayMetrics(); - mDisplay.getMetrics(dm); + mDisplay.getRealMetrics(dm); + + // Override display width and height with what we are computing, + // to be sure they remain consistent. + dm.widthPixels = dw; + dm.heightPixels = dh; + CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); config.screenWidthDp = (int)(dm.widthPixels / dm.density); config.screenHeightDp = (int)(dm.heightPixels / dm.density); - if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { - // Note we only do this once because at this point we don't - // expect the screen to change in this way at runtime, and want - // to avoid all of this computation for every config change. - int longSize = dw; - int shortSize = dh; - if (longSize < shortSize) { - int tmp = longSize; - longSize = shortSize; - shortSize = tmp; - } - longSize = (int)(longSize/dm.density); - shortSize = (int)(shortSize/dm.density); - - // These semi-magic numbers define our compatibility modes for - // applications with different screens. These are guarantees to - // app developers about the space they can expect for a particular - // configuration. DO NOT CHANGE! - if (longSize < 470) { - // This is shorter than an HVGA normal density screen (which - // is 480 pixels on its long side). - mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL - | Configuration.SCREENLAYOUT_LONG_NO; + // Compute the screen layout size class. + int screenLayout; + int longSize = dw; + int shortSize = dh; + if (longSize < shortSize) { + int tmp = longSize; + longSize = shortSize; + shortSize = tmp; + } + longSize = (int)(longSize/dm.density); + shortSize = (int)(shortSize/dm.density); + + // These semi-magic numbers define our compatibility modes for + // applications with different screens. These are guarantees to + // app developers about the space they can expect for a particular + // configuration. DO NOT CHANGE! + if (longSize < 470) { + // This is shorter than an HVGA normal density screen (which + // is 480 pixels on its long side). + screenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL + | Configuration.SCREENLAYOUT_LONG_NO; + } else { + // What size is this screen screen? + if (longSize >= 960 && shortSize >= 720) { + // 1.5xVGA or larger screens at medium density are the point + // at which we consider it to be an extra large screen. + screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; + } else if (longSize >= 640 && shortSize >= 480) { + // VGA or larger screens at medium density are the point + // at which we consider it to be a large screen. + screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; } else { - // What size is this screen screen? - if (longSize >= 960 && shortSize >= 720) { - // 1.5xVGA or larger screens at medium density are the point - // at which we consider it to be an extra large screen. - mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; - } else if (longSize >= 640 && shortSize >= 480) { - // VGA or larger screens at medium density are the point - // at which we consider it to be a large screen. - mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; - } else { - mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; - } - - // If this screen is wider than normal HVGA, or taller - // than FWVGA, then for old apps we want to run in size - // compatibility mode. - if (shortSize > 321 || longSize > 570) { - mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; - } + screenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; + } - // Is this a long screen? - if (((longSize*3)/5) >= (shortSize-1)) { - // Anything wider than WVGA (5:3) is considering to be long. - mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; - } else { - mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; - } + // If this screen is wider than normal HVGA, or taller + // than FWVGA, then for old apps we want to run in size + // compatibility mode. + if (shortSize > 321 || longSize > 570) { + screenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; + } + + // Is this a long screen? + if (((longSize*3)/5) >= (shortSize-1)) { + // Anything wider than WVGA (5:3) is considering to be long. + screenLayout |= Configuration.SCREENLAYOUT_LONG_YES; + } else { + screenLayout |= Configuration.SCREENLAYOUT_LONG_NO; } } - config.screenLayout = mScreenLayout; + config.screenLayout = screenLayout; // Determine whether a hard keyboard is available and enabled. boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; @@ -6722,8 +6795,8 @@ public class WindowManagerService extends IWindowManager.Stub } final long currentTime = SystemClock.uptimeMillis(); - final int dw = mCurDisplayWidth = mDisplay.getRealWidth(); - final int dh = mCurDisplayHeight = mDisplay.getRealHeight(); + final int dw = mCurDisplayWidth; + final int dh = mCurDisplayHeight; int i; @@ -8709,8 +8782,9 @@ public class WindowManagerService extends IWindowManager.Stub pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); pw.print(" mRotation="); pw.print(mRotation); - pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); - pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); + pw.print(" mForcedAppOrientation="); pw.print(mForcedAppOrientation); + pw.print(" mRequestedRotation="); pw.print(mRequestedRotation); + pw.print(" mAltOrientation="); pw.println(mAltOrientation); pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags); pw.print(" mAnimationPending="); pw.print(mAnimationPending); |