Bug 1498787 - Support seconds in time inputs r=jchen
authorRob Wu <rob@robwu.nl>
Tue, 16 Oct 2018 15:59:24 +0000
changeset 441483 12fcdbe6ef8d97441fe879432bd664bf1c048ba4
parent 441482 d530c99c2be5dc8f5cfa39f1f965bb9751f274e2
child 441484 f992e8a4e7e61a599e8007bf6dfdcb15a3b132f8
push id34866
push usershindli@mozilla.com
push dateWed, 17 Oct 2018 00:54:47 +0000
treeherdermozilla-central@d4fe026dee75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1498787
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498787 - Support seconds in time inputs r=jchen When a time input expects seconds, e.g. via `<input type=time step=1>`, then the UI should show a way to input seconds. On Nougat, `data:text/html,<input type=time step=1>`, the UI used to show a clock to select hours and minutes. As of this commit, three spinners are shown (HH mm ss), and if 24-hour mode is disabled, four of them (HH mm ss AM). Depends on D8667 Differential Revision: https://phabricator.services.mozilla.com/D8668
mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
--- a/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
+++ b/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
@@ -214,16 +214,24 @@ public abstract class PromptInput {
                     input.setCalendarViewShown(false);
                 }
 
                 mView = (View)input;
             } else if (mType.equals("week")) {
                 DateTimePicker input = new DateTimePicker(context, "yyyy-'W'ww", mValue,
                                                           DateTimePicker.PickersState.WEEK, mMinValue, mMaxValue);
                 mView = (View)input;
+            } else if (mType.equals("time") && mSecondEnabled) {
+                // When seconds are requested, use DateTimePicker since FocusableDatePicker does not support seconds.
+                DateTimePicker input = new DateTimePicker(context, "HH:mm:ss",
+                                                          formatDateTimeSeconds(mValue),
+                                                          DateTimePicker.PickersState.TIME,
+                                                          formatDateTimeSeconds(mMinValue),
+                                                          formatDateTimeSeconds(mMaxValue));
+                mView = (View)input;
             } else if (mType.equals("time")) {
                 // FocusableDatePicker allow us to have priority in responding to scroll events.
                 TimePicker input = new FocusableTimePicker(context);
                 input.setIs24HourView(DateFormat.is24HourFormat(context));
 
                 GregorianCalendar calendar = new GregorianCalendar();
                 if (!TextUtils.isEmpty(mValue)) {
                     try {
@@ -279,16 +287,22 @@ public abstract class PromptInput {
 
         private static String formatDateString(String dateFormat, Calendar calendar) {
             return new SimpleDateFormat(dateFormat).format(calendar.getTime());
         }
 
         @Override
         public Object getValue() {
             if (mType.equals("time")) {
+                if (mSecondEnabled) {
+                    DateTimePicker dp = (DateTimePicker) mView;
+                    GregorianCalendar calendar = new GregorianCalendar();
+                    calendar.setTimeInMillis(dp.getTimeInMillis());
+                    return formatDateString("HH:mm:ss", calendar);
+                }
                 TimePicker tp = (TimePicker)mView;
                 GregorianCalendar calendar =
                     new GregorianCalendar(0, 0, 0, tp.getCurrentHour(), tp.getCurrentMinute());
                 return formatDateString("HH:mm", calendar);
             } else if (mType.equals("date")) {
                 DatePicker dp = (DatePicker) mView;
                 GregorianCalendar calendar =
                         new GregorianCalendar(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
@@ -190,16 +190,22 @@ public class DateTimePicker extends Fram
         set12HourShown(mIs12HourMode);
         if (mState == PickersState.DATETIME) {
             setSecondShown(false);
             return;
         }
         if (mState == PickersState.DATETIME_WITH_SECOND) {
             return;
         }
+        if (mState == PickersState.TIME) {
+            setYearShown(false);
+            setMonthShown(false);
+            setDayShown(false);
+            return;
+        }
 
         setHourShown(false);
         setMinuteShown(false);
         setSecondShown(false);
         if (mState == PickersState.WEEK) {
             setDayShown(false);
             setMonthShown(false);
             setWeekShown(true);
@@ -542,17 +548,17 @@ public class DateTimePicker extends Fram
         }
     }
 
     void notifyDateChanged() {
         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
     }
 
     public void toggleCalendar(boolean shown) {
-        if (mState != PickersState.DATE && mState != PickersState.DATETIME && mState != PickersState.DATETIME_WITH_SECOND) {
+        if (mState != PickersState.DATE && mState != PickersState.DATETIME && mState != PickersState.DATETIME_WITH_SECOND && mState != PickersState.TIME) {
             return;
         }
 
         if (shown) {
             mCalendarEnabled = true;
             mCalendar.setVisibility(VISIBLE);
             setYearShown(false);
             setWeekShown(false);