Bug 1245692 - Force height for CalendarView on pre-lollipop r=sebastian
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 03 Jun 2016 08:48:05 -0700
changeset 339352 6666bf0ccb50f6a59f2ce4f6ff5d68dd1f38b762
parent 339351 bf1bb13cc6249d9c807f79e775e0361f2ea2f1bd
child 339353 7e530b2a462aeb163112e30c869442e2d6a54eef
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1245692
milestone49.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 1245692 - Force height for CalendarView on pre-lollipop r=sebastian By default CalendarView doesn't receive sufficient height on pre-lollipop devices, in fact the entire dialog won't even appear unless we manually assign height. This is slightly hacky, but necessary to ensure correct layouting. (We previously assigned both height and width to the CalendarView, however that results in all kinds of odd behaviour - this change is necessary only to have acceptable behaviour on older devices.) MozReview-Commit-ID: H7wzHsrOJy4
mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
@@ -16,24 +16,26 @@
 
 package org.mozilla.gecko.widget;
 
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Locale;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.R;
 
 import android.content.Context;
 import android.text.format.DateFormat;
 import android.text.format.DateUtils;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.Display;
 import android.view.LayoutInflater;
 import android.view.WindowManager;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.CalendarView;
 import android.widget.EditText;
 import android.widget.FrameLayout;
@@ -333,17 +335,27 @@ public class DateTimePicker extends Fram
                 public void onSelectedDayChange(
                     CalendarView view, int year, int month, int monthDay) {
                     mTempDate.set(year, month, monthDay);
                     setDate(mTempDate);
                     notifyDateChanged();
                 }
             });
 
-            mPickers.addView(mCalendar);
+            final int height;
+            if (Versions.preLollipop) {
+                // The 4.X version of CalendarView doesn't request any height, resulting in
+                // the whole dialog not appearing unless we manually request height.
+                height =  (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics());;
+            } else {
+                height = LayoutParams.WRAP_CONTENT;
+            }
+
+            mPickers.addView(mCalendar, LayoutParams.MATCH_PARENT, height);
+
         } else {
             // If the screen is more wide than high, we are displaying day and
             // time spinners, and if there is no calendar displayed, we should
             // display the fields in one row.
             if (mScreenWidth > mScreenHeight && mState == PickersState.DATETIME) {
                 mPickers.setOrientation(LinearLayout.HORIZONTAL);
             }
             mCalendar = null;