Merge "Make AdapterView auto-focusable-aware" into oc-dev

This commit is contained in:
Evan Rosky
2017-04-12 00:02:21 +00:00
committed by Android (Google) Code Review

View File

@@ -216,7 +216,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
* @see #setFocusable(boolean)
* @see #checkFocus()
*/
private boolean mDesiredFocusableState;
private int mDesiredFocusableState = FOCUSABLE_AUTO;
private boolean mDesiredFocusableInTouchModeState;
/** Lazily-constructed runnable for dispatching selection events. */
@@ -250,6 +250,12 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
}
mDesiredFocusableState = getFocusable();
if (mDesiredFocusableState == FOCUSABLE_AUTO) {
// Starts off without an adapter, so NOT_FOCUSABLE by default.
super.setFocusable(NOT_FOCUSABLE);
}
}
/**
@@ -710,16 +716,16 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
}
@Override
public void setFocusable(boolean focusable) {
public void setFocusable(@Focusable int focusable) {
final T adapter = getAdapter();
final boolean empty = adapter == null || adapter.getCount() == 0;
mDesiredFocusableState = focusable;
if (!focusable) {
if ((focusable & (FOCUSABLE_AUTO | FOCUSABLE)) == 0) {
mDesiredFocusableInTouchModeState = false;
}
super.setFocusable(focusable && (!empty || isInFilterMode()));
super.setFocusable((!empty || isInFilterMode()) ? focusable : NOT_FOCUSABLE);
}
@Override
@@ -729,7 +735,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
mDesiredFocusableInTouchModeState = focusable;
if (focusable) {
mDesiredFocusableState = true;
mDesiredFocusableState = FOCUSABLE;
}
super.setFocusableInTouchMode(focusable && (!empty || isInFilterMode()));
@@ -743,7 +749,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
// for the client, see View.setFocusableInTouchMode() comments for more
// details
super.setFocusableInTouchMode(focusable && mDesiredFocusableInTouchModeState);
super.setFocusable(focusable && mDesiredFocusableState);
super.setFocusable(focusable ? mDesiredFocusableState : NOT_FOCUSABLE);
if (mEmptyView != null) {
updateEmptyStatus((adapter == null) || adapter.isEmpty());
}