Skip to content

Commit

Permalink
Fix zero-width text views for LEGACY graphics in Android U+
Browse files Browse the repository at this point in the history
Previously, in Android U, for LEGACY graphics, TextViews were always considered
to be zero-width. Add a shadow implementation for Paint.nGetRunCharacterAdvance
in U. This logic is used in the TextView width calculation. Also preemptively
add support for it in V, where the signature has already changed.

This also fixes the Robolectric EspressoTest when running with LEGACY graphics.

PiperOrigin-RevId: 576275359
  • Loading branch information
hoisie committed Oct 27, 2023
1 parent d068642 commit a29c7a6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
3 changes: 0 additions & 3 deletions integration_tests/androidx_test/build.gradle
Expand Up @@ -25,9 +25,6 @@ android {
testOptions {
unitTests {
includeAndroidResources = true
all {
systemProperty 'robolectric.graphicsMode', 'NATIVE'
}
}
}
sourceSets {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.PathEffect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Typeface;
import org.robolectric.annotation.Implementation;
Expand Down Expand Up @@ -559,6 +560,47 @@ protected static float nGetRunAdvance(
return 0f;
}

@Implementation(minSdk = U.SDK_INT, maxSdk = U.SDK_INT)
protected static float nGetRunCharacterAdvance(
long paintPtr,
char[] text,
int start,
int end,
int contextStart,
int contextEnd,
boolean isRtl,
int offset,
float[] advances,
int advancesIndex) {
return nGetRunAdvance(paintPtr, text, start, end, contextStart, contextEnd, isRtl, offset);
}

@Implementation(minSdk = V.SDK_INT)
protected static float nGetRunCharacterAdvance(
long paintPtr,
char[] text,
int start,
int end,
int contextStart,
int contextEnd,
boolean isRtl,
int offset,
float[] advances,
int advancesIndex,
RectF drawingBounds) {
return nGetRunCharacterAdvance(
paintPtr,
text,
start,
end,
contextStart,
contextEnd,
isRtl,
offset,
advances,
advancesIndex);
}

@Implementation(minSdk = N, maxSdk = O_MR1)
protected static float nGetRunAdvance(
long paintPtr,
Expand Down

0 comments on commit a29c7a6

Please sign in to comment.