1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/widget/GeckoViewFlipper.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.widget; 1.10 + 1.11 +import org.mozilla.gecko.animation.ViewHelper; 1.12 + 1.13 +import android.content.Context; 1.14 +import android.graphics.Rect; 1.15 +import android.os.Build; 1.16 +import android.view.MotionEvent; 1.17 +import android.widget.ViewFlipper; 1.18 +import android.util.Log; 1.19 +import android.util.AttributeSet; 1.20 + 1.21 +/* This extends the normal ViewFlipper only to fix bug 956075 on < 3.0 devices. 1.22 + * i.e. It ignores touch events on the ViewFlipper when its hidden. */ 1.23 + 1.24 +public class GeckoViewFlipper extends ViewFlipper { 1.25 + private static final String LOGTAG = "GeckoViewFlipper"; 1.26 + private Rect mRect = new Rect(); 1.27 + 1.28 + public GeckoViewFlipper(Context context) { 1.29 + super(context); 1.30 + } 1.31 + 1.32 + public GeckoViewFlipper(Context context, AttributeSet attrs) { 1.33 + super(context, attrs); 1.34 + } 1.35 + 1.36 + @Override 1.37 + public boolean dispatchTouchEvent(MotionEvent ev) { 1.38 + if (Build.VERSION.SDK_INT < 11) { 1.39 + // Fix bug 956075. Don't allow touching this View if its hidden. 1.40 + getHitRect(mRect); 1.41 + mRect.offset((int) ViewHelper.getTranslationX(this), (int) ViewHelper.getTranslationY(this)); 1.42 + 1.43 + if (!mRect.contains((int) ev.getX(), (int) ev.getY())) { 1.44 + return false; 1.45 + } 1.46 + } 1.47 + 1.48 + return super.dispatchTouchEvent(ev); 1.49 + } 1.50 +}