Skip to content

Instantly share code, notes, and snippets.

View patrickhammond's full-sized avatar

Patrick Hammond patrickhammond

View GitHub Profile
@patrickhammond
patrickhammond / EspressoTestRule.java
Last active September 2, 2018 12:14
Hacking through Espresso issues...
import android.app.Activity;
import android.app.Instrumentation;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.test.InstrumentationRegistry;
@patrickhammond
patrickhammond / 1_before.java
Last active August 29, 2015 14:22
Work in progress...
public class MyActivity extends Activity {
private static final String STATEFUL_COUNT = “count”;
private int count;
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
@patrickhammond
patrickhammond / README.md
Last active April 30, 2018 21:13
Steps and tools to see decompiled Android apps.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The smarter thing to do would be to use what is Guava, etc...but Guava is a big fat library that
* will blow the dex count and this is pretty much the only thing we are using out of it.
@patrickhammond
patrickhammond / app_build.gradle
Created July 6, 2015 14:11
Including AARs in your project. Works with build tools com.android.tools.build:gradle:1.2.3 and gradle-2.4.
repositories {
...
flatDir {
dirs 'aars'
}
...
}
dependencies {
...
@patrickhammond
patrickhammond / 1_models.java
Last active August 29, 2015 14:26
Sample of how we might make variant types suck less with Java. See: https://en.wikipedia.org/wiki/Tagged_union for part of the CS theory.
// ------------------------------------------------------------------------
// App code: These classes that describe the state of executing a query
// that we want to consume as a stream of events.
public class Loading {
}
public class Results<T> {
final List<T> results;
@patrickhammond
patrickhammond / gist:d529f29bf6e3077ac920
Last active August 29, 2015 14:26
Gradle build script with API 21 min SDK to skip some dex overhead when developing against Lollipop and above.
android {
productFlavors {
app {
}
appFast {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
// Put this at the end of your project build.gradle
// Execute on your CI server with something like:
// ./gradlew continuousIntegration -Pfingerprint=asdf -PbuildNumber=2 -PdisablePreDex
evaluationDependsOnChildren();
task staticAnalysis() {
def appProject = subprojects.find { project -> 'app' == project.name }
dependsOn appProject.getTasksByName('findbugs', true)
@Singleton
@Component(modules = {
AndroidModule.class,
BusModule.class,
NetworkModule.class,
AppModule.class
})
public interface ApplicationComponent {
...
Bus bus();
@Override
protected void onCreate(Bundle savedInstanceState) {
...
BarcodeLoggerActivityPermissionsDispatcher.startBarcodeCaptureWithCheck(this);
}
@NeedsPermission(Manifest.permission.CAMERA)
void startBarcodeCapture() {
int orientation = WindowManagerHelper.getCurrentAccurateOrientation(this);
Intent intent = CaptureActivity.buildIntent(this, orientation);