michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.widget; michael@0: michael@0: import org.mozilla.gecko.animation.ViewHelper; michael@0: michael@0: import android.content.Context; michael@0: import android.graphics.Rect; michael@0: import android.os.Build; michael@0: import android.view.MotionEvent; michael@0: import android.widget.ViewFlipper; michael@0: import android.util.Log; michael@0: import android.util.AttributeSet; michael@0: michael@0: /* This extends the normal ViewFlipper only to fix bug 956075 on < 3.0 devices. michael@0: * i.e. It ignores touch events on the ViewFlipper when its hidden. */ michael@0: michael@0: public class GeckoViewFlipper extends ViewFlipper { michael@0: private static final String LOGTAG = "GeckoViewFlipper"; michael@0: private Rect mRect = new Rect(); michael@0: michael@0: public GeckoViewFlipper(Context context) { michael@0: super(context); michael@0: } michael@0: michael@0: public GeckoViewFlipper(Context context, AttributeSet attrs) { michael@0: super(context, attrs); michael@0: } michael@0: michael@0: @Override michael@0: public boolean dispatchTouchEvent(MotionEvent ev) { michael@0: if (Build.VERSION.SDK_INT < 11) { michael@0: // Fix bug 956075. Don't allow touching this View if its hidden. michael@0: getHitRect(mRect); michael@0: mRect.offset((int) ViewHelper.getTranslationX(this), (int) ViewHelper.getTranslationY(this)); michael@0: michael@0: if (!mRect.contains((int) ev.getX(), (int) ev.getY())) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return super.dispatchTouchEvent(ev); michael@0: } michael@0: }