am 38ed7d77: * Adjust canvas size under compatibility mode.
Merge commit '38ed7d7701514ee7127d0430e952930854608c4f'
* commit '38ed7d7701514ee7127d0430e952930854608c4f':
* Adjust canvas size under compatibility mode.
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index a87c622..e6bbf9f5 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -19,6 +19,7 @@
import android.graphics.*;
import android.os.Parcelable;
import android.os.Parcel;
+import android.util.DisplayMetrics;
import android.util.Log;
/**
@@ -133,6 +134,10 @@
@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
*/
@@ -169,7 +174,23 @@
* {@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 a814586..277b347 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;
@@ -302,6 +303,11 @@
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 48dbb77..242690b 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -42,6 +42,7 @@
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;
@@ -393,10 +394,14 @@
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;