Home | History | Annotate | Download | only in shadows
      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 
     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
     42     public int getFlags() {
     43     	return flags;
     44     }
     45 
     46     @Implementation
     47     public Shader setShader(Shader shader) {
     48         this.shader = shader;
     49         return shader;
     50     }
     51 
     52     @Implementation
     53     public int getAlpha() {
     54         return alpha;
     55     }
     56 
     57     @Implementation
     58     public void setAlpha(int alpha) {
     59         this.alpha = alpha;
     60     }
     61 
     62 
     63     @Implementation
     64     public Shader getShader() {
     65         return shader;
     66     }
     67 
     68     @Implementation
     69     public void setColor(int color) {
     70         this.color = color;
     71     }
     72 
     73     @Implementation
     74     public int getColor() {
     75         return color;
     76     }
     77 
     78     @Implementation
     79     public void setStyle(Paint.Style style) {
     80         this.style = style;
     81     }
     82 
     83     @Implementation
     84     public Paint.Style getStyle() {
     85         return style;
     86     }
     87 
     88     @Implementation
     89     public void setStrokeCap(Paint.Cap cap) {
     90         this.cap = cap;
     91     }
     92 
     93     @Implementation
     94     public Paint.Cap getStrokeCap() {
     95         return cap;
     96     }
     97 
     98     @Implementation
     99     public void setStrokeJoin(Paint.Join join) {
    100         this.join = join;
    101     }
    102 
    103     @Implementation
    104     public Paint.Join getStrokeJoin() {
    105         return join;
    106     }
    107 
    108     @Implementation
    109     public void setStrokeWidth(float width) {
    110         this.width = width;
    111     }
    112 
    113     @Implementation
    114     public float getStrokeWidth() {
    115         return width;
    116     }
    117 
    118     @Implementation
    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      */
    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      */
    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      */
    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      */
    158     public int getShadowColor() {
    159         return shadowColor;
    160     }
    161 
    162     /**
    163      * Non-Android accessor.
    164      *
    165      * @return cap
    166      */
    167     public Paint.Cap getCap() {
    168         return cap;
    169     }
    170 
    171     /**
    172      * Non-Android accessor.
    173      *
    174      * @return join
    175      */
    176     public Paint.Join getJoin() {
    177         return join;
    178     }
    179 
    180     /**
    181      * Non-Android accessor.
    182      *
    183      * @return width
    184      */
    185     public float getWidth() {
    186         return width;
    187     }
    188 
    189     @Implementation
    190     public ColorFilter getColorFilter() {
    191         return filter;
    192     }
    193 
    194     @Implementation
    195     public ColorFilter setColorFilter(ColorFilter filter) {
    196         this.filter = filter;
    197         return filter;
    198     }
    199 
    200     @Implementation
    201     public void setAntiAlias(boolean antiAlias) {
    202     	this.antiAlias = antiAlias;
    203     }
    204 
    205     @Implementation
    206     public void setDither(boolean dither) {
    207     	this.dither = dither;
    208     }
    209 
    210     @Implementation
    211     public final boolean isDither() {
    212     	return dither;
    213     }
    214 
    215     @Implementation
    216     public final boolean isAntiAlias() {
    217     	return antiAlias;
    218     }
    219 }
    220