Skip to content

Instantly share code, notes, and snippets.

@dlew
dlew / gist:3fee09af5ff946997551
Last active December 24, 2017 05:04
Android library artifact tasks
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 / androidmanifest.xml
Created May 1, 2015 20:05
Fully supporting "note to self" and "take a note" on Android
<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>
import rx.Observable;
import rx.subjects.PublishSubject;
public class Property<T> {
private T value;
private PublishSubject<T> property;
public Property() {
property = PublishSubject.create();
@dlew
dlew / gist:8c754d9b5e5b145d23ca
Created March 9, 2015 20:53
Wrapping with transformers
private CompositeSubscription subscriptions = new CompositeSubscription();
public <T> Observable<T> subscribe(Observable<T> observable) {
subscriptions.add(observable.subscribe());
return observable;
}
public <T> Observable.Transformer<T, T> subscribeTransformer() {
return new Observable.Transformer<T, T>() {
@Override
@dlew
dlew / build.gradle
Last active September 11, 2019 18:35
Sample gradle.build for Crashlytics
// 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 / RxActivityLifecycleCallbacks.java
Created November 26, 2014 21:35
RxActivityLifecycleCallbacks
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 / themes-debug.xml
Last active March 1, 2024 15:46
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.
<!-- 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 / gist:b808900466685749f1bd
Last active August 29, 2015 14:08
Everything you need to do to change the color of the title of your ActionBar.
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
@dlew
dlew / gist:f7026c13fa09fe6df0d6
Last active August 29, 2015 14:06
Why I hate mixing implicit/explicit styles
<style name="Widget" />

<style name="Widget.Button" />

<style name="Widget.Button.Alternative" parent="@android:style/SomeOtherStyle />

All buttons either use Widget.Button or Widget.Button.Alternative.

I decide to change something in Widget.Button.

RetrofitService.doTheThing(params) // Your typical API call
.subscribeOn(Schedulers.io()) // Execute API call on IO thread
.observeOn(AndroidSchedulers.mainThread()) // Execute observers on Android's main thread
.subscribe(results -> handle(results)); // Handling the results of the API call