Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: ui/android/java/src/org/chromium/ui/widget/TextViewWithLeading.java

Issue 1955813002: Create TextViewWithLeading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/java/res/values/attrs.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ }
+}
« no previous file with comments | « ui/android/java/res/values/attrs.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698