Bug 1462299 - input[date] unusable on Android 4.x. r=jchen, a=lizzard
authorPetru Lingurar <petru.lingurar@softvision.ro>
Tue, 10 Jul 2018 11:26:01 +0300
changeset 480840 7480f990a1045fa8a9975d02debbb2df8339d943
parent 480839 0fc394c4200944c32d4ee096010c16258d4399f8
child 480841 6eea74660c1c42b43bb4ee8fd20204c043455eea
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, lizzard
bugs1462299, 1460585
milestone62.0
Bug 1462299 - input[date] unusable on Android 4.x. r=jchen, a=lizzard The issue stemmed from platform's DatePicker. To make amends and fix both this bug and Bug 1460585 I went with hiding the calendar and showing only the spinners for Api <21. MozReview-Commit-ID: CS9pFdlMSTd
mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
--- a/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
+++ b/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.prompts;
 
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.widget.AllCapsTextView;
 import org.mozilla.gecko.widget.DateTimePicker;
 
 import android.content.Context;
 import android.content.res.Configuration;
 import android.support.design.widget.TextInputLayout;
 import android.text.Html;
@@ -184,16 +185,26 @@ public abstract class PromptInput {
                         calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(mValue));
                         input.updateDate(calendar.get(Calendar.YEAR),
                                          calendar.get(Calendar.MONTH),
                                          calendar.get(Calendar.DAY_OF_MONTH));
                     }
                 } catch (Exception e) {
                     Log.e(LOGTAG, "error parsing format string: " + e);
                 }
+
+                // The Material CalendarView is only available on Android >= API 21
+                // Prior to this, using DatePicker with CalendarUI would cause issues
+                // such as in Bug 1460585 and Bug 1462299
+                // Because of this, on Android versions earlier than API 21 we'll force use the SpinnerUI
+                if (AppConstants.Versions.preLollipop) {
+                    input.setSpinnersShown(true);
+                    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")) {
                 TimePicker input = new TimePicker(context);
                 input.setIs24HourView(DateFormat.is24HourFormat(context));