Skip to content

Instantly share code, notes, and snippets.

View brettwold's full-sized avatar

Brett Cherrington brettwold

View GitHub Profile
@brettwold
brettwold / AlertTest.java
Last active September 16, 2015 14:29
Robolectric test for AlertDialog display
public class AlertTest {
@Test
public void check_alert() {
AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alert);
ShadowAlertDialog sAlert = Robolectric.shadowOf(alert);
assertThat(sAlert.getTitle().toString(), is(Robolectric.application.getString(R.string.adb_warning_title)));
}
}
@brettwold
brettwold / BaseTestClass.java
Last active February 10, 2016 18:17
How to make RxJava threading run instantly in JUnit/Robolectric tests
public class BaseTestClass {
@Before
public void setup() {
ShadowLog.stream = System.out;
RxJavaTestPlugins.resetPlugins();
RxJavaTestPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
@Override
@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 {
@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 / 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 / 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 / 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 / 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 / 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 / PdfPrint.java
Last active January 2, 2024 03:41
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 {