Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Blundell blundell

View GitHub Profile
@blundell
blundell / Code Readability
Last active Aug 29, 2015
This is an example of possible code when you have a maximum line length of 150 to attain max readability
View Code Readability
// Code readability - 4 possibilities
// A
context.getContentResolver().update(getDownloadUri(context, intent), values, null, null);
// vs
// B
context.getContentResolver().update(
getDownloadUri(context, intent), values, null, null);
// vs
@blundell
blundell / 0_reuse_code.js
Created Jun 6, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@blundell
blundell / WatchFaceLifecycle-ExampleActivity.java
Last active Aug 29, 2015
Unofficial Base WatchFace Listener
View WatchFaceLifecycle-ExampleActivity.java
public class ExampleActivity extends Activity implements WatchFaceLifecycle.Listener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_layout);
WatchFaceLifecycle.attach(this, savedInstanceState, this);
}
@Override
@blundell
blundell / 0-AdMobPokerExampleActivity.java
Last active Aug 29, 2015
Google Play Services AdMob loader - boiler plater saver
View 0-AdMobPokerExampleActivity.java
public class AdMobPokerExampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdMobPoker.track(findViewById(R.id.adView), savedInstanceState);
}
@blundell
blundell / Brittle-AndroidManifest.xml
Last active Aug 29, 2015
Your AndroidManifest is a public api
View Brittle-AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blundell.brittle.example">
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
@blundell
blundell / Test.java
Last active Aug 29, 2015
Compare two Intents with FEST
View Test.java
import static org.fest.assertions.api.Assertions.assertThat;
assertThat(intentOne).usingComparator(new IntentComparator()).isEqualTo(intentTwo);
private static class IntentComparator implements Comparator<Intent> {
@Override
public int compare(Intent left, Intent right) {
return left.filterEquals(right) ? 0 : 1;
}
}
@blundell
blundell / AndroidManifest.xml
Last active Aug 29, 2015
assertActivityRequiresPermission() Why doesn't this test pass?
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blundell.myapplication">
<application>
<activity
android:name=".SecondActivity"
android:permission="perm.foo.bar" />
</application>
@blundell
blundell / parsing
Created Mar 30, 2015
Android Json Parsing of a YouTube response
View parsing
private Vector<ContentValues> parseJson(String jsonStr) {
Vector<ContentValues> cVVector = new Vector<ContentValues>();
try {
JSONObject json = new JSONObject(jsonStr);
JSONObject data = json.getJSONObject("data");
JSONArray items = data.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
// Get the JSON object representing the day
JSONObject videoDetails = items.getJSONObject(i);
@blundell
blundell / UniqueActivityLifecycleCallbacks
Created May 23, 2015
Android ActivityLifecycleCallbacks that will only call back for a specific activity (not all activities)
View UniqueActivityLifecycleCallbacks
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import java.util.Locale;
public class UniqueActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
private final String activityName;
private final Application.ActivityLifecycleCallbacks lifecycleCallbacks;
@blundell
blundell / SpotifyApiBuilder.java
Created Jun 20, 2015
Creates a builder for the SpotifyApi allowing easier client creation & hiding retrofit implementation. Idea from: https://github.com/kaaes/spotify-web-api-android/pull/75
View SpotifyApiBuilder.java
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import kaaes.spotify.webapi.android.SpotifyApi;
import retrofit.android.MainThreadExecutor;
final class SpotifyApiBuilder {
private Executor executeExecutor;
private Executor callbackExecutor;