OSDN Git Service

Disable extracting the bg color from the window background.
authorWinson <winsonc@google.com>
Tue, 1 Mar 2016 00:04:40 +0000 (16:04 -0800)
committerWinson <winsonc@google.com>
Tue, 1 Mar 2016 00:09:18 +0000 (16:09 -0800)
Bug: 27406401
Change-Id: Id03a7d5d199d324d67301c060551db2d3a52e5ac

core/java/android/app/Activity.java
core/res/res/values/attrs.xml

index 4792dc9..90d5d59 100644 (file)
@@ -1119,34 +1119,6 @@ public class Activity extends ContextThemeWrapper
     }
 
     /**
-     * Attempts to extract the color from a given drawable.
-     *
-     * @return the extracted color or 0 if no color could be extracted.
-     */
-    private int tryExtractColorFromDrawable(Drawable drawable) {
-        if (drawable instanceof ColorDrawable) {
-            return ((ColorDrawable) drawable).getColor();
-        } else if (drawable instanceof InsetDrawable) {
-            return tryExtractColorFromDrawable(((InsetDrawable) drawable).getDrawable());
-        } else if (drawable instanceof ShapeDrawable) {
-            Paint p = ((ShapeDrawable) drawable).getPaint();
-            if (p != null) {
-                return p.getColor();
-            }
-        } else if (drawable instanceof LayerDrawable) {
-            LayerDrawable ld = (LayerDrawable) drawable;
-            int numLayers = ld.getNumberOfLayers();
-            for (int i = 0; i < numLayers; i++) {
-                int color = tryExtractColorFromDrawable(ld.getDrawable(i));
-                if (color != 0) {
-                    return color;
-                }
-            }
-        }
-        return 0;
-    }
-
-    /**
      * Called when activity start-up is complete (after {@link #onStart}
      * and {@link #onRestoreInstanceState} have been called).  Applications will
      * generally not implement this method; it is intended for system
@@ -1168,35 +1140,6 @@ public class Activity extends ContextThemeWrapper
             onTitleChanged(getTitle(), getTitleColor());
         }
 
-        Resources.Theme theme = getTheme();
-        if (theme != null) {
-            // Get the primary color and update the TaskDescription for this activity
-            TypedArray a = theme.obtainStyledAttributes(
-                    com.android.internal.R.styleable.ActivityTaskDescription);
-            if (mTaskDescription.getPrimaryColor() == 0) {
-                int colorPrimary = a.getColor(
-                        com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0);
-                if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) {
-                    mTaskDescription.setPrimaryColor(colorPrimary);
-                }
-            }
-            if (mTaskDescription.getBackgroundColor() == 0) {
-                int windowBgResourceId = a.getResourceId(
-                        com.android.internal.R.styleable.ActivityTaskDescription_windowBackground,
-                        0);
-                int windowBgFallbackResourceId = a.getResourceId(
-                        com.android.internal.R.styleable.ActivityTaskDescription_windowBackgroundFallback,
-                        0);
-                int colorBg = tryExtractColorFromDrawable(DecorView.getResizingBackgroundDrawable(
-                        this, windowBgResourceId, windowBgFallbackResourceId));
-                if (colorBg != 0 && Color.alpha(colorBg) == 0xFF) {
-                    mTaskDescription.setBackgroundColor(colorBg);
-                }
-            }
-            a.recycle();
-            setTaskDescription(mTaskDescription);
-        }
-
         mCalled = true;
     }
 
@@ -4036,6 +3979,27 @@ public class Activity extends ContextThemeWrapper
             }
             theme.applyStyle(resid, false);
         }
+
+        // Get the primary color and update the TaskDescription for this activity
+        TypedArray a = theme.obtainStyledAttributes(
+                com.android.internal.R.styleable.ActivityTaskDescription);
+        if (mTaskDescription.getPrimaryColor() == 0) {
+            int colorPrimary = a.getColor(
+                    com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0);
+            if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) {
+                mTaskDescription.setPrimaryColor(colorPrimary);
+            }
+        }
+        // For dev-preview only.
+        if (mTaskDescription.getBackgroundColor() == 0) {
+            int colorBackground = a.getColor(
+                    com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0);
+            if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) {
+                mTaskDescription.setBackgroundColor(colorBackground);
+            }
+        }
+        a.recycle();
+        setTaskDescription(mTaskDescription);
     }
 
     /**
index 7c02128..90a573b 100644 (file)
@@ -8189,11 +8189,8 @@ i
         <!-- @hide From Theme.colorPrimary, used for the TaskDescription primary 
                    color. -->
         <attr name="colorPrimary" />
-        <!-- @hide From Theme.windowBackground, used for calculating the 
-                   TaskDescription background color. -->
-        <attr name="windowBackground" />
-        <!-- @hide From Theme.windowBackgroundFallback, used for calculating the 
-                   TaskDescription background color. -->
-        <attr name="windowBackgroundFallback" />
+        <!-- @hide From Theme.colorBackground, used for the TaskDescription background 
+                   color. -->
+        <attr name="colorBackground" />
     </declare-styleable>
 </resources>