1 package com.xtremelabs.robolectric.shadows; 2 3 import android.graphics.ColorFilter; 4 import android.graphics.Paint; 5 import android.graphics.Shader; 6 import com.xtremelabs.robolectric.internal.Implementation; 7 import com.xtremelabs.robolectric.internal.Implements; 8 import com.xtremelabs.robolectric.internal.RealObject; 9 10 /** 11 * Shadow of {@code Paint} that has some extra accessors so that tests can tell whether a {@code Paint} object was 12 * created with the expected parameters. 13 */ 14 @SuppressWarnings({"UnusedDeclaration"}) 15 @Implements(Paint.class) 16 public class ShadowPaint { 17 18 private int color; 19 private Paint.Style style; 20 private Paint.Cap cap; 21 private Paint.Join join; 22 private float width; 23 private float shadowRadius; 24 private float shadowDx; 25 private float shadowDy; 26 private int shadowColor; 27 private Shader shader; 28 private int alpha; 29 private ColorFilter filter; 30 private boolean antiAlias; 31 private boolean dither; 32 private int flags; 33 34 @RealObject Paint paint; 35 __constructor__(int flags)36 public void __constructor__(int flags) { 37 this.flags = flags; 38 antiAlias = ( flags & Paint.ANTI_ALIAS_FLAG ) == Paint.ANTI_ALIAS_FLAG; 39 } 40 41 @Implementation getFlags()42 public int getFlags() { 43 return flags; 44 } 45 46 @Implementation setShader(Shader shader)47 public Shader setShader(Shader shader) { 48 this.shader = shader; 49 return shader; 50 } 51 52 @Implementation getAlpha()53 public int getAlpha() { 54 return alpha; 55 } 56 57 @Implementation setAlpha(int alpha)58 public void setAlpha(int alpha) { 59 this.alpha = alpha; 60 } 61 62 63 @Implementation getShader()64 public Shader getShader() { 65 return shader; 66 } 67 68 @Implementation setColor(int color)69 public void setColor(int color) { 70 this.color = color; 71 } 72 73 @Implementation getColor()74 public int getColor() { 75 return color; 76 } 77 78 @Implementation setStyle(Paint.Style style)79 public void setStyle(Paint.Style style) { 80 this.style = style; 81 } 82 83 @Implementation getStyle()84 public Paint.Style getStyle() { 85 return style; 86 } 87 88 @Implementation setStrokeCap(Paint.Cap cap)89 public void setStrokeCap(Paint.Cap cap) { 90 this.cap = cap; 91 } 92 93 @Implementation getStrokeCap()94 public Paint.Cap getStrokeCap() { 95 return cap; 96 } 97 98 @Implementation setStrokeJoin(Paint.Join join)99 public void setStrokeJoin(Paint.Join join) { 100 this.join = join; 101 } 102 103 @Implementation getStrokeJoin()104 public Paint.Join getStrokeJoin() { 105 return join; 106 } 107 108 @Implementation setStrokeWidth(float width)109 public void setStrokeWidth(float width) { 110 this.width = width; 111 } 112 113 @Implementation getStrokeWidth()114 public float getStrokeWidth() { 115 return width; 116 } 117 118 @Implementation setShadowLayer(float radius, float dx, float dy, int color)119 public void setShadowLayer(float radius, float dx, float dy, int color) { 120 shadowRadius = radius; 121 shadowDx = dx; 122 shadowDy = dy; 123 shadowColor = color; 124 } 125 126 /** 127 * Non-Android accessor. 128 * 129 * @return shadow radius (Paint related shadow, not Robolectric Shadow) 130 */ getShadowRadius()131 public float getShadowRadius() { 132 return shadowRadius; 133 } 134 135 /** 136 * Non-Android accessor. 137 * 138 * @return shadow Dx (Paint related shadow, not Robolectric Shadow) 139 */ getShadowDx()140 public float getShadowDx() { 141 return shadowDx; 142 } 143 144 /** 145 * Non-Android accessor. 146 * 147 * @return shadow Dx (Paint related shadow, not Robolectric Shadow) 148 */ getShadowDy()149 public float getShadowDy() { 150 return shadowDy; 151 } 152 153 /** 154 * Non-Android accessor. 155 * 156 * @return shadow color (Paint related shadow, not Robolectric Shadow) 157 */ getShadowColor()158 public int getShadowColor() { 159 return shadowColor; 160 } 161 162 /** 163 * Non-Android accessor. 164 * 165 * @return cap 166 */ getCap()167 public Paint.Cap getCap() { 168 return cap; 169 } 170 171 /** 172 * Non-Android accessor. 173 * 174 * @return join 175 */ getJoin()176 public Paint.Join getJoin() { 177 return join; 178 } 179 180 /** 181 * Non-Android accessor. 182 * 183 * @return width 184 */ getWidth()185 public float getWidth() { 186 return width; 187 } 188 189 @Implementation getColorFilter()190 public ColorFilter getColorFilter() { 191 return filter; 192 } 193 194 @Implementation setColorFilter(ColorFilter filter)195 public ColorFilter setColorFilter(ColorFilter filter) { 196 this.filter = filter; 197 return filter; 198 } 199 200 @Implementation setAntiAlias(boolean antiAlias)201 public void setAntiAlias(boolean antiAlias) { 202 this.antiAlias = antiAlias; 203 } 204 205 @Implementation setDither(boolean dither)206 public void setDither(boolean dither) { 207 this.dither = dither; 208 } 209 210 @Implementation isDither()211 public final boolean isDither() { 212 return dither; 213 } 214 215 @Implementation isAntiAlias()216 public final boolean isAntiAlias() { 217 return antiAlias; 218 } 219 } 220