Skip to content

Instantly share code, notes, and snippets.

Avatar

Brett Cherrington brettwold

View GitHub Profile
@brettwold
brettwold / CustomAdapter.java
Last active Sep 24, 2020
Android adding a popup context menu to a RecyclerView
View CustomAdapter.java
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 {
@BindView(R.id.custom_name)
View PdfPrintUsage.java
public class PdfPrintUsage extends Activity {
private WebView wv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
wv = (WebView) findViewById(R.id.web_view);
}
@brettwold
brettwold / PdfPrint.java
Last active Jul 9, 2020
How to save a PDF from any Android WebView
View PdfPrint.java
package android.print;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import java.io.File;
public class PdfPrint {
@brettwold
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);
}
@NgModule({
...
providers: [
{
@brettwold
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
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
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
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 = parent.name
}
variant.outputs.each { output ->
def newApkName = "${appName}-${output.baseName}-${version}.aar"
@brettwold
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 = variant.buildType.name
if (name.indexOf("debug") > -1) {
return; // Skip debug builds.
}
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.baseName = "${project.name}-${rootProject.version}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
artifacts.add('archives', task);
@brettwold
brettwold / README.md
Last active Mar 20, 2019
Upload APK file S3 bucket
View README.md

Publish Android APKs to S3

Usage

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 {