am 11b14e39: LayoutLib: Use ICU\'s line break algo. [DO NOT MERGE]
* commit '11b14e3996d3602155d6a61afb286e5bc0941a1f': LayoutLib: Use ICU's line break algo. [DO NOT MERGE]
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
package android.text;
|
||||||
|
|
||||||
|
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
|
||||||
|
|
||||||
|
import java.text.CharacterIterator;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import com.ibm.icu.lang.UCharacter;
|
||||||
|
import com.ibm.icu.text.BreakIterator;
|
||||||
|
import com.ibm.icu.util.ULocale;
|
||||||
|
import javax.swing.text.Segment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate that provides implementation for native methods in {@link android.text.StaticLayout}
|
||||||
|
*
|
||||||
|
* Through the layoutlib_create tool, selected methods of Handler have been replaced
|
||||||
|
* by calls to methods of the same name in this delegate class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StaticLayout_Delegate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the recycle array with positions that are suitable to break the text at. The array
|
||||||
|
* must be terminated by '-1'.
|
||||||
|
*/
|
||||||
|
@LayoutlibDelegate
|
||||||
|
/*package*/ static int[] nLineBreakOpportunities(String locale, char[] text, int length,
|
||||||
|
int[] recycle) {
|
||||||
|
BreakIterator iterator = BreakIterator.getLineInstance(new ULocale(locale));
|
||||||
|
Segment segment = new Segment(text, 0, length);
|
||||||
|
iterator.setText(segment);
|
||||||
|
if (recycle == null) {
|
||||||
|
// Because 42 is the answer to everything.
|
||||||
|
recycle = new int[42];
|
||||||
|
}
|
||||||
|
int breakOpp = iterator.first();
|
||||||
|
recycle[0] = breakOpp;
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
assert BreakIterator.DONE == -1;
|
||||||
|
for (int i = 1; breakOpp != BreakIterator.DONE; ++i) {
|
||||||
|
if (i >= recycle.length) {
|
||||||
|
recycle = doubleSize(recycle);
|
||||||
|
}
|
||||||
|
assert (i < recycle.length);
|
||||||
|
breakOpp = iterator.next();
|
||||||
|
recycle[i] = breakOpp;
|
||||||
|
}
|
||||||
|
return recycle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] doubleSize(int[] array) {
|
||||||
|
return Arrays.copyOf(array, array.length * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -193,6 +193,7 @@ public final class CreateInfo implements ICreateInfo {
|
|||||||
"android.os.SystemClock",
|
"android.os.SystemClock",
|
||||||
"android.os.SystemProperties",
|
"android.os.SystemProperties",
|
||||||
"android.text.AndroidBidi",
|
"android.text.AndroidBidi",
|
||||||
|
"android.text.StaticLayout",
|
||||||
"android.text.format.Time",
|
"android.text.format.Time",
|
||||||
"android.util.FloatMath",
|
"android.util.FloatMath",
|
||||||
"android.view.Display",
|
"android.view.Display",
|
||||||
|
|||||||
Reference in New Issue
Block a user