summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-11-03 17:40:17 -0700
committerXavier Ducrohet <xav@android.com>2010-11-03 19:15:07 -0700
commit4b606da91d2d76dd90a427cb3e37ea7df655e8e0 (patch)
treee12029f7b29397ff9a01755f3bd46f5a5758efb2 /tools
parent079fd674fb9005771dd383a1a483d7dc5072b5b3 (diff)
downloadframeworks_base-4b606da91d2d76dd90a427cb3e37ea7df655e8e0.zip
frameworks_base-4b606da91d2d76dd90a427cb3e37ea7df655e8e0.tar.gz
frameworks_base-4b606da91d2d76dd90a427cb3e37ea7df655e8e0.tar.bz2
Layoutlib native delegate: path effects and xfermode.
Change-Id: Iafaac6dbaf452e2dba3e77c801089dad33ac4ea9
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java86
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java54
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java68
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java60
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java40
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java61
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java60
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java6
8 files changed, 304 insertions, 131 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index bfe5c86..80db8c3 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -970,6 +970,8 @@ public class Canvas_Delegate {
Graphics2D g = getGraphics2d();
g = (Graphics2D)g.create();
+ // configure it
+
if (paint.isAntiAliased()) {
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -977,60 +979,74 @@ public class Canvas_Delegate {
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
- // configure it
- g.setColor(new Color(paint.getColor()));
- int alpha = paint.getAlpha();
- float falpha = alpha / 255.f;
+ boolean useColorPaint = true;
+
+ // get the shader first, as it'll replace the color if it can be used it.
+ Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(paint.getShader());
+ if (shaderDelegate != null) {
+ java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
+ if (shaderPaint != null) {
+ g.setPaint(shaderPaint);
+ useColorPaint = false;
+ } else {
+ if (mLogger != null) {
+ mLogger.warning(String.format(
+ "Shader '%1$s' is not supported in the Layout Editor.",
+ shaderDelegate.getClass().getCanonicalName()));
+ }
+ }
+ }
+
+ // need to get the alpha to set it in the composite.
+ float falpha = 1.f;
+
+ if (useColorPaint) {
+ g.setColor(new Color(paint.getColor()));
+
+ // the alpha is taken from the alpha channel of the color
+ int alpha = paint.getAlpha();
+ falpha = alpha / 255.f;
+ }
int style = paint.getStyle();
if (style == Paint.Style.STROKE.nativeInt ||
style == Paint.Style.FILL_AND_STROKE.nativeInt) {
- /* FIXME
- PathEffect e = paint.getPathEffect();
- if (e instanceof DashPathEffect) {
- DashPathEffect dpe = (DashPathEffect)e;
+
+ PathEffect_Delegate effectDelegate = PathEffect_Delegate.getDelegate(
+ paint.getPathEffect());
+
+ if (effectDelegate instanceof DashPathEffect_Delegate) {
+ DashPathEffect_Delegate dpe = (DashPathEffect_Delegate)effectDelegate;
g.setStroke(new BasicStroke(
paint.getStrokeWidth(),
- paint.getStrokeCap().getJavaCap(),
- paint.getStrokeJoin().getJavaJoin(),
+ paint.getJavaCap(),
+ paint.getJavaJoin(),
paint.getStrokeMiter(),
dpe.getIntervals(),
dpe.getPhase()));
- } else {*/
+ } else {
g.setStroke(new BasicStroke(
paint.getStrokeWidth(),
paint.getJavaCap(),
paint.getJavaJoin(),
paint.getStrokeMiter()));
- /* }*/
+ }
}
-/*
- Xfermode xfermode = paint.getXfermode();
- if (xfermode instanceof PorterDuffXfermode) {
- PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode();
- setModeInGraphics(mode, g, falpha);
+ Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(paint.getXfermode());
+ if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) {
+ int mode = ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode();
+
+ setModeInGraphics(g, mode, falpha);
} else {
- if (mLogger != null && xfermode != null) {
+ // default mode is src_over
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
+
+ // if xfermode wasn't null, then it's something we don't support. log it.
+ if (mLogger != null && xfermodeDelegate != null) {
mLogger.warning(String.format(
"Xfermode '%1$s' is not supported in the Layout Editor.",
- xfermode.getClass().getCanonicalName()));
- }
- g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
- }
-*/
- int nativeShader = paint.getShader();
- Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(nativeShader);
- if (shaderDelegate != null) {
- java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
- if (shaderPaint != null) {
- g.setPaint(shaderPaint);
- } else {
- if (mLogger != null) {
- mLogger.warning(String.format(
- "Shader '%1$s' is not supported in the Layout Editor.",
- shaderDelegate.getClass().getCanonicalName()));
- }
+ xfermodeDelegate.getClass().getCanonicalName()));
}
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java
deleted file mode 100644
index 46d4c70..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java
+++ /dev/null
@@ -1,54 +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.graphics;
-
-public class DashPathEffect extends PathEffect {
-
- private final float[] mIntervals;
- private final float mPhase;
-
- /**
- * The intervals array must contain an even number of entries (>=2), with
- * the even indices specifying the "on" intervals, and the odd indices
- * specifying the "off" intervals. phase is an offset into the intervals
- * array (mod the sum of all of the intervals). The intervals array
- * controls the length of the dashes. The paint's strokeWidth controls the
- * thickness of the dashes.
- * Note: this patheffect only affects drawing with the paint's style is set
- * to STROKE or STROKE_AND_FILL. It is ignored if the drawing is done with
- * style == FILL.
- * @param intervals array of ON and OFF distances
- * @param phase offset into the intervals array
- */
- public DashPathEffect(float intervals[], float phase) {
- if (intervals.length < 2) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- mIntervals = intervals;
- mPhase = phase;
- }
-
- public float[] getIntervals() {
- return mIntervals;
- }
-
- public float getPhase() {
- return mPhase;
- }
-}
-
diff --git a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
new file mode 100644
index 0000000..59b6a91
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
@@ -0,0 +1,68 @@
+/*
+ * 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.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+/**
+ * Delegate implementing the native methods of android.graphics.DashPathEffect
+ *
+ * Through the layoutlib_create tool, the original native methods of DashPathEffect have been
+ * replaced by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original DashPathEffect class.
+ *
+ * Because this extends {@link PathEffect_Delegate}, there's no need to use a
+ * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
+ * {@link PathEffect_Delegate}.
+ *
+ */
+public class DashPathEffect_Delegate extends PathEffect_Delegate {
+
+ // ---- delegate data ----
+
+ private final float[] mIntervals;
+ private final float mPhase;
+
+ // ---- Public Helper methods ----
+
+ public float[] getIntervals() {
+ return mIntervals;
+ }
+
+ public float getPhase() {
+ return mPhase;
+ }
+
+ // ---- native methods ----
+
+ /*package*/ static int nativeCreate(float intervals[], float phase) {
+ DashPathEffect_Delegate newDelegate = new DashPathEffect_Delegate(intervals, phase);
+ return sManager.addDelegate(newDelegate);
+ }
+
+ // ---- Private delegate/helper methods ----
+
+ private DashPathEffect_Delegate(float intervals[], float phase) {
+ mIntervals = new float[intervals.length];
+ System.arraycopy(intervals, 0, mIntervals, 0, intervals.length);
+ mPhase = phase;
+ }
+}
+
diff --git a/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java
new file mode 100644
index 0000000..6827ae7
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java
@@ -0,0 +1,60 @@
+/*
+ * 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.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+/**
+ * Delegate implementing the native methods of android.graphics.PathEffect
+ *
+ * Through the layoutlib_create tool, the original native methods of PathEffect have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original PathEffect class.
+ *
+ * This also serve as a base class for all PathEffect delegate classes.
+ *
+ * @see DelegateManager
+ *
+ */
+public class PathEffect_Delegate {
+
+ // ---- delegate manager ----
+ protected static final DelegateManager<PathEffect_Delegate> sManager =
+ new DelegateManager<PathEffect_Delegate>();
+
+ // ---- delegate helper data ----
+
+ // ---- delegate data ----
+
+ // ---- Public Helper methods ----
+
+ public static PathEffect_Delegate getDelegate(int nativeShader) {
+ return sManager.getDelegate(nativeShader);
+ }
+
+ // ---- native methods ----
+
+ /*package*/ static void nativeDestructor(int native_patheffect) {
+ sManager.removeDelegate(native_patheffect);
+ }
+
+ // ---- Private delegate/helper methods ----
+
+}
diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java
deleted file mode 100644
index 974ae49..0000000
--- a/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2008 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;
-
-import android.graphics.PorterDuff.Mode;
-
-public class PorterDuffXfermode extends Xfermode {
- private final Mode mMode;
-
- /**
- * Create an xfermode that uses the specified porter-duff mode.
- *
- * @param mode The porter-duff mode that is applied
- */
- public PorterDuffXfermode(PorterDuff.Mode mode) {
- mMode = mode;
- }
-
- //---------- Custom Methods
-
- public PorterDuff.Mode getMode() {
- return mMode;
- }
-
- //----------
-}
diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java
new file mode 100644
index 0000000..c242e80
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java
@@ -0,0 +1,61 @@
+/*
+ * 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.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+/**
+ * Delegate implementing the native methods of android.graphics.PorterDuffXfermode
+ *
+ * Through the layoutlib_create tool, the original native methods of PorterDuffXfermode have been
+ * replaced by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original PorterDuffXfermode class.
+ *
+ * Because this extends {@link Xfermode_Delegate}, there's no need to use a
+ * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
+ * {@link Xfermode_Delegate}.
+ *
+ */
+public class PorterDuffXfermode_Delegate extends Xfermode_Delegate {
+
+ // ---- delegate data ----
+
+ private final int mMode;
+
+ // ---- Public Helper methods ----
+
+ public int getMode() {
+ return mMode;
+ }
+
+ // ---- native methods ----
+
+ /*package*/ static int nativeCreateXfermode(int mode) {
+ PorterDuffXfermode_Delegate newDelegate = new PorterDuffXfermode_Delegate(mode);
+ return sManager.addDelegate(newDelegate);
+ }
+
+ // ---- Private delegate/helper methods ----
+
+ private PorterDuffXfermode_Delegate(int mode) {
+ mMode = mode;
+ }
+
+}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java
new file mode 100644
index 0000000..d4408cf
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java
@@ -0,0 +1,60 @@
+/*
+ * 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.graphics;
+
+import com.android.layoutlib.bridge.DelegateManager;
+
+/**
+ * Delegate implementing the native methods of android.graphics.Xfermode
+ *
+ * Through the layoutlib_create tool, the original native methods of Xfermode have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ * This class behaves like the original native implementation, but in Java, keeping previously
+ * native data into its own objects and mapping them to int that are sent back and forth between
+ * it and the original Xfermode class.
+ *
+ * This also serve as a base class for all Xfermode delegate classes.
+ *
+ * @see DelegateManager
+ *
+ */
+public class Xfermode_Delegate {
+
+ // ---- delegate manager ----
+ protected static final DelegateManager<Xfermode_Delegate> sManager =
+ new DelegateManager<Xfermode_Delegate>();
+
+ // ---- delegate helper data ----
+
+ // ---- delegate data ----
+
+ // ---- Public Helper methods ----
+
+ public static Xfermode_Delegate getDelegate(int native_instance) {
+ return sManager.getDelegate(native_instance);
+ }
+
+ // ---- native methods ----
+
+ /*package*/ static void finalizer(int native_instance) {
+ sManager.removeDelegate(native_instance);
+ }
+
+ // ---- Private delegate/helper methods ----
+
+}
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
index 2a6ef4d..19bdb2c 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
@@ -105,13 +105,17 @@ public final class CreateInfo implements ICreateInfo {
private final static String[] DELEGATE_CLASS_NATIVES = new String[] {
"android.graphics.Bitmap",
"android.graphics.Canvas",
+ "android.graphics.DashPathEffect",
"android.graphics.LinearGradient",
"android.graphics.Matrix",
"android.graphics.Paint",
+ "android.graphics.PathEffect",
+ "android.graphics.PorterDuffXfermode",
"android.graphics.RadialGradient",
"android.graphics.Shader",
"android.graphics.SweepGradient",
"android.graphics.Typeface",
+ "android.graphics.Xfermode",
};
/**
@@ -131,9 +135,7 @@ public final class CreateInfo implements ICreateInfo {
private final static String[] RENAMED_CLASSES =
new String[] {
"android.graphics.BitmapFactory", "android.graphics._Original_BitmapFactory",
- "android.graphics.DashPathEffect", "android.graphics._Original_DashPathEffect",
"android.graphics.Path", "android.graphics._Original_Path",
- "android.graphics.PorterDuffXfermode", "android.graphics._Original_PorterDuffXfermode",
"android.os.ServiceManager", "android.os._Original_ServiceManager",
"android.util.FloatMath", "android.util._Original_FloatMath",
"android.view.SurfaceView", "android.view._Original_SurfaceView",