Skip to content

Instantly share code, notes, and snippets.

Bhargav Mogra bhargavms

Block or report user

Report or block bhargavms

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bhargavms
bhargavms / LinearLayoutManagerWithAccurateOffset.kt
Created Jun 19, 2018
Accurate vertical scroll offset computation for LinearLayoutManager
View LinearLayoutManagerWithAccurateOffset.kt
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 Jul 27, 2016
A gradle plugin for checking test coverage using jacoco.
View jacoco.gradle
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 Jul 27, 2016
A persistent queue implemented using realm for persistence.
View RealmQueue.java
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 Jul 18, 2016
An interpolator that eases past the final value then back towards it elastically.
View EaseOutElasticInterpolator.java
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 Apr 24, 2016
A utility class for bitmap related operations.
View BitmapUtils.java
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;
@bhargavms
bhargavms / SeekBarWithHint.java
Created Mar 31, 2016
Seek bar with text near the thumb that shows the progress value
View SeekBarWithHint.java
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.SeekBar;
import com.myAppNameSpace.R;
You can’t perform that action at this time.