Skip to content

Commit 035a1fc

Browse files
committed
View pressed state dispatching tweaks
Bugs 6075823, 6050563 Revise pressed state dispatch logic: Only propagate pressed state to non-clickable views. This should eliminate the "double glow" problem in some list items where a clickable child button has a secondary glow along with a clickable parent. This only applies to setPressed(true) calls; setPressed(false) must propagate. Don't early-out in setPressed to support this use case. Change-Id: Ibbe2309f5030282fad8d23e4a9bc4616b3f5dc7c
1 parent 41c31ef commit 035a1fc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

core/java/android/view/View.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,16 +5048,17 @@ public void setLongClickable(boolean longClickable) {
50485048
* the View's internal state from a previously set "pressed" state.
50495049
*/
50505050
public void setPressed(boolean pressed) {
5051-
if (pressed == ((mPrivateFlags & PRESSED) == PRESSED)) {
5052-
return;
5053-
}
5051+
final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED);
50545052

50555053
if (pressed) {
50565054
mPrivateFlags |= PRESSED;
50575055
} else {
50585056
mPrivateFlags &= ~PRESSED;
50595057
}
5060-
refreshDrawableState();
5058+
5059+
if (needsRefresh) {
5060+
refreshDrawableState();
5061+
}
50615062
dispatchSetPressed(pressed);
50625063
}
50635064

core/java/android/view/ViewGroup.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,13 @@ protected void dispatchSetPressed(boolean pressed) {
27702770
final View[] children = mChildren;
27712771
final int count = mChildrenCount;
27722772
for (int i = 0; i < count; i++) {
2773-
children[i].setPressed(pressed);
2773+
final View child = children[i];
2774+
// Children that are clickable on their own should not
2775+
// show a pressed state when their parent view does.
2776+
// Clearing a pressed state always propagates.
2777+
if (!pressed || (!child.isClickable() && !child.isLongClickable())) {
2778+
child.setPressed(pressed);
2779+
}
27742780
}
27752781
}
27762782

0 commit comments

Comments
 (0)