Skip to content

Instantly share code, notes, and snippets.

Jay Newstrom JayNewstrom

View GitHub Profile
@dlew
dlew / script.sh
Created Nov 9, 2018
Simple AndroidX Migration Script
View script.sh
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@neworld
neworld / howto.md
Last active Nov 27, 2018
How to make faster Android build without sacrificing new api lint check
View howto.md

Original solution sacrifices new api lint check.

Here my solution:

int minSdk = hasProperty('minSdk') ? minSdk.toInteger() : 16

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
@JakeWharton
JakeWharton / Java6.java
Last active Mar 15, 2019
A comparison between non-capturing and capturing expressions across Java 6, Java 8, Java 8 with Retrolambda, Kotlin with native function expressions, and Kotlin with Java SAM expression.
View Java6.java
import java.util.Arrays;
class NonCapturing {
public static void main(String... args) {
run(new Runnable() {
@Override public void run() {
System.out.println("Hey!");
}
});
}
@RomainPiel
RomainPiel / MyTest.java
Last active Feb 9, 2019
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
View MyTest.java
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview))
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});
@JakeWharton
JakeWharton / ShampooRule.java
Last active Jan 11, 2019
Got flaky tests? Shampoo them away with a quick JUnit rule. Apache 2.
View ShampooRule.java
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/** Got flaky tests? Shampoo them away. */
public final class ShampooRule implements TestRule {
private final int iterations;
public ShampooRule(int iterations) {
if (iterations < 1) throw new IllegalArgumentException("iterations < 1: " + iterations);
View Dexter.java
public class Dexter {
private static String optimizedDirectory = "optimized";
private static String workDirectory = "working";
public static void loadFromAssets(Context context, String fileName) throws Exception {
File optimized = new File(optimizedDirectory);
optimized = context.getDir(optimized.toString(), Context.MODE_PRIVATE);
optimized = new File(optimized, fileName);
@JakeWharton
JakeWharton / AspectRatioImageView.java
Created Jun 2, 2012
ImageView that respects an aspect ratio applied to a specific measurement.
View AspectRatioImageView.java
// Copyright 2012 Square, Inc.
package com.squareup.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
/** Maintains an aspect ratio based on either width or height. Disabled by default. */
public class AspectRatioImageView extends ImageView {
You can’t perform that action at this time.