1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.Q;
import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.graphics.text.LineBreaker;
import org.robolectric.annotation.InDevelopment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.nativeruntime.DefaultNativeRuntimeLoader;
import org.robolectric.nativeruntime.LineBreakerNatives;
import org.robolectric.shadows.ShadowNativeLineBreaker.Picker;
import org.robolectric.versioning.AndroidVersions.U;
import org.robolectric.versioning.AndroidVersions.V;
/** Shadow for {@link LineBreaker} that is backed by native code */
@Implements(
value = LineBreaker.class,
minSdk = Q,
shadowPicker = Picker.class,
callNativeMethodsByDefault = true)
public class ShadowNativeLineBreaker {
@Implementation(minSdk = V.SDK_INT)
@InDevelopment
protected static void __staticInitializer__() {}
@Implementation(maxSdk = U.SDK_INT)
protected static long nInit(
int breakStrategy, int hyphenationFrequency, boolean isJustified, int[] indents) {
return LineBreakerNatives.nInit(breakStrategy, hyphenationFrequency, isJustified, indents);
}
@Implementation(maxSdk = U.SDK_INT)
protected static long nGetReleaseFunc() {
// Called first by the static initializer.
DefaultNativeRuntimeLoader.injectAndLoad();
return LineBreakerNatives.nGetReleaseFunc();
}
@Implementation(maxSdk = U.SDK_INT)
protected static long nComputeLineBreaks(
long nativePtr,
char[] text,
long measuredTextPtr,
@IntRange(from = 0) int length,
@FloatRange(from = 0.0f) float firstWidth,
@IntRange(from = 0) int firstWidthLineCount,
@FloatRange(from = 0.0f) float restWidth,
float[] variableTabStops,
float defaultTabStop,
@IntRange(from = 0) int indentsOffset) {
return LineBreakerNatives.nComputeLineBreaks(
nativePtr,
text,
measuredTextPtr,
length,
firstWidth,
firstWidthLineCount,
restWidth,
variableTabStops,
defaultTabStop,
indentsOffset);
}
// Result accessors
@Implementation(maxSdk = U.SDK_INT)
protected static int nGetLineCount(long ptr) {
return LineBreakerNatives.nGetLineCount(ptr);
}
@Implementation(maxSdk = U.SDK_INT)
protected static int nGetLineBreakOffset(long ptr, int idx) {
return LineBreakerNatives.nGetLineBreakOffset(ptr, idx);
}
@Implementation(maxSdk = U.SDK_INT)
protected static float nGetLineWidth(long ptr, int idx) {
return LineBreakerNatives.nGetLineWidth(ptr, idx);
}
@Implementation(maxSdk = U.SDK_INT)
protected static float nGetLineAscent(long ptr, int idx) {
return LineBreakerNatives.nGetLineAscent(ptr, idx);
}
@Implementation(maxSdk = U.SDK_INT)
protected static float nGetLineDescent(long ptr, int idx) {
return LineBreakerNatives.nGetLineDescent(ptr, idx);
}
@Implementation(maxSdk = U.SDK_INT)
protected static int nGetLineFlag(long ptr, int idx) {
return LineBreakerNatives.nGetLineFlag(ptr, idx);
}
@Implementation(maxSdk = U.SDK_INT)
protected static long nGetReleaseResultFunc() {
return LineBreakerNatives.nGetReleaseResultFunc();
}
/** Shadow picker for {@link LineBreaker}. */
public static final class Picker extends GraphicsShadowPicker<Object> {
public Picker() {
super(ShadowLineBreaker.class, ShadowNativeLineBreaker.class);
}
}
}
|