summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2012-02-14 15:52:17 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-02-14 15:52:17 -0800
commitdd29f8c4e3db3338bc055302145c3bc51a27566f (patch)
tree5ae5f5c6fb6e6aa899bfbf6c63b72f3e19f16d80 /core/java/android
parent9ae763133238ad5a1963d99a69cf891293345cb3 (diff)
parent73eb97f628b298c7bd032aa9db11dadf05f5b539 (diff)
downloadframeworks_base-dd29f8c4e3db3338bc055302145c3bc51a27566f.zip
frameworks_base-dd29f8c4e3db3338bc055302145c3bc51a27566f.tar.gz
frameworks_base-dd29f8c4e3db3338bc055302145c3bc51a27566f.tar.bz2
Merge "Revert "Incorrect behavior of View clear focus.""
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/View.java23
-rw-r--r--core/java/android/view/ViewGroup.java19
-rw-r--r--core/java/android/view/ViewRootImpl.java35
3 files changed, 24 insertions, 53 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ba1b7af..87104f4 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -3766,14 +3766,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
}
if ((mPrivateFlags & FOCUSED) != 0) {
- // If this is the first focusable do not clear focus since the we
- // try to give it focus every time a view clears its focus. Hence,
- // the view that would gain focus already has it.
- View firstFocusable = getFirstFocusable();
- if (firstFocusable == this) {
- return;
- }
-
mPrivateFlags &= ~FOCUSED;
if (mParent != null) {
@@ -3782,24 +3774,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
onFocusChanged(false, 0, null);
refreshDrawableState();
-
- // The view cleared focus and invoked the callbacks, so now is the
- // time to give focus to the the first focusable to ensure that the
- // gain focus is announced after clear focus.
- if (firstFocusable != null) {
- firstFocusable.requestFocus(FOCUS_FORWARD);
- }
}
}
- private View getFirstFocusable() {
- ViewRootImpl viewRoot = getViewRootImpl();
- if (viewRoot != null) {
- return viewRoot.focusSearch(null, FOCUS_FORWARD);
- }
- return null;
- }
-
/**
* Called to clear the focus of a view that is about to be removed.
* Doesn't call clearChildFocus, which prevents this view from taking
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index a2e85a3..bc147ac 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -675,14 +675,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
*/
@Override
public void clearFocus() {
- if (DBG) {
- System.out.println(this + " clearFocus()");
- }
- if (mFocused == null) {
- super.clearFocus();
- } else {
+ super.clearFocus();
+
+ // clear any child focus if it exists
+ if (mFocused != null) {
mFocused.clearFocus();
- mFocused = null;
}
}
@@ -694,12 +691,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
if (DBG) {
System.out.println(this + " unFocus()");
}
- if (mFocused == null) {
- super.unFocus();
- } else {
+
+ super.unFocus();
+ if (mFocused != null) {
mFocused.unFocus();
- mFocused = null;
}
+ mFocused = null;
}
/**
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 1930a5e..1c3bbfa 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -174,7 +174,6 @@ public final class ViewRootImpl extends Handler implements ViewParent,
View mView;
View mFocusedView;
View mRealFocusedView; // this is not set to null in touch mode
- View mOldFocusedView;
int mViewVisibility;
boolean mAppVisible = true;
int mOrigWindowType = -1;
@@ -2273,34 +2272,33 @@ public final class ViewRootImpl extends Handler implements ViewParent,
public void requestChildFocus(View child, View focused) {
checkThread();
-
- if (DEBUG_INPUT_RESIZE) {
- Log.v(TAG, "Request child focus: focus now " + focused);
+ if (mFocusedView != focused) {
+ mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(mFocusedView, focused);
+ scheduleTraversals();
}
-
- mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(mOldFocusedView, focused);
- scheduleTraversals();
-
mFocusedView = mRealFocusedView = focused;
+ if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Request child focus: focus now "
+ + mFocusedView);
}
public void clearChildFocus(View child) {
checkThread();
- if (DEBUG_INPUT_RESIZE) {
- Log.v(TAG, "Clearing child focus");
- }
-
- mOldFocusedView = mFocusedView;
-
- // Invoke the listener only if there is no view to take focus
- if (focusSearch(null, View.FOCUS_FORWARD) == null) {
- mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(mOldFocusedView, null);
- }
+ View oldFocus = mFocusedView;
+ if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Clearing child focus");
mFocusedView = mRealFocusedView = null;
+ if (mView != null && !mView.hasFocus()) {
+ // If a view gets the focus, the listener will be invoked from requestChildFocus()
+ if (!mView.requestFocus(View.FOCUS_FORWARD)) {
+ mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, null);
+ }
+ } else if (oldFocus != null) {
+ mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, null);
+ }
}
+
public void focusableViewAvailable(View v) {
checkThread();
@@ -2772,7 +2770,6 @@ public final class ViewRootImpl extends Handler implements ViewParent,
mView.unFocus();
mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(focused, null);
mFocusedView = null;
- mOldFocusedView = null;
return true;
}
}