Merge "Focus content or button on AlertController"
This commit is contained in:
@@ -559,6 +559,13 @@ public class AlertController {
|
||||
final boolean hasButtonPanel = buttonPanel != null
|
||||
&& buttonPanel.getVisibility() != View.GONE;
|
||||
|
||||
if (!parentPanel.isInTouchMode()) {
|
||||
final View content = hasCustomPanel ? customPanel : contentPanel;
|
||||
if (!requestFocusForContent(content)) {
|
||||
requestFocusForDefaultButton();
|
||||
}
|
||||
}
|
||||
|
||||
// Only display the text spacer if we don't have buttons.
|
||||
if (!hasButtonPanel) {
|
||||
if (contentPanel != null) {
|
||||
@@ -624,6 +631,29 @@ public class AlertController {
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
private boolean requestFocusForContent(View content) {
|
||||
if (content != null && content.requestFocus()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mListView != null) {
|
||||
mListView.setSelection(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void requestFocusForDefaultButton() {
|
||||
if (mButtonPositive.getVisibility() == View.VISIBLE) {
|
||||
mButtonPositive.requestFocus();
|
||||
} else if (mButtonNegative.getVisibility() == View.VISIBLE) {
|
||||
mButtonNegative.requestFocus();
|
||||
} else if (mButtonNeutral.getVisibility() == View.VISIBLE) {
|
||||
mButtonNeutral.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupCustomContent(ViewGroup customPanel) {
|
||||
final View customView;
|
||||
if (mView != null) {
|
||||
|
||||
Reference in New Issue
Block a user