Permalink
Browse files

Fix drawable handling for ActionBarContainer

ActionBarContainer drawables for primary/stacked/split backgrounds
will now properly respect callbacks, layout direction, etc.

Bug 6905932

Change-Id: I20a089861c66a2a378f4b70c0b6cb4bb27476049
  • Loading branch information...
1 parent 8ab8fbb commit a7cc06d82e45918c37429a59b14545c6a57db4e4 Adam Powell committed Aug 1, 2012
Showing with 84 additions and 0 deletions.
  1. +84 −0 core/java/com/android/internal/widget/ActionBarContainer.java
@@ -77,20 +77,104 @@ public void onFinishInflate() {
}
public void setPrimaryBackground(Drawable bg) {
+ if (mBackground != null) {
+ mBackground.setCallback(null);
+ unscheduleDrawable(mBackground);
+ }
mBackground = bg;
+ if (bg != null) {
+ bg.setCallback(this);
+ }
+ setWillNotDraw(mIsSplit ? mSplitBackground == null :
+ mBackground == null && mStackedBackground == null);
invalidate();
}
public void setStackedBackground(Drawable bg) {
+ if (mStackedBackground != null) {
+ mStackedBackground.setCallback(null);
+ unscheduleDrawable(mStackedBackground);
+ }
mStackedBackground = bg;
+ if (bg != null) {
+ bg.setCallback(this);
+ }
+ setWillNotDraw(mIsSplit ? mSplitBackground == null :
+ mBackground == null && mStackedBackground == null);
invalidate();
}
public void setSplitBackground(Drawable bg) {
+ if (mSplitBackground != null) {
+ mSplitBackground.setCallback(null);
+ unscheduleDrawable(mSplitBackground);
+ }
mSplitBackground = bg;
+ if (bg != null) {
+ bg.setCallback(this);
+ }
+ setWillNotDraw(mIsSplit ? mSplitBackground == null :
+ mBackground == null && mStackedBackground == null);
invalidate();
}
+ @Override
+ public void setVisibility(int visibility) {
+ super.setVisibility(visibility);
+ final boolean isVisible = visibility == VISIBLE;
+ if (mBackground != null) mBackground.setVisible(isVisible, false);
+ if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false);
+ if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false);
+ }
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) ||
+ (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who);
+ }
+
+ @Override
+ protected void drawableStateChanged() {
+ super.drawableStateChanged();
+ if (mBackground != null && mBackground.isStateful()) {
+ mBackground.setState(getDrawableState());
+ }
+ if (mStackedBackground != null && mStackedBackground.isStateful()) {
+ mStackedBackground.setState(getDrawableState());
+ }
+ if (mSplitBackground != null && mSplitBackground.isStateful()) {
+ mSplitBackground.setState(getDrawableState());
+ }
+ }
+
+ @Override
+ public void jumpDrawablesToCurrentState() {
+ super.jumpDrawablesToCurrentState();
+ if (mBackground != null) {
+ mBackground.jumpToCurrentState();
+ }
+ if (mStackedBackground != null) {
+ mStackedBackground.jumpToCurrentState();
+ }
+ if (mSplitBackground != null) {
+ mSplitBackground.jumpToCurrentState();
+ }
+ }
+
+ @Override
+ public void onResolveDrawables(int layoutDirection) {
+ super.onResolveDrawables(layoutDirection);
+ if (mBackground != null) {
+ mBackground.setLayoutDirection(layoutDirection);
+ }
+ if (mStackedBackground != null) {
+ mStackedBackground.setLayoutDirection(layoutDirection);
+ }
+ if (mSplitBackground != null) {
+ mSplitBackground.setLayoutDirection(layoutDirection);
+ }
+ }
+
/**
* Set the action bar into a "transitioning" state. While transitioning
* the bar will block focus and touch from all of its descendants. This

0 comments on commit a7cc06d

Please sign in to comment.