Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.graphics.Matrix;
      4 import com.xtremelabs.robolectric.internal.Implementation;
      5 import com.xtremelabs.robolectric.internal.Implements;
      6 
      7 import static com.xtremelabs.robolectric.Robolectric.shadowOf;
      8 
      9 @SuppressWarnings({"UnusedDeclaration"})
     10 @Implements(Matrix.class)
     11 public class ShadowMatrix {
     12     private float scaleX = 1;
     13     private float transX;
     14 
     15     private float scaleY = 1;
     16     private float transY;
     17 
     18     // scaleX=0, skewX=1,  transX=2
     19     // skewY=3,  scaleY=4, transY=5
     20     // persp0=6, persp1=7, persp2=8
     21 
     22     // identity: Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
     23 
     24     // drag down: Matrix{[1.0, 0.0, -1.3872986][0.0, 1.0, 0.37722778][0.0, 0.0, 1.0]}
     25 
     26 
     27     public void __constructor__(Matrix src) {
     28         set(src);
     29     }
     30 
     31     @Implementation
     32     public void set(Matrix src) {
     33         transX = shadowOf(src).transX;
     34         scaleX = shadowOf(src).scaleX;
     35 
     36         transY = shadowOf(src).transY;
     37         scaleY = shadowOf(src).scaleY;
     38     }
     39 
     40     @Implementation
     41     public void setTranslate(float dx, float dy) {
     42         transX = dx;
     43         transY = dy;
     44     }
     45 
     46     @Implementation
     47     public void postTranslate(float dx, float dy) {
     48         transX += dx;
     49         transY += dy;
     50     }
     51 
     52     public float getTransX() {
     53         return transX;
     54     }
     55 
     56     public float getTransY() {
     57         return transY;
     58     }
     59 
     60     @Implementation
     61     public boolean postScale(float sx, float sy, float px, float py) {
     62         scaleX *= sx;
     63         scaleY *= sy;
     64         return true;
     65     }
     66 
     67     public float getScaleX() {
     68         return scaleX;
     69     }
     70 
     71     public float getScaleY() {
     72         return scaleY;
     73     }
     74 }
     75