Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
kaushikgopal / Truss.java
Created June 5, 2014 15:50 — forked from JakeWharton/Truss.java
Extremely simple wrapper around SpannableStringBuilder to make the API more logical and less awful. Apache 2 licensed. (courtesy JakeWharton)
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 {
@kaushikgopal
kaushikgopal / ReuseCachedViewAdapter.java
Last active May 22, 2020 19:46
Reusable View Adapter along with view holder pattern. Apache 2 licensed
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.micromobs.pkk.R;
import com.micromobs.pkk.ui.adapters.viewholders.ViewHolder;
/**
* 1. reusableView (convertView) caching from the Android framework
@kaushikgopal
kaushikgopal / Bundler.java
Last active August 29, 2015 14:02
A nice helper utility that creates your Bundle with extras quickly. Apache 2 licensed
import android.os.Bundle;
// see my gist for [https://gist.github.com/kaushikgopal/9eea148a2188dc58fe37](ParcelableSparseArray) implementation
public class Bundler {
private Bundle _bundle;
public Bundler() {
_bundle = new Bundle();
@kaushikgopal
kaushikgopal / ScopedBus.java
Created July 3, 2014 00:16
An enhanced (otto) event bus - Apache 2 Licensed
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
import java.util.HashSet;
import java.util.Set;
/*
@kaushikgopal
kaushikgopal / CircleTransformation.java
Last active March 24, 2017 22:22
A set of Picasso Transformation Examples
package co.kaush.mystarterapp.myappmodule.ui.transformations;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import com.squareup.picasso.Transformation;
@kaushikgopal
kaushikgopal / AndroidColorUtils.java
Created August 2, 2014 18:31
Some handy utility methods for dealing with Color in Android
private int _darkenOrLightenColor(int color, boolean darken) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
// value component
if (darken) {
hsv[2] *= Math.max(hsv[2] * 0.99f, 0);
} else {
hsv[2] = Math.max(hsv[2] * 1.5f, 1);
}
@kaushikgopal
kaushikgopal / RandomUtils.java
Created August 5, 2014 19:12
Java Random Utilities Helper
/*
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@kaushikgopal
kaushikgopal / RoundedBitmapDrawableUsage.java
Last active March 25, 2024 13:55
RoundedImageView - drop dead easy way to do this with RoundedBitmapDrawable
Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);
// option 1 h/t [Chris Banes](https://chris.banes.me/)
circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());
// option 2 h/t @csorgod in the comments
circularBitmapDrawable.setCircular(true);
@kaushikgopal
kaushikgopal / .phoenix.1.js
Last active September 13, 2017 23:32
Kaushik Gopal's Phoenix.Js window management script
// Forked originally from @JasonM23’s config in literate coffee-script
// https://github.com/jasonm23/Phoenix-config/blob/master/Phoenix-config.litcoffee
// Released under MIT license - http://opensource.org/licenses/MIT
var BROWSER, EDITOR, FINDER, GRID_HEIGHT, GRID_WIDTH, MARGIN_X, MARGIN_Y, MUSIC, TERMINAL, VIDEO,
changeGridHeight, changeGridWidth, debug, forApp, key_binding, lastFrames, layouts, mash,
moveWindowLeftOneColumn, moveWindowRightOneColumn, moveWindowToNextScreen, moveWindowToPreviousScreen,
snapAllToGrid, switchLayout, transposeWindows,
windowDownOneRow, windowGrowOneGridColumn, windowGrowOneGridRow, windowShrinkOneGridColumn,
windowShrinkOneGridRow, windowToFullHeight, windowUpOneRow,
@kaushikgopal
kaushikgopal / bp_rxjava_warm_share.java
Created July 11, 2015 22:28
warm observable snippet for a blog post
Observable
.interval(1, TimeUnit.SECONDS)
.map(new Func1<Long, Integer>() {
@Override
public Integer call(Long aLong) {
return aLong.intValue();
}
})
.take(20)
.share();