summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java2
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java14
2 files changed, 10 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
index 5e7543a..9ea4538 100644
--- a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java
@@ -146,6 +146,8 @@ public class FontFamily_Delegate {
@LayoutlibDelegate
/*package*/ static void nUnrefFamily(long nativePtr) {
+ // Removing the java reference for the object doesn't mean that it's freed for garbage
+ // collection. Typeface_Delegate may still hold a reference for it.
sManager.removeJavaReferenceFor(nativePtr);
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
index ed8f3b4..9746b48 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
@@ -54,7 +54,7 @@ public final class Typeface_Delegate {
// ---- delegate data ----
- private final long[] mFontFamilies; // the reference to FontFamily_Delegate.
+ private final FontFamily_Delegate[] mFontFamilies; // the reference to FontFamily_Delegate.
private int mStyle;
private static long sDefaultTypeface;
@@ -71,8 +71,7 @@ public final class Typeface_Delegate {
public List<Font> getFonts(boolean compact) {
List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
- for (long fontFamily : mFontFamilies) {
- FontFamily_Delegate ffd = FontFamily_Delegate.getDelegate(fontFamily);
+ for (FontFamily_Delegate ffd : mFontFamilies) {
if (ffd != null) {
Font font = ffd.getFont(mStyle, compact);
if (font != null) {
@@ -122,7 +121,11 @@ public final class Typeface_Delegate {
@LayoutlibDelegate
/*package*/ static synchronized long nativeCreateFromArray(long[] familyArray) {
- Typeface_Delegate delegate = new Typeface_Delegate(familyArray, Typeface.NORMAL);
+ FontFamily_Delegate[] fontFamilies = new FontFamily_Delegate[familyArray.length];
+ for (int i = 0; i < familyArray.length; i++) {
+ fontFamilies[i] = FontFamily_Delegate.getDelegate(familyArray[i]);
+ }
+ Typeface_Delegate delegate = new Typeface_Delegate(fontFamilies, Typeface.NORMAL);
return sManager.addNewDelegate(delegate);
}
@@ -153,9 +156,8 @@ public final class Typeface_Delegate {
// ---- Private delegate/helper methods ----
- private Typeface_Delegate(long[] fontFamilies, int style) {
+ private Typeface_Delegate(FontFamily_Delegate[] fontFamilies, int style) {
mFontFamilies = fontFamilies;
mStyle = style;
}
-
}