Skip to content

Instantly share code, notes, and snippets.

View patrickhammond's full-sized avatar

Patrick Hammond patrickhammond

View GitHub Profile
@patrickhammond
patrickhammond / Cucumber console output (partial)
Created November 21, 2012 01:02
Brazenhead issues while trying to invoke the action bar home button
Scenario: View the navigation menu
When I expose the navigation menu
{"exception":"java.lang.reflect.InvocationTargetException","theCause":{"exception":"java.lang.NullPointerException"}} (Exception)
./features/step_definitions/screenshot_defs.rb:12:in `/^I expose the navigation menu$/'
features/screenshots.feature:8:in `When I expose the navigation menu'
Then I can take a screenshot of the "navigation menu"
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/**
* An implementation of {@link BaseAdapter} which uses the new/bind pattern and
* view holder pattern for its views.
*
@patrickhammond
patrickhammond / gist:7598623
Last active August 13, 2021 03:03
Adds list dividers between children in a linear layout. showDividers takes a set of flags (ex: you can specify beginning|middle|end to get dividers at the start of the layout, through the layout, and at the end of the layout. API 11+ http://developer.android.com/reference/android/widget/LinearLayout.html#setShowDividers(int)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="middle"
android:divider="?android:listDivider"
android:dividerPadding="16dp">
</LinearLayout>
Compiled files:
SamplePojoTest$SamplePojo$$Parcelable$1.class
SamplePojoTest$SamplePojo$$Parcelable$Parcelable$Creator$$0.class
SamplePojoTest$SamplePojo$$Parcelable.class
SamplePojoTest$SamplePojo.class
SamplePojoTest.class
Output from: javap SamplePojoTest\$SamplePojo
Compiled from "SamplePojoTest.java"
public class com.atomicrobot.floss.SamplePojoTest$SamplePojo {
@patrickhammond
patrickhammond / ViewTreeObserverHelper.java
Created February 3, 2014 20:03
Safe usage of a ViewTreeObserver to get view measurements. This ensures that the layout listener isn't leaked and the right API calls are made.
public static void notifyWhenMeasured(final View view, final ViewTreeObserver.OnGlobalLayoutListener listener) {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
listener.onGlobalLayout();
// Need to get a fresh ViewTreeObserver
ViewTreeObserver freshVto = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT < 16) {
@patrickhammond
patrickhammond / YourApplication.java
Created February 10, 2014 13:54
Easy way to get rough screen level analytics in your app with very little work. API 14+
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import com.google.analytics.tracking.android.EasyTracker;
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
setupAnalytics();
@patrickhammond
patrickhammond / screenrecord.sh
Last active April 30, 2018 21:32
Script to simplify screen recording with Android 4.4 and later devices. This takes care of setting the screenrecord flags, pulling files from the device, cleaning up after the recording, and optionally automatically opening the recording for you. Assumes only one connected device. Works for OSX but probably easy to make work with Linux (I believ…
#!/bin/bash
bitrate_flag=""
rotate_flag=""
open_when_done=0
OPTIND=1
while getopts "hron:" opt; do
case "$opt" in
h)
@patrickhammond
patrickhammond / android_instructions.md
Last active October 13, 2024 21:08
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@patrickhammond
patrickhammond / outline.markdown
Last active April 30, 2018 21:34
Getting Started with Android Wear Outline

Getting Started with Android Wear

Disclaimer

Details presented tonight are likely to change after Google I/O.

What is Android Wear and why should I care

  • New API to support wearable devices (currently only watches) coming to market soon.
  • Lots of wearable attention at Google I/O
  • Incredibly easy to make your apps work well on Android Wear devices
package com.atomicrobot.app;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class ActivityFirstRunHelper {