From be1f62260ae4798cd80404dc595e1146f346cfe9 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Thu, 20 Jan 2011 15:24:28 -0800 Subject: Fix issue #3374356: Buttons sometimes don't highlight On touch up, View would move itself to the pressed state if it hadn't already shown as pressed. However, it did this *after* scheduling the message to deliver the onClick(). Thus if the app took a little too long to execute inside of onClick(), the invalidate to draw the highlight state would be executed right before the following message to remove the highlight state, causing it to basically not be shown. This change just does the invalidate before scheduling the onClick, so we can be sure it gets done first. Change-Id: I6a4d1742a3aab60969c38b44bb3e163f48de62d4 --- core/java/android/view/View.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 2447f8cd986f..811a633920de 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -5027,6 +5027,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility focusTaken = requestFocus(); } + if (prepressed) { + // The button is being released before we actually + // showed it as pressed. Make it show the pressed + // state now (before scheduling the click) to ensure + // the user sees it. + mPrivateFlags |= PRESSED; + refreshDrawableState(); + } + if (!mHasPerformedLongPress) { // This is a tap, so remove the longpress check removeLongPressCallback(); @@ -5050,8 +5059,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility } if (prepressed) { - mPrivateFlags |= PRESSED; - refreshDrawableState(); postDelayed(mUnsetPressedState, ViewConfiguration.getPressedStateDuration()); } else if (!post(mUnsetPressedState)) { -- cgit v1.2.3-59-g8ed1b