Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / ripple_gradient_layer-list.xml
Created August 22, 2019 14:11
A ripple with a gradient overlay
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorPrimary">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#00ffffff"
android:endColor="#00ffffff"
@dominicthomas
dominicthomas / android_instructions.md
Created May 13, 2019 14:13 — forked from patrickhammond/android_instructions.md
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@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 / MatchChildViewWithText.kt
Created June 6, 2018 14:01
Use this to iterate through a recycler view item and check each position to see if a view exists that has some specific text set
fun matchChildViewOfAccountTile(accountName: String, targetViewId: Int, itemMatcher: Matcher<View>): Matcher<View> =
object : BoundedMatcher<View, RecyclerView>(RecyclerView::class.java) {
override fun describeTo(description: Description) {
description.appendText("Has view id $targetViewId and matches $itemMatcher for item with name $accountName")
}
public override fun matchesSafely(recyclerView: RecyclerView): Boolean {
val itemCount = recyclerView.adapter.itemCount
for (i in 0 until itemCount) {
val holder = recyclerView.findViewHolderForAdapterPosition(i)
@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 / 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 / setup_bottom_navigation_view.txt
Created January 23, 2017 16:24
Quick guide on setting up a BottomNavigationView programatically..
final BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
bottomNavigationView.inflateMenu(R.menu.bottom_navigation_main);
bottomNavigationView.setItemBackgroundResource(R.color.colorPrimary);
bottomNavigationView.setItemTextColor(ContextCompat.getColorStateList(bottomNavigationView.getContext(), R.color.bottom_navigation_color_selector));
bottomNavigationView.setItemIconTintList(ContextCompat.getColorStateList(bottomNavigationView.getContext(), R.color.bottom_navigation_color_selector));
bottomNavigationView.setOnNavigationItemSelectedListener(...);
@dominicthomas
dominicthomas / max_height_linear_layout.txt
Created December 8, 2016 12:23
Enables you to set a max height for a linear layout while also using wrap content.. this means the layout will be collapsable but also have height constraints!
public class MaxHeightLinearLayout extends LinearLayout {
private int maxHeightDp;
public MaxHeightLinearLayout(Context context) {
super(context);
}
public MaxHeightLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@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 {