Override View.drawableStateChanged to detect state_pressed
Unlike on JB, View.setPressed(boolean) is never called when the view is pressed on ICS. To detect a pressed state of the view, we need to override View.drawableStateChanged() and check the drawable state contains state_pressed. Bug: 8159728 Change-Id: I481051364d6f3d1370742723c3ce19d898ea5463main
parent
7b2114a428
commit
47a66b12ec
|
@ -51,11 +51,32 @@ public final class SetupStartIndicatorView extends LinearLayout {
|
||||||
mIndicatorView = indicatorView;
|
mIndicatorView = indicatorView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Once we stop supporting ICS, uncomment {@link #setPressed(boolean)} method and
|
||||||
|
// remove this method.
|
||||||
@Override
|
@Override
|
||||||
public void setPressed(final boolean pressed) {
|
protected void drawableStateChanged() {
|
||||||
super.setPressed(pressed);
|
super.drawableStateChanged();
|
||||||
|
for (final int state : getDrawableState()) {
|
||||||
|
if (state == android.R.attr.state_pressed) {
|
||||||
|
updateIndicatorView(true /* pressed */);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateIndicatorView(false /* pressed */);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Once we stop supporting ICS, uncomment this method and remove
|
||||||
|
// {@link #drawableStateChanged()} method.
|
||||||
|
// @Override
|
||||||
|
// public void setPressed(final boolean pressed) {
|
||||||
|
// super.setPressed(pressed);
|
||||||
|
// updateIndicatorView(pressed);
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void updateIndicatorView(final boolean pressed) {
|
||||||
if (mIndicatorView != null) {
|
if (mIndicatorView != null) {
|
||||||
mIndicatorView.setPressed(pressed);
|
mIndicatorView.setPressed(pressed);
|
||||||
|
mIndicatorView.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,12 +93,6 @@ public final class SetupStartIndicatorView extends LinearLayout {
|
||||||
mIndicatorPaint.setStyle(Paint.Style.FILL);
|
mIndicatorPaint.setStyle(Paint.Style.FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPressed(final boolean pressed) {
|
|
||||||
super.setPressed(pressed);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(final Canvas canvas) {
|
protected void onDraw(final Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
Loading…
Reference in New Issue