1 package com.xtremelabs.robolectric.shadows; 2 3 import android.graphics.ColorMatrix; 4 import com.xtremelabs.robolectric.internal.Implementation; 5 import com.xtremelabs.robolectric.internal.Implements; 6 import com.xtremelabs.robolectric.util.Join; 7 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 12 13 @SuppressWarnings({"UnusedDeclaration"}) 14 @Implements(ColorMatrix.class) 15 public class ShadowColorMatrix { 16 17 private float[] src; 18 19 public void __constructor__(float[] src) { 20 this.src = src; 21 } 22 23 public void __constructor__() { 24 reset(); 25 } 26 27 public void __constructor__(ColorMatrix src) { 28 this.src = shadowOf(src).src; 29 } 30 31 @Implementation 32 public void reset() { 33 src = new float[20]; 34 src[0] = src[6] = src[12] = src[18] = 1; 35 } 36 37 @Implementation 38 public void setSaturation(float sat) { 39 reset(); 40 float[] m = src; 41 42 final float invSat = 1 - sat; 43 final float R = 0.213f * invSat; 44 final float G = 0.715f * invSat; 45 final float B = 0.072f * invSat; 46 47 m[0] = R + sat; 48 m[1] = G; 49 m[2] = B; 50 51 m[5] = R; 52 m[6] = G + sat; 53 m[7] = B; 54 55 m[10] = R; 56 m[11] = G; 57 m[12] = B + sat; 58 } 59 60 @Override @Implementation 61 public String toString() { 62 List<String> floats = new ArrayList<String>(); 63 for (float f : src) { 64 String format = String.format("%.2f", f); 65 format = format.replace(".00", ""); 66 floats.add(format); 67 } 68 return Join.join(",", floats); 69 } 70 } 71