summaryrefslogtreecommitdiff
path: root/core/java/android/text/DynamicLayout.java
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2015-03-25 13:18:20 -0700
committerRaph Levien <raph@google.com>2015-04-01 11:01:41 -0700
commit39b4db73c3340ff955f67e4e5318159d19d1ab3a (patch)
tree87132866cf1892b1669981789cc5b2b57aa7ece9 /core/java/android/text/DynamicLayout.java
parent066be66d6060c3dd23a84690a396d1df12c6404d (diff)
Add breakStrategy attribute to TextView
This patch adds plumbing to TextView to control the strategy used for breaking paragraphs into lines. The default for TextView is "quality", while the default for EditText is "simple", largely to avoid too much re-layout when editing. StaticLayout now has a builder which provides access to more functionality and is also cleaner than the old mechanism of having lots of constructors with varying numbers of arguments. This patch changes TextView to use that builder, and also contains cleanups of the Builder within StaticLayout. Change-Id: Iee3cf3a05a3e51ba0834554e4a3ec606e9cabca5
Diffstat (limited to 'core/java/android/text/DynamicLayout.java')
-rw-r--r--core/java/android/text/DynamicLayout.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index 7d2e1ef757b5..239b3869c9d9 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -79,7 +79,8 @@ public class DynamicLayout extends Layout
boolean includepad,
TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
this(base, display, paint, width, align, TextDirectionHeuristics.FIRSTSTRONG_LTR,
- spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth);
+ spacingmult, spacingadd, includepad, StaticLayout.BREAK_STRATEGY_SIMPLE,
+ ellipsize, ellipsizedWidth);
}
/**
@@ -95,7 +96,7 @@ public class DynamicLayout extends Layout
TextPaint paint,
int width, Alignment align, TextDirectionHeuristic textDir,
float spacingmult, float spacingadd,
- boolean includepad,
+ boolean includepad, int breakStrategy,
TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
super((ellipsize == null)
? display
@@ -120,6 +121,7 @@ public class DynamicLayout extends Layout
mObjects = new PackedObjectVector<Directions>(1);
mIncludePad = includepad;
+ mBreakStrategy = breakStrategy;
/*
* This is annoying, but we can't refer to the layout until
@@ -279,10 +281,9 @@ public class DynamicLayout extends Layout
sBuilder = null;
}
- // TODO: make sure reflowed is properly initialized
if (reflowed == null) {
reflowed = new StaticLayout(null);
- b = StaticLayout.Builder.obtain();
+ b = StaticLayout.Builder.obtain(text, where, where + after, getWidth());
}
b.setText(text, where, where + after)
@@ -292,7 +293,8 @@ public class DynamicLayout extends Layout
.setSpacingMult(getSpacingMultiplier())
.setSpacingAdd(getSpacingAdd())
.setEllipsizedWidth(mEllipsizedWidth)
- .setEllipsize(mEllipsizeAt);
+ .setEllipsize(mEllipsizeAt)
+ .setBreakStrategy(mBreakStrategy);
reflowed.generate(b, false, true);
int n = reflowed.getLineCount();
@@ -717,6 +719,7 @@ public class DynamicLayout extends Layout
private boolean mEllipsize;
private int mEllipsizedWidth;
private TextUtils.TruncateAt mEllipsizeAt;
+ private int mBreakStrategy;
private PackedIntVector mInts;
private PackedObjectVector<Directions> mObjects;