Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Perry christopherperry

View GitHub Profile
@christopherperry
christopherperry / activity_stack
Created Jul 8, 2014
Display current Activity stack in Android
View activity_stack
adb shell dumpsys activity package <your.package.name>
@christopherperry
christopherperry / AndroidVersion.java
Created Jul 27, 2012
Robolectric test runner with Guice injection, custom class binding using annotations, and android version support.
View AndroidVersion.java
package annotations;
import android.os.Build;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
@christopherperry
christopherperry / robolectric-library-resource-loading.java
Created Aug 30, 2012 — forked from pplante/robolectric-library-resource-loading.java
Robolectric does not support loading resources from an Android Library project such as ActionBarSherlock of FlyInMenu, so this patch allows you to specify a library project to load resources in tests.
View robolectric-library-resource-loading.java
// In ResourceLoader.java I added the following method:
//
public void loadLibraryProjectResources(File libraryProjectRoot) throws Exception {
File systemResourceDir = getSystemResourceDir(getPathToAndroidResources());
File localValueResourceDir = getValueResourceDir(libraryProjectRoot);
File systemValueResourceDir = getValueResourceDir(systemResourceDir);
loadStringResources(localValueResourceDir, systemValueResourceDir);
loadPluralsResources(localValueResourceDir, systemValueResourceDir);
loadValueResources(localValueResourceDir, systemValueResourceDir);
@christopherperry
christopherperry / Intellij Unit Test VM options
Last active Dec 24, 2015
IntelliJ memory setting for unit tests
View Intellij Unit Test VM options
Set VM options to: -ea -Xms800m -Xmx800m -XX:MaxPermSize=500m
View HappyDebuggingSuckers.java
@Test
public void happyDebuggingSuckers() throws SecurityException, NoSuchFieldException, IllegalAccessException {
Field value = Boolean.class.getDeclaredField("value");
value.setAccessible(true);
Boolean trueBool = true;
Boolean falseBool = false;
value.setBoolean(trueBool, false);
View Logger.java
package com.example;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright 2015 Christopher Perry
*
@christopherperry
christopherperry / CoffeeMaker1.java
Last active Apr 10, 2016
Coffee Maker Dependency Inversion Example
View CoffeeMaker1.java
package coffee.maker;
import coffee.maker.heater.ElectricHeater;
import coffee.maker.pump.Thermosiphon;
public class CoffeeMaker {
private final ElectricHeater heater;
private final Thermosiphon thermosiphon;
public CoffeeMaker() {
View CoffeeMaker2.java
package coffee.maker;
import coffee.maker.heater.Heater;
import coffee.maker.pump.Pump;
public class CoffeeMaker {
private final Heater heater;
private final Pump thermosiphon;
public CoffeeMaker(Heater heater, Pump pump) {
View ArcUtils.java
/**
* ArcUtils.java
*
* Copyright (c) 2014 BioWink GmbH.
*
* 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