Skip to content

Instantly share code, notes, and snippets.


Brett Cherrington brettwold

View GitHub Profile
brettwold /
Last active Sep 24, 2020
Android adding a popup context menu to a RecyclerView
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private List<CustomObject> objects;
private OnItemSelectedListener listener;
private final boolean withContextMenu;
class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, View.OnCreateContextMenuListener, PopupMenu.OnMenuItemClickListener {
public class PdfPrintUsage extends Activity {
private WebView wv;
public void onCreate(Bundle savedInstanceState) {
wv = (WebView) findViewById(;
brettwold /
Last active Jul 9, 2020
How to save a PDF from any Android WebView
package android.print;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.util.Log;
public class PdfPrint {
brettwold / module.ts
Created Feb 26, 2017
Adding HttpAuthInterceptor to @NgModule
View module.ts
export function getHttpAuth(backend: ConnectionBackend, defaultOptions: RequestOptions, storage: Storage) {
return new HttpAuth(backend, defaultOptions, storage);
providers: [
brettwold / http-auth.ts
Last active Aug 11, 2017
Using HttpAuthInterceptor example Ionic2
View http-auth.ts
import { Response, RequestOptions, ConnectionBackend } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Storage } from '@ionic/storage';
import { HttpAuthInterceptor, InterceptorConfig } from './http-auth-interceptor';
export class HttpAuth extends HttpAuthInterceptor {
// In production code do not put your API keys here make sure they are obtained some other way.
// perhaps a env variables.
brettwold / http-auth-interceptor.ts
Last active Jan 11, 2018
Angular2 Http Interceptor to be used with accessing authenticated APIs
View http-auth-interceptor.ts
import { Http, Request, RequestOptions, RequestOptionsArgs, Response, ConnectionBackend, Headers } from "@angular/http";
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/fromPromise";
import "rxjs/add/operator/mergeMap";
export interface InterceptorConfigOptional {
headerName?: string;
headerPrefix?: string;
noTokenError?: boolean;
brettwold / dist.gradle
Created Jun 15, 2016
Gradle script to create a distribution archive (zip) file from a multi-module project
View dist.gradle
task distArchive(type: Zip, dependsOn: ['App1:build', 'App2:build', 'Lib1:build', 'JavaLib2:build']) {
from(["Lib1/build/outputs/aar", "JavaLib2/build/libs"]) {
include "*-release-${project.version}.aar"
include "*.jar"
into "libs/"
rename { filename ->
filename.replace 'release-', ''
brettwold / artifacts-library.gradle
Last active Jun 15, 2016
Add SemVer version number to main android artifact
View artifacts-library.gradle
android.libraryVariants.all { variant ->
def appName
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName =
variant.outputs.each { output ->
def newApkName = "${appName}-${output.baseName}-${version}.aar"
brettwold / android-library-jar.gradle
Created Jun 14, 2016
Gradle create a jar file from an android library module
View android-library-jar.gradle
android.libraryVariants.all { variant ->
def name =
if (name.indexOf("debug") > -1) {
return; // Skip debug builds.
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.baseName = "${}-${rootProject.version}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
artifacts.add('archives', task);
brettwold /
Last active Mar 20, 2019
Upload APK file S3 bucket

Publish Android APKs to S3


Setup your S3 variables. Highly recommend that the access key and id are referred to as environment variables then they don't end up in your source repo. The snippet below sets up the variables for all projects in your build but you can do it on an individual project basis as well if you prefer.

allprojects {