Skip to content

Instantly share code, notes, and snippets.

View brettwold's full-sized avatar

Brett Cherrington brettwold

View GitHub Profile
@brettwold
brettwold / CustomAdapter.java
Last active December 14, 2022 17:52
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 {
@BindView(R.id.custom_name)
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 September 22, 2024 06:14
How to save a PDF from any Android WebView
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 February 26, 2017 14:06
Adding HttpAuthInterceptor to @NgModule
export function getHttpAuth(backend: ConnectionBackend, defaultOptions: RequestOptions, storage: Storage) {
return new HttpAuth(backend, defaultOptions, storage);
}
@NgModule({
...
providers: [
{
@brettwold
brettwold / http-auth.ts
Last active August 11, 2017 13:43
Using HttpAuthInterceptor example Ionic2
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 January 11, 2018 12:54
Angular2 Http Interceptor to be used with accessing authenticated APIs
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 June 15, 2016 12:32
Gradle script to create a distribution archive (zip) file from a multi-module project
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 June 15, 2016 12:29
Add SemVer version number to main android artifact
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 June 14, 2016 11:10
Gradle create a jar file from an android library module
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 July 21, 2021 02:26
Upload APK file S3 bucket

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 {