Skip to content

Instantly share code, notes, and snippets.

Avatar

Saket Narayan saket

View GitHub Profile
@saket
saket / maven_terminology.md
Last active Feb 6, 2021
Maven terminology
View maven_terminology.md

Maven: a build automation tool maintained by Apache

Maven repository: a host for maven artifacts

Maven Central: the biggest host, maintained by Sonatype


JFrog: a company

@saket
saket / RxPreferencesEnumTypeAdapter.java
Last active May 22, 2018
A generic enum type converter for RxPreferences library
View RxPreferencesEnumTypeAdapter.java
import com.f2prateek.rx.preferences2.Preference;
public class RxPreferencesEnumTypeAdapter<T extends Enum<T>> implements Preference.Converter<T> {
private final Class<T> enumClass;
public RxPreferencesEnumTypeAdapter(Class<T> enumClass) {
this.enumClass = enumClass;
}
@saket
saket / StoreLruFileSystem.java
Created Mar 18, 2018
A FileSystem for NYT-Store that uses DiskLruCache
View StoreLruFileSystem.java
import com.jakewharton.disklrucache.DiskLruCache;
import com.nytimes.android.external.fs3.filesystem.FileSystem;
import com.nytimes.android.external.store3.base.RecordState;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
View Pair.java
import android.support.annotation.Nullable;
import com.google.auto.value.AutoValue;
/**
* Copied from {@link android.support.v4.util.Pair} to remove all @Nullable annotations.
* <p>
* Container to ease passing around a tuple of two objects.
*/
public abstract class Pair<F, S> {
View glide rx issue
private void foo() {
String imageUrl = "https://i1.wp.com/saket.me/wp-content/uploads/2017/08/notification-progress-issue-2.png?w=1200";
Single
.<Drawable>create(emitter -> {
Glide.with(this)
.load(imageUrl)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
View ScrollInterceptibleViewPager.java
package me.saket.dank.widgets;
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
/**
@saket
saket / GlidePaddingTransformation.java
Last active Jul 20, 2017
Adds empty spaces to inflate the height of images
View GlidePaddingTransformation.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
@saket
saket / Truss.java
Created May 9, 2016
Copied from some project by Jake Wharton. He describees it as "A SpannableStringBuilder wrapper whose API doesn't make me want to stab my eyes out"
View Truss.java
package com.jakewharton.u2020.ui.misc;
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 {
@saket
saket / EachDirectoryPath.md
Created May 2, 2016 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.
View EachDirectoryPath.md

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@saket
saket / AccountUtils.java
Created Feb 14, 2016 — forked from imminent/AccountUtils.java
Utility to retrieve user profile on Android device
View AccountUtils.java
/**
* A collection of authentication and account connection utilities. With strong inspiration from the Google IO session
* app.
* @author Dandré Allison
*/
public class AccountUtils {
/**
* Interface for interacting with the result of {@link AccountUtils#getUserProfile}.
*/