Bug 840346: Cleanup persona methods. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 13 Feb 2013 08:50:57 -0800
changeset 121762 eb2e980741b7b09208a0189ba454f2fb53c46444
parent 121761 700ef0823d91b3e8163bc7d7496cb01bc97bbd84
child 121763 2813cfcfd1c168f4bb5baf0224be4ad8f3dad638
push id24307
push useremorley@mozilla.com
push dateThu, 14 Feb 2013 10:47:46 +0000
treeherdermozilla-central@aceeea086ccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs840346
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 840346: Cleanup persona methods. [r=mfinkle]
mobile/android/base/LightweightTheme.java
mobile/android/base/LightweightThemeDrawable.java
mobile/android/base/TabsButton.java
mobile/android/base/TabsPanel.java
--- a/mobile/android/base/LightweightTheme.java
+++ b/mobile/android/base/LightweightTheme.java
@@ -260,70 +260,50 @@ public class LightweightTheme implements
 
         BitmapDrawable drawable = new BitmapDrawable(view.getContext().getResources(), bitmap);
         drawable.setGravity(Gravity.TOP|Gravity.RIGHT);
         drawable.setTileModeXY(Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
         return drawable;
     }
 
     /**
-     * Converts the cropped bitmap to a LightweightThemeDrawable, with the required texture.
-     * The texture can either be an actual texture to be repeated or a bitmap-drawable that 
-     * specifies how to repeat it.
-     *
-     * @param view The view for which a background drawable is required.
-     * @param textureId The resource id of the texture.
-     * @return Either the cropped bitmap as a Drawable or null.
-     */
-    public LightweightThemeDrawable getTextureDrawable(View view, int textureId) {
-        return getTextureDrawable(view, textureId, false);
-    }
-
-    /**
-     * Converts the cropped bitmap to a LightweightThemeDrawable, with the required texture.
-     * The texture can either be an actual texture to be repeated or a bitmap-drawable that 
-     * specifies how to repeat it. The dominant color can be drawn over the texture, if specified.
-     *
-     * @param view The view for which a background drawable is required.
-     * @param textureId The resource id of the texture.
-     * @param needsColor A layer of dominant color is needed or not.
-     * @return Either the cropped bitmap as a Drawable or null.
-     */
-    public LightweightThemeDrawable getTextureDrawable(View view, int textureId, boolean needsColor) {
-        Bitmap bitmap = getCroppedBitmap(view);
-        if (bitmap == null)
-            return null;
-
-        LightweightThemeDrawable drawable = new LightweightThemeDrawable(view.getContext().getResources(), bitmap);
-        drawable.setTexture(textureId);
-
-        if (needsColor)
-            drawable.setColor(mColor & 0x22FFFFFF);
-
-        return drawable;
-    }
-
-    /**
      * Converts the cropped bitmap to a LightweightThemeDrawable, placing it over the dominant color.
      *
      * @param view The view for which a background drawable is required.
      * @return Either the cropped bitmap as a Drawable or null.
      */
      public LightweightThemeDrawable getColorDrawable(View view) {
-         return getColorDrawable(view, mColor);
+         return getColorDrawable(view, mColor, false);
      }
 
     /**
      * Converts the cropped bitmap to a LightweightThemeDrawable, placing it over the required color.
      *
      * @param view The view for which a background drawable is required.
+     * @param color The color over which the drawable should be drawn.
      * @return Either the cropped bitmap as a Drawable or null.
      */
     public LightweightThemeDrawable getColorDrawable(View view, int color) {
+        return getColorDrawable(view, color, false);
+    }
+
+    /**
+     * Converts the cropped bitmap to a LightweightThemeDrawable, placing it over the required color.
+     *
+     * @param view The view for which a background drawable is required.
+     * @param color The color over which the drawable should be drawn.
+     * @param needsDominantColor A layer of dominant color is needed or not.
+     * @return Either the cropped bitmap as a Drawable or null.
+     */
+    public LightweightThemeDrawable getColorDrawable(View view, int color, boolean needsDominantColor) {
         Bitmap bitmap = getCroppedBitmap(view);
         if (bitmap == null)
             return null;
 
         LightweightThemeDrawable drawable = new LightweightThemeDrawable(view.getContext().getResources(), bitmap);
-        drawable.setColor(color);
+        if (needsDominantColor)
+            drawable.setColorWithFilter(color, (mColor & 0x22FFFFFF));
+        else
+            drawable.setColor(color);
+
         return drawable;
     }
 }
--- a/mobile/android/base/LightweightThemeDrawable.java
+++ b/mobile/android/base/LightweightThemeDrawable.java
@@ -11,31 +11,30 @@ import android.graphics.BitmapFactory;
 import android.graphics.BitmapShader;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.ComposeShader;
 import android.graphics.LinearGradient;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
 import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
 import android.graphics.Shader;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 
 /**
- * A special drawable used with lightweight themes. This draws a texture,
- * a color (usually with an alpha value) and a bitmap (with a linear gradient
- * to specify the alpha) in order. The bitmap is drawn either over a texture 
- * or over a color and rarely over both.
+ * A special drawable used with lightweight themes. This draws a color 
+ * (with an optional color-filter) and a bitmap (with a linear gradient 
+ * to specify the alpha) in order.
  */
 public class LightweightThemeDrawable extends Drawable {
     private Paint mPaint;
     private Paint mColorPaint;
-    private Paint mTexturePaint;
 
     private Bitmap mBitmap;
     private Resources mResources;
 
     private int mStartColor;
     private int mEndColor;
 
     public LightweightThemeDrawable(Resources resources, Bitmap bitmap) {
@@ -50,21 +49,17 @@ public class LightweightThemeDrawable ex
     @Override
     protected void onBoundsChange(Rect bounds) {
         super.onBoundsChange(bounds);
         initializeBitmapShader();
     }
 
     @Override
     public void draw(Canvas canvas) {
-	// Draw the texture, if available.
-        if (mTexturePaint != null)
-            canvas.drawPaint(mTexturePaint);
-
-        // Draw the color, if available.
+        // Draw the colors, if available.
         if (mColorPaint != null)
             canvas.drawPaint(mColorPaint);
 
         // Draw the bitmap.
         canvas.drawPaint(mPaint);
     }
 
     @Override
@@ -80,39 +75,38 @@ public class LightweightThemeDrawable ex
     }
 
     @Override
     public void setColorFilter(ColorFilter filter) {
         mPaint.setColorFilter(filter);
     }		
 
     /**
-     * Creates a shader based on a texture. The texture could be a resource in 
-     * drawable-nodpi/ folder. In which case, the tile modes are set to repeat.
-     * The texture could be a BitmapDrawable which could specify the tile mode 
-     * in each direction. In that case, the intrinsic tile mode values are used.
-     *
-     * @param textureId The resource if of the texture.
-     */
-    public void setTexture(int textureId) {
-        mTexturePaint = new Paint(mPaint);
-        mTexturePaint.setColor(mResources.getColor(textureId));
-    }
-
-    /**
      * Creates a paint that paint a particular color.
      *
      * @param color The color to be painted.
      */
     public void setColor(int color) {
         mColorPaint = new Paint(mPaint);
         mColorPaint.setColor(color);
     }
 
     /**
+     * Creates a paint that paint a particular color, and a filter for the color.
+     *
+     * @param color The color to be painted.
+     * @param filter The filter color to be applied using SRC_OVER mode.
+     */
+    public void setColorWithFilter(int color, int filter) {
+        mColorPaint = new Paint(mPaint);
+        mColorPaint.setColor(color);
+        mColorPaint.setColorFilter(new PorterDuffColorFilter(filter, PorterDuff.Mode.SRC_OVER));
+    }
+
+    /**
      * Set the alpha for the linear gradient used with the bitmap's shader.
      *
      * @param startAlpha The starting alpha (0..255) value to be applied to the LinearGradient.
      * @param startAlpha The ending alpha (0..255) value to be applied to the LinearGradient.
      */
     public void setAlpha(int startAlpha, int endAlpha) {
         mStartColor = startAlpha << 24;
         mEndColor = endAlpha << 24;
--- a/mobile/android/base/TabsButton.java
+++ b/mobile/android/base/TabsButton.java
@@ -155,18 +155,20 @@ public class TabsButton extends ShapedBu
         // Additionally draw a black curve for cropped button's default level.
         if (mCropped && background.getLevel() != 2)
             canvas.drawPath(mBackgroundPath, mPaint);
     }
 
     // The drawable is constructed as per @drawable/tabs_button.
     @Override
     public void onLightweightThemeChanged() {
-        LightweightThemeDrawable lightWeight1 = mActivity.getLightweightTheme().getTextureDrawable(this, R.color.background_tabs_light);
-        LightweightThemeDrawable lightWeight2 = mActivity.getLightweightTheme().getTextureDrawable(this, R.color.background_tabs_dark);
+        int background1 = mActivity.getResources().getColor(R.color.background_tabs_light);
+        LightweightThemeDrawable lightWeight1 = mActivity.getLightweightTheme().getColorDrawable(this, background1);
+        int background2 = mActivity.getResources().getColor(R.color.background_tabs_dark);
+        LightweightThemeDrawable lightWeight2 = mActivity.getLightweightTheme().getColorDrawable(this, background2);
         if (lightWeight1 == null || lightWeight2 == null)
             return;
 
         lightWeight1.setAlpha(34, 34);
         lightWeight2.setAlpha(34, 34);
 
         Resources resources = this.getContext().getResources();
         StateListDrawable stateList1 = new StateListDrawable();
--- a/mobile/android/base/TabsPanel.java
+++ b/mobile/android/base/TabsPanel.java
@@ -200,17 +200,18 @@ public class TabsPanel extends LinearLay
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         mActivity.getLightweightTheme().removeListener(this);
     }
     
     @Override
     public void onLightweightThemeChanged() {
-        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.color.background_tabs_light, true);
+        int background = mActivity.getResources().getColor(R.color.background_tabs_light);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this, background, true);
         if (drawable == null)
             return;
 
         drawable.setAlpha(34, 0);
         setBackgroundDrawable(drawable);
     }
 
     @Override
@@ -268,17 +269,18 @@ public class TabsPanel extends LinearLay
         @Override
         public void onDetachedFromWindow() {
             super.onDetachedFromWindow();
             mActivity.getLightweightTheme().removeListener(this);
         }
     
         @Override
         public void onLightweightThemeChanged() {
-            LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.color.background_tabs_dark);
+            int background = mActivity.getResources().getColor(R.color.background_tabs_dark);
+            LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this, background);
             if (drawable == null)
                 return;
 
             drawable.setAlpha(34, 34);
             setBackgroundDrawable(drawable);
         }
 
         @Override