Loading tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +9 −0 Original line number Diff line number Diff line Loading @@ -828,9 +828,18 @@ public final class BridgeTypedArray extends TypedArray { @Override public int[] extractThemeAttrs() { // The drawables are always inflated with a Theme and we don't care about caching. So, // just return. return null; } @Override public int getChangingConfigurations() { // We don't care about caching. Any change in configuration is a fresh render. So, // just return. return 0; } /** * Retrieve the raw TypedValue for the attribute at <var>index</var>. * Loading tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +26 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import javax.imageio.ImageIO; */ public final class Bitmap_Delegate { public enum BitmapCreateFlags { PREMULTIPLIED, MUTABLE } Loading @@ -68,6 +69,7 @@ public final class Bitmap_Delegate { private BufferedImage mImage; private boolean mHasAlpha = true; private boolean mHasMipMap = false; // TODO: check the default. private boolean mIsPremultiplied = true; private int mGenerationId = 0; Loading Loading @@ -393,21 +395,19 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y, boolean isPremultiplied) { /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return 0; } // TODO: Support isPremultiplied. return delegate.mImage.getRGB(x, y); } @LayoutlibDelegate /*package*/ static void nativeGetPixels(long nativeBitmap, int[] pixels, int offset, int stride, int x, int y, int width, int height, boolean isPremultiplied) { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading @@ -418,8 +418,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color, boolean isPremultiplied) { /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading @@ -430,7 +429,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeSetPixels(long nativeBitmap, int[] colors, int offset, int stride, int x, int y, int width, int height, boolean isPremultiplied) { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading Loading @@ -518,7 +517,26 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate /*package*/ static void nativeSetAlphaAndPremultiplied(long nativeBitmap, boolean hasAlpha, /*package*/ static boolean nativeIsPremultiplied(long nativeBitmap) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); return delegate != null && delegate.mIsPremultiplied; } @LayoutlibDelegate /*package*/ static void nativeSetPremultiplied(long nativeBitmap, boolean isPremul) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; } delegate.mIsPremultiplied = isPremul; } @LayoutlibDelegate /*package*/ static void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha, boolean isPremul) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); Loading tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +2 −54 Original line number Diff line number Diff line Loading @@ -17,19 +17,14 @@ package android.graphics; import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.ide.common.rendering.api.LayoutLog; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.content.res.AssetManager; import android.graphics.FontFamily_Delegate.FontVariant; import java.awt.Font; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** Loading Loading @@ -58,10 +53,8 @@ public final class Typeface_Delegate { // ---- delegate data ---- @Nullable @NonNull private final FontFamily_Delegate[] mFontFamilies; // the reference to FontFamily_Delegate. @Nullable private final Font mFont; /** @see FontFamily_Delegate.FontInfo#mStyle */ private final int mStyle; Loading @@ -87,11 +80,6 @@ public final class Typeface_Delegate { @NonNull public List<Font> getFonts(FontVariant variant) { assert variant != FontVariant.NONE; if (mFontFamilies == null) { // We don't care about the variant here, since the Typeface was created with a single // Font File. So, we simply return that Font. return getFontAsList(); } List<Font> fonts = new ArrayList<Font>(mFontFamilies.length); for (int i = 0; i < mFontFamilies.length; i++) { FontFamily_Delegate ffd = mFontFamilies[i]; Loading Loading @@ -127,14 +115,6 @@ public final class Typeface_Delegate { // ---- native methods ---- @LayoutlibDelegate /*package*/ static synchronized long nativeCreate(String familyName, int style) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Could not find font with family \"" + familyName + "\".", null /*throwable*/, null /*data*/); return 0; } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromTypeface(long native_instance, int style) { Typeface_Delegate delegate = sManager.getDelegate(native_instance); Loading @@ -148,24 +128,6 @@ public final class Typeface_Delegate { return sManager.addNewDelegate(new Typeface_Delegate(delegate.mFontFamilies, style)); } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromAsset(AssetManager mgr, String path) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Typeface.createFromAsset() is not supported.", null /*throwable*/, null /*data*/); return 0; } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromFile(String path) { if (!path.startsWith(SYSTEM_FONTS)) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Typeface.createFromFile() can only work with platform fonts located in " + SYSTEM_FONTS, null, null); return 0; } return sManager.addNewDelegate(new Typeface_Delegate(path)); } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromArray(long[] familyArray) { FontFamily_Delegate[] fontFamilies = new FontFamily_Delegate[familyArray.length]; Loading Loading @@ -203,22 +165,8 @@ public final class Typeface_Delegate { // ---- Private delegate/helper methods ---- private Typeface_Delegate(FontFamily_Delegate[] fontFamilies, int style) { private Typeface_Delegate(@NonNull FontFamily_Delegate[] fontFamilies, int style) { mFontFamilies = fontFamilies; mFont = null; mStyle = style; } private Typeface_Delegate(String path) { mFont = FontFamily_Delegate.loadFont(path); mFontFamilies = null; mStyle = FontFamily_Delegate.getFontStyle(path); } private List<Font> getFontAsList() { if (mFont != null) { return Collections.singletonList(mFont); } return Collections.emptyList(); } } Loading
tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +9 −0 Original line number Diff line number Diff line Loading @@ -828,9 +828,18 @@ public final class BridgeTypedArray extends TypedArray { @Override public int[] extractThemeAttrs() { // The drawables are always inflated with a Theme and we don't care about caching. So, // just return. return null; } @Override public int getChangingConfigurations() { // We don't care about caching. Any change in configuration is a fresh render. So, // just return. return 0; } /** * Retrieve the raw TypedValue for the attribute at <var>index</var>. * Loading
tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +26 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import javax.imageio.ImageIO; */ public final class Bitmap_Delegate { public enum BitmapCreateFlags { PREMULTIPLIED, MUTABLE } Loading @@ -68,6 +69,7 @@ public final class Bitmap_Delegate { private BufferedImage mImage; private boolean mHasAlpha = true; private boolean mHasMipMap = false; // TODO: check the default. private boolean mIsPremultiplied = true; private int mGenerationId = 0; Loading Loading @@ -393,21 +395,19 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y, boolean isPremultiplied) { /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return 0; } // TODO: Support isPremultiplied. return delegate.mImage.getRGB(x, y); } @LayoutlibDelegate /*package*/ static void nativeGetPixels(long nativeBitmap, int[] pixels, int offset, int stride, int x, int y, int width, int height, boolean isPremultiplied) { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading @@ -418,8 +418,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color, boolean isPremultiplied) { /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading @@ -430,7 +429,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeSetPixels(long nativeBitmap, int[] colors, int offset, int stride, int x, int y, int width, int height, boolean isPremultiplied) { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; Loading Loading @@ -518,7 +517,26 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate /*package*/ static void nativeSetAlphaAndPremultiplied(long nativeBitmap, boolean hasAlpha, /*package*/ static boolean nativeIsPremultiplied(long nativeBitmap) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); return delegate != null && delegate.mIsPremultiplied; } @LayoutlibDelegate /*package*/ static void nativeSetPremultiplied(long nativeBitmap, boolean isPremul) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; } delegate.mIsPremultiplied = isPremul; } @LayoutlibDelegate /*package*/ static void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha, boolean isPremul) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); Loading
tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +2 −54 Original line number Diff line number Diff line Loading @@ -17,19 +17,14 @@ package android.graphics; import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.ide.common.rendering.api.LayoutLog; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.content.res.AssetManager; import android.graphics.FontFamily_Delegate.FontVariant; import java.awt.Font; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** Loading Loading @@ -58,10 +53,8 @@ public final class Typeface_Delegate { // ---- delegate data ---- @Nullable @NonNull private final FontFamily_Delegate[] mFontFamilies; // the reference to FontFamily_Delegate. @Nullable private final Font mFont; /** @see FontFamily_Delegate.FontInfo#mStyle */ private final int mStyle; Loading @@ -87,11 +80,6 @@ public final class Typeface_Delegate { @NonNull public List<Font> getFonts(FontVariant variant) { assert variant != FontVariant.NONE; if (mFontFamilies == null) { // We don't care about the variant here, since the Typeface was created with a single // Font File. So, we simply return that Font. return getFontAsList(); } List<Font> fonts = new ArrayList<Font>(mFontFamilies.length); for (int i = 0; i < mFontFamilies.length; i++) { FontFamily_Delegate ffd = mFontFamilies[i]; Loading Loading @@ -127,14 +115,6 @@ public final class Typeface_Delegate { // ---- native methods ---- @LayoutlibDelegate /*package*/ static synchronized long nativeCreate(String familyName, int style) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Could not find font with family \"" + familyName + "\".", null /*throwable*/, null /*data*/); return 0; } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromTypeface(long native_instance, int style) { Typeface_Delegate delegate = sManager.getDelegate(native_instance); Loading @@ -148,24 +128,6 @@ public final class Typeface_Delegate { return sManager.addNewDelegate(new Typeface_Delegate(delegate.mFontFamilies, style)); } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromAsset(AssetManager mgr, String path) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Typeface.createFromAsset() is not supported.", null /*throwable*/, null /*data*/); return 0; } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromFile(String path) { if (!path.startsWith(SYSTEM_FONTS)) { Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "Typeface.createFromFile() can only work with platform fonts located in " + SYSTEM_FONTS, null, null); return 0; } return sManager.addNewDelegate(new Typeface_Delegate(path)); } @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromArray(long[] familyArray) { FontFamily_Delegate[] fontFamilies = new FontFamily_Delegate[familyArray.length]; Loading Loading @@ -203,22 +165,8 @@ public final class Typeface_Delegate { // ---- Private delegate/helper methods ---- private Typeface_Delegate(FontFamily_Delegate[] fontFamilies, int style) { private Typeface_Delegate(@NonNull FontFamily_Delegate[] fontFamilies, int style) { mFontFamilies = fontFamilies; mFont = null; mStyle = style; } private Typeface_Delegate(String path) { mFont = FontFamily_Delegate.loadFont(path); mFontFamilies = null; mStyle = FontFamily_Delegate.getFontStyle(path); } private List<Font> getFontAsList() { if (mFont != null) { return Collections.singletonList(mFont); } return Collections.emptyList(); } }