Merge change 8098 into donut

* changes:
  cast is floor. Use round instead.  This fixes a few layout issues (that was due to smaller widnow size)
This commit is contained in:
Android (Google) Code Review
2009-07-21 17:39:05 -07:00
6 changed files with 29 additions and 23 deletions

View File

@ -342,8 +342,8 @@ public class CompatibilityInfo {
public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation, public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation,
Rect outRect) { Rect outRect) {
int width = dm.widthPixels; int width = dm.widthPixels;
int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density); int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density + 0.5f);
int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density); int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density + 0.5f);
if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
int xOffset = (width - portraitHeight) / 2 ; int xOffset = (width - portraitHeight) / 2 ;
outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth); outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth);

View File

@ -136,15 +136,19 @@ public class DisplayMetrics {
int defaultHeight; int defaultHeight;
switch (orientation) { switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE: { case Configuration.ORIENTATION_LANDSCAPE: {
defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density); defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density); 0.5f);
defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
0.5f);
break; break;
} }
case Configuration.ORIENTATION_PORTRAIT: case Configuration.ORIENTATION_PORTRAIT:
case Configuration.ORIENTATION_SQUARE: case Configuration.ORIENTATION_SQUARE:
default: { default: {
defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density); defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density); 0.5f);
defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
0.5f);
break; break;
} }
case Configuration.ORIENTATION_UNDEFINED: { case Configuration.ORIENTATION_UNDEFINED: {
@ -172,8 +176,8 @@ public class DisplayMetrics {
scaledDensity *= invertedRatio; scaledDensity *= invertedRatio;
xdpi *= invertedRatio; xdpi *= invertedRatio;
ydpi *= invertedRatio; ydpi *= invertedRatio;
widthPixels *= invertedRatio; widthPixels = (int) (widthPixels * invertedRatio + 0.5f);
heightPixels *= invertedRatio; heightPixels = (int) (heightPixels * invertedRatio + 0.5f);
} }
} }

View File

@ -309,8 +309,8 @@ public class SurfaceView extends View {
// Use original size if the app specified the size of the view, // Use original size if the app specified the size of the view,
// and let the flinger to scale up. // and let the flinger to scale up.
if (mRequestedWidth <= 0 && mTranslator != null) { if (mRequestedWidth <= 0 && mTranslator != null) {
myWidth *= appScale; myWidth = (int) (myWidth * appScale + 0.5f);
myHeight *= appScale; myHeight = (int) (myHeight * appScale + 0.5f);
mScaled = true; mScaled = true;
} else { } else {
mScaled = false; mScaled = false;

View File

@ -907,7 +907,8 @@ public final class ViewRoot extends Handler implements ViewParent,
mHeight = frame.height(); mHeight = frame.height();
if (initialized) { if (initialized) {
mGlCanvas.setViewport((int) (mWidth * appScale), (int) (mHeight * appScale)); mGlCanvas.setViewport((int) (mWidth * appScale + 0.5f),
(int) (mHeight * appScale + 0.5f));
} }
boolean focusChangedDueToTouchMode = ensureTouchModeLocally( boolean focusChangedDueToTouchMode = ensureTouchModeLocally(
@ -1237,7 +1238,7 @@ public final class ViewRoot extends Handler implements ViewParent,
if (fullRedrawNeeded) { if (fullRedrawNeeded) {
mAttachInfo.mIgnoreDirtyState = true; mAttachInfo.mIgnoreDirtyState = true;
dirty.union(0, 0, (int) (mWidth * appScale), (int) (mHeight * appScale)); dirty.union(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f));
} }
if (DEBUG_ORIENTATION || DEBUG_DRAW) { if (DEBUG_ORIENTATION || DEBUG_DRAW) {
@ -1749,7 +1750,8 @@ public final class ViewRoot extends Handler implements ViewParent,
if (mGlCanvas != null) { if (mGlCanvas != null) {
float appScale = mAttachInfo.mApplicationScale; float appScale = mAttachInfo.mApplicationScale;
mGlCanvas.setViewport( mGlCanvas.setViewport(
(int) (mWidth * appScale), (int) (mHeight * appScale)); (int) (mWidth * appScale + 0.5f),
(int) (mHeight * appScale + 0.5f));
} }
} }
} }
@ -2394,8 +2396,8 @@ public final class ViewRoot extends Handler implements ViewParent,
} }
int relayoutResult = sWindowSession.relayout( int relayoutResult = sWindowSession.relayout(
mWindow, params, mWindow, params,
(int) (mView.mMeasuredWidth * appScale), (int) (mView.mMeasuredWidth * appScale + 0.5f),
(int) (mView.mMeasuredHeight * appScale), (int) (mView.mMeasuredHeight * appScale + 0.5f),
viewVisibility, insetsPending, mWinFrame, viewVisibility, insetsPending, mWinFrame,
mPendingContentInsets, mPendingVisibleInsets, mSurface); mPendingContentInsets, mPendingVisibleInsets, mSurface);
if (restore) { if (restore) {

View File

@ -991,13 +991,13 @@ public interface WindowManager extends ViewManager {
* @hide * @hide
*/ */
public void scale(float scale) { public void scale(float scale) {
x *= scale; x = (int) (x * scale + 0.5f);
y *= scale; y = (int) (y * scale + 0.5f);
if (width > 0) { if (width > 0) {
width *= scale; width = (int) (width * scale + 0.5f);
} }
if (height > 0) { if (height > 0) {
height *= scale; height = (int) (height * scale + 0.5f);
} }
} }

View File

@ -552,10 +552,10 @@ public final class Rect implements Parcelable {
*/ */
public void scale(float scale) { public void scale(float scale) {
if (scale != 1.0f) { if (scale != 1.0f) {
left *= scale; left = (int) (left * scale + 0.5f);
top *= scale; top = (int) (top * scale + 0.5f);
right *= scale; right = (int) (right * scale + 0.5f);
bottom*= scale; bottom = (int) (bottom * scale + 0.5f);
} }
} }
} }