Skip to content

Instantly share code, notes, and snippets.

@bhargavms
bhargavms / LinearLayoutManagerWithAccurateOffset.kt
Created June 19, 2018 10:16
Accurate vertical scroll offset computation for LinearLayoutManager
class LinearLayoutManagerWithAccurateOffset(context: Context?) : LinearLayoutManager(context) {
// map of child adapter position to its height.
private val childSizesMap = mutableMapOf<Int, Int>()
override fun onLayoutCompleted(state: RecyclerView.State?) {
super.onLayoutCompleted(state)
for (i in 0 until childCount) {
val child = getChildAt(i)
childSizesMap[getPosition(child)] = child.height
@bhargavms
bhargavms / jacoco.gradle
Created July 27, 2016 05:40
A gradle plugin for checking test coverage using jacoco.
apply plugin: 'jacoco'
jacoco {
toolVersion "0.7.1.201405082137"
reportsDir = file("$buildDir/intermediates/test")
}
// Taken from https://blog.gouline.net/2015/06/23/code-coverage-on-android-with-jacoco/
project.afterEvaluate {
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
@bhargavms
bhargavms / RealmQueue.java
Last active July 27, 2016 05:40
A persistent queue implemented using realm for persistence.
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
@bhargavms
bhargavms / EaseOutElasticInterpolator.java
Created July 18, 2016 20:28
An interpolator that eases past the final value then back towards it elastically.
import android.view.animation.Interpolator;
/**
* An interpolator that eases past the final value then back towards it elastically.
* <p/>
* math taken from link provided in see also section.
*
* @see <a href="https://github.com/greensock/GreenSock-JS/blob/master/src/uncompressed/easing/EasePack.js">Greensock Github</a></a>
*/
public class EaseOutElasticInterpolator implements Interpolator {
@bhargavms
bhargavms / BitmapUtils.java
Last active January 26, 2020 21:21
A utility class for bitmap related operations.
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.koushikdutta.ion.Ion;