summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android
diff options
context:
space:
mode:
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
-rw-r--r--tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java59
-rw-r--r--tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java104
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java8
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java7
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java23
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java46
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java2
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java6
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java14
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java6
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java23
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java83
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java7
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java14
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java10
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java31
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java14
-rw-r--r--tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java164
18 files changed, 175 insertions, 446 deletions
diff --git a/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java b/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java
deleted file mode 100644
index 7b444aa..0000000
--- a/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2010 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.animation;
-
-import com.android.layoutlib.bridge.impl.DelegateManager;
-import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
-
-/**
- * Delegate implementing the native methods of android.animation.PropertyValuesHolder
- *
- * Through the layoutlib_create tool, the original native methods of PropertyValuesHolder have been
- * replaced by calls to methods of the same name in this delegate class.
- *
- * Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
- * around to map int to instance of the delegate.
- *
- * The main goal of this class' methods are to provide a native way to access setters and getters
- * on some object. In this case we want to default to using Java reflection instead so the native
- * methods do nothing.
- *
- */
-/*package*/ class PropertyValuesHolder_Delegate {
-
- @LayoutlibDelegate
- /*package*/ static int nGetIntMethod(Class<?> targetClass, String methodName) {
- // return 0 to force PropertyValuesHolder to use Java reflection.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int nGetFloatMethod(Class<?> targetClass, String methodName) {
- // return 0 to force PropertyValuesHolder to use Java reflection.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static void nCallIntMethod(Object target, int methodID, int arg) {
- // do nothing
- }
-
- @LayoutlibDelegate
- /*package*/ static void nCallFloatMethod(Object target, int methodID, float arg) {
- // do nothing
- }
-}
diff --git a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
deleted file mode 100644
index aabd3f1..0000000
--- a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2010 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.app;
-
-import com.android.ide.common.rendering.api.IProjectCallback;
-import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
-
-import android.content.Context;
-import android.os.Bundle;
-
-/**
- * Delegate used to provide new implementation of a select few methods of {@link Fragment}
- *
- * Through the layoutlib_create tool, the original methods of Fragment have been replaced
- * by calls to methods of the same name in this delegate class.
- *
- * The methods being re-implemented are the ones responsible for instantiating Fragment objects.
- * Because the classes of these objects are found in the project, these methods need access to
- * {@link IProjectCallback} object. They are however static methods, so the callback is set
- * before the inflation through {@link #setProjectCallback(IProjectCallback)}.
- */
-public class Fragment_Delegate {
-
- private static IProjectCallback sProjectCallback;
-
- /**
- * Sets the current {@link IProjectCallback} to be used to instantiate classes coming
- * from the project being rendered.
- */
- public static void setProjectCallback(IProjectCallback projectCallback) {
- sProjectCallback = projectCallback;
- }
-
- /**
- * Like {@link #instantiate(Context, String, Bundle)} but with a null
- * argument Bundle.
- */
- @LayoutlibDelegate
- /*package*/ static Fragment instantiate(Context context, String fname) {
- return instantiate(context, fname, null);
- }
-
- /**
- * Create a new instance of a Fragment with the given class name. This is
- * the same as calling its empty constructor.
- *
- * @param context The calling context being used to instantiate the fragment.
- * This is currently just used to get its ClassLoader.
- * @param fname The class name of the fragment to instantiate.
- * @param args Bundle of arguments to supply to the fragment, which it
- * can retrieve with {@link #getArguments()}. May be null.
- * @return Returns a new fragment instance.
- * @throws InstantiationException If there is a failure in instantiating
- * the given fragment class. This is a runtime exception; it is not
- * normally expected to happen.
- */
- @LayoutlibDelegate
- /*package*/ static Fragment instantiate(Context context, String fname, Bundle args) {
- try {
- if (sProjectCallback != null) {
- Fragment f = (Fragment) sProjectCallback.loadView(fname,
- new Class[0], new Object[0]);
-
- if (args != null) {
- args.setClassLoader(f.getClass().getClassLoader());
- f.mArguments = args;
- }
- return f;
- }
-
- return null;
- } catch (ClassNotFoundException e) {
- throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
- + ": make sure class name exists, is public, and has an"
- + " empty constructor that is public", e);
- } catch (java.lang.InstantiationException e) {
- throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
- + ": make sure class name exists, is public, and has an"
- + " empty constructor that is public", e);
- } catch (IllegalAccessException e) {
- throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
- + ": make sure class name exists, is public, and has an"
- + " empty constructor that is public", e);
- } catch (Exception e) {
- throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
- + ": make sure class name exists, is public, and has an"
- + " empty constructor that is public", e);
- }
- }
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java
index 080b85f..9c86e80 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java
@@ -136,20 +136,17 @@ import java.io.InputStream;
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
Rect padding, Options opts) {
- opts.inBitmap = null;
return null;
}
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts) {
- opts.inBitmap = null;
return null;
}
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeByteArray(byte[] data, int offset,
int length, Options opts) {
- opts.inBitmap = null;
return null;
}
@@ -159,9 +156,4 @@ import java.io.InputStream;
// BitmapFactory.finishDecode();
return chunk;
}
-
- @LayoutlibDelegate
- /*package*/ static boolean nativeIsSeekable(FileDescriptor fd) {
- return true;
- }
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
index 9a8cf04..8eb0693 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
@@ -79,13 +79,6 @@ public class BitmapShader_Delegate extends Shader_Delegate {
return sManager.addNewDelegate(newDelegate);
}
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate(int native_shader, int native_bitmap,
- int shaderTileModeX, int shaderTileModeY) {
- // pass, not needed.
- return 0;
- }
-
// ---- Private delegate/helper methods ----
private BitmapShader_Delegate(java.awt.image.BufferedImage image,
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index 66e59d8..87c3eb6 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -62,8 +62,6 @@ public final class Bitmap_Delegate {
private final Config mConfig;
private BufferedImage mImage;
private boolean mHasAlpha = true;
- private int mGenerationId = 0;
-
// ---- Public Helper methods ----
@@ -186,15 +184,6 @@ public final class Bitmap_Delegate {
return mHasAlpha && mConfig != Config.RGB_565;
}
- /**
- * Update the generationId.
- *
- * @see Bitmap#getGenerationId()
- */
- public void change() {
- mGenerationId++;
- }
-
// ---- native methods ----
@LayoutlibDelegate
@@ -395,16 +384,6 @@ public final class Bitmap_Delegate {
}
@LayoutlibDelegate
- /*package*/ static int nativeGenerationId(int nativeBitmap) {
- Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
- if (delegate == null) {
- return 0;
- }
-
- return delegate.mGenerationId;
- }
-
- @LayoutlibDelegate
/*package*/ static Bitmap nativeCreateFromParcel(Parcel p) {
// This is only called by Bitmap.CREATOR (Parcelable.Creator<Bitmap>), which is only
// used during aidl call so really this should not be called.
@@ -525,7 +504,7 @@ public final class Bitmap_Delegate {
int nativeInt = sManager.addNewDelegate(delegate);
// and create/return a new Bitmap with it
- return new Bitmap(nativeInt, null /* buffer */, isMutable, null /*ninePatchChunk*/, density);
+ return new Bitmap(nativeInt, isMutable, null /*ninePatchChunk*/, density);
}
/**
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 4decd1a..02a2ddf 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -270,6 +270,13 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
+ /*package*/ static void drawText(Canvas thisCanvas,
+ String text, float x, float y, Paint paint) {
+ native_drawText(thisCanvas.mNativeCanvas, text, 0, text.length(), x, y,
+ paint.mNativePaint);
+ }
+
+ @LayoutlibDelegate
/*package*/ static void drawPoints(Canvas thisCanvas, float[] pts, int offset, int count,
Paint paint) {
// FIXME
@@ -323,6 +330,12 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
+ /*package*/ static int initGL() {
+ // not supported.
+ return 0;
+ }
+
+ @LayoutlibDelegate
/*package*/ static void native_setBitmap(int nativeCanvas, int bitmap) {
// get the delegate from the native int.
Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
@@ -340,6 +353,11 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
+ /*package*/ static void nativeSetViewport(int nCanvas, int w, int h) {
+ // only useful in GL which is not supported, so no need to do anything.
+ }
+
+ @LayoutlibDelegate
/*package*/ static int native_saveLayer(int nativeCanvas, RectF bounds,
int paint, int layerFlags) {
// get the delegate from the native int.
@@ -944,7 +962,7 @@ public final class Canvas_Delegate {
@LayoutlibDelegate
/*package*/ static void native_drawText(int nativeCanvas,
final char[] text, final int index, final int count,
- final float startX, final float startY, int flags, int paint) {
+ final float startX, final float startY, int paint) {
draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
new GcSnapshot.Drawable() {
public void draw(Graphics2D graphics, Paint_Delegate paint) {
@@ -1044,30 +1062,12 @@ public final class Canvas_Delegate {
@LayoutlibDelegate
/*package*/ static void native_drawText(int nativeCanvas, String text,
int start, int end, float x,
- float y, int flags, int paint) {
+ float y, int paint) {
int count = end - start;
char[] buffer = TemporaryBuffer.obtain(count);
TextUtils.getChars(text, start, end, buffer, 0);
- native_drawText(nativeCanvas, buffer, 0, count, x, y, flags, paint);
- }
-
- @LayoutlibDelegate
- /*package*/ static void native_drawTextRun(int nativeCanvas, String text,
- int start, int end, int contextStart, int contextEnd,
- float x, float y, int flags, int paint) {
- int count = end - start;
- char[] buffer = TemporaryBuffer.obtain(count);
- TextUtils.getChars(text, start, end, buffer, 0);
-
- native_drawText(nativeCanvas, buffer, start, end, x, y, flags, paint);
- }
-
- @LayoutlibDelegate
- /*package*/ static void native_drawTextRun(int nativeCanvas, char[] text,
- int start, int count, int contextStart, int contextCount,
- float x, float y, int flags, int paint) {
- native_drawText(nativeCanvas, text, start, count, x, y, flags, paint);
+ native_drawText(nativeCanvas, buffer, 0, count, x, y, paint);
}
@LayoutlibDelegate
@@ -1094,7 +1094,7 @@ public final class Canvas_Delegate {
char[] text, int index,
int count, int path,
float hOffset,
- float vOffset, int bidiFlags,
+ float vOffset,
int paint) {
// FIXME
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1106,7 +1106,7 @@ public final class Canvas_Delegate {
String text, int path,
float hOffset,
float vOffset,
- int flags, int paint) {
+ int paint) {
// FIXME
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
"Canvas.drawTextOnPath is not supported.", null, null /*data*/);
diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
index e5a7ab6..4c692c2 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
@@ -56,7 +56,7 @@ public abstract class ColorFilter_Delegate {
// ---- native methods ----
@LayoutlibDelegate
- /*package*/ static void finalizer(int native_instance, int nativeColorFilter) {
+ /*package*/ static void finalizer(int native_instance) {
sManager.removeJavaReferenceFor(native_instance);
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
index 2de344b..d4c5b8d 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
@@ -60,11 +60,5 @@ public class ColorMatrixColorFilter_Delegate extends ColorFilter_Delegate {
return sManager.addNewDelegate(newDelegate);
}
- @LayoutlibDelegate
- /*package*/ static int nColorMatrixFilter(int nativeFilter, float[] array) {
- // pass
- return 0;
- }
-
// ---- Private delegate/helper methods ----
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
index f6e1d00..fcc12d7 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
@@ -78,20 +78,6 @@ public class ComposeShader_Delegate extends Shader_Delegate {
return sManager.addNewDelegate(newDelegate);
}
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate1(int native_shader, int native_skiaShaderA,
- int native_skiaShaderB, int native_mode) {
- // pass, not needed.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate2(int native_shader, int native_skiaShaderA,
- int native_skiaShaderB, int porterDuffMode) {
- // pass, not needed.
- return 0;
- }
-
// ---- Private delegate/helper methods ----
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
index 0ee883d..3afe965 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
@@ -60,11 +60,5 @@ public class LightingColorFilter_Delegate extends ColorFilter_Delegate {
return sManager.addNewDelegate(newDelegate);
}
- @LayoutlibDelegate
- /*package*/ static int nCreateLightingFilter(int nativeFilter, int mul, int add) {
- // pass
- return 0;
- }
-
// ---- Private delegate/helper methods ----
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
index a2ba758..a735ea1 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
@@ -54,7 +54,7 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
// ---- native methods ----
@LayoutlibDelegate
- /*package*/ static int nativeCreate1(LinearGradient thisGradient,
+ /*package*/ static int nativeCreate1(
float x0, float y0, float x1, float y1,
int colors[], float positions[], int tileMode) {
LinearGradient_Delegate newDelegate = new LinearGradient_Delegate(x0, y0, x1, y1,
@@ -63,30 +63,13 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
}
@LayoutlibDelegate
- /*package*/ static int nativeCreate2(LinearGradient thisGradient,
+ /*package*/ static int nativeCreate2(
float x0, float y0, float x1, float y1,
int color0, int color1, int tileMode) {
- return nativeCreate1(thisGradient,
- x0, y0, x1, y1, new int[] { color0, color1}, null /*positions*/,
+ return nativeCreate1(x0, y0, x1, y1, new int[] { color0, color1}, null /*positions*/,
tileMode);
}
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate1(LinearGradient thisGradient,
- int native_shader, float x0, float y0, float x1, float y1,
- int colors[], float positions[], int tileMode) {
- // nothing to be done here.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate2(LinearGradient thisGradient,
- int native_shader, float x0, float y0, float x1, float y1,
- int color0, int color1, int tileMode) {
- // nothing to be done here.
- return 0;
- }
-
// ---- Private delegate/helper methods ----
/**
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index 373f482..d4cf1f6 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -23,7 +23,6 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.graphics.Paint.FontMetrics;
import android.graphics.Paint.FontMetricsInt;
-import android.text.TextUtils;
import java.awt.BasicStroke;
import java.awt.Font;
@@ -90,7 +89,6 @@ public class Paint_Delegate {
private MaskFilter_Delegate mMaskFilter;
private Rasterizer_Delegate mRasterizer;
-
// ---- Public Helper methods ----
public static Paint_Delegate getDelegate(int native_paint) {
@@ -393,7 +391,7 @@ public class Paint_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nSetShadowLayer(Paint thisPaint, float radius, float dx, float dy,
+ /*package*/ static void setShadowLayer(Paint thisPaint, float radius, float dx, float dy,
int color) {
// FIXME
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -940,82 +938,7 @@ public class Paint_Delegate {
}
@LayoutlibDelegate
- /*package*/ static float native_getTextRunAdvances(int native_object,
- char[] text, int index, int count, int contextIndex, int contextCount,
- int flags, float[] advances, int advancesIndex) {
- // get the delegate from the native int.
- Paint_Delegate delegate = sManager.getDelegate(native_object);
- if (delegate == null) {
- return 0.f;
- }
-
- if (delegate.mFonts.size() > 0) {
- // FIXME: handle multi-char characters (see measureText)
- float totalAdvance = 0;
- for (int i = 0; i < count; i++) {
- char c = text[i + index];
- boolean found = false;
- for (FontInfo info : delegate.mFonts) {
- if (info.mFont.canDisplay(c)) {
- float adv = info.mMetrics.charWidth(c);
- totalAdvance += adv;
- if (advances != null) {
- advances[i] = adv;
- }
-
- found = true;
- break;
- }
- }
-
- if (found == false) {
- // no advance for this char.
- if (advances != null) {
- advances[i] = 0.f;
- }
- }
- }
-
- return totalAdvance;
- }
-
- return 0;
-
- }
-
- @LayoutlibDelegate
- /*package*/ static float native_getTextRunAdvances(int native_object,
- String text, int start, int end, int contextStart, int contextEnd,
- int flags, float[] advances, int advancesIndex) {
- // FIXME: support contextStart, contextEnd and direction flag
- int count = end - start;
- char[] buffer = TemporaryBuffer.obtain(count);
- TextUtils.getChars(text, start, end, buffer, 0);
-
- return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart,
- contextEnd - contextStart, flags, advances, advancesIndex);
- }
-
- @LayoutlibDelegate
- /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, char[] text,
- int contextStart, int contextLength, int flags, int offset, int cursorOpt) {
- // FIXME
- Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
- "Paint.getTextRunCursor is not supported.", null, null /*data*/);
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, String text,
- int contextStart, int contextEnd, int flags, int offset, int cursorOpt) {
- // FIXME
- Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
- "Paint.getTextRunCursor is not supported.", null, null /*data*/);
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
+ /*package*/ static void native_getTextPath(int native_object,
char[] text, int index, int count, float x, float y, int path) {
// FIXME
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1023,7 +946,7 @@ public class Paint_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
+ /*package*/ static void native_getTextPath(int native_object,
String text, int start, int end, float x, float y, int path) {
// FIXME
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
index c45dbaa..65c65a1 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
@@ -60,12 +60,5 @@ public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate {
return sManager.addNewDelegate(newDelegate);
}
- @LayoutlibDelegate
- /*package*/ static int nCreatePorterDuffFilter(int nativeFilter, int srcColor,
- int porterDuffMode) {
- // pass
- return 0;
- }
-
// ---- Private delegate/helper methods ----
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
index 9bf78b4..bdc0ab1 100644
--- a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
@@ -68,20 +68,6 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
tileMode);
}
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate1(int native_shader, float x, float y, float radius,
- int colors[], float positions[], int tileMode) {
- // nothing to be done here.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate2(int native_shader, float x, float y, float radius,
- int color0, int color1, int tileMode) {
- // nothing to be done here.
- return 0;
- }
-
// ---- Private delegate/helper methods ----
/**
diff --git a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
index cb31b8f..b0ee5c2 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
@@ -469,16 +469,6 @@ public class Region_Delegate {
return region1.mArea.equals(region2.mArea);
}
- @LayoutlibDelegate
- /*package*/ static String nativeToString(int native_region) {
- Region_Delegate region = sManager.getDelegate(native_region);
- if (region == null) {
- return "not found";
- }
-
- return region.mArea.toString();
- }
-
// ---- Private delegate/helper methods ----
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
index 368c0384..c6dd54b 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
@@ -76,13 +76,38 @@ public abstract class Shader_Delegate {
// ---- native methods ----
@LayoutlibDelegate
- /*package*/ static void nativeDestructor(int native_shader, int native_skiaShader) {
+ /*package*/ static void nativeDestructor(int native_shader) {
sManager.removeJavaReferenceFor(native_shader);
}
@LayoutlibDelegate
- /*package*/ static void nativeSetLocalMatrix(int native_shader, int native_skiaShader,
- int matrix_instance) {
+ /*package*/ static boolean nativeGetLocalMatrix(int native_shader, int matrix_instance) {
+ // get the delegate from the native int.
+ Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
+ if (shaderDelegate == null) {
+ return false;
+ }
+
+ // get the (optional) out matrix.
+ Matrix_Delegate outMatrixDelegate = Matrix_Delegate.getDelegate(matrix_instance);
+
+ if (shaderDelegate.mLocalMatrix == null || shaderDelegate.mLocalMatrix.isIdentity()) {
+ if (outMatrixDelegate != null) {
+ outMatrixDelegate.reset();
+ }
+ return false;
+ }
+
+ if (outMatrixDelegate != null) {
+ outMatrixDelegate.set(shaderDelegate.mLocalMatrix);
+ }
+
+ return true;
+ }
+
+
+ @LayoutlibDelegate
+ /*package*/ static void nativeSetLocalMatrix(int native_shader, int matrix_instance) {
// get the delegate from the native int.
Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
if (shaderDelegate == null) {
diff --git a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
index 966e06e..f70f9cf 100644
--- a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
@@ -62,20 +62,6 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
return nativeCreate1(x, y, new int[] { color0, color1 }, null /*positions*/);
}
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate1(int native_shader, float cx, float cy,
- int[] colors, float[] positions) {
- // nothing to be done here.
- return 0;
- }
-
- @LayoutlibDelegate
- /*package*/ static int nativePostCreate2(int native_shader, float cx, float cy,
- int color0, int color1) {
- // nothing to be done here.
- return 0;
- }
-
// ---- Private delegate/helper methods ----
/**
diff --git a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
index 0f3cf57..d5266a5 100644
--- a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
@@ -22,7 +22,10 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
+import android.util.Xml;
import java.io.IOException;
@@ -32,66 +35,131 @@ import java.io.IOException;
* Through the layoutlib_create tool, the original methods of LayoutInflater have been replaced
* by calls to methods of the same name in this delegate class.
*
+ * Generally we don't want to copy-paste a huge method like that just for one small features,
+ * but because this is done after this platform is final and the next version (Honeycomb) has a
+ * better mechanism (or slightly less copy-paste), maintenance of this duplicated code is not
+ * a problem.
+ *
*/
public class LayoutInflater_Delegate {
- /**
- * Recursive method used to descend down the xml hierarchy and instantiate
- * views, instantiate their children, and then call onFinishInflate().
- */
@LayoutlibDelegate
- /*package*/ static void rInflate(LayoutInflater thisInflater,
- XmlPullParser parser, View parent, final AttributeSet attrs,
- boolean finishInflate) throws XmlPullParserException, IOException {
-
- if (finishInflate == false) {
- // this is a merge rInflate!
- if (thisInflater instanceof BridgeInflater) {
- ((BridgeInflater) thisInflater).setIsInMerge(true);
- }
- }
-
- // ---- START DEFAULT IMPLEMENTATION.
+ /*package*/ static void parseInclude(LayoutInflater thisInflater,
+ XmlPullParser parser, View parent, AttributeSet attrs)
+ throws XmlPullParserException, IOException {
- final int depth = parser.getDepth();
int type;
- while (((type = parser.next()) != XmlPullParser.END_TAG ||
- parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
-
- if (type != XmlPullParser.START_TAG) {
- continue;
- }
-
- final String name = parser.getName();
-
- if (LayoutInflater.TAG_REQUEST_FOCUS.equals(name)) {
- thisInflater.parseRequestFocus(parser, parent);
- } else if (LayoutInflater.TAG_INCLUDE.equals(name)) {
- if (parser.getDepth() == 0) {
- throw new InflateException("<include /> cannot be the root element");
+ if (parent instanceof ViewGroup) {
+ final int layout = attrs.getAttributeResourceValue(null, "layout", 0);
+ if (layout == 0) {
+ final String value = attrs.getAttributeValue(null, "layout");
+ if (value == null) {
+ throw new InflateException("You must specifiy a layout in the"
+ + " include tag: <include layout=\"@layout/layoutID\" />");
+ } else {
+ throw new InflateException("You must specifiy a valid layout "
+ + "reference. The layout ID " + value + " is not valid.");
}
- thisInflater.parseInclude(parser, parent, attrs);
- } else if (LayoutInflater.TAG_MERGE.equals(name)) {
- throw new InflateException("<merge /> must be the root element");
} else {
- final View view = thisInflater.createViewFromTag(parent, name, attrs);
- final ViewGroup viewGroup = (ViewGroup) parent;
- final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs);
- thisInflater.rInflate(parser, view, attrs, true);
- viewGroup.addView(view, params);
+ final XmlResourceParser childParser =
+ thisInflater.getContext().getResources().getLayout(layout);
+
+ try {
+ final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
+
+ while ((type = childParser.next()) != XmlPullParser.START_TAG &&
+ type != XmlPullParser.END_DOCUMENT) {
+ // Empty.
+ }
+
+ if (type != XmlPullParser.START_TAG) {
+ throw new InflateException(childParser.getPositionDescription() +
+ ": No start tag found!");
+ }
+
+ final String childName = childParser.getName();
+
+ if (LayoutInflater.TAG_MERGE.equals(childName)) {
+ // ---- START MODIFICATIONS ----
+ if (thisInflater instanceof BridgeInflater) {
+ ((BridgeInflater) thisInflater).setIsInMerge(true);
+ }
+ // ---- END MODIFICATIONS ----
+
+ // Inflate all children.
+ thisInflater.rInflate(childParser, parent, childAttrs);
+
+ // ---- START MODIFICATIONS ----
+ if (thisInflater instanceof BridgeInflater) {
+ ((BridgeInflater) thisInflater).setIsInMerge(false);
+ }
+ // ---- END MODIFICATIONS ----
+ } else {
+ final View view = thisInflater.createViewFromTag(childName, childAttrs);
+ final ViewGroup group = (ViewGroup) parent;
+
+ // We try to load the layout params set in the <include /> tag. If
+ // they don't exist, we will rely on the layout params set in the
+ // included XML file.
+ // During a layoutparams generation, a runtime exception is thrown
+ // if either layout_width or layout_height is missing. We catch
+ // this exception and set localParams accordingly: true means we
+ // successfully loaded layout params from the <include /> tag,
+ // false means we need to rely on the included layout params.
+ ViewGroup.LayoutParams params = null;
+ try {
+ params = group.generateLayoutParams(attrs);
+ } catch (RuntimeException e) {
+ params = group.generateLayoutParams(childAttrs);
+ } finally {
+ if (params != null) {
+ view.setLayoutParams(params);
+ }
+ }
+
+ // Inflate all children.
+ thisInflater.rInflate(childParser, view, childAttrs);
+
+ // Attempt to override the included layout's android:id with the
+ // one set on the <include /> tag itself.
+ TypedArray a = thisInflater.mContext.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.View, 0, 0);
+ int id = a.getResourceId(com.android.internal.R.styleable.View_id, View.NO_ID);
+ // While we're at it, let's try to override android:visibility.
+ int visibility = a.getInt(com.android.internal.R.styleable.View_visibility, -1);
+ a.recycle();
+
+ if (id != View.NO_ID) {
+ view.setId(id);
+ }
+
+ switch (visibility) {
+ case 0:
+ view.setVisibility(View.VISIBLE);
+ break;
+ case 1:
+ view.setVisibility(View.INVISIBLE);
+ break;
+ case 2:
+ view.setVisibility(View.GONE);
+ break;
+ }
+
+ group.addView(view);
+ }
+ } finally {
+ childParser.close();
+ }
}
+ } else {
+ throw new InflateException("<include /> can only be used inside of a ViewGroup");
}
- if (finishInflate) parent.onFinishInflate();
-
- // ---- END DEFAULT IMPLEMENTATION.
-
- if (finishInflate == false) {
- // this is a merge rInflate!
- if (thisInflater instanceof BridgeInflater) {
- ((BridgeInflater) thisInflater).setIsInMerge(false);
- }
+ final int currentDepth = parser.getDepth();
+ while (((type = parser.next()) != XmlPullParser.END_TAG ||
+ parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
+ // Empty
}
}
}