Bug 1331431 - Use baseline and FontMetrics instead of textview's center and text size to get the real text height. r=sebastian
authorNevin Chen <cnevinchen@gmail.com>
Wed, 18 Jan 2017 17:59:23 +0800
changeset 377543 21e0b0c5284a9f2bad562a79764b0de32be7ec74
parent 377542 8bfeb8f4a4f5f63b220e18ee817f90281ef4c242
child 377544 cf116f73a2d29667c763e916003dcba54b55e70e
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1331431
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1331431 - Use baseline and FontMetrics instead of textview's center and text size to get the real text height. r=sebastian MozReview-Commit-ID: 4HJKZP0F0ow
mobile/android/base/java/org/mozilla/gecko/widget/FadedMultiColorTextView.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/FadedMultiColorTextView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/FadedMultiColorTextView.java
@@ -49,22 +49,23 @@ public class FadedMultiColorTextView ext
 
         final boolean needsEllipsis = needsEllipsis();
         if (needsEllipsis) {
             final int right = getWidth() - getCompoundPaddingRight();
             final float left = right - fadeWidth;
 
             updateGradientShader(needsEllipsis, right);
 
-            final float center = getHeight() / 2;
-
             // Shrink height of gradient to prevent it overlaying parent view border.
             // The shrunk size just nee to cover the text itself.
-            final float top = center - getTextSize() / 2;
-            final float bottom = center + getTextSize() / 2;
+            final float density = getResources().getDisplayMetrics().density;
+            final float h = Math.abs(fadePaint.getFontMetrics().top) + 1;
+            final float l = fadePaint.getFontMetrics().bottom + 1;
+            final float top = getBaseline() - h * density;
+            final float bottom = getBaseline() + l * density;
 
             canvas.drawRect(left, top, right, bottom, fadePaint);
         }
     }
 
     private void updateGradientShader(final boolean needsEllipsis, final int gradientEndRight) {
         final int backgroundColor =
                 fadeBackgroundColorList.getColorForState(getDrawableState(), Color.RED);