Skip to content

Commit a7cc06d

Browse files
committed
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
1 parent 8ab8fbb commit a7cc06d

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

core/java/com/android/internal/widget/ActionBarContainer.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,104 @@ public void onFinishInflate() {
7777
}
7878

7979
public void setPrimaryBackground(Drawable bg) {
80+
if (mBackground != null) {
81+
mBackground.setCallback(null);
82+
unscheduleDrawable(mBackground);
83+
}
8084
mBackground = bg;
85+
if (bg != null) {
86+
bg.setCallback(this);
87+
}
88+
setWillNotDraw(mIsSplit ? mSplitBackground == null :
89+
mBackground == null && mStackedBackground == null);
8190
invalidate();
8291
}
8392

8493
public void setStackedBackground(Drawable bg) {
94+
if (mStackedBackground != null) {
95+
mStackedBackground.setCallback(null);
96+
unscheduleDrawable(mStackedBackground);
97+
}
8598
mStackedBackground = bg;
99+
if (bg != null) {
100+
bg.setCallback(this);
101+
}
102+
setWillNotDraw(mIsSplit ? mSplitBackground == null :
103+
mBackground == null && mStackedBackground == null);
86104
invalidate();
87105
}
88106

89107
public void setSplitBackground(Drawable bg) {
108+
if (mSplitBackground != null) {
109+
mSplitBackground.setCallback(null);
110+
unscheduleDrawable(mSplitBackground);
111+
}
90112
mSplitBackground = bg;
113+
if (bg != null) {
114+
bg.setCallback(this);
115+
}
116+
setWillNotDraw(mIsSplit ? mSplitBackground == null :
117+
mBackground == null && mStackedBackground == null);
91118
invalidate();
92119
}
93120

121+
@Override
122+
public void setVisibility(int visibility) {
123+
super.setVisibility(visibility);
124+
final boolean isVisible = visibility == VISIBLE;
125+
if (mBackground != null) mBackground.setVisible(isVisible, false);
126+
if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false);
127+
if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false);
128+
}
129+
130+
@Override
131+
protected boolean verifyDrawable(Drawable who) {
132+
return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) ||
133+
(who == mSplitBackground && mIsSplit) || super.verifyDrawable(who);
134+
}
135+
136+
@Override
137+
protected void drawableStateChanged() {
138+
super.drawableStateChanged();
139+
if (mBackground != null && mBackground.isStateful()) {
140+
mBackground.setState(getDrawableState());
141+
}
142+
if (mStackedBackground != null && mStackedBackground.isStateful()) {
143+
mStackedBackground.setState(getDrawableState());
144+
}
145+
if (mSplitBackground != null && mSplitBackground.isStateful()) {
146+
mSplitBackground.setState(getDrawableState());
147+
}
148+
}
149+
150+
@Override
151+
public void jumpDrawablesToCurrentState() {
152+
super.jumpDrawablesToCurrentState();
153+
if (mBackground != null) {
154+
mBackground.jumpToCurrentState();
155+
}
156+
if (mStackedBackground != null) {
157+
mStackedBackground.jumpToCurrentState();
158+
}
159+
if (mSplitBackground != null) {
160+
mSplitBackground.jumpToCurrentState();
161+
}
162+
}
163+
164+
@Override
165+
public void onResolveDrawables(int layoutDirection) {
166+
super.onResolveDrawables(layoutDirection);
167+
if (mBackground != null) {
168+
mBackground.setLayoutDirection(layoutDirection);
169+
}
170+
if (mStackedBackground != null) {
171+
mStackedBackground.setLayoutDirection(layoutDirection);
172+
}
173+
if (mSplitBackground != null) {
174+
mSplitBackground.setLayoutDirection(layoutDirection);
175+
}
176+
}
177+
94178
/**
95179
* Set the action bar into a "transitioning" state. While transitioning
96180
* the bar will block focus and touch from all of its descendants. This

0 commit comments

Comments
 (0)