Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/widget/TextViewWithLeading.java |
| diff --git a/ui/android/java/src/org/chromium/ui/widget/TextViewWithLeading.java b/ui/android/java/src/org/chromium/ui/widget/TextViewWithLeading.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b41635a12f7daac382cd1458267f7840804033d |
| --- /dev/null |
| +++ b/ui/android/java/src/org/chromium/ui/widget/TextViewWithLeading.java |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.ui.widget; |
| + |
| +import android.content.Context; |
| +import android.content.res.TypedArray; |
| +import android.util.AttributeSet; |
| +import android.widget.TextView; |
| + |
| +import org.chromium.ui.R; |
| + |
| +/** |
| + * A TextView with the added leading property. |
| + * Leading is the distance between the baselines of successive lines of text (so the space between |
| + * rules on ruled paper). This class performs the calculation to setup leading correctly and allows |
| + * it to be set in XML. It overwrites android:lineSpacingExtra and android:lineSpacingMultiplier. |
| + */ |
| +public class TextViewWithLeading extends TextView { |
| + // TODO(peconn): Add a lint check to ensure no lineSpacingExtr or lineSpacingMultiplier. |
| + public TextViewWithLeading(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + |
| + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextViewWithLeading, 0, 0); |
| + if (a.hasValue(R.styleable.TextViewWithLeading_leading)) { |
| + final float leading = a.getDimension(R.styleable.TextViewWithLeading_leading, 0f); |
| + final float oldLeading = getPaint().getFontMetrics(null); |
|
Ted C
2016/05/11 17:25:53
out of curiosity, did you try this on pre-L?
Dan
|
| + setLineSpacing(leading - oldLeading, 1f); |
| + } |
| + |
| + a.recycle(); |
| + } |
| +} |