Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / MissingXmlHeaderDetector.java
Created November 26, 2018 12:57
Custom lint class for check for and enforce custom xml headers
public class MissingXmlHeaderDetector extends ResourceXmlDetector {
public static final Issue ISSUE_MISSING_XML_HEADER = Issue.create(
"MissingXmlHeader",
"Flags xml files that don't have a header.",
"An xml file should always have the xml header to declare that it is an xml file despite the file ending.",
Category.CORRECTNESS, 10, Severity.ERROR,
new Implementation(MissingXmlHeaderDetector.class, Scope.RESOURCE_FILE_SCOPE));
@Override
@dominicthomas
dominicthomas / connectedAndroidTest.sh
Created July 4, 2018 13:17
Script that could be used to prepare and run ui tests
#!/bin/bash
EMULATOR_NAME=$1
USER_NAME=$2
ENVIRONMENT=$3
# Start an emulator
${ANDROID_HOME}/tools/emulator -avd ${EMULATOR_NAME} -wipe-data &
EMULATOR_PID=$!
# Wait for Android to finish booting
@dominicthomas
dominicthomas / Update gradlew
Created October 23, 2013 10:07
Update the gradle wrapper. To update the system gradle use the guide here http://devopsnet.com/2012/05/24/upgrading-gradle/. The graddlew wrapper is packaged in with your project so is independent of the gradle version on your system.
gradlew with --refresh-dependencies
@dominicthomas
dominicthomas / rxjavathreadtest.java
Created April 4, 2018 10:36
Small snippet to check which thread an rxjava observable is requesting/returning on
@Test
public void testRxjavaThreading() throws InterruptedException {
final BlockingQueue<Runnable> tasks = new LinkedBlockingQueue<>();
System.out.println("Caller thread: " + Thread.currentThread().getName());
final Disposable subscribe = Observable.fromCallable(
new Callable<Integer>() {
@Override
public Integer call() throws Exception {
System.out.println("Observable thread: " + Thread.currentThread().getName());
@dominicthomas
dominicthomas / Rainbow_Brush_Demo
Last active March 26, 2018 09:22
A simple activity with a drawing view and a rainbow brush. Proof of concept. Potential to be improved.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MotionEvent;
import android.view.View;
@dominicthomas
dominicthomas / Android ViewTreeObserver
Created November 1, 2013 14:41
How to add and remove a viewtreeobserver to an android view. This lets you call stuff when the view is finished rendering.
final ViewTreeObserver vto = myview.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
// do stuff
// remove this layout listener - as it will run every time the view updates
if (myview.getViewTreeObserver().isAlive()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
@dominicthomas
dominicthomas / picasso_marker_image_target.txt
Last active March 26, 2017 20:16
Android Picasso target to display an image view in a map icon
// Create new image target
final SimpleImageTarget newTarget = new SimpleImageTarget(
clusterItem.getSpot(), marker, markerImageView, iconGenerator);
// Store target reference - remove later
if (!imageTargets.containsKey(clusterItem.getSpot().getId())) {
imageTargets.put(clusterItem.getSpot().getId(), newTarget);
}
// Kick off image loading
@dominicthomas
dominicthomas / gradle_fabric_upload.txt
Created November 25, 2016 10:54
Code to upload a build to crashlytics even when setting a custom apk name.
android {
...
debug {
debuggable true
...
ext.betaDistributionGroupAliases = "Android-Test"
}
...
project.android.applicationVariants.all { variant ->
variant.preBuild.doLast {
@dominicthomas
dominicthomas / Android Touch Area Extender
Last active November 1, 2016 07:28
A lovely android view touch area extender builder class. Made to provide a larger touch area to views that aren't standard clickable android view widgets. Works well on things like a small bit of text or a little drop down arrow. The code here is from a project that uses retrolamda and google's guava library for preconditions and optionals.
import android.graphics.Rect;
import android.view.TouchDelegate;
import android.view.View;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
/**
* Utility used to extend the touchable area around a view in a viewgroup
* Usage: TouchAreaExtender.Builder.with(mReJamCaptionInput)
@dominicthomas
dominicthomas / PhoneNumberFormatter.java
Last active October 7, 2016 12:45
Simple class to format and convert to E164, mobile phone numbers for the UK and the US. Probably better to just use google libphonenumber.
public class PhoneNumberFormatter {
private final String simCountryIso;
private final Map<String, String> countryCodeMap = Collections.unmodifiableMap(
new HashMap<String, String>() {{
put("GB", "44");
put("US", "1");
}});