Bug 1097193 - Increase close button hit area in tabs panel (r=lucasr)

This commit is contained in:
Martyn Haigh 2014-11-17 14:03:49 +00:00
parent 7925fb0e28
commit 963757124b

View File

@ -12,6 +12,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewTreeObserver;
@ -93,12 +94,21 @@ public class TabsLayoutItemView extends LinearLayout
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
final Rect r = new Rect();
mCloseButton.getHitRect(r);
r.left -= 25;
r.bottom += 25;
final Rect hitRect = new Rect();
mCloseButton.getHitRect(hitRect);
setTouchDelegate(new TouchDelegate(r, mCloseButton));
// Ideally we want the close button hit area to be 40x40dp but we are constrained by the height of the parent, so
// we make it as tall as the parent view and 40dp across.
final int targetHitArea = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());;
final View parent = ((View) mCloseButton.getParent());
hitRect.top = 0;
hitRect.right = getWidth();
hitRect.left = getWidth() - targetHitArea;
hitRect.bottom = parent.getHeight();
setTouchDelegate(new TouchDelegate(hitRect, mCloseButton));
return true;
}