Skip to content

Instantly share code, notes, and snippets.

import rx.Observable;
import rx.functions.Func0;
/**
* Wraps a source observable for creating a new observable
* on every subscribe.
* <p/>
* For use with {@link Observable#defer(rx.functions.Func0)}
*/
public class DeferredObservable<T> implements Func0<Observable<T>> {
@DanielGrech
DanielGrech / FloatingActionButton.java
Created July 24, 2014 20:58
FloatingActionButton to simulate Material design look
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
@DanielGrech
DanielGrech / image_with_overlapping_label.xml
Created July 24, 2014 20:51
Layout for an image with 2 labels at the bottom. Overlay is applied to bleed out any images
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="200dp" />
@DanielGrech
DanielGrech / BlurredImageView.java
Last active December 22, 2016 03:44
Blurred Image background with a rounded image bottom center. Image view which blurs its contents only supports API 17+. Older API's will just display the image as is
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.util.AttributeSet;
@DanielGrech
DanielGrech / BaseListAdapter.java
Last active August 29, 2015 14:04
Base adapter subclasses which take some of the boilerplate out of displaying a list of items
import android.widget.BaseAdapter;
import java.util.List;
public abstract class BaseListAdapter<DataType> extends BaseAdapter {
private List<DataType> mItems;
@Override
public final int getCount() {
@DanielGrech
DanielGrech / TwoLineImageListItem.java
Created July 22, 2014 22:16
List item for displaying 2 lines of text with an image to the right
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;
@DanielGrech
DanielGrech / .bash_profile
Last active March 12, 2021 03:25
Bash profile with some useful shortcuts I like
export BASH_SILENCE_DEPRECATION_WARNING=1
export HGEDITOR=nano
export PS1='\w: '
# important
alias shrug="printf '¯\_(ツ)_/¯' | pbcopy"
@DanielGrech
DanielGrech / BouncyTouch.java
Created July 23, 2013 07:32
Creates a 'bouncy effect' on the passed view (code from DevBytes episode - http://www.youtube.com/watch?v=uQ7PTe7QMQM) Note this version depends on nineoldandroids
/**
* Applies a touch listener to <code>v</code> which causes the view to 'expand and contract'
* based on it's touch state
*
* @param v
* The view to apply the touch listener too
* @param bounceTension
* The tension (bounce back) to apply when the user lifts their finger from the view
*/
public static void applyBounceTouchListener(final View v, final int bounceTension) {
@DanielGrech
DanielGrech / BouncyAndSquashyAndStretchyButtonActivity.java
Created June 13, 2013 07:16
Create's a 'bounce' animation as shown in the Google IO 2013 session 'A Moving Experience' (https://developers.google.com/events/io/sessions/326431311)
/*
<main.xml>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
@DanielGrech
DanielGrech / MultiThreadedService.java
Created November 16, 2012 01:15
Like an Android IntentService, but avoids the pitfalls of using a queue. Namely, it can process multiple intents in parallel
public abstract class MultiThreadedService extends Service {
private volatile List<Looper> mServiceLoopers;
private volatile List<ServiceHandler> mServiceHandlers;
private String mName;
private boolean mRedelivery;
public IBinder onBind(Intent intent) {
return null;
}