From 18811dfb457eff8ba8b5436bd2641a4215480cdf Mon Sep 17 00:00:00 2001 From: Ben Komalo Date: Mon, 18 Jul 2011 17:53:45 -0700 Subject: [PATCH] Add touch slop to message list items Bug: 5016987 Change-Id: Iddeb9a7bc244d3215a418f0897778b9ddcb3e955 --- .../email/activity/MessageListItem.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/activity/MessageListItem.java b/src/com/android/email/activity/MessageListItem.java index 8f24a2351..19c6a3310 100644 --- a/src/com/android/email/activity/MessageListItem.java +++ b/src/com/android/email/activity/MessageListItem.java @@ -17,6 +17,7 @@ package com.android.email.activity; import android.content.Context; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -427,16 +428,37 @@ public class MessageListItem extends View { mAdapter = adapter; } + + private static final int TOUCH_SLOP = 16; + private static int sScaledTouchSlop = -1; + + private void initializeSlop(Context context) { + if (sScaledTouchSlop == -1) { + final Resources res = context.getResources(); + final Configuration config = res.getConfiguration(); + final float density = res.getDisplayMetrics().density; + final float sizeAndDensity; + if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) { + sizeAndDensity = density * 1.5f; + } else { + sizeAndDensity = density; + } + sScaledTouchSlop = (int) (sizeAndDensity * TOUCH_SLOP + 0.5f); + } + } + /** * Overriding this method allows us to "catch" clicks in the checkbox or star * and process them accordingly. */ @Override public boolean onTouchEvent(MotionEvent event) { + initializeSlop(getContext()); + boolean handled = false; int touchX = (int) event.getX(); - int checkRight = mCoordinates.checkmarkWidthIncludingMargins; - int starLeft = mViewWidth - mCoordinates.starWidthIncludingMargins; + int checkRight = mCoordinates.checkmarkWidthIncludingMargins + sScaledTouchSlop; + int starLeft = mViewWidth - mCoordinates.starWidthIncludingMargins - sScaledTouchSlop; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: