summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2009-04-30 16:30:00 -0700
committerRomain Guy <romainguy@google.com>2009-04-30 17:57:47 -0700
commita2431d0ba24ca7d79d21b2df63f9a58025702c7e (patch)
treeedecb2d82ffc41cc02d083625aec70e0e9c94fa8 /core/java/android/view
parenta039d465a85e8a7dea1ec4b5814e1a6e84e676f8 (diff)
downloadframeworks_base-a2431d0ba24ca7d79d21b2df63f9a58025702c7e.zip
frameworks_base-a2431d0ba24ca7d79d21b2df63f9a58025702c7e.tar.gz
frameworks_base-a2431d0ba24ca7d79d21b2df63f9a58025702c7e.tar.bz2
Fixes #1712631. Whenever a View loses focus/selection, reset its pressed state.
Diffstat (limited to 'core/java/android/view')
-rw-r--r--core/java/android/view/View.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ec1c733..894045a 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -2424,6 +2424,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
&& mAttachInfo.mHasWindowFocus) {
imm.focusOut(this);
}
+ onFocusLost();
} else if (imm != null && mAttachInfo != null
&& mAttachInfo.mHasWindowFocus) {
imm.focusIn(this);
@@ -2436,6 +2437,39 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
}
/**
+ * Invoked whenever this view loses focus, either by losing window focus or by losing
+ * focus within its window. This method can be used to clear any state tied to the
+ * focus. For instance, if a button is held pressed with the trackball and the window
+ * loses focus, this method can be used to cancel the press.
+ *
+ * Subclasses of View overriding this method should always call super.onFocusLost().
+ *
+ * @see #onFocusChanged(boolean, int, android.graphics.Rect)
+ * @see #onWindowFocusChanged(boolean)
+ *
+ * @hide pending API council approval
+ */
+ protected void onFocusLost() {
+ resetPressedState();
+ }
+
+ private void resetPressedState() {
+ if ((mViewFlags & ENABLED_MASK) == DISABLED) {
+ return;
+ }
+
+ if (isPressed()) {
+ setPressed(false);
+
+ if (!mHasPerformedLongPress) {
+ if (mPendingCheckForLongPress != null) {
+ removeCallbacks(mPendingCheckForLongPress);
+ }
+ }
+ }
+ }
+
+ /**
* Returns true if this view has focus
*
* @return True if this view has focus, false otherwise.
@@ -3416,6 +3450,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
+ onFocusLost();
} else if (imm != null && (mPrivateFlags & FOCUSED) != 0) {
imm.focusIn(this);
}
@@ -5635,7 +5670,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
* Create a snapshot of the view into a bitmap. We should probably make
* some form of this public, but should think about the API.
*/
- /*package*/ Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor) {
+ Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor) {
final int width = mRight - mLeft;
final int height = mBottom - mTop;
@@ -6705,6 +6740,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
public void setSelected(boolean selected) {
if (((mPrivateFlags & SELECTED) != 0) != selected) {
mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0);
+ if (!selected) resetPressedState();
invalidate();
refreshDrawableState();
dispatchSetSelected(selected);