Merge "Handle data changed during FlingRunnable."
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index 0d4a067..be00aa5 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -915,6 +915,7 @@
                     com.android.internal.R.styleable.ActionBar_LayoutParams);
             gravity = a.getInt(
                     com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity, -1);
+            a.recycle();
         }
 
         public LayoutParams(int width, int height) {
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index d7f901a..4f19010 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -72,6 +72,7 @@
     static final String TAG = "Resources";
     private static final boolean DEBUG_LOAD = false;
     private static final boolean DEBUG_CONFIG = false;
+    private static final boolean DEBUG_ATTRIBUTES_CACHE = false;
     private static final boolean TRACE_FOR_PRELOAD = false;
     private static final boolean TRACE_FOR_MISS_PRELOAD = false;
 
@@ -104,6 +105,7 @@
     private boolean mPreloading;
 
     /*package*/ TypedArray mCachedStyledAttributes = null;
+    RuntimeException mLastRetrievedAttrs = null;
 
     private int mLastCachedXmlBlockIndex = -1;
     private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 };
@@ -2167,6 +2169,10 @@
             TypedArray attrs = mCachedStyledAttributes;
             if (attrs != null) {
                 mCachedStyledAttributes = null;
+                if (DEBUG_ATTRIBUTES_CACHE) {
+                    mLastRetrievedAttrs = new RuntimeException("here");
+                    mLastRetrievedAttrs.fillInStackTrace();
+                }
 
                 attrs.mLength = len;
                 int fullLen = len * AssetManager.STYLE_NUM_ENTRIES;
@@ -2177,6 +2183,15 @@
                 attrs.mIndices = new int[1+len];
                 return attrs;
             }
+            if (DEBUG_ATTRIBUTES_CACHE) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                if (mLastRetrievedAttrs != null) {
+                    Log.i(TAG, "Allocated new TypedArray of " + len + " in " + this, here);
+                    Log.i(TAG, "Last retrieved attributes here", mLastRetrievedAttrs);
+                }
+                mLastRetrievedAttrs = here;
+            }
             return new TypedArray(this,
                     new int[len*AssetManager.STYLE_NUM_ENTRIES],
                     new int[1+len], len);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 1463e09..1cc428b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -27,7 +27,6 @@
 import android.graphics.Interpolator;
 import android.graphics.LinearGradient;
 import android.graphics.Matrix;
-import android.graphics.Matrix.ScaleToFit;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
@@ -2272,8 +2271,6 @@
      */
     int mOldHeightMeasureSpec = Integer.MIN_VALUE;
 
-    private Resources mResources = null;
-
     private Drawable mBGDrawable;
 
     private int mBackgroundResource;
@@ -2336,6 +2333,8 @@
      */
     protected Context mContext;
 
+    private final Resources mResources;
+
     private ScrollabilityCache mScrollCache;
 
     private int[] mDrawableState = null;
@@ -3017,6 +3016,8 @@
             }
         }
 
+        a.recycle();
+
         setOverScrollMode(overScrollMode);
 
         if (background != null) {
@@ -3074,14 +3075,13 @@
         }
 
         computeOpaqueFlags();
-
-        a.recycle();
     }
 
     /**
      * Non-public constructor for use in testing
      */
     View() {
+        mResources = null;
     }
 
     /**
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index c1eec6f..0d57c9b 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -232,11 +232,6 @@
         setFillBefore(a.getBoolean(com.android.internal.R.styleable.Animation_fillBefore, mFillBefore));
         setFillAfter(a.getBoolean(com.android.internal.R.styleable.Animation_fillAfter, mFillAfter));
 
-        final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
-        if (resID > 0) {
-            setInterpolator(context, resID);
-        }
-
         setRepeatCount(a.getInt(com.android.internal.R.styleable.Animation_repeatCount, mRepeatCount));
         setRepeatMode(a.getInt(com.android.internal.R.styleable.Animation_repeatMode, RESTART));
 
@@ -245,10 +240,16 @@
         setBackgroundColor(a.getInt(com.android.internal.R.styleable.Animation_background, 0));
 
         setDetachWallpaper(a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
-        
-        ensureInterpolator();
+
+        final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
 
         a.recycle();
+
+        if (resID > 0) {
+            setInterpolator(context, resID);
+        }
+
+        ensureInterpolator();
     }
 
     @Override
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 77f6776..9c44138 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -643,10 +643,10 @@
 
     /**
      * Set whether the WebView will enable smooth transition while panning or
-     * zooming. If it is true, WebView will choose a solution to maximize the
-     * performance. e.g. the WebView's content may not be updated during the
-     * transition. If it is false, WebView will keep its fidelity. The default
-     * value is false.
+     * zooming or while the window hosting the WebView does not have focus.
+     * If it is true, WebView will choose a solution to maximize the performance.
+     * e.g. the WebView's content may not be updated during the transition.
+     * If it is false, WebView will keep its fidelity. The default value is false.
      */
     public void setEnableSmoothTransition(boolean enable) {
         mEnableSmoothTransition = enable;
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 47abbc2..065beb1 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -908,6 +908,9 @@
     // used for serializing asynchronously handled touch events.
     private final TouchEventQueue mTouchEventQueue = new TouchEventQueue();
 
+    // Used to track whether picture updating was paused due to a window focus change.
+    private boolean mPictureUpdatePausedForFocusChange = false;
+
     // Used to notify listeners of a new picture.
     private PictureListener mPictureListener;
     /**
@@ -5570,8 +5573,20 @@
         setActive(hasWindowFocus);
         if (hasWindowFocus) {
             JWebCoreJavaBridge.setActiveWebView(this);
+            if (mPictureUpdatePausedForFocusChange) {
+                WebViewCore.resumeUpdatePicture(mWebViewCore);
+                nativeSetIsScrolling(false);
+                mPictureUpdatePausedForFocusChange = false;
+            }
         } else {
             JWebCoreJavaBridge.removeActiveWebView(this);
+            final WebSettings settings = getSettings();
+            if (settings != null && settings.enableSmoothTransition() &&
+                    mWebViewCore != null && !WebViewCore.isUpdatePicturePaused(mWebViewCore)) {
+                WebViewCore.pauseUpdatePicture(mWebViewCore);
+                nativeSetIsScrolling(true);
+                mPictureUpdatePausedForFocusChange = true;
+            }
         }
         super.onWindowFocusChanged(hasWindowFocus);
     }
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index c61bd48..843a624 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -2107,6 +2107,10 @@
         }
     }
 
+    static boolean isUpdatePicturePaused(WebViewCore core) {
+        return core != null ? core.mDrawIsPaused : false;
+    }
+
     //////////////////////////////////////////////////////////////////////////
 
     private void restoreState(int index) {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 40d85d8..70d2bd7 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -461,10 +461,6 @@
         mMovement = getDefaultMovementMethod();
         mTransformation = null;
 
-        TypedArray a =
-            context.obtainStyledAttributes(
-                attrs, com.android.internal.R.styleable.TextView, defStyle, 0);
-
         int textColorHighlight = 0;
         ColorStateList textColor = null;
         ColorStateList textColorHint = null;
@@ -474,18 +470,23 @@
         int styleIndex = -1;
         boolean allCaps = false;
 
+        final Resources.Theme theme = context.getTheme();
+
         /*
          * Look the appearance up without checking first if it exists because
          * almost every TextView has one and it greatly simplifies the logic
          * to be able to parse the appearance first and then let specific tags
          * for this View override it.
          */
+        TypedArray a = theme.obtainStyledAttributes(
+                    attrs, com.android.internal.R.styleable.TextViewAppearance, defStyle, 0);
         TypedArray appearance = null;
-        int ap = a.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
+        int ap = a.getResourceId(
+                com.android.internal.R.styleable.TextViewAppearance_textAppearance, -1);
+        a.recycle();
         if (ap != -1) {
-            appearance = context.obtainStyledAttributes(ap,
-                                com.android.internal.R.styleable.
-                                TextAppearance);
+            appearance = theme.obtainStyledAttributes(
+                    ap, com.android.internal.R.styleable.TextAppearance);
         }
         if (appearance != null) {
             int n = appearance.getIndexCount();
@@ -552,6 +553,9 @@
         boolean password = false;
         int inputType = EditorInfo.TYPE_NULL;
 
+        a = theme.obtainStyledAttributes(
+                    attrs, com.android.internal.R.styleable.TextView, defStyle, 0);
+
         int n = a.getIndexCount();
         for (int i = 0; i < n; i++) {
             int attr = a.getIndex(i);
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index fc84f53..c990125 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3177,6 +3177,10 @@
         <!-- Present the text in ALL CAPS. This may use a small-caps form when available. -->
         <attr name="textAllCaps" />
     </declare-styleable>
+    <declare-styleable name="TextViewAppearance">
+        <!-- Base text color, typeface, size, and style. -->
+        <attr name="textAppearance" />
+    </declare-styleable>
     <declare-styleable name="SuggestionSpan">
         <attr name="textUnderlineColor" />
         <attr name="textUnderlineThickness" />