Skip to content

Instantly share code, notes, and snippets.

Daniel Lew dlew

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`.
@dlew
dlew / themes-debug.xml
Last active Mar 23, 2019
With the new theming in AppCompat, a lot of assets are tinted automatically for you via theme attributes. That has often led me to wonder "where the hell did this color come from?" You can replace your normal theme with this debug theme to help figure out the source of that color.
View themes-debug.xml
<!-- You can change the parent around to whatever you normally use -->
<style name="DebugColors" parent="Theme.AppCompat">
<!-- System colors -->
<item name="android:windowBackground">@color/__debugWindowBackground</item>
<item name="android:colorPressedHighlight">#FF4400</item>
<item name="android:colorLongPressedHighlight">#FF0044</item>
<item name="android:colorFocusedHighlight">#44FF00</item>
<item name="android:colorActivatedHighlight">#00FF44</item>
@dlew
dlew / RxActivityLifecycleCallbacks.java
Created Nov 26, 2014
RxActivityLifecycleCallbacks
View RxActivityLifecycleCallbacks.java
package rx.android.lifecycle;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import rx.Observable;
import rx.subjects.BehaviorSubject;
import java.util.Map;
@dlew
dlew / gist:3fee09af5ff946997551
Last active Dec 24, 2017
Android library artifact tasks
View gist:3fee09af5ff946997551
if (project.android.hasProperty('libraryVariants')) {
android.libraryVariants.all { variant ->
Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
group = 'artifact'
description "Generates Javadoc for $variant.name"
// Source files from the variant
source = variant.javaCompiler.source
// Classpath from the variant + android.jar
@dlew
dlew / artifact-hunter.py
Created Nov 1, 2017
Simple Python script that tells you all the current artifact spots on a Stardew Valley save
View artifact-hunter.py
import xml.etree.ElementTree as ET
tree = ET.parse('/path/to/save/file')
root = tree.getroot()
locations = root.find('locations')
for location in locations:
name = location.find('name').text
objects = location.find('objects')
for thing in objects:
View gist:9fd280bbc057af800213
/**
* Returns the Java Compilation task if javac was configured to compile the source files.
* @deprecated prefer {@link #getJavaCompiler} which always return the java compiler task
* irrespective of which tool chain (javac or jack) used.
*/
@Nullable
@Deprecated
JavaCompile getJavaCompile() throws IllegalStateException;
/**
@dlew
dlew / build.gradle
Last active Jun 23, 2017
Sample gradle.build for Crashlytics
View build.gradle
// Follow the five numbered instructions for setting up Crashlytics
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
// 1. Add the Crashlytics Maven repository to your build script.
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
@dlew
dlew / androidmanifest.xml
Created May 1, 2015
Fully supporting "note to self" and "take a note" on Android
View androidmanifest.xml
<activity
android:name="com.yourapp.ui.NoteTaker">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.google.android.voicesearch.SELF_NOTE" />
<data android:mimeType="*/*" />
</intent-filter>
@dlew
dlew / File.java
Created Mar 1, 2016
Automated onError() message generation
View File.java
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());
You can’t perform that action at this time.