Merge "Focus search in AbsListView returns invisible views." into jb-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
30384653d2
@@ -1359,8 +1359,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
|||||||
case ACCESSIBILITY_FOCUS_FORWARD: {
|
case ACCESSIBILITY_FOCUS_FORWARD: {
|
||||||
// If we are the focused view try giving it to the first child.
|
// If we are the focused view try giving it to the first child.
|
||||||
if (focused == this) {
|
if (focused == this) {
|
||||||
if (getChildCount() > 0) {
|
final int childCount = getChildCount();
|
||||||
return getChildAt(0);
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
View child = getChildAt(i);
|
||||||
|
if (child.getVisibility() == View.VISIBLE) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.focusSearch(this, direction);
|
return super.focusSearch(this, direction);
|
||||||
}
|
}
|
||||||
@@ -1371,19 +1375,24 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
|||||||
}
|
}
|
||||||
// Try to advance focus in the current item.
|
// Try to advance focus in the current item.
|
||||||
View currentItem = getChildAt(currentPosition - getFirstVisiblePosition());
|
View currentItem = getChildAt(currentPosition - getFirstVisiblePosition());
|
||||||
if (currentItem instanceof ViewGroup) {
|
if (currentItem.getVisibility() == View.VISIBLE) {
|
||||||
ViewGroup currentItemGroup = (ViewGroup) currentItem;
|
if (currentItem instanceof ViewGroup) {
|
||||||
View nextFocus = FocusFinder.getInstance().findNextFocus(currentItemGroup,
|
ViewGroup currentItemGroup = (ViewGroup) currentItem;
|
||||||
focused, direction);
|
View nextFocus = FocusFinder.getInstance().findNextFocus(currentItemGroup,
|
||||||
if (nextFocus != null && nextFocus != currentItemGroup
|
focused, direction);
|
||||||
&& nextFocus != focused) {
|
if (nextFocus != null && nextFocus != currentItemGroup
|
||||||
return nextFocus;
|
&& nextFocus != focused) {
|
||||||
|
return nextFocus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Try to move focus to the next item.
|
// Try to move focus to the next item.
|
||||||
final int nextPosition = currentPosition - getFirstVisiblePosition() + 1;
|
final int nextPosition = currentPosition - getFirstVisiblePosition() + 1;
|
||||||
if (nextPosition < getChildCount()) {
|
for (int i = nextPosition; i <= getLastVisiblePosition(); i++) {
|
||||||
return getChildAt(nextPosition);
|
View child = getChildAt(i);
|
||||||
|
if (child.getVisibility() == View.VISIBLE) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// No next item start searching from the list.
|
// No next item start searching from the list.
|
||||||
return super.focusSearch(this, direction);
|
return super.focusSearch(this, direction);
|
||||||
@@ -1393,8 +1402,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
|||||||
// as closer to the bottom as possible.
|
// as closer to the bottom as possible.
|
||||||
if (focused == this) {
|
if (focused == this) {
|
||||||
final int childCount = getChildCount();
|
final int childCount = getChildCount();
|
||||||
if (childCount > 0) {
|
for (int i = childCount - 1; i >= 0; i--) {
|
||||||
return super.focusSearch(getChildAt(childCount - 1), direction);
|
View child = getChildAt(i);
|
||||||
|
if (child.getVisibility() == View.VISIBLE) {
|
||||||
|
return super.focusSearch(child, direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.focusSearch(this, direction);
|
return super.focusSearch(this, direction);
|
||||||
}
|
}
|
||||||
@@ -1410,28 +1422,39 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
|||||||
// in the previous item since in reverse the item contents
|
// in the previous item since in reverse the item contents
|
||||||
// get accessibility focus before the item itself.
|
// get accessibility focus before the item itself.
|
||||||
if (currentItem == focused) {
|
if (currentItem == focused) {
|
||||||
// This list gets accessibility focus after the last first item.
|
currentItem = null;
|
||||||
final int previoustPosition = currentPosition - getFirstVisiblePosition() - 1;
|
focused = null;
|
||||||
if (previoustPosition < 0) {
|
// This list gets accessibility focus after the last item.
|
||||||
|
final int previousPosition = currentPosition - getFirstVisiblePosition() - 1;
|
||||||
|
for (int i = previousPosition; i >= 0; i--) {
|
||||||
|
View child = getChildAt(i);
|
||||||
|
if (child.getVisibility() == View.VISIBLE) {
|
||||||
|
currentItem = child;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentItem == null) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
currentItem = getChildAt(previoustPosition);
|
|
||||||
focused = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for into the item.
|
if (currentItem.getVisibility() == View.VISIBLE) {
|
||||||
if (currentItem instanceof ViewGroup) {
|
// Search into the item.
|
||||||
ViewGroup currentItemGroup = (ViewGroup) currentItem;
|
if (currentItem instanceof ViewGroup) {
|
||||||
View nextFocus = FocusFinder.getInstance().findNextFocus(currentItemGroup,
|
ViewGroup currentItemGroup = (ViewGroup) currentItem;
|
||||||
focused, direction);
|
View nextFocus = FocusFinder.getInstance().findNextFocus(currentItemGroup,
|
||||||
if (nextFocus != null && nextFocus != currentItemGroup
|
focused, direction);
|
||||||
&& nextFocus != focused) {
|
if (nextFocus != null && nextFocus != currentItemGroup
|
||||||
return nextFocus;
|
&& nextFocus != focused) {
|
||||||
|
return nextFocus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If not item content wants focus we give it to the item.
|
||||||
|
return currentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not item content wants focus we give it to the item.
|
return super.focusSearch(this, direction);
|
||||||
return currentItem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.focusSearch(focused, direction);
|
return super.focusSearch(focused, direction);
|
||||||
|
|||||||
Reference in New Issue
Block a user