Skip to content

Instantly share code, notes, and snippets.

View patrickhammond's full-sized avatar

Patrick Hammond patrickhammond

View GitHub Profile
@patrickhammond
patrickhammond / CustomView.java
Created August 12, 2014 18:59
Custom views tricks
public Class CustomView {
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
// Makes the developer tools happy when previewing stuff
if (isInEditMode()) {
return;
}
}
}
@patrickhammond
patrickhammond / README.md
Last active April 30, 2018 21:24
Faster way to include stripped down Google Mobile Services in your application as a workaround to the 64k dex method limit problem that GMS frequently introduces. See README.md for details.

Context

I was previously using https://gist.github.com/dmarcato/d7c91b94214acd936e42 to strip down Google Mobiele Services, but the build times for my project in Android Studio consistently exceeded 75 seconds; this solution is much less dynamic (and even a little ugly) but keeps my build times less than 15s.

Assumptions

  • Your app module has a directory named aars that will work as a project specific Maven repository; this directory should be placed under version control.
  • Maven (mvn) is installed and available on your path when running this script.

Usage

@patrickhammond
patrickhammond / DevicePhoneNumber.java
Created September 25, 2014 19:30
User and device info helper code
public class DevicePhoneNumber {
public final String phoneNumber;
public DevicePhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Override
public String toString() {
return "DevicePhoneNumber{" +
@patrickhammond
patrickhammond / crashlyticsInfo.sh
Last active April 30, 2018 21:22
Simple script to display info associated with your Crashlytics account.
#!/bin/sh
echo "Crashlytics username (e-mail):"
read email
echo "Crashlytics password:"
read -s password
data="{\"email\":\"${email}\",\"password\":\"${password}\"}"
@patrickhammond
patrickhammond / SampleApplication.java
Last active April 30, 2018 21:20
Android Application class that is aware of if it is being created in the context of unit/instrumentation tests where the full application initialization is not desirable.
package com.myapp;
public class SampleApplication extends TestingAwareApplication {
@Override
protected String getFullyQualifiedTestFile() {
return "com.myapp.TestMode";
}
@Override
protected void initAppInstance() {
@patrickhammond
patrickhammond / bouncewifi.sh
Last active April 30, 2018 21:19
Utility to bounce the wifi connection every 55 minutes (to prevent an hourly boot).
#!/bin/sh
while true; do
sleep 3300 # 55 min * 60 sec
echo "Bouncing the wifi at `date`"
# You might need to change en1 to something else.
# ifconfig can tell you what network adapter to use
networksetup -setairportpower en1 off
sleep 2
@patrickhammond
patrickhammond / app_build.gradle
Created January 22, 2015 19:06
FindBugs snippet
...
apply plugin: 'findbugs'
...
task findbugs(type: FindBugs, dependsOn: assembleDebug) {
excludeFilter file("${project.rootDir}/config/findbugs/exclude.xml")
classes = fileTree('build/intermediates/classes/debug/') // Varies based on your app build configs and flavors...
source = fileTree('src/main/java/')
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import com.google.analytics.tracking.android.EasyTracker;
public class MainApplication extends Application {
private boolean locationNeedsUpdated = true;
private int createdActivityInstanceCount = 0;
@patrickhammond
patrickhammond / TextViewHelper.java
Created March 12, 2015 13:51
Helper class that makes setting up links easier.
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.widget.TextView;
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;