|
31 | 31 | import android.view.LayoutInflater; |
32 | 32 | import android.view.accessibility.AccessibilityEvent; |
33 | 33 | import android.view.accessibility.AccessibilityManager; |
| 34 | +import android.view.inputmethod.EditorInfo; |
34 | 35 | import android.widget.NumberPicker.OnValueChangeListener; |
35 | 36 |
|
36 | 37 | import com.android.internal.R; |
@@ -81,10 +82,10 @@ public class DatePicker extends FrameLayout { |
81 | 82 |
|
82 | 83 | private static final boolean DEFAULT_ENABLED_STATE = true; |
83 | 84 |
|
84 | | - private final NumberPicker mDaySpinner; |
85 | | - |
86 | 85 | private final LinearLayout mSpinners; |
87 | 86 |
|
| 87 | + private final NumberPicker mDaySpinner; |
| 88 | + |
88 | 89 | private final NumberPicker mMonthSpinner; |
89 | 90 |
|
90 | 91 | private final NumberPicker mYearSpinner; |
@@ -481,16 +482,20 @@ private Calendar getCalendarForLocale(Calendar oldCalendar, Locale locale) { |
481 | 482 | private void reorderSpinners() { |
482 | 483 | mSpinners.removeAllViews(); |
483 | 484 | char[] order = DateFormat.getDateFormatOrder(getContext()); |
484 | | - for (int i = 0; i < order.length; i++) { |
| 485 | + final int spinnerCount = order.length; |
| 486 | + for (int i = 0; i < spinnerCount; i++) { |
485 | 487 | switch (order[i]) { |
486 | 488 | case DateFormat.DATE: |
487 | 489 | mSpinners.addView(mDaySpinner); |
| 490 | + setImeOptions(mDaySpinner, spinnerCount, i); |
488 | 491 | break; |
489 | 492 | case DateFormat.MONTH: |
490 | 493 | mSpinners.addView(mMonthSpinner); |
| 494 | + setImeOptions(mMonthSpinner, spinnerCount, i); |
491 | 495 | break; |
492 | 496 | case DateFormat.YEAR: |
493 | 497 | mSpinners.addView(mYearSpinner); |
| 498 | + setImeOptions(mYearSpinner, spinnerCount, i); |
494 | 499 | break; |
495 | 500 | default: |
496 | 501 | throw new IllegalArgumentException(); |
@@ -668,6 +673,42 @@ private void notifyDateChanged() { |
668 | 673 | } |
669 | 674 | } |
670 | 675 |
|
| 676 | + /** |
| 677 | + * Sets the IME options for a spinner based on its ordering. |
| 678 | + * |
| 679 | + * @param spinner The spinner. |
| 680 | + * @param spinnerCount The total spinner count. |
| 681 | + * @param spinnerIndex The index of the given spinner. |
| 682 | + */ |
| 683 | + private void setImeOptions(NumberPicker spinner, int spinnerCount, int spinnerIndex) { |
| 684 | + final int imeOptions; |
| 685 | + if (spinnerIndex < spinnerCount - 1) { |
| 686 | + imeOptions = EditorInfo.IME_ACTION_NEXT; |
| 687 | + } else { |
| 688 | + imeOptions = EditorInfo.IME_ACTION_DONE; |
| 689 | + } |
| 690 | + TextView input = (TextView) spinner.findViewById(R.id.numberpicker_input); |
| 691 | + input.setImeOptions(imeOptions); |
| 692 | + } |
| 693 | + |
| 694 | + private void setContentDescriptions() { |
| 695 | + // Day |
| 696 | + String text = mContext.getString(R.string.date_picker_increment_day_button); |
| 697 | + mDaySpinner.findViewById(R.id.increment).setContentDescription(text); |
| 698 | + text = mContext.getString(R.string.date_picker_decrement_day_button); |
| 699 | + mDaySpinner.findViewById(R.id.decrement).setContentDescription(text); |
| 700 | + // Month |
| 701 | + text = mContext.getString(R.string.date_picker_increment_month_button); |
| 702 | + mMonthSpinner.findViewById(R.id.increment).setContentDescription(text); |
| 703 | + text = mContext.getString(R.string.date_picker_decrement_month_button); |
| 704 | + mMonthSpinner.findViewById(R.id.decrement).setContentDescription(text); |
| 705 | + // Year |
| 706 | + text = mContext.getString(R.string.date_picker_increment_year_button); |
| 707 | + mYearSpinner.findViewById(R.id.increment).setContentDescription(text); |
| 708 | + text = mContext.getString(R.string.date_picker_decrement_year_button); |
| 709 | + mYearSpinner.findViewById(R.id.decrement).setContentDescription(text); |
| 710 | + } |
| 711 | + |
671 | 712 | /** |
672 | 713 | * Class for managing state storing/restoring. |
673 | 714 | */ |
@@ -720,22 +761,4 @@ public SavedState[] newArray(int size) { |
720 | 761 | } |
721 | 762 | }; |
722 | 763 | } |
723 | | - |
724 | | - private void setContentDescriptions() { |
725 | | - // Day |
726 | | - String text = mContext.getString(R.string.date_picker_increment_day_button); |
727 | | - mDaySpinner.findViewById(R.id.increment).setContentDescription(text); |
728 | | - text = mContext.getString(R.string.date_picker_decrement_day_button); |
729 | | - mDaySpinner.findViewById(R.id.decrement).setContentDescription(text); |
730 | | - // Month |
731 | | - text = mContext.getString(R.string.date_picker_increment_month_button); |
732 | | - mMonthSpinner.findViewById(R.id.increment).setContentDescription(text); |
733 | | - text = mContext.getString(R.string.date_picker_decrement_month_button); |
734 | | - mMonthSpinner.findViewById(R.id.decrement).setContentDescription(text); |
735 | | - // Year |
736 | | - text = mContext.getString(R.string.date_picker_increment_year_button); |
737 | | - mYearSpinner.findViewById(R.id.increment).setContentDescription(text); |
738 | | - text = mContext.getString(R.string.date_picker_decrement_year_button); |
739 | | - mYearSpinner.findViewById(R.id.decrement).setContentDescription(text); |
740 | | - } |
741 | 764 | } |
0 commit comments