Skip to content

Instantly share code, notes, and snippets.

Avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / ripple_gradient_layer-list.xml
Created Aug 22, 2019
A ripple with a gradient overlay
View ripple_gradient_layer-list.xml
<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 — forked from patrickhammond/android_instructions.md
Easily setup an Android development environment on a Mac
View android_instructions.md

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 Nov 26, 2018
Custom lint class for check for and enforce custom xml headers
View MissingXmlHeaderDetector.java
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 Jul 4, 2018
Script that could be used to prepare and run ui tests
View connectedAndroidTest.sh
#!/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 Jun 6, 2018
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
View MatchChildViewWithText.kt
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 Apr 4, 2018
Small snippet to check which thread an rxjava observable is requesting/returning on
View rxjavathreadtest.java
@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 Mar 26, 2017
Android Picasso target to display an image view in a map icon
View picasso_marker_image_target.txt
// 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 Jan 23, 2017
Quick guide on setting up a BottomNavigationView programatically..
View setup_bottom_navigation_view.txt
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 Dec 8, 2016
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!
View max_height_linear_layout.txt
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 Nov 25, 2016
Code to upload a build to crashlytics even when setting a custom apk name.
View gradle_fabric_upload.txt
android {
...
debug {
debuggable true
...
ext.betaDistributionGroupAliases = "Android-Test"
}
...
project.android.applicationVariants.all { variant ->
variant.preBuild.doLast {