Bug 1347476 - [RTL] Update TouchDelegate Rect for tab close button relatively, r=sebastian
MozReview-Commit-ID: 2ptzHWBVvUq
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
@@ -10,16 +10,17 @@ import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.widget.TabThumbnailWrapper;
import org.mozilla.gecko.widget.TouchDelegateWithReset;
import org.mozilla.gecko.widget.themed.ThemedRelativeLayout;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.TextViewCompat;
+import android.support.v7.widget.ViewUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -104,29 +105,35 @@ public class TabsLayoutItemView extends
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
// 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 Rect hitRect = new Rect();
- hitRect.top = 0;
- hitRect.right = getWidth();
- hitRect.left = getWidth() - targetHitArea;
- hitRect.bottom = targetHitArea;
+ final Rect hitRect = getHitRectRelatively(targetHitArea);
setTouchDelegate(new TouchDelegateWithReset(hitRect, mCloseButton));
return true;
}
});
}
+ private Rect getHitRectRelatively(int targetHitArea) {
+ final boolean isRtl = ViewUtils.isLayoutRtl(this);
+ final Rect hitRect = new Rect();
+ hitRect.top = 0;
+ hitRect.right = isRtl ? targetHitArea : getWidth();
+ hitRect.left = isRtl ? 0 : getWidth() - targetHitArea;
+ hitRect.bottom = targetHitArea;
+ return hitRect;
+ }
+
protected void assignValues(Tab tab) {
if (tab == null) {
return;
}
mTabId = tab.getId();
setChecked(Tabs.getInstance().isSelectedTab(tab));