Skip to content

Instantly share code, notes, and snippets.

Adam Speakman adamsp

Block or report user

Report or block adamsp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamsp
adamsp / PagedList.kt
Created Oct 10, 2017
Paging Lib Blog PagedList.kt
View PagedList.kt
val mainHandler = Handler(Looper.getMainLooper())
val pagedList = PagedList.Builder<Int, Screenshot>()
.setDataSource(dataSource)
.setMainThreadExecutor({ mainHandler.post(it) })
.setBackgroundThreadExecutor(diskExecutor)
.setConfig(PagedList.Config.Builder()
.setPageSize(8)
.setEnablePlaceholders(true)
.build())
@adamsp
adamsp / MainActivity.kt
Last active Oct 10, 2017
Paging Lib Blog MainActivity.kt
View MainActivity.kt
var screenshotLoader: ScreenshotLoader? = null
var adapter: ScreenshotPickerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
screenshotLoader = SAFScreenshotLoader(contentResolver, diskExecutor)
adapter = ScreenshotPickerAdapter(this)
val recycler = findViewById(R.id.main_recycler) as RecyclerView?
recycler?.layoutManager = GridLayoutManager(this, 2)
@adamsp
adamsp / gist:44b075f40ed5ff4e3ca7
Created Mar 10, 2015
Pull DB from Android device
View gist:44b075f40ed5ff4e3ca7
adb shell "run-as com.your.app.package chmod 666 /data/data/com.your.app.package/databases/yourDbName.db"
adb pull /data/data/com.your.app.package/databases/yourDbName.db
@adamsp
adamsp / update.sh
Created Feb 11, 2014
Simple bash script for updating & deploying an Octopress site, and committing your changes to git. Usage: "./update.sh This is your commit message"
View update.sh
#!/bin/bash
ERR_SITE_GEN=1
ERR_SITE_DEPLOY=2
ERR_GIT_ADD=3
ERR_GIT_COMMIT=4
ERR_GIT_PUSH=5
ERR_NO_COMMIT_MESSAGE=6
if [ $# -eq 0 ]; then
@adamsp
adamsp / update.sh
Created Feb 5, 2014
Simple script to update my Octopress blog and push changes to git in one go. Now I type one command instead of 5!
View update.sh
#!/bin/bash
ERR_SITE_GEN=1
ERR_SITE_DEPLOY=2
ERR_GIT_ADD=3
ERR_GIT_COMMIT=4
ERR_GIT_PUSH=5
ERR_NO_COMMIT_MESSAGE=6
if [ $# -eq 0 ]; then
@adamsp
adamsp / MainActivity.java
Created Dec 16, 2013
Date formatting inconsistencies on Android. Varies across locales, Date format settings, devices, and presumably across Android versions too.
View MainActivity.java
package com.example.dtmformattingexamples;
import java.util.Date;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;
@adamsp
adamsp / GsonRequest.java
Created Nov 25, 2013
A Volley request class for easy parsing of JSON using Gson.
View GsonRequest.java
/**
* Copyright 2013 Adam Speakman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@adamsp
adamsp / TextViewLinkHider.java
Created Oct 28, 2013
If you've got a TextView with clickable links setup using HTML and LinkMovementMethod ( http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable/2746708#2746708 ), this class allows you to hide either the underlines or the entire link - useful, for example, if you're showing tweets and need to link to profiles etc.
View TextViewLinkHider.java
/**
* Copyright 2013 Adam Speakman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@adamsp
adamsp / DreamLinkMovementMethod.java
Last active Dec 26, 2015
How to create clickable links from TextViews within a DreamService.
View DreamLinkMovementMethod.java
/**
* Copyright 2013 Adam Speakman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@adamsp
adamsp / WCFDateTimeParser.java
Last active Dec 25, 2015
WCF services supply Dates over JSON in a strange format. This method takes a WCF-formatted Date string and parses it into a JodaTime DateTime object.
View WCFDateTimeParser.java
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
public class WCFDateTimeParser {
/**
* <p>WCF services supply Dates over JSON in a strange format. This method
* takes a WCF-formatted Date string and parses it into a JodaTime DateTime
* object. Assumes valid input matching a format described below.</p>
*
You can’t perform that action at this time.