From 8506ab4ac062d0e1ccde136e5e2f4081560e0c11 Mon Sep 17 00:00:00 2001
From: Romain Guy
Date: Thu, 11 Jun 2009 17:35:47 -0700
Subject: [PATCH] Fixes #1886237. Views drawing cache was not generated
properly.
In compatibility mode, a View's drawing cache was created at the 160 density
scale instead of the right scale.
---
core/java/android/view/View.java | 103 ++++++++++-------
core/java/android/view/ViewGroup.java | 66 ++++++-----
core/java/android/view/ViewRoot.java | 156 +++++++++++++-------------
3 files changed, 181 insertions(+), 144 deletions(-)
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index bcb97edbcdf60..0497344f9ad7e 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -75,17 +75,17 @@ import java.util.WeakHashMap;
* This class represents the basic building block for user interface components. A View
* occupies a rectangular area on the screen and is responsible for drawing and
* event handling. View is the base class for widgets, which are
- * used to create interactive UI components (buttons, text fields, etc.). The
+ * used to create interactive UI components (buttons, text fields, etc.). The
* {@link android.view.ViewGroup} subclass is the base class for layouts, which
* are invisible containers that hold other Views (or other ViewGroups) and define
* their layout properties.
*
*
*
- *
For an introduction to using this class to develop your
- * application's user interface, read the Developer Guide documentation on
+ *
- * Note that the framework will not draw views that are not in the invalid region.
+ * Note that the framework will not draw views that are not in the invalid region.
*
*
*
@@ -1830,7 +1830,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
int viewFlagMasks = 0;
boolean setScrollContainer = false;
-
+
int x = 0;
int y = 0;
@@ -2464,7 +2464,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (!(parent instanceof View)) {
break;
}
-
+
child = (View) parent;
parent = child.getParent();
}
@@ -2556,7 +2556,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* and previouslyFocusedRect provide insight into where the focus is coming from.
* When overriding, be sure to call up through to the super class so that
* the standard focus handling will occur.
- *
+ *
* @param gainFocus True if the View has focus; false otherwise.
* @param direction The direction focus has moved when requestFocus()
* is called to give this view focus. Values are
@@ -2587,7 +2587,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
&& mAttachInfo.mHasWindowFocus) {
imm.focusIn(this);
}
-
+
invalidate();
if (mOnFocusChangeListener != null) {
mOnFocusChangeListener.onFocusChange(this, gainFocus);
@@ -2676,7 +2676,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* Subclasses of View overriding this method should always call super.onFocusLost().
*
* @see #onFocusChanged(boolean, int, android.graphics.Rect)
- * @see #onWindowFocusChanged(boolean)
+ * @see #onWindowFocusChanged(boolean)
*
* @hide pending API council approval
*/
@@ -3578,14 +3578,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
*/
public void onStartTemporaryDetach() {
}
-
+
/**
* Called after {@link #onStartTemporaryDetach} when the container is done
* changing the view.
*/
public void onFinishTemporaryDetach() {
}
-
+
/**
* capture information of this view for later analysis: developement only
* check dynamic switch to make sure we only dump view
@@ -3970,25 +3970,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* a call on that method would return a non-null InputConnection, and
* they are really a first-class editor that the user would normally
* start typing on when the go into a window containing your view.
- *
+ *
*
The default implementation always returns false. This does
* not mean that its {@link #onCreateInputConnection(EditorInfo)}
* will not be called or the user can not otherwise perform edits on your
* view; it is just a hint to the system that this is not the primary
* purpose of this view.
- *
+ *
* @return Returns true if this view is a text editor, else false.
*/
public boolean onCheckIsTextEditor() {
return false;
}
-
+
/**
* Create a new InputConnection for an InputMethod to interact
* with the view. The default implementation returns null, since it doesn't
* support input methods. You can override this to implement such support.
* This is only needed for views that take focus and text input.
- *
+ *
*
When implementing this, you probably also want to implement
* {@link #onCheckIsTextEditor()} to indicate you will return a
* non-null InputConnection.
@@ -4012,7 +4012,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
public boolean checkInputConnectionProxy(View view) {
return false;
}
-
+
/**
* Show the context menu for this view. It is not safe to hold on to the
* menu after returning from this method.
@@ -4743,7 +4743,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* whether an instance is opaque. Opaque Views are treated in a special way by
* the View hierarchy, possibly allowing it to perform optimizations during
* invalidate/draw passes.
- *
+ *
* @return True if this View is guaranteed to be fully opaque, false otherwise.
*
* @hide Pending API council approval
@@ -5343,9 +5343,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
}
}
}
-
+
/**
- * Override this if the vertical scrollbar needs to be hidden in a subclass, like when
+ * Override this if the vertical scrollbar needs to be hidden in a subclass, like when
* FastScroller is visible.
* @return whether to temporarily hide the vertical scrollbar
* @hide
@@ -5868,8 +5868,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
EventLog.writeEvent(60002, hashCode());
}
- final int width = mRight - mLeft;
- final int height = mBottom - mTop;
+ int width = mRight - mLeft;
+ int height = mBottom - mTop;
+
+ final AttachInfo attachInfo = mAttachInfo;
+ if (attachInfo != null) {
+ final boolean scalingRequired = attachInfo.mScalingRequired;
+ if (scalingRequired) {
+ width = (int) ((width * attachInfo.mApplicationScale) + 0.5f);
+ height = (int) ((height * attachInfo.mApplicationScale) + 0.5f);
+ }
+ }
final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor;
final boolean opaque = drawingCacheBackgroundColor != 0 ||
@@ -5925,11 +5934,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
}
Canvas canvas;
- final AttachInfo attachInfo = mAttachInfo;
if (attachInfo != null) {
canvas = attachInfo.mCanvas;
if (canvas == null) {
canvas = new Canvas();
+
+ // NOTE: This should have to happen only once since compatibility
+ // mode should not change at runtime
+ if (attachInfo.mScalingRequired) {
+ final float scale = attachInfo.mApplicationScale;
+ canvas.scale(scale, scale);
+ }
}
canvas.setBitmap(bitmap);
// Temporarily clobber the cached Canvas in case one of our children
@@ -6031,7 +6046,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
// Restore the cached Canvas for our siblings
attachInfo.mCanvas = canvas;
}
-
+
return bitmap;
}
@@ -6971,7 +6986,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
mUserPaddingBottom = bottom;
final int viewFlags = mViewFlags;
-
+
// Common case is there are no scroll bars.
if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) {
// TODO: Deal with RTL languages to adjust left padding instead of right.
@@ -6984,7 +6999,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
? 0 : getHorizontalScrollbarHeight();
}
}
-
+
if (mPaddingLeft != left) {
changed = true;
mPaddingLeft = left;
@@ -7121,7 +7136,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
return v;
}
}
-
+
View parent = this;
while (parent.mParent != null && parent.mParent instanceof View) {
@@ -7169,7 +7184,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
location[1] += view.mTop - view.mScrollY;
viewParent = view.mParent;
}
-
+
if (viewParent instanceof ViewRoot) {
// *cough*
final ViewRoot vr = (ViewRoot)viewParent;
@@ -7320,7 +7335,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @return the Object stored in this view as a tag
*
* @see #setTag(int, Object)
- * @see #getTag()
+ * @see #getTag()
*/
public Object getTag(int key) {
SparseArray