Skip to content

Instantly share code, notes, and snippets.

@kingargyle
kingargyle / ShadowSupportFragment.java
Created June 3, 2016 13:44
ShadowSupportFragment implementation for Robolectric
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowApplication;
@kingargyle
kingargyle / ShadowTextInputLayout.java
Created May 31, 2016 17:08
A bare bones Shadow for Robolectric and TextInputLayout from the design library
import android.support.design.widget.TextInputLayout;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadows.ShadowViewGroup;
@Implements(TextInputLayout.class)
public class ShadowTextInputLayout extends ShadowViewGroup {
@RealObject private TextInputLayout realTextInputLayout;
@kingargyle
kingargyle / RobolectricLoggingRule.java
Last active May 9, 2016 13:53
A Junit 4 Rule to easily access the Log Output from Robolectric.
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.rules.ExternalResource;
import org.robolectric.shadows.ShadowLog;
public class RobolectricLoggingRule extends ExternalResource {
PrintStream loggingStream;
ByteArrayOutputStream loggingOutputStream;
PrintStream defaultStream;
@kingargyle
kingargyle / init.gradle
Created March 10, 2016 17:15
Add Nexus Mirrors to gradle builds with Init Script
// Replace the location of the nexus repository with your specific location.
// To enable this: gradlew build -I init.gradle
// This will now have gradle use the mirrors first and jcenter and other repositories second if it can't find the artifacts.
// Make sure your mirror Jcenter in your nexus repository.
allprojects{
buildscript{
repositories{
maven{ url 'http://localhost:8081/nexus/content/groups/public' }
}
@kingargyle
kingargyle / multifilepicker.java
Created October 19, 2015 18:15
Android 4.4+ Select Multiple Files with UI File Picker
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
// In code that handles the result returned to process the files:
ClipData clipData = intent.getClipData();
# Copyright (c) 2013 Embark Mobile
# Modified to work with Eclipse HIPP instance by David Carver
# Licensed under the MIT License.
# https://github.com/embarkmobile/android-sdk-installer
set +e
#detecting os
os=linux
if [[ `uname` == 'Darwin' ]]; then
@kingargyle
kingargyle / SampleRecommendationContentProvider
Created November 15, 2014 21:39
RecomendationCardView ContentProvider Example
/**
* The MIT License (MIT)
* Copyright (c) 2014 David Carver
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@kingargyle
kingargyle / update-manifest.xml
Last active August 29, 2015 14:06
Update Version Number in AndroidManifest with POM version number.
<!--
Include the following snippet in a profile or as part of your standard build.
It will parse out the POM version number and then use it to update the
version number in your AndroidManfiest.xml. It will also increment the
versionCode based on the version number.
No more manually having to update the vesion number as part of a release!! Yipee!
-->
<plugin>
@kingargyle
kingargyle / TransitionDrawableRunnable.java
Created August 21, 2014 13:25
A runable that handles only transitioning and crossfading when the bitmaps are different.
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.preference.PreferenceManager;
import android.view.View;
/**
* A runnable that transitions between a drawable and a bitmap.
@kingargyle
kingargyle / VerifyRunOnUiThread
Created August 20, 2014 18:11
Verify that activity runOnUiThread is called using Robolectric and Mockito
/*
* Verifies that an activities runOnUiThread method is called and that
* appropriate class is called. In most cases we don't care about
* actually executing the runOnUiThread, just that it got called.
* By mocking out the Activity, we can use Mockito's verify method to
* make sure the method was called, with the expected Runnable class implementation
* passed into it.
*
* By doing this we avoid having to pause Robolectrics's UIScheduler and BackgroundSchedulers
* and then kick off the task. Since in this case it isn't actually necessary to run the code as it