import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
+import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ActionMode;
public ActionBarContainer(Context context, AttributeSet attrs) {
super(context, attrs);
- setBackgroundDrawable(null);
+ // Set a transparent background so that we project appropriately.
+ setBackground(new ActionBarBackgroundDrawable());
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.ActionBar);
}
@Override
- public void onDraw(Canvas canvas) {
- if (getWidth() == 0 || getHeight() == 0) {
- return;
- }
-
- if (mIsSplit) {
- if (mSplitBackground != null) mSplitBackground.draw(canvas);
- } else {
- if (mBackground != null) {
- mBackground.draw(canvas);
- }
- if (mStackedBackground != null && mIsStacked) {
- mStackedBackground.draw(canvas);
- }
- }
- }
-
- @Override
public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) {
// No starting an action mode for an action bar child! (Where would it go?)
return null;
public void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
- final boolean hasTabs = mTabContainer != null && mTabContainer.getVisibility() != GONE;
+ final View tabContainer = mTabContainer;
+ final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE;
- if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
+ if (tabContainer != null && tabContainer.getVisibility() != GONE) {
final int containerHeight = getMeasuredHeight();
- final int tabHeight = mTabContainer.getMeasuredHeight();
- mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
+ final int tabHeight = tabContainer.getMeasuredHeight();
+ tabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
}
boolean needsInvalidate = false;
}
} else {
if (mBackground != null) {
- mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
- mActionBarView.getRight(), mActionBarView.getBottom());
+ final ActionBarView actionBarView = mActionBarView;
+ mBackground.setBounds(actionBarView.getLeft(), actionBarView.getTop(),
+ actionBarView.getRight(), actionBarView.getBottom());
needsInvalidate = true;
}
- if ((mIsStacked = hasTabs && mStackedBackground != null)) {
- mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(),
- mTabContainer.getRight(), mTabContainer.getBottom());
+ mIsStacked = hasTabs;
+ if (hasTabs && mStackedBackground != null) {
+ mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(),
+ tabContainer.getRight(), tabContainer.getBottom());
needsInvalidate = true;
}
}
invalidate();
}
}
+
+ /**
+ * Dummy drawable so that we don't break background display lists and
+ * projection surfaces.
+ */
+ private class ActionBarBackgroundDrawable extends Drawable {
+ @Override
+ public void draw(Canvas canvas) {
+ if (mIsSplit) {
+ if (mSplitBackground != null) mSplitBackground.draw(canvas);
+ } else {
+ if (mBackground != null) {
+ mBackground.draw(canvas);
+ }
+ if (mStackedBackground != null && mIsStacked) {
+ mStackedBackground.draw(canvas);
+ }
+ }
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ }
+
+ @Override
+ public int getOpacity() {
+ return 0;
+ }
+ }
}
import android.content.res.Resources;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
getDrawable(0).draw(canvas);
+ final Rect bounds = getBounds();
final ArrayList<Ripple> activeRipples = mActiveRipples;
- if (layerCount == 1 || activeRipples == null || activeRipples.isEmpty()) {
+ if (layerCount == 1 || bounds.isEmpty() || activeRipples == null
+ || activeRipples.isEmpty()) {
// Nothing to reveal, we're done here.
return;
}
- final Rect bounds = getBounds();
- final int width = bounds.width();
- final int height = bounds.height();
-
if (mRipplePaint == null) {
mRipplePaint = new Paint();
mRipplePaint.setAntiAlias(true);
n--;
} else {
if (layerSaveCount < 0) {
- layerSaveCount = canvas.saveLayer(0, 0, width, height, null, 0);
+ layerSaveCount = canvas.saveLayer(
+ bounds.left, bounds.top, bounds.right, bounds.bottom, null, 0);
+ // Ripples must be clipped to bounds, otherwise SRC_IN will
+ // miss them and we'll get artifacts.
+ canvas.clipRect(bounds);
}
needsMask |= ripple.draw(canvas, mRipplePaint);
// TODO: When Drawable.setXfermode() is supported by all drawables,
// we won't need an extra layer.
- canvas.saveLayer(0, 0, width, height, mMaskingPaint, 0);
+ canvas.saveLayer(
+ bounds.left, bounds.top, bounds.right, bounds.bottom, mMaskingPaint, 0);
getDrawable(1).draw(canvas);
}