Skip to content

Instantly share code, notes, and snippets.

View saket's full-sized avatar

Saket Narayan saket

View GitHub Profile
@saket
saket / Readme.md
Last active November 30, 2015 10:34 — forked from gabrielemariotti/Readme.md
A SimpleSectionedRecyclerViewAdapter: use this class to realize a simple sectioned `RecyclerView.Adapter`.

You can use this class to realize a simple sectioned RecyclerView.Adapter without changing your code.

The RecyclerView should use a LinearLayoutManager. You can use this code also with the TwoWayView with the ListLayoutManager (https://github.com/lucasr/twoway-view)

This is a porting of the class SimpleSectionedListAdapter provided by Google

Screen

Example:

@saket
saket / AccountUtils.java
Created February 14, 2016 07:59 — forked from imminent/AccountUtils.java
Utility to retrieve user profile on Android device
/**
* 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}.
*/
@saket
saket / EachDirectoryPath.md
Created May 2, 2016 17:41 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.

System directories

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

External storage directories

@saket
saket / Truss.java
Created May 9, 2016 14:32
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"
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 {
public Bitmap getScreenshotFromRecyclerView(RecyclerView view) {
RecyclerView.Adapter adapter = view.getAdapter();
Bitmap bigBitmap = null;
if (adapter != null) {
int size = adapter.getItemCount();
int height = 0;
Paint paint = new Paint();
int iHeight = 0;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
/*
* Copyright (C) 2014 darnmason
*
* 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
@saket
saket / GlidePaddingTransformation.java
Last active July 20, 2017 05:27
Adds empty spaces to inflate the height of images
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;
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;
/**
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) {
@saket
saket / Pair.java
Last active February 3, 2018 08:34
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> {