Bug 1474925 - TimePicker swipe not possible in landscape; r?jchen
MozReview-Commit-ID: DVp6d40OLE3
--- a/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
+++ b/mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
@@ -8,16 +8,17 @@ 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 org.mozilla.gecko.widget.FocusableTimePicker;
import android.content.Context;
import android.content.res.Configuration;
import android.support.design.widget.TextInputLayout;
import android.text.Html;
import android.text.InputType;
import android.text.TextUtils;
import android.text.format.DateFormat;
@@ -203,17 +204,18 @@ public abstract class PromptInput {
}
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);
+ // 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 {
calendar.setTime(new SimpleDateFormat("HH:mm").parse(mValue));
} catch (Exception e) { }
}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/FocusableTimePicker.java
@@ -0,0 +1,49 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.widget;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.ViewParent;
+import android.widget.TimePicker;
+
+/**
+ * This is based on the platform's {@link TimePicker}.<br>
+ * The only difference is that it will prevent it's parent from receiving touch events.
+ */
+public class FocusableTimePicker extends TimePicker {
+ public FocusableTimePicker(Context context) {
+ super(context);
+ }
+
+ public FocusableTimePicker(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public FocusableTimePicker(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @SuppressLint("NewApi")
+ public FocusableTimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ ViewParent parentView = getParent();
+
+ if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
+ if (parentView != null) {
+ parentView.requestDisallowInterceptTouchEvent(true);
+ }
+ }
+
+ return false;
+ }
+}