Skip to content

Instantly share code, notes, and snippets.

View patrickhammond's full-sized avatar

Patrick Hammond patrickhammond

View GitHub Profile
@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
@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 / 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 {
...
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 / README.md
Last active April 30, 2018 21:13
Steps and tools to see decompiled Android apps.
@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 / 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;
package com.androidfu.nowplaying.app.api;
import android.content.Context;
import com.androidfu.nowplaying.app.util.Log;
import com.androidfu.nowplaying.app.util.Preconditions;
import com.jakewharton.byteunits.DecimalByteUnit;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
@patrickhammond
patrickhammond / NoSSLv3Util.java
Last active August 29, 2015 14:18
Workaround to https://code.google.com/p/android/issues/detail?id=78187 where a connection from the upgraded Play Services SSL provider will be downgraded to use SSLv3 on older versions of Android and result in a connection failure if the server does not accept that protocol (and it shouldn't due to POODLE).
import android.os.Build;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
@patrickhammond
patrickhammond / close_slide_enter.xml
Created March 25, 2015 16:31
Slide in and slide out animations.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-100%"
android:toXDelta="0" />
</set>