Skip to content

Commit 912ab85

Browse files
committed
Revamp of the NumberPicker widget.
1. The number picker no longer shows up and down arrows, it has only three touch targets which are the currently selected number in the middle with a lesser one above and greater below, now what you touch is what you get, flingability and long press are still supported. 2. Removed the restriction for a View with an AccessibilityNodeProvider to not have any concrete children. If the View has a provider, then this provider is responsible for creating the AccessibilityNodeInfos for all its descendants, concrete and virtual. The number picker is a good example for such a case - it has a concrete input view and two virtual buttons as its children. This is a safe change since this behavior has not been released. 3. This patch also fixes bug where the number picker is stretched too much in the Theme theme. bug:6177794 bug:5728294 Change-Id: Id8c0b3549174b9599f971d6e3086ca427cfbaa39
1 parent 958ec9d commit 912ab85

File tree

89 files changed

+820
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+820
-901
lines changed

api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26924,7 +26924,6 @@ package android.widget {
2692426924
method public void setOnValueChangedListener(android.widget.NumberPicker.OnValueChangeListener);
2692526925
method public void setValue(int);
2692626926
method public void setWrapSelectorWheel(boolean);
26927-
field public static final int SELECTOR_WHEEL_ITEM_COUNT = 5; // 0x5
2692826927
}
2692926928

2693026929
public static abstract interface NumberPicker.Formatter {

core/java/android/view/ViewGroup.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,15 +2679,6 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
26792679
return child.draw(canvas, this, drawingTime);
26802680
}
26812681

2682-
@Override
2683-
public void requestLayout() {
2684-
if (mChildrenCount > 0 && getAccessibilityNodeProvider() != null) {
2685-
throw new IllegalStateException("Views with AccessibilityNodeProvider"
2686-
+ " can't have children.");
2687-
}
2688-
super.requestLayout();
2689-
}
2690-
26912682
/**
26922683
*
26932684
* @param enabled True if children should be drawn with layers, false otherwise.
@@ -3109,11 +3100,6 @@ protected void cleanupLayoutState(View child) {
31093100
private void addViewInner(View child, int index, LayoutParams params,
31103101
boolean preventRequestLayout) {
31113102

3112-
if (getAccessibilityNodeProvider() != null) {
3113-
throw new IllegalStateException("Views with AccessibilityNodeProvider"
3114-
+ " can't have children.");
3115-
}
3116-
31173103
if (mTransition != null) {
31183104
// Don't prevent other add transitions from completing, but cancel remove
31193105
// transitions to let them complete the process before we add to the container

core/java/android/widget/DatePicker.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import android.util.Log;
3030
import android.util.SparseArray;
3131
import android.view.LayoutInflater;
32+
import android.view.View;
3233
import android.view.accessibility.AccessibilityEvent;
33-
import android.view.accessibility.AccessibilityManager;
3434
import android.view.accessibility.AccessibilityNodeInfo;
3535
import android.view.inputmethod.EditorInfo;
3636
import android.view.inputmethod.InputMethodManager;
@@ -280,9 +280,7 @@ public void onSelectedDayChange(CalendarView view, int year, int month, int mont
280280
reorderSpinners();
281281

282282
// set content descriptions
283-
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
284-
setContentDescriptions();
285-
}
283+
setContentDescriptions();
286284
}
287285

288286
/**
@@ -717,20 +715,27 @@ private void setImeOptions(NumberPicker spinner, int spinnerCount, int spinnerIn
717715

718716
private void setContentDescriptions() {
719717
// Day
720-
String text = mContext.getString(R.string.date_picker_increment_day_button);
721-
mDaySpinner.findViewById(R.id.increment).setContentDescription(text);
722-
text = mContext.getString(R.string.date_picker_decrement_day_button);
723-
mDaySpinner.findViewById(R.id.decrement).setContentDescription(text);
718+
trySetContentDescription(mDaySpinner, R.id.increment,
719+
R.string.date_picker_increment_day_button);
720+
trySetContentDescription(mDaySpinner, R.id.decrement,
721+
R.string.date_picker_decrement_day_button);
724722
// Month
725-
text = mContext.getString(R.string.date_picker_increment_month_button);
726-
mMonthSpinner.findViewById(R.id.increment).setContentDescription(text);
727-
text = mContext.getString(R.string.date_picker_decrement_month_button);
728-
mMonthSpinner.findViewById(R.id.decrement).setContentDescription(text);
723+
trySetContentDescription(mMonthSpinner, R.id.increment,
724+
R.string.date_picker_increment_month_button);
725+
trySetContentDescription(mMonthSpinner, R.id.decrement,
726+
R.string.date_picker_decrement_month_button);
729727
// Year
730-
text = mContext.getString(R.string.date_picker_increment_year_button);
731-
mYearSpinner.findViewById(R.id.increment).setContentDescription(text);
732-
text = mContext.getString(R.string.date_picker_decrement_year_button);
733-
mYearSpinner.findViewById(R.id.decrement).setContentDescription(text);
728+
trySetContentDescription(mYearSpinner, R.id.increment,
729+
R.string.date_picker_increment_year_button);
730+
trySetContentDescription(mYearSpinner, R.id.decrement,
731+
R.string.date_picker_decrement_year_button);
732+
}
733+
734+
private void trySetContentDescription(View root, int viewId, int contDescResId) {
735+
View target = root.findViewById(viewId);
736+
if (target != null) {
737+
target.setContentDescription(mContext.getString(contDescResId));
738+
}
734739
}
735740

736741
private void updateInputState() {

0 commit comments

Comments
 (0)