Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.ui.widget; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.content.res.TypedArray; | |
| 9 import android.util.AttributeSet; | |
| 10 import android.widget.TextView; | |
| 11 | |
| 12 import org.chromium.ui.R; | |
| 13 | |
| 14 /** | |
| 15 * A TextView with the added leading property. | |
| 16 * Leading is the distance between the baselines of successive lines of text (so the space between | |
| 17 * rules on ruled paper). This class performs the calculation to setup leading c orrectly and allows | |
| 18 * it to be set in XML. It overwrites android:lineSpacingExtra and android:lineS pacingMultiplier. | |
| 19 */ | |
| 20 public class TextViewWithLeading extends TextView { | |
| 21 // TODO(peconn): Add a lint check to ensure no lineSpacingExtr or lineSpacin gMultiplier. | |
| 22 public TextViewWithLeading(Context context, AttributeSet attrs) { | |
| 23 super(context, attrs); | |
| 24 | |
| 25 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextVie wWithLeading, 0, 0); | |
| 26 if (a.hasValue(R.styleable.TextViewWithLeading_leading)) { | |
| 27 final float leading = a.getDimension(R.styleable.TextViewWithLeading _leading, 0f); | |
| 28 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
| |
| 29 setLineSpacing(leading - oldLeading, 1f); | |
| 30 } | |
| 31 | |
| 32 a.recycle(); | |
| 33 } | |
| 34 } | |
| OLD | NEW |