Skip to content

Instantly share code, notes, and snippets.

View blundell's full-sized avatar
😶‍🌫️

Paul Blundell blundell

😶‍🌫️
View GitHub Profile
@blundell
blundell / 0-AdMobPokerExampleActivity.java
Last active August 29, 2015 14:04
Google Play Services AdMob loader - boiler plater saver
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 August 29, 2015 14:05
Your AndroidManifest is a public api
<?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 August 29, 2015 14:05
Compare two Intents with FEST
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 August 29, 2015 14:08
assertActivityRequiresPermission() Why doesn't this test pass?
<?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 / ForegroundImageView.java
Created January 4, 2015 13:00
An ImageView which supports a centered foreground drawable. - Based on Jake Wharton's ForegroundImageView
/**
* https://gist.github.com/JakeWharton/0a251d67649305d84e8a
* <p/>
* Then modified to :
* not scale the foreground to the ImageView size
* draw the foreground centered
*/
public class ForegroundImageView extends ImageView {
private Drawable foreground;
@blundell
blundell / parsing
Created March 30, 2015 18:27
Android Json Parsing of a YouTube response
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 17:57
Android ActivityLifecycleCallbacks that will only call back for a specific activity (not all activities)
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 June 20, 2015 15:40
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
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;
@blundell
blundell / clear-android-things-apps.sh
Last active April 22, 2022 17:23
Uninstall all apps on an Android Device that have the intent-filter category IOT_LAUNCHER
#!/bin/bash
sp="/-\|"
sc=0
spin() {
printf "\b${sp:sc++:1}"
((sc==${#sp})) && sc=0
}
endspin() {
printf "\r"
}
@blundell
blundell / 1_use.java
Created April 17, 2017 09:46
An AndroidThings button you can use to run something in a 1 liner call
Runnable somethingIWannaDo = new Runnable() {
@Override
public void run() {
Log.d("EZ", "I got ran");
}
};
// In Android Activity onCreate:
RunnableButton.create("BCM21", somethingIWannaDo).onCreateInjectInto(this);