Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Blundell blundell

View GitHub Profile
@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 / 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 / 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 / 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_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 / 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 / anti-hungarian-checkstyle
Created Jan 25, 2014
Anti-Hungarian CheckStyle check
View anti-hungarian-checkstyle
import com.puppycrawl.tools.checkstyle.api.*;
public class AntiHungarianCheck extends Check {
private static final String CATCH_MSG = "Hungarian notation belongs in the 90's. " +
"Don't prefix member variables with 'm'. " +
"Use your IDE's shiny colors. Culprit was: ";
private final HungarianNotationMemberDetector detector = new HungarianNotationMemberDetector();
@blundell
blundell / VideoView Buffering Spinner
Created Jan 21, 2014
Adding a progress spinner to a video view for before it starts or whilst it is buffering.
View VideoView Buffering Spinner
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/my_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
@blundell
blundell / Gradle handle repos
Created Jan 20, 2014
Handle the declaration of all source code repositories in your base build file, and you don't have to worry about declaring them in any child modules. The code below would go at the top of your build.gradle, in your 'base' or 'top' build.gradle file. You don't have to add anything to child modules. You will get full repository source retrieval.
View Gradle handle repos
subprojects {
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url "https://github.com/novoda/public-mvn-repo/raw/master/releases"
}
@blundell
blundell / Crazy Array Init
Last active Dec 31, 2015
1 line annon inner class array initialisation because I want to be able to add & remove but I'm too lazy to extend BaseAdapter.
View Crazy Array Init
public class NavDrawerArrayAdapter extends ArrayAdapter<String> {
public NavDrawerArrayAdapter(final Context context) {
super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1,
new ArrayList<String>() {{
add(context.getString(R.string.nav_drawer_section_explore));
add(context.getString(R.string.nav_drawer_section_rewards));
add(context.getString(R.string.nav_drawer_section_offers));
add(context.getString(R.string.nav_drawer_section_events));
}});
refresh();