Bug 821453: Android 4.2.1 messes up BitmapDrawable. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Thu, 13 Dec 2012 13:13:36 -0800
changeset 125225 bc1e8c9266ea5718dc1bc12790e2916048e4e7b1
parent 125224 a0e351bde9463d0b0212d824c9aaa633fe3320a7
child 125226 96b591267cb3ac21eadce063289f81734a60498c
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs821453
milestone20.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 821453: Android 4.2.1 messes up BitmapDrawable. [r=mfinkle]
mobile/android/base/AboutHomeContent.java
mobile/android/base/AwesomeBarTabs.java
mobile/android/base/LightweightTheme.java
mobile/android/base/LightweightThemeDrawable.java
mobile/android/base/MenuButton.java
mobile/android/base/TabsButton.java
mobile/android/base/TabsPanel.java
mobile/android/base/TabsPanelButton.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -24,17 +24,16 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Color;
-import android.graphics.drawable.Drawable;
 import android.graphics.Path;
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffXfermode;
 import android.graphics.RectF;
 import android.os.SystemClock;
 import android.text.SpannableString;
 import android.text.TextUtils;
@@ -679,20 +678,21 @@ public class AboutHomeContent extends Sc
         }
         
         mRemoteTabs.setSubtitle(client);
         mRemoteTabs.show();
     }
 
     @Override
     public void onLightweightThemeChanged() {
-        final Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 255, 0);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this);
         if (drawable == null)
             return;
 
+         drawable.setAlpha(255, 0);
          setBackgroundDrawable(drawable);
     }
 
     @Override
     public void onLightweightThemeReset() {
         setBackgroundResource(R.drawable.abouthome_bg_repeat);
     }
 
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -1,17 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.Context;
-import android.graphics.drawable.Drawable;
 import android.graphics.drawable.StateListDrawable;
 import android.net.Uri;
 import android.support.v4.view.ViewPager;
 import android.support.v4.view.PagerAdapter;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -317,23 +316,25 @@ public class AwesomeBarTabs extends TabH
         @Override
         public void onDetachedFromWindow() {
             super.onDetachedFromWindow();
             mActivity.getLightweightTheme().removeListener(this);
         }
 
         @Override
         public void onLightweightThemeChanged() {
-            Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 255, 0);
+            LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this);
             if (drawable == null)
                 return;
 
-        StateListDrawable stateList = new StateListDrawable();
-        stateList.addState(new int[] { R.attr.state_private }, mActivity.getResources().getDrawable(R.drawable.address_bar_bg_private));
-        stateList.addState(new int[] {}, drawable);
+            drawable.setAlpha(255, 0);
+
+            StateListDrawable stateList = new StateListDrawable();
+            stateList.addState(new int[] { R.attr.state_private }, mActivity.getResources().getDrawable(R.drawable.address_bar_bg_private));
+            stateList.addState(new int[] {}, drawable);
 
             int[] padding =  new int[] { getPaddingLeft(),
                                          getPaddingTop(),
                                          getPaddingRight(),
                                          getPaddingBottom()
                                        };
             setBackgroundDrawable(stateList);
             setPadding(padding[0], padding[1], padding[2], padding[3]);
--- a/mobile/android/base/LightweightTheme.java
+++ b/mobile/android/base/LightweightTheme.java
@@ -239,48 +239,70 @@ 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 alpha.
-     * LightweightThemeDrawable is optionally placed over a ColorDrawable (of dominant color),
-     * if the cropped bitmap cannot fill the entire view.
+     * 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 alpha The alpha (0..255) value to be applied to the Drawable.
+     * @param textureId The resource id of the texture.
      * @return Either the cropped bitmap as a Drawable or null.
      */
-    public Drawable getDrawableWithAlpha(View view, int alpha) {
-        return getDrawableWithAlpha(view, alpha, alpha);
+    public LightweightThemeDrawable getTextureDrawable(View view, int textureId) {
+        return getTextureDrawable(view, textureId, false);
     }
 
     /**
-     * Converts the cropped bitmap to a LightweightThemeDrawable, with the required alpha applied as 
-     * a LinearGradient. LightweightThemeDrawable is optionally placed over a ColorDrawable 
-     * (of dominant color), if the cropped bitmap cannot fill the entire view.
+     * 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 startAlpha The top alpha (0..255) of the linear gradient to be applied to the Drawable.
-     * @param endAlpha The bottom alpha (0..255) of the linear gradient to be applied to the Drawable.
+     * @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 Drawable getDrawableWithAlpha(View view, int startAlpha, int endAlpha) {
+    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.setAlpha(startAlpha, endAlpha);
-        drawable.setGravity(Gravity.TOP|Gravity.RIGHT|Gravity.FILL_HORIZONTAL);
+        drawable.setTexture(textureId);
+
+        if (needsColor)
+            drawable.setColor(mColor & 0x22FFFFFF);
+
+        return drawable;
+    }
 
-        if (bitmap.getHeight() != view.getHeight()) {
-            ColorDrawable colorDrawable = new ColorDrawable(mColor);
-            LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{ colorDrawable, drawable });
-            return layerDrawable;
-        } else {
-            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);
+     }
+
+    /**
+     * Converts the cropped bitmap to a LightweightThemeDrawable, placing it over the required 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, int color) {
+        Bitmap bitmap = getCroppedBitmap(view);
+        if (bitmap == null)
+            return null;
+
+        LightweightThemeDrawable drawable = new LightweightThemeDrawable(view.getContext().getResources(), bitmap);
+        drawable.setColor(color);
+        return drawable;
     }
 }
--- a/mobile/android/base/LightweightThemeDrawable.java
+++ b/mobile/android/base/LightweightThemeDrawable.java
@@ -2,58 +2,155 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
 import android.graphics.Canvas;
-import android.graphics.drawable.BitmapDrawable;
+import android.graphics.ColorFilter;
+import android.graphics.ComposeShader;
 import android.graphics.LinearGradient;
-import android.graphics.Path;
-import android.graphics.PorterDuff.Mode;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
 import android.graphics.Rect;
 import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 
-public class LightweightThemeDrawable extends BitmapDrawable
-                                      implements CanvasDelegate.DrawManager { 
-    private static final String LOGTAG = "GeckoLightweightThemeDrawable";
-    private Path mPath;
-    private CanvasDelegate mCanvasDelegate;
+/**
+ * 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.
+ */
+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) {
-        super(resources, bitmap);
         mBitmap = bitmap;
+        mResources = resources;
 
-        mPath = new Path();
-        mCanvasDelegate = new CanvasDelegate(this, Mode.DST_IN);
-    }
-
-    public void setAlpha(int startAlpha, int endAlpha) {
-        mStartColor = startAlpha << 24;
-        mEndColor = endAlpha << 24;
+        mPaint = new Paint();
+        mPaint.setAntiAlias(true);
+        mPaint.setStrokeWidth(0.0f);
     }
 
     @Override
     protected void onBoundsChange(Rect bounds) {
-        mCanvasDelegate.setShader(new LinearGradient(0, 0, 
-                                                     0, mBitmap.getHeight(), 
-                                                     mStartColor, mEndColor,
-                                                     Shader.TileMode.CLAMP));
-
-        mPath.addRect(0, 0, mBitmap.getWidth(), mBitmap.getHeight(), Path.Direction.CW);
+        super.onBoundsChange(bounds);
+        initializeBitmapShader();
     }
 
     @Override
     public void draw(Canvas canvas) {
-        mCanvasDelegate.draw(canvas, mPath, canvas.getWidth(), canvas.getHeight());
+	// Draw the texture, if available.
+        if (mTexturePaint != null)
+            canvas.drawPaint(mTexturePaint);
+
+        // Draw the color, if available.
+        if (mColorPaint != null)
+            canvas.drawPaint(mColorPaint);
+
+        // Draw the bitmap.
+        canvas.drawPaint(mPaint);
+    }
+
+    @Override
+    public int getOpacity() {
+        return PixelFormat.TRANSLUCENT;
+    }
+
+    @Override
+    public void setAlpha(int alpha) {
+        // A StateListDrawable will reset the alpha value with 255.
+        // We cannot use to be the bitmap alpha.
+        mPaint.setAlpha(alpha);
     }
 
     @Override
-    public void defaultDraw(Canvas canvas) {
-        super.draw(canvas);
+    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) {
+        Shader.TileMode modeX = Shader.TileMode.REPEAT;
+        Shader.TileMode modeY = Shader.TileMode.REPEAT;
+
+        // The texture to be repeated.
+        Bitmap texture = BitmapFactory.decodeResource(mResources, textureId);
+
+        if (texture == null) {
+            // Texture may be used inside a BitmapDrawable.
+            Drawable drawable = mResources.getDrawable(textureId);
+            if (drawable != null && drawable instanceof BitmapDrawable) {
+                BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
+                texture = bitmapDrawable.getBitmap();
+                modeX = bitmapDrawable.getTileModeX();
+                modeY = bitmapDrawable.getTileModeY();
+            }
+        }
+
+        // Set the shader for the texture paint.
+        if (texture != null) {
+            mTexturePaint = new Paint(mPaint);
+            mTexturePaint.setShader(new BitmapShader(texture, modeX, modeY));
+        }
+    }
+
+    /**
+     * 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);
+    }
+
+    /**
+     * 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;
+        initializeBitmapShader();
+    }
+
+    private void initializeBitmapShader() {
+	// A bitmap-shader to draw the bitmap.
+        // Clamp mode will repeat the last row of pixels.
+        // Hence its better to have an endAlpha of 0 for the linear-gradient.
+	BitmapShader bitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
+
+	// A linear-gradient to specify the opacity of the bitmap.
+	LinearGradient gradient = new LinearGradient(0, 0, 0, mBitmap.getHeight(), mStartColor, mEndColor, Shader.TileMode.CLAMP);
+
+	// Make a combined shader -- a performance win.
+        // The linear-gradient is the 'SRC' and the bitmap-shader is the 'DST'.
+	// Drawing the DST in the SRC will provide the opacity.
+	mPaint.setShader(new ComposeShader(bitmapShader, gradient, PorterDuff.Mode.DST_IN));
     }
 }
--- a/mobile/android/base/MenuButton.java
+++ b/mobile/android/base/MenuButton.java
@@ -6,17 +6,17 @@ package org.mozilla.gecko;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Path;
 import android.graphics.PorterDuff.Mode;
 import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
+import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.LayerDrawable;
 import android.graphics.drawable.LevelListDrawable;
 import android.graphics.drawable.StateListDrawable;
 import android.util.AttributeSet;
 
 public class MenuButton extends ShapedButton {
 
     public MenuButton(Context context, AttributeSet attrs) {
@@ -53,27 +53,27 @@ public class MenuButton extends ShapedBu
             mPath.lineTo(width, height);
             mPath.lineTo(width, 0);
         }
     }
 
     // The drawable is constructed as per @drawable/menu_button.
     @Override
     public void onLightweightThemeChanged() {
-        Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 34);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this, Color.BLACK);
         if (drawable == null)
             return;
 
+        drawable.setAlpha(34, 34);
+
         Resources resources = getContext().getResources();
-        LayerDrawable layers = new LayerDrawable(new Drawable[] { new ColorDrawable(Color.BLACK), drawable }); 
-
         StateListDrawable stateList = new StateListDrawable();
         stateList.addState(new int[] { R.attr.state_private }, new ColorDrawable(Color.BLACK));
         stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
-        stateList.addState(new int[] {}, layers);
+        stateList.addState(new int[] {}, drawable);
 
         LevelListDrawable levelList = new LevelListDrawable();
         levelList.addLevel(0, 1, stateList);
         levelList.addLevel(2, 2, new ColorDrawable(Color.TRANSPARENT));
 
         setBackgroundDrawable(levelList);
     }
 
--- a/mobile/android/base/TabsButton.java
+++ b/mobile/android/base/TabsButton.java
@@ -159,27 +159,27 @@ 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() {
-        Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 34);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.drawable.tabs_tray_bg_repeat);
         if (drawable == null)
             return;
 
+        drawable.setAlpha(34, 34);
+
         Resources resources = this.getContext().getResources();
-        LayerDrawable layers = new LayerDrawable(new Drawable[] { resources.getDrawable(R.drawable.tabs_tray_bg_repeat), drawable }); 
-
         StateListDrawable stateList = new StateListDrawable();
         stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
         stateList.addState(new int[] { R.attr.state_private }, resources.getDrawable(R.drawable.tabs_tray_bg_repeat));
-        stateList.addState(new int[] {}, layers);
+        stateList.addState(new int[] {}, drawable);
 
         LevelListDrawable levelList = new LevelListDrawable();
         levelList.addLevel(0, 1, stateList);
 
         // If there is a side bar, the expanded state will have a filled button.
         if (mSideBar)
             levelList.addLevel(2, 2, stateList);
         else
--- a/mobile/android/base/TabsPanel.java
+++ b/mobile/android/base/TabsPanel.java
@@ -8,17 +8,16 @@ package org.mozilla.gecko;
 import org.mozilla.gecko.sync.setup.SyncAccounts;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Color;
 import android.graphics.Rect;
 import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
 import android.graphics.drawable.LayerDrawable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
@@ -216,24 +215,22 @@ public class TabsPanel extends LinearLay
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         mActivity.getLightweightTheme().removeListener(this);
     }
     
     @Override
     public void onLightweightThemeChanged() {
-        Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 255, 0);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.drawable.tabs_tray_bg_repeat, true);
         if (drawable == null)
             return;
 
-        drawable.setAlpha(30);
-
-        LayerDrawable layers = new LayerDrawable(new Drawable[] { mContext.getResources().getDrawable(R.drawable.tabs_tray_bg_repeat), drawable });
-        setBackgroundDrawable(layers);
+        drawable.setAlpha(34, 0);
+        setBackgroundDrawable(drawable);
     }
 
     @Override
     public void onLightweightThemeReset() {
         setBackgroundResource(R.drawable.tabs_tray_bg_repeat);
     }
 
     @Override
@@ -286,23 +283,22 @@ public class TabsPanel extends LinearLay
         @Override
         public void onDetachedFromWindow() {
             super.onDetachedFromWindow();
             mActivity.getLightweightTheme().removeListener(this);
         }
     
         @Override
         public void onLightweightThemeChanged() {
-            Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 34);
+            LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.drawable.tabs_tray_bg_repeat);
             if (drawable == null)
                 return;
 
-            Resources resources = this.getContext().getResources();
-            LayerDrawable layers = new LayerDrawable(new Drawable[] { resources.getDrawable(R.drawable.tabs_tray_bg_repeat), drawable }); 
-            setBackgroundDrawable(layers);
+            drawable.setAlpha(34, 34);
+            setBackgroundDrawable(drawable);
         }
 
         @Override
         public void onLightweightThemeReset() {
             setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
         }
 
         @Override
--- a/mobile/android/base/TabsPanelButton.java
+++ b/mobile/android/base/TabsPanelButton.java
@@ -4,17 +4,16 @@
 
 package org.mozilla.gecko;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Path;
 import android.graphics.PorterDuff.Mode;
-import android.graphics.drawable.Drawable;
 import android.graphics.drawable.LayerDrawable;
 import android.graphics.drawable.StateListDrawable;
 import android.util.AttributeSet;
 
 public class TabsPanelButton extends ShapedButton {
 
     public TabsPanelButton(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -50,26 +49,26 @@ public class TabsPanelButton extends Sha
             mPath.lineTo(width, 0);
             mPath.lineTo(width, height);
         }
     }
 
     // The drawable is constructed as per @drawable/tab_new_button.
     @Override
     public void onLightweightThemeChanged() {
-        Drawable drawable = mActivity.getLightweightTheme().getDrawableWithAlpha(this, 34);
+        LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getTextureDrawable(this, R.drawable.tabs_tray_bg_repeat);
         if (drawable == null)
             return;
 
+        drawable.setAlpha(34, 34);
+
         Resources resources = getContext().getResources();
-        LayerDrawable layers = new LayerDrawable(new Drawable[] { resources.getDrawable(R.drawable.tabs_tray_bg_repeat), drawable }); 
-
         StateListDrawable stateList = new StateListDrawable();
         stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
-        stateList.addState(new int[] {}, layers);
+        stateList.addState(new int[] {}, drawable);
 
         setBackgroundDrawable(stateList);
     }
 
     @Override
     public void onLightweightThemeReset() {
         setBackgroundResource(R.drawable.tab_new_button);
     }