diff options
author | Diego Perez <diegoperez@google.com> | 2015-03-09 10:43:18 +0000 |
---|---|---|
committer | Diego Perez <diegoperez@google.com> | 2015-03-10 13:51:01 +0000 |
commit | fe12aa77743c4a4a98409418a6cbb0be11b8fee5 (patch) | |
tree | 64d0ab05a9af74ecb22a543c6299858576621868 /tools | |
parent | 7f602b75eec50ffeb07657bdb0310144dc90df9b (diff) | |
download | frameworks_base-fe12aa77743c4a4a98409418a6cbb0be11b8fee5.zip frameworks_base-fe12aa77743c4a4a98409418a6cbb0be11b8fee5.tar.gz frameworks_base-fe12aa77743c4a4a98409418a6cbb0be11b8fee5.tar.bz2 |
Add support for the new native Builder class on StaticLayout.
This patch updates StaticLayout_Delegate to support the new Builder
class introduced in ag/646289.
Change-Id: I9f8c528b8751ce69482e33ac6f1bc42406a0b606
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/android/text/StaticLayout_Delegate.java | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/tools/layoutlib/bridge/src/android/text/StaticLayout_Delegate.java b/tools/layoutlib/bridge/src/android/text/StaticLayout_Delegate.java index 929d625..e24b3d5 100644 --- a/tools/layoutlib/bridge/src/android/text/StaticLayout_Delegate.java +++ b/tools/layoutlib/bridge/src/android/text/StaticLayout_Delegate.java @@ -1,6 +1,7 @@ package android.text; import com.android.annotations.NonNull; +import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.text.StaticLayout.LineBreaks; @@ -27,14 +28,19 @@ public class StaticLayout_Delegate { private static final char CHAR_NEWLINE = 0x0A; private static final char CHAR_ZWSP = 0x200B; // Zero width space. + // ---- Builder delegate manager ---- + private static final DelegateManager<Builder> sBuilderManager = + new DelegateManager<Builder>(Builder.class); + @LayoutlibDelegate - /*package*/ static int nComputeLineBreaks(String locale, char[] inputText, float[] widths, + /*package*/ static int nComputeLineBreaks(long nativeBuilder, char[] inputText, float[] widths, int length, float firstWidth, int firstWidthLineCount, float restWidth, int[] variableTabStops, int defaultTabStop, boolean optimize, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, boolean[] recycleFlags, int recycleLength) { + Builder builder = sBuilderManager.getDelegate(nativeBuilder); // compute all possible breakpoints. - BreakIterator it = BreakIterator.getLineInstance(new ULocale(locale)); + BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale)); it.setText(new Segment(inputText, 0, length)); // average word length in english is 5. So, initialize the possible breaks with a guess. List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d)); @@ -97,4 +103,32 @@ public class StaticLayout_Delegate { PrimitiveType.PENALTY.getNewPrimitive(length, 0, -PrimitiveType.PENALTY_INFINITY)); return primitives; } + + @LayoutlibDelegate + /*package*/ static long nNewBuilder() { + return sBuilderManager.addNewDelegate(new Builder()); + } + + @LayoutlibDelegate + /*package*/ static void nFinishBuilder(long nativeBuilder) { + } + + @LayoutlibDelegate + /*package*/ static void nFreeBuilder(long nativeBuilder) { + sBuilderManager.removeJavaReferenceFor(nativeBuilder); + } + + @LayoutlibDelegate + /*package*/ static void nBuilderSetLocale(long nativeBuilder, String locale) { + Builder builder = sBuilderManager.getDelegate(nativeBuilder); + builder.mLocale = locale; + } + + /** + * Java representation of the native Builder class. It currently only stores the locale + * set by nBuilderSetLocale. + */ + static class Builder { + String mLocale; + } } |