*/
public final class Bitmap_Delegate {
+
public enum BitmapCreateFlags {
PREMULTIPLIED, MUTABLE
}
private BufferedImage mImage;
private boolean mHasAlpha = true;
private boolean mHasMipMap = false; // TODO: check the default.
+ private boolean mIsPremultiplied = true;
private int mGenerationId = 0;
}
@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;
@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;
@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;
}
@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);
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;
/**
// ---- 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;
@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];
// ---- 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);
if (delegate == null) {
}
@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];
for (int i = 0; i < familyArray.length; i++) {
// ---- 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();
- }
}