Loading tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +51 −35 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -977,60 +979,74 @@ public class Canvas_Delegate { RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } // configure it 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(); float falpha = alpha / 255.f; 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(); } Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(paint.getXfermode()); if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) { int mode = ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode(); setModeInGraphics(mode, g, falpha); setModeInGraphics(g, mode, falpha); } else { if (mLogger != null && xfermode != null) { mLogger.warning(String.format( "Xfermode '%1$s' is not supported in the Layout Editor.", xfermode.getClass().getCanonicalName())); } // default mode is src_over 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) { // if xfermode wasn't null, then it's something we don't support. log it. if (mLogger != null && xfermodeDelegate != null) { mLogger.warning(String.format( "Shader '%1$s' is not supported in the Layout Editor.", shaderDelegate.getClass().getCanonicalName())); } "Xfermode '%1$s' is not supported in the Layout Editor.", xfermodeDelegate.getClass().getCanonicalName())); } } Loading tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java→tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java +68 −0 Original line number Diff line number Diff line Loading @@ -16,32 +16,31 @@ package android.graphics; public class DashPathEffect extends PathEffect { private final float[] mIntervals; private final float mPhase; import com.android.layoutlib.bridge.DelegateManager; /** * 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 * 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 DashPathEffect(float intervals[], float phase) { if (intervals.length < 2) { throw new ArrayIndexOutOfBoundsException(); } public class DashPathEffect_Delegate extends PathEffect_Delegate { mIntervals = intervals; mPhase = phase; } // ---- delegate data ---- private final float[] mIntervals; private final float mPhase; // ---- Public Helper methods ---- public float[] getIntervals() { return mIntervals; Loading @@ -50,5 +49,20 @@ public class DashPathEffect extends PathEffect { 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; } } tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 ---- } tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java→tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java +61 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * 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. Loading @@ -16,25 +16,46 @@ package android.graphics; import android.graphics.PorterDuff.Mode; public class PorterDuffXfermode extends Xfermode { private final Mode mMode; import com.android.layoutlib.bridge.DelegateManager; /** * Create an xfermode that uses the specified porter-duff mode. * 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}. * * @param mode The porter-duff mode that is applied */ public PorterDuffXfermode(PorterDuff.Mode mode) { mMode = mode; } public class PorterDuffXfermode_Delegate extends Xfermode_Delegate { // ---- delegate data ---- private final int mMode; //---------- Custom Methods // ---- Public Helper methods ---- public PorterDuff.Mode getMode() { 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; } } tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 ---- } Loading
tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +51 −35 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -977,60 +979,74 @@ public class Canvas_Delegate { RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } // configure it 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(); float falpha = alpha / 255.f; 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(); } Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(paint.getXfermode()); if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) { int mode = ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode(); setModeInGraphics(mode, g, falpha); setModeInGraphics(g, mode, falpha); } else { if (mLogger != null && xfermode != null) { mLogger.warning(String.format( "Xfermode '%1$s' is not supported in the Layout Editor.", xfermode.getClass().getCanonicalName())); } // default mode is src_over 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) { // if xfermode wasn't null, then it's something we don't support. log it. if (mLogger != null && xfermodeDelegate != null) { mLogger.warning(String.format( "Shader '%1$s' is not supported in the Layout Editor.", shaderDelegate.getClass().getCanonicalName())); } "Xfermode '%1$s' is not supported in the Layout Editor.", xfermodeDelegate.getClass().getCanonicalName())); } } Loading
tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java→tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java +68 −0 Original line number Diff line number Diff line Loading @@ -16,32 +16,31 @@ package android.graphics; public class DashPathEffect extends PathEffect { private final float[] mIntervals; private final float mPhase; import com.android.layoutlib.bridge.DelegateManager; /** * 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 * 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 DashPathEffect(float intervals[], float phase) { if (intervals.length < 2) { throw new ArrayIndexOutOfBoundsException(); } public class DashPathEffect_Delegate extends PathEffect_Delegate { mIntervals = intervals; mPhase = phase; } // ---- delegate data ---- private final float[] mIntervals; private final float mPhase; // ---- Public Helper methods ---- public float[] getIntervals() { return mIntervals; Loading @@ -50,5 +49,20 @@ public class DashPathEffect extends PathEffect { 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; } }
tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 ---- }
tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode.java→tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java +61 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * 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. Loading @@ -16,25 +16,46 @@ package android.graphics; import android.graphics.PorterDuff.Mode; public class PorterDuffXfermode extends Xfermode { private final Mode mMode; import com.android.layoutlib.bridge.DelegateManager; /** * Create an xfermode that uses the specified porter-duff mode. * 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}. * * @param mode The porter-duff mode that is applied */ public PorterDuffXfermode(PorterDuff.Mode mode) { mMode = mode; } public class PorterDuffXfermode_Delegate extends Xfermode_Delegate { // ---- delegate data ---- private final int mMode; //---------- Custom Methods // ---- Public Helper methods ---- public PorterDuff.Mode getMode() { 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; } }
tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 ---- }