OSDN Git Service

Update delegates
authorDeepanshu Gupta <deepanshu@google.com>
Thu, 10 Jul 2014 20:57:52 +0000 (13:57 -0700)
committerDeepanshu Gupta <deepanshu@google.com>
Fri, 11 Jul 2014 21:40:27 +0000 (21:40 +0000)
Change-Id: Icd93c31b4e8c8ee5ea242fb8295578937f48ff2a

tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java

index 105803e..f939678 100644 (file)
@@ -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>.
      *
index bd88ae2..f4282ad 100644 (file)
@@ -53,6 +53,7 @@ import javax.imageio.ImageIO;
  */
 public final class Bitmap_Delegate {
 
+
     public enum BitmapCreateFlags {
         PREMULTIPLIED, MUTABLE
     }
@@ -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;
 
 
@@ -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;
@@ -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;
@@ -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;
@@ -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);
index 887e8f6..f044def 100644 (file)
 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;
 
 /**
@@ -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;
 
@@ -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];
@@ -128,14 +116,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);
         if (delegate == null) {
@@ -149,24 +129,6 @@ public final class Typeface_Delegate {
     }
 
     @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++) {
@@ -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();
-    }
 }