Bug 1300144 - Increase touch area for menu button r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 19 Oct 2016 16:32:29 -0700
changeset 427177 98e4cbfef0c65ace9b4214c62d10b1242192a70f
parent 426420 dc89484d4b45abf442162e5ea2dd46f9de40197d
child 427178 25d59819f5aec22ce083dd81168158d18346317d
push id32952
push userahunt@mozilla.com
push dateWed, 19 Oct 2016 23:43:13 +0000
reviewerssebastian
bugs1300144
milestone52.0a1
Bug 1300144 - Increase touch area for menu button r?sebastian MozReview-Commit-ID: GBdLisIwFuH
mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
@@ -2,22 +2,24 @@
  * 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.home.activitystream;
 
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.Color;
+import android.graphics.Rect;
 import android.support.v4.view.ViewPager;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
+import android.view.TouchDelegate;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.home.HomePager;
@@ -75,31 +77,52 @@ public abstract class StreamItem extends
         final TextView vLabel;
         final TextView vTimeSince;
         final TextView vSourceView;
         final TextView vPageView;
 
         private Future<IconResponse> ongoingIconLoad;
         private int tilesMargin;
 
-        public HighlightItem(View itemView) {
+        public HighlightItem(final View itemView) {
             super(itemView);
 
             tilesMargin = itemView.getResources().getDimensionPixelSize(R.dimen.activity_stream_base_margin);
 
             vLabel = (TextView) itemView.findViewById(R.id.card_history_label);
             vTimeSince = (TextView) itemView.findViewById(R.id.card_history_time_since);
             vIconView = (FaviconView) itemView.findViewById(R.id.icon);
             vSourceView = (TextView) itemView.findViewById(R.id.card_history_source);
             vPageView = (TextView) itemView.findViewById(R.id.page);
 
-            ImageView menuButton = (ImageView) itemView.findViewById(R.id.menu);
+            final ImageView menuButton = (ImageView) itemView.findViewById(R.id.menu);
 
             menuButton.setImageDrawable(
                     DrawableUtil.tintDrawable(menuButton.getContext(), R.drawable.menu, Color.LTGRAY));
+
+            itemView.post(new Runnable() {
+                @Override
+                public void run() {
+                    Rect delegateArea = new Rect();
+                    menuButton.getHitRect(delegateArea);
+
+                    final int targetHitArea = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, itemView.getContext().getResources().getDisplayMetrics());;
+
+                    final int widthDelta = (targetHitArea - delegateArea.width()) / 2;
+                    delegateArea.right += widthDelta;
+                    delegateArea.left -= widthDelta;
+
+                    final int heightDelta = (targetHitArea - delegateArea.height()) / 2;
+                    delegateArea.bottom += heightDelta;
+                    delegateArea.top -= heightDelta;
+
+                    TouchDelegate touchDelegate = new TouchDelegate(delegateArea, menuButton);
+                    itemView.setTouchDelegate(touchDelegate);
+                }
+            });
         }
 
         public void bind(Cursor cursor, int tilesWidth, int tilesHeight) {
             final long time = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.DATE));
             final String ago = DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
             final String url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
 
             vLabel.setText(cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.History.TITLE)));