diff options
| author | Haoyu Zhang <haoyuchang@google.com> | 2018-11-16 00:19:07 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-11-16 00:19:07 +0000 |
| commit | c826047f85c2f8ab3ac119ffc618df8fdaa3f225 (patch) | |
| tree | 4e443d1d3253cc183452eaf8ebd9c66ef1334aec /core/java/android | |
| parent | 235c7199a871cc01fb281c7febe3368fbe2e70b9 (diff) | |
| parent | d1e6d2e3c6803e7fbc06963e425724dd36516ea7 (diff) | |
Merge "Fix getLineLeft crashes when alignment is null"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/text/Layout.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index c8e0dd291041..2d5f3bf8c862 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -1270,7 +1270,13 @@ public abstract class Layout { */ public float getLineLeft(int line) { final int dir = getParagraphDirection(line); - final Alignment align = getParagraphAlignment(line); + Alignment align = getParagraphAlignment(line); + // Before Q, StaticLayout.Builder.setAlignment didn't check whether the input alignment + // is null. And when it is null, the old behavior is the same as ALIGN_CENTER. + // To keep consistency, we convert a null alignment to ALIGN_CENTER. + if (align == null) { + align = Alignment.ALIGN_CENTER; + } // First convert combinations of alignment and direction settings to // three basic cases: ALIGN_LEFT, ALIGN_RIGHT and ALIGN_CENTER. @@ -1319,7 +1325,13 @@ public abstract class Layout { */ public float getLineRight(int line) { final int dir = getParagraphDirection(line); - final Alignment align = getParagraphAlignment(line); + Alignment align = getParagraphAlignment(line); + // Before Q, StaticLayout.Builder.setAlignment didn't check whether the input alignment + // is null. And when it is null, the old behavior is the same as ALIGN_CENTER. + // To keep consistency, we convert a null alignment to ALIGN_CENTER. + if (align == null) { + align = Alignment.ALIGN_CENTER; + } final Alignment resultAlign; switch(align) { |
