Merge "Check Bridge init before disposing." into lmp-dev
automerge: 568f16c
* commit '568f16ccfbe95d5a68e3e3a732565a1063d5160e':
Check Bridge init before disposing.
This commit is contained in:
@@ -213,6 +213,10 @@ public class FontFamily_Delegate {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
/*package*/ static String getFontLocation() {
|
||||||
|
return sFontLocation;
|
||||||
|
}
|
||||||
|
|
||||||
// ---- native methods ----
|
// ---- native methods ----
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.graphics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class allowing access to package-protected methods/fields.
|
|
||||||
*/
|
|
||||||
public class Typeface_Accessor {
|
|
||||||
|
|
||||||
public static void resetDefaults() {
|
|
||||||
Typeface.sDefaults = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,6 +27,8 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.graphics.FontFamily_Delegate.getFontLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate implementing the native methods of android.graphics.Typeface
|
* Delegate implementing the native methods of android.graphics.Typeface
|
||||||
*
|
*
|
||||||
@@ -48,8 +50,6 @@ public final class Typeface_Delegate {
|
|||||||
private static final DelegateManager<Typeface_Delegate> sManager =
|
private static final DelegateManager<Typeface_Delegate> sManager =
|
||||||
new DelegateManager<Typeface_Delegate>(Typeface_Delegate.class);
|
new DelegateManager<Typeface_Delegate>(Typeface_Delegate.class);
|
||||||
|
|
||||||
// ---- delegate helper data ----
|
|
||||||
private static String sFontLocation;
|
|
||||||
|
|
||||||
// ---- delegate data ----
|
// ---- delegate data ----
|
||||||
|
|
||||||
@@ -61,11 +61,8 @@ public final class Typeface_Delegate {
|
|||||||
|
|
||||||
private static long sDefaultTypeface;
|
private static long sDefaultTypeface;
|
||||||
|
|
||||||
|
|
||||||
// ---- Public Helper methods ----
|
// ---- Public Helper methods ----
|
||||||
public static synchronized void setFontLocation(String fontLocation) {
|
|
||||||
sFontLocation = fontLocation;
|
|
||||||
FontFamily_Delegate.setFontLocation(fontLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Typeface_Delegate getDelegate(long nativeTypeface) {
|
public static Typeface_Delegate getDelegate(long nativeTypeface) {
|
||||||
return sManager.getDelegate(nativeTypeface);
|
return sManager.getDelegate(nativeTypeface);
|
||||||
@@ -131,6 +128,18 @@ public final class Typeface_Delegate {
|
|||||||
return fonts;
|
return fonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the default typefaces when disposing bridge.
|
||||||
|
*/
|
||||||
|
public static void resetDefaults() {
|
||||||
|
// Sometimes this is called before the Bridge is initialized. In that case, we don't want to
|
||||||
|
// initialize Typeface because the SDK fonts location hasn't been set.
|
||||||
|
if (FontFamily_Delegate.getFontLocation() != null) {
|
||||||
|
Typeface.sDefaults = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---- native methods ----
|
// ---- native methods ----
|
||||||
|
|
||||||
@LayoutlibDelegate
|
@LayoutlibDelegate
|
||||||
@@ -193,7 +202,7 @@ public final class Typeface_Delegate {
|
|||||||
|
|
||||||
@LayoutlibDelegate
|
@LayoutlibDelegate
|
||||||
/*package*/ static File getSystemFontConfigLocation() {
|
/*package*/ static File getSystemFontConfigLocation() {
|
||||||
return new File(sFontLocation);
|
return new File(getFontLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Private delegate/helper methods ----
|
// ---- Private delegate/helper methods ----
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import com.ibm.icu.util.ULocale;
|
|||||||
|
|
||||||
import android.content.res.BridgeAssetManager;
|
import android.content.res.BridgeAssetManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Typeface_Accessor;
|
import android.graphics.FontFamily_Delegate;
|
||||||
import android.graphics.Typeface_Delegate;
|
import android.graphics.Typeface_Delegate;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Looper_Accessor;
|
import android.os.Looper_Accessor;
|
||||||
@@ -250,7 +250,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load the fonts.
|
// load the fonts.
|
||||||
Typeface_Delegate.setFontLocation(fontLocation.getAbsolutePath());
|
FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
|
||||||
|
|
||||||
// now parse com.android.internal.R (and only this one as android.R is a subset of
|
// now parse com.android.internal.R (and only this one as android.R is a subset of
|
||||||
// the internal version), and put the content in the maps.
|
// the internal version), and put the content in the maps.
|
||||||
@@ -303,7 +303,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
BridgeAssetManager.clearSystem();
|
BridgeAssetManager.clearSystem();
|
||||||
|
|
||||||
// dispose of the default typeface.
|
// dispose of the default typeface.
|
||||||
Typeface_Accessor.resetDefaults();
|
Typeface_Delegate.resetDefaults();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user