Skip to content

Instantly share code, notes, and snippets.


Jon F Hancock jonfhancock

View GitHub Profile
jonfhancock / KotlinShared.xml
Last active Dec 10, 2020
Android Studio live templates. Apply them following directions here:
View KotlinShared.xml
<templateSet group="KotlinShared">
<template name="krequire" value="requireNotNull($VAR$) {&#10; &quot;Required value '$VAR$' in $CLASS_NAME$.$FUNCTION_NAME$() was null.&quot;&#10;}&#10;$END$" description="Require Not Null with a helpful print statement" toReformat="true" toShortenFQNames="true">
<variable name="VAR" expression="kotlinVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="CLASS_NAME" expression="kotlinClassName()" defaultValue="" alwaysStopAt="false" />
<variable name="FUNCTION_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<option name="KOTLIN" value="true" />
View gist:2aa60fa6623d390515fb67e0ebf4e312
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
lastOrientationRequested = Configuration.ORIENTATION_PORTRAIT;
} else {
lastOrientationRequested = Configuration.ORIENTATION_LANDSCAPE;
public class DumbViewHolder extends RecyclerView.ViewHolder {
TextView textTitle;
TextView textLocation;
TextView textDate;
ImageView mapIcon;
public DumbViewHolder(View itemView) {
textTitle = (TextView) itemView.findViewById(;
textLocation = (TextView) itemView.findViewById(;
jonfhancock /
Last active Feb 25, 2021
This set of classes demonstrates what a Not Dumb ViewHolder should look like. It lightens the load on the Adapter, and places decisions about what to do with user interactions on the Activity where it belongs.
public class ExcellentAdventure {
@StringDef({ERA_BC, ERA_AD})
public @interface Era {
public static final String ERA_BC = "BC";
public static final String ERA_AD = "AD";
jonfhancock /
Created Jun 14, 2016
This method can be called by your Application class onCreate(), or even your first Activity. After that, for debug builds only, you can manipulate StrictMode settings at any time without inconveniencing your QA team.
* For debug builds, this adds the ability to set up StrictMode on the fly via the command line with a command like
* adb shell am broadcast -a com.your.pakcage.action_change_strict_mode --ez enabled true --esa penalties log\,flash\,death
private void setupStrictModeReceiver() {
if (BuildConfig.DEBUG) {
final String tag = "StrictModeReceiver";
IntentFilter intentFilter = new IntentFilter();
registerReceiver(new BroadcastReceiver() {
public class IconFontMapping {
public enum Icon {
CURSOR(0, ""), CROSSHAIR(1, ""), SCREENSHOT(2, ""), SEARCH(3, "🔎"), ZOOM(4, ""), ZOOMIN(5, ""), ZOOMOUT(
6, ""), VIEW(7, "👀"), EYE(8, "👀"), LOOK(9, "👀"), VISIBLE(10, "👀"), VISIBILITY(11, "👀"), ATTACH(
12, "📎"), ATTACHMENT(13, "📎"), PAPERCLIP(14, "📎"), LINK(15, "🔗"), UNLINK(16, ""), MOVE(17, ""), EDIT(
18, ""), WRITE(19, ""), PENCIL(20, ""), WRITINGDISABLED(21, ""), PENCILDISABLED(22, ""), ERASE(23,
""), ERASER(24, ""), COMPOSE(25, "📝"), LOCK(26, "🔒"), LOCKED(27, "🔒"), PRIVATE(28, "🔒"), SECURE(
jonfhancock /
Created Aug 23, 2013
then from the command line, I run: ./
#! /bin/bash
cp /data/data/ /sdcard/
cp /data/data/ /sdcard/
jonfhancock /
Created Oct 19, 2012
A pair of servlets to manage nonces and signature verfication for Android in-app billing.
public class GetNonceServlet extends HttpServlet{
public final static String KNOWN_NONCES = "KNOWN_NONCES";
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// We need a session object to store temporary data for the user.
HttpSession session = req.getSession();