diff options
author | Mitsuru Oshima <oshima@google.com> | 2009-07-21 14:39:34 -0700 |
---|---|---|
committer | Mitsuru Oshima <oshima@google.com> | 2009-07-21 17:41:16 -0700 |
commit | 38ed7d7701514ee7127d0430e952930854608c4f (patch) | |
tree | 6ead3e12bd2d4590db80a68ef65407495127d4a6 /core | |
parent | fe6f45c81463d2d28e11ac6083f2653e1286c5ef (diff) | |
download | frameworks_base-38ed7d7701514ee7127d0430e952930854608c4f.zip frameworks_base-38ed7d7701514ee7127d0430e952930854608c4f.tar.gz frameworks_base-38ed7d7701514ee7127d0430e952930854608c4f.tar.bz2 |
* Adjust canvas size under compatibility mode.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/Surface.java | 23 | ||||
-rw-r--r-- | core/java/android/view/SurfaceView.java | 6 | ||||
-rw-r--r-- | core/java/android/view/ViewRoot.java | 11 |
3 files changed, 36 insertions, 4 deletions
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 0178d63..83c30e1 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -19,6 +19,7 @@ package android.view; import android.graphics.*; import android.os.Parcelable; import android.os.Parcel; +import android.util.DisplayMetrics; import android.util.Log; /** @@ -131,6 +132,10 @@ public class Surface implements Parcelable { @SuppressWarnings("unused") private Canvas mCanvas; + // The display metrics used to provide the pseudo canvas size for applications + // running in compatibility mode. This is set to null for regular mode. + private DisplayMetrics mDisplayMetrics; + /** * Exception thrown when a surface couldn't be created or resized */ @@ -167,7 +172,23 @@ public class Surface implements Parcelable { * {@hide} */ public Surface() { - mCanvas = new Canvas(); + mCanvas = new Canvas() { + @Override + public int getWidth() { + return mDisplayMetrics == null ? super.getWidth() : mDisplayMetrics.widthPixels; + } + @Override + public int getHeight() { + return mDisplayMetrics == null ? super.getHeight() : mDisplayMetrics.heightPixels; + } + }; + } + + /** + * Sets the display metrics used to provide canva's width/height in comaptibility mode. + */ + void setCompatibleDisplayMetrics(DisplayMetrics metrics) { + mDisplayMetrics = metrics; } /** diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index fdc0c16..95bba97 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -17,6 +17,7 @@ package android.view; import android.content.Context; +import android.content.res.Resources; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.PixelFormat; @@ -301,6 +302,11 @@ public class SurfaceView extends View { float appScale = mTranslator == null ? 1.0f : mTranslator.applicationScale; + Resources res = getContext().getResources(); + if (mTranslator != null || !res.getCompatibilityInfo().supportsScreen()) { + mSurface.setCompatibleDisplayMetrics(res.getDisplayMetrics()); + } + int myWidth = mRequestedWidth; if (myWidth <= 0) myWidth = getWidth(); int myHeight = mRequestedHeight; diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index 049b44f..2f92b32 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -42,6 +42,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.Scroller; import android.content.pm.PackageManager; import android.content.res.CompatibilityInfo; +import android.content.res.Resources; import android.content.Context; import android.app.ActivityManagerNative; import android.Manifest; @@ -386,10 +387,14 @@ public final class ViewRoot extends Handler implements ViewParent, mView = view; mWindowAttributes.copyFrom(attrs); attrs = mWindowAttributes; - - CompatibilityInfo compatibilityInfo = - mView.getContext().getResources().getCompatibilityInfo(); + Resources resources = mView.getContext().getResources(); + CompatibilityInfo compatibilityInfo = resources.getCompatibilityInfo(); mTranslator = compatibilityInfo.getTranslator(attrs); + + if (mTranslator != null || !compatibilityInfo.supportsScreen()) { + mSurface.setCompatibleDisplayMetrics(resources.getDisplayMetrics()); + } + boolean restore = false; if (attrs != null && mTranslator != null) { restore = true; |