This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Type; | |
import android.util.Base64; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import com.google.gson.JsonDeserializationContext; | |
import com.google.gson.JsonDeserializer; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonParseException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: <code>org.eclipse.jetty.util.log.Log.setLog(new JettySilentLogger());</code> | |
*/ | |
public class JettySilentLogger implements org.eclipse.jetty.util.log.Logger { | |
@Override public void debug(Throwable arg0) {} | |
@Override public void debug(String arg0, Object... arg1) {} | |
@Override public void debug(String arg0, Throwable arg1) {} | |
@Override public Logger getLogger(String arg0) { return this; } | |
@Override public String getName() { return this.getName(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependency: Guava | |
// From an Activity, assets = getAssets(); | |
// From a test, assets = getInstrumentation().getContext().getAssets(); | |
ByteStreams.copy(assets.open(assetFileName), new FileOutputStream(targetPath)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input: byte[] data, int width, int height, File jpegFile | |
YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null); | |
FileOutputStream jepgFileOS = new FileOutputStream(jpegFile); | |
yuvimage.compressToJpeg(new Rect(0, 0, width, height), 95, jpegFileOS); | |
jpegFileOS.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sugar for has(int, isAssignableFrom(Class)). | |
* | |
* Example: onView(rootView).check(has(3, EditText.class); | |
*/ | |
public static ViewAssertion has(final int expectedCount, Class<? extends View> clazz) { | |
return has(expectedCount, isAssignableFrom(clazz)); | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void assertBitmapsAreSimilar(Bitmap expectedBitmap, Bitmap actualBitmap, double tolerance) { | |
Bitmap reducedExpectedBitmap = Bitmap.createScaledBitmap(expectedBitmap, 32, 32, true); | |
Bitmap reducedActualBitmap = Bitmap.createScaledBitmap(actualBitmap, 32, 32, true); | |
int cumulatedColorDistance = 0; | |
for (int x = 0 ; x < reducedExpectedBitmap.getWidth() ; x++) { | |
for (int y = 0 ; y<reducedExpectedBitmap.getHeight() ; y++) { | |
int expectedColor = reducedExpectedBitmap.getPixel(x, y); | |
int actualColor = reducedActualBitmap.getPixel(x, y); |