Skip to content

Instantly share code, notes, and snippets.

View jonfhancock's full-sized avatar

Jon F Hancock jonfhancock

View GitHub Profile
@jonfhancock
jonfhancock / KotlinShared.xml
Last active December 10, 2020 01:35
Android Studio live templates. Apply them following directions here: https://www.jetbrains.com/help/idea/sharing-live-templates.html
<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" />
<context>
<option name="KOTLIN" value="true" />
</context>
</template>
</templateSet>
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
lastOrientationRequested = Configuration.ORIENTATION_PORTRAIT;
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
lastOrientationRequested = Configuration.ORIENTATION_LANDSCAPE;
}
public class DumbViewHolder extends RecyclerView.ViewHolder {
TextView textTitle;
TextView textLocation;
TextView textDate;
ImageView mapIcon;
public DumbViewHolder(View itemView) {
super(itemView);
textTitle = (TextView) itemView.findViewById(R.id.text_title);
textLocation = (TextView) itemView.findViewById(R.id.text_location);
@jonfhancock
jonfhancock / ExcellentAdventure.java
Last active February 25, 2021 07:00
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 {
@Retention(SOURCE)
@StringDef({ERA_BC, ERA_AD})
public @interface Era {
}
public static final String ERA_BC = "BC";
public static final String ERA_AD = "AD";
@jonfhancock
jonfhancock / ChangeStrictMode.java
Created June 14, 2016 16:12
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();
intentFilter.addAction("com.your.package.action_change_strict_mode");
registerReceiver(new BroadcastReceiver() {
package com.signnow.android.util;
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
jonfhancock / cpdb.sh
Created August 23, 2013 18:26
then from the command line, I run: ./pulldb.sh
#! /bin/bash
cp /data/data/com.signnow.android/databases/documents.db /sdcard/
cp /data/data/com.signnow.android/databases/signnow.db /sdcard/
exit
exit
@jonfhancock
jonfhancock / GetNonceServlet.java
Created October 19, 2012 17:23
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";
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
// We need a session object to store temporary data for the user.
HttpSession session = req.getSession();