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

am: 7d6bf45428

Change-Id: I1f44573ac5aa04c097f7d93298e27d99c54c6ce8
This commit is contained in:
Evan Rosky
2017-04-12 00:11:54 +00:00
committed by android-build-merger

View File

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