Skip to content

Instantly share code, notes, and snippets.

View xrigau's full-sized avatar
:shipit:
🚀

Xavi Rigau xrigau

:shipit:
🚀
View GitHub Profile
@xrigau
xrigau / Url.java
Created May 28, 2015 14:47
Custom Url implementation
package com.foo.bar;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
public class Url implements Serializable {
private final URL url;
@xrigau
xrigau / MyInstrumentationTestCase.java
Created November 24, 2014 17:50
Disable Animations for Espresso tests v2.0
package com.novoda.espresso;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import com.mypackage.EntryPointActivity;
public class EspressoInstrumentationTestCase extends ActivityInstrumentationTestCase2<EntryPointActivity> {
private SystemAnimations systemAnimations;
public static WidgetImageLoader newInstance(Resources resources) {
BitmapAdjuster adjuster = BitmapAdjuster.newInstance(resources);
Retriever defaultRetriever = new MemoryRetriever();
Retriever fileRetriever = FileRetriever.newInstance(resources);
return new WidgetImageLoader(defaultRetriever, fileRetriever, adjuster);
}
WidgetImageLoader(Retriever memoryRetriever, Retriever fileRetriever, BitmapAdjuster adjuster) {
this.memoryRetriever = memoryRetriever;
this.fileRetriever = fileRetriever;
@xrigau
xrigau / ImageCache.java
Created August 4, 2014 16:44
Simple Image cache
public class ImageCache implements Map<String, Bitmap> {
private final Map<String, Bitmap> cache = new HashMap<String, Bitmap>();
private final Context context;
public ImageCache(Context context) {
this.context = context;
}
@Override
@xrigau
xrigau / SortingAlgorithms.java
Created June 7, 2014 19:24
Sorting Algorithms
interface SortingAlgorithm {
int[] sort(int[] values);
}
class QuickSort implements SortingAlgorithm {
@Override
int[] sort(int[] values) {
return quickSort(values);
}
// ...
@xrigau
xrigau / AndroidManifest.xml
Last active October 22, 2022 02:36
Disable animations for Espresso tests - run with `gradle cATDD`
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novoda.espresso">
<!-- For espresso testing purposes, this is removed in live builds, but not in dev builds -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<!-- ... -->
@xrigau
xrigau / gist:2500278
Created April 26, 2012 15:12
Define custom attributes namespace in Android layout
<RelativeLayout xmlns:myAttrs="http://schemas.android.com/apk/res-auto" ...>
...
@xrigau
xrigau / gist:2351804
Last active October 3, 2015 00:08
Parse a list of items to Json using Gson
final Type listType = new TypeToken<ArrayList<T>>() {}.getType();
String json = new Gson().toJson(list, listType);