Skip to content

Instantly share code, notes, and snippets.

View Sloy's full-sized avatar

Rafa Vázquez Sloy

View GitHub Profile
@Sloy
Sloy / AutoSummaryListPreference
Created June 29, 2013 13:16
Android custom ListPreference which shows its selected value as summary, as suggested in the official guidelines. No need to use OnPreferenceChangeListener in the Activity or anything like that. Only assign entries and entryValues.
package com.your.package;
import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
/**
* Created by Rafa Vázquez on 29/06/13.
*
* ListPreference item that shows its selected value as summary.
@Sloy
Sloy / video2gif.py
Last active December 30, 2015 09:59
Este script genera una animación gif a partir de un archivo de vídeo, colocando opcionalmente un fondo en cada frame. Está pensado para convertir los vídeos obtenidos en Android mediante 'adb shell screenrecord' o con la herramienta de Android Studio.
#coding=utf-8
"""
Por: Rafa Vázquez
http://sloydev.com/
Este script genera una animación gif a partir de un archivo de vídeo, colocando opcionalmente un fondo en cada frame.
Está pensado para convertir los vídeos obtenidos en Android mediante 'adb shell screenrecord' o con la herramienta de Android Studio.
Un ejemplo del resultado puede verse en http://i.imgur.com/Opu5aG3.gif
@Sloy
Sloy / build.gradle
Last active August 29, 2015 14:15
Dex Count Gradle
buildscript {
repositories {
jcenter()
maven { url 'http://dl.bintray.com/sloy/maven'} //<- only needed while jcenter refresh to the new version
}
dependencies {
classpath 'com.sloydev:dexcountprettify-plugin:0.1.2'
}
}
@Sloy
Sloy / MockParcel.java
Created February 26, 2015 12:50
MockParcel for testing Parcelables implementations with the new Android's Unit testing support (http://tools.android.com/tech-docs/unit-testing-support). Only String and Long read/write implemented here. Add mock methods for other types.
import android.os.Parcel;
import java.util.ArrayList;
import java.util.List;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;
@Sloy
Sloy / build.gradle
Created June 26, 2015 14:41
Automatic apk signing for CI
android {
...
signingConfigs {
release {
storeFile file('../certs/release.keystore')
def (releaseKeystorePassword, releaseKeyAlias, releaseKeyPassword) = signingConfig()
storePassword releaseKeystorePassword
keyAlias releaseKeyAlias
keyPassword releaseKeyPassword
@Sloy
Sloy / AutocompleteViewActions.java
Created August 17, 2016 08:49
Custom Espresso action for AutoCompleteTextView. It replaces the text without showing the annoying popup in your tests.
public class AutocompleteViewActions {
public static ViewAction replaceAutocomplete(@Nonnull String stringToBeSet) {
return actionWithAssertions(new ReplaceAutocompleteTextAction(stringToBeSet));
}
/**
* This is based on {@link ReplaceTextAction}
* with modifications thanks to "http://www.grokkingandroid.com/how-androids-autocompletetextview-nearly-drove-me-nuts/".
* <p>
@Sloy
Sloy / SimpleContextMenu.java
Created August 21, 2016 17:48
A context menu alternative with a simpler API, without the fuzz of all that lifecycle mess
public class SimpleContextMenu {
private final Context context;
private final String[] titles;
private final Runnable[] callbacks;
public static Builder builder(Context context) {
return new Builder(context);
}
@Sloy
Sloy / Monitor GcmNetworkManager tasks
Created September 29, 2016 09:18
GcmNetworkManager monitoring command
$ while sleep 1; do adb shell dumpsys activity service GcmService --endpoints my.package.name | grep "Pending:" -A 20; done
@Sloy
Sloy / MenuItemValueHolder.java
Last active November 2, 2016 09:57
Wrap your MenuItem with this class and forget about activity/fragment lifecycle with menu items. Initializing the visibility and your menu is not created yet? Don't worry, it will queue actions and trigger them once it's ready.
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.ActionProvider;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import java.util.LinkedList;
import java.util.List;
@Sloy
Sloy / InjectedInstrumentationTest.java
Last active June 7, 2018 11:15
Injector (Dagger 1)
public class InjectedInstrumentationTestRule implements MethodRule {
private final Object testModule;
public InjectedInstrumentationTestRule(Object testModule) {
this.testModule = testModule;
}
@Override
public Statement apply(final Statement statement, FrameworkMethod frameworkMethod, final Object testClassInstance) {