From 47a66b12ec49179a09642bf48a0d2bd49d9f3458 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 1 May 2013 13:13:21 +0900 Subject: [PATCH] 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: I481051364d6f3d1370742723c3ce19d898ea5463 --- .../latin/setup/SetupStartIndicatorView.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java b/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java index ca974f6b8..974dfddd3 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java @@ -51,11 +51,32 @@ public final class SetupStartIndicatorView extends LinearLayout { mIndicatorView = indicatorView; } + // TODO: Once we stop supporting ICS, uncomment {@link #setPressed(boolean)} method and + // remove this method. @Override - public void setPressed(final boolean pressed) { - super.setPressed(pressed); + protected void drawableStateChanged() { + 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) { mIndicatorView.setPressed(pressed); + mIndicatorView.invalidate(); } } } @@ -72,12 +93,6 @@ public final class SetupStartIndicatorView extends LinearLayout { mIndicatorPaint.setStyle(Paint.Style.FILL); } - @Override - public void setPressed(final boolean pressed) { - super.setPressed(pressed); - invalidate(); - } - @Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas);