Skip to content

Instantly share code, notes, and snippets.

@gitanuj
gitanuj / CenterBottomImageView.java
Created February 22, 2015 15:31
Android ImageView which scales the bitmap to fit in a center-bottom manner
import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* This ImageView scales the image to match either the width or height of the
* ImageView and places in the center-bottom. For eg. if the ImageView is 10x6
* units and the image is 4x4 units, it will scale the image to 6x6 units and
* place as follows:
@gitanuj
gitanuj / FailSafeFile.java
Created April 13, 2015 18:33
FailSafeFile for Java. Ensures that only complete file is written to the disk.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* FailSafeFile guarantees that the complete file is written before renaming it
* to its actual name. Everything is written to a .tmp hidden file unless
* finishWrite() is called.
@gitanuj
gitanuj / RecursiveFileObserver.java
Created May 20, 2015 19:15
A FileObserver for Android which monitors all the files/folders in a directory recursively.
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import android.os.FileObserver;
/**
* A FileObserver that observes all the files/folders within given directory
* recursively. It automatically starts/stops monitoring new folders/files
@gitanuj
gitanuj / MultiImageLoader.java
Created September 13, 2015 23:56
A MultiImageLoader for loading multiple images using Volley on Android. Implementation of MultiNetworkImageView included.
import java.util.ArrayList;
import java.util.List;
import android.widget.ImageView;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.android.volley.toolbox.ImageLoader.ImageListener;