Skip to content

Instantly share code, notes, and snippets.

View rhoadster91's full-sized avatar
🐢

Girish Kamath rhoadster91

🐢
View GitHub Profile
@rhoadster91
rhoadster91 / DatabaseMigrator.java
Last active May 26, 2016 14:20
Class to help you put all data from one SQLite table to another during database migration. You can selectively choose which columns to migrate. Currently supports columns that are of type String, Int, Long, Double, Float, but adding a new type is easy: just add a new Parser<YourType> in the supportedParsers list.
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@rhoadster91
rhoadster91 / LevelTransitionDrawable.java
Last active February 5, 2019 15:45
Modified version of TransitionDrawable to let you create transition based on level (as against transition based on alpha). In this case contains a ScaleLevelTransitionDrawable implementation, but you can make your own implementation by nesting drawables.
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff.Mode;
import android.graphics.Rect;
@rhoadster91
rhoadster91 / TangentialInterpolator.java
Created August 4, 2015 15:34
Interpolator that tends to (but never reaches) specified asymptotic value. Easing factor specifies how quickly it should approach the asymptote.
import android.view.animation.Interpolator;
public class TangentialInterpolator implements Interpolator {
private float asymptote = 1f;
private float easing = 1f;
public TangentialInterpolator(float asymptote, float easing) {
this.asymptote = asymptote;
this.easing = easing;
@rhoadster91
rhoadster91 / MultiTouchSwipeableAdapter.java
Created July 31, 2015 17:02
Adapter that turns any ordinary AdapterView (ListView, GridView etc) into a collection with items that can be dismissed with swipes. Built off the source from Android Developers YouTube video for animating ListView deletion which can be found here: https://www.youtube.com/watch?v=YCHNAi9kJI4
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Collections;
@rhoadster91
rhoadster91 / PagedListView.java
Created May 26, 2015 11:54
Extended ListView to easily handle pagination. Set OnPageEndReachedListener to get callbacks on page change. Pause pagination while fetching new data. Resume pagination after getting data. Stop pagination once you're done.
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
@rhoadster91
rhoadster91 / ViewMapper.java
Last active August 29, 2015 14:18
ViewMapper
import android.app.Activity;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;