Bug 1474925 - TimePicker swipe not possible in landscape; r?jchen draft
authorPetru Lingurar <petru.lingurar@softvision.ro>
Wed, 18 Jul 2018 10:23:09 +0300
changeset 819606 3c2391143a1bdce18286c2030586e130c3fee330
parent 819486 afa310dc89beeb4b7a9564d2c89ff32906f427ad
push id116595
push userplingurar@mozilla.com
push dateWed, 18 Jul 2018 07:27:37 +0000
reviewersjchen
bugs1474925
milestone63.0a1
Bug 1474925 - TimePicker swipe not possible in landscape; r?jchen MozReview-Commit-ID: DVp6d40OLE3
mobile/android/base/java/org/mozilla/gecko/prompts/PromptInput.java
mobile/android/base/java/org/mozilla/gecko/widget/FocusableTimePicker.java
--- 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;
+    }
+}