Skip to content

Instantly share code, notes, and snippets.

@dmarcato
dmarcato / strip_play_services.gradle
Last active December 21, 2022 10:10
Gradle task to strip unused packages on Google Play Services library
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')
@lgvalle
lgvalle / FacebookHomeProvider.java
Last active August 8, 2016 03:50
rxjava + facebook
public class FacebookHomeProvider {
protected final PublishSubject<FbPost> behaviorSubject;
private Request request;
public FacebookHomeProvider() {
behaviorSubject = PublishSubject.create();
behaviorSubject.subscribeOn(Schedulers.io());
}
/**
@balysv
balysv / EndlessBindableAdapter.java
Last active August 29, 2015 14:01
Endless Collection adapter using RxJava and Bindable pattern for Android
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import rx.Observable;
@f2prateek
f2prateek / ActivitySubscriptionManager.java
Last active October 23, 2017 14:30
Managing Subscriptions in Android with RxJava
/*
* Copyright 2014 Prateek Srivastava
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@devunwired
devunwired / ExampleFragment.java
Created May 15, 2014 17:03
Method for animating Android fragment positions during a add/replace/remove transition using custom properties. This method does not require subclassing target views with additional setter methods, but instead requires subclassing the fragment...something you are likely already doing.
/**
* An example of adding these transitions to a Fragment. This simple
* version just applies opposite transitions to any Fragment whether it is
* entering or exiting view. You can also inspect the transit mode parameter
* (i.e. TRANSIT_FRAGMENT_OPEN, TRANSIT_FRAGMENT_CLOSE) in combination to do
* different animations for, say, adding a fragment versus popping the back stack.
*
* Transactions without an explicit transit mode set, in this example, will not
* animate. Allowing the initial fragment add, for example, to simply appear.
*/
@mkuprionis
mkuprionis / README.md
Created May 14, 2014 10:41
Embeded ActionBar tabs

Copied from Cyril Mottier's post on G+

His comments:

In order to implement tabs I decided to go for an entirely custom solution. I created the tab bar from scratch and added it as a custom ActionBar View. The tabs container is called TabBarView and extends LinearLayout. TabBarView actually handles the "selection strip".

The TabBarView is then filled with several TabView (one for each tab). The main purpose of TabView is to provide a nice API to deal with icon and the optional text (only visible in landscape) and handle the long press gesture (long pressing a tab displays a hint).

Once the TabBarView is initialized with a bunch of TabView, it is added as a custom View to the ActionBar:

@lgvalle
lgvalle / gist:3ad43349c4e0202ec147
Last active August 8, 2016 03:52
rxjava + twitter4j
public class HomePresenterImpl implements HomePresenter {
private static final String TAG = HomePresenterImpl.class.getSimpleName();
private final HomeScreen screen;
private final DataProvider provider;
private Subscription subscription1;
public HomePresenterImpl(HomeScreenImpl screen, DataProvider dataProvider) {
this.screen = screen;
this.provider = dataProvider;
}
@fappel
fappel / Repeat.java
Last active June 5, 2023 16:58
JUnit 4 TestRule to run a test repeatedly for a specified amount of repititions
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention( RetentionPolicy.RUNTIME )
@Target( {
java.lang.annotation.ElementType.METHOD
} )
public @interface Repeat {
public abstract int times();
@xrigau
xrigau / AndroidManifest.xml
Last active February 6, 2025 22:38
Disable animations for Espresso tests - run with `gradle cATDD`
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novoda.espresso">
<!-- For espresso testing purposes, this is removed in live builds, but not in dev builds -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<!-- ... -->
@JakeWharton
JakeWharton / Truss.java
Last active August 12, 2024 07:31
Extremely simple wrapper around SpannableStringBuilder to make the API more logical and less awful. Apache 2 licensed.
import android.text.SpannableStringBuilder;
import java.util.ArrayDeque;
import java.util.Deque;
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */
public class Truss {
private final SpannableStringBuilder builder;
private final Deque<Span> stack;