Skip to content

Instantly share code, notes, and snippets.

View castorflex's full-sized avatar

Antoine Merle castorflex

View GitHub Profile
@castorflex
castorflex / NearestPowerOf2.java
Last active December 12, 2015 05:38
Get the nearest power of 2 of your number
public static int nearestPowerOf2(int number) {
--number;
number |= number >>> 1;
number |= number >>> 2;
number |= number >>> 4;
number |= number >>> 8;
number |= number >>> 16;
return ++number;
}
@castorflex
castorflex / FlipImageView.java
Created March 9, 2013 10:09
Added possibility to set drawables programmatically
public void setFlippedDrawable(Drawable flippedDrawable){
mFlippedDrawable = flippedDrawable;
if(mIsFlipped) setImageDrawable(mFlippedDrawable);
}
public void setDrawable(Drawable drawable){
mDrawable = drawable;
if(!mIsFlipped) setImageDrawable(mDrawable);
}
import android.view.animation.Interpolator;
/**
* Created with IntelliJ IDEA, best IDE in the world. User: castorflex Date: 06/06/13 Time: 22:18
*/
public class CustomBounceInterpolator implements Interpolator {
@Override
public float getInterpolation(float t) {
return -(float) Math.abs(Math.sin((float) Math.PI * (t + 1) * (t + 1)) * (1 - t));

Make your multiple type view adapter with annotations!

Gist for Making a Multiple View Types Adapter With Annotations

Pretty easy to use.

  1. Create your delegate adapters, implementing DelegateAdapter, and with the annotation DelegateAdapterType. e.g:
@DelegateAdapterType(itemType = 0)
@castorflex
castorflex / .gitignore
Last active May 10, 2016 16:13
android .gitignore
# Eclipse
.project
.classpath
.settings
.checkstyle
# IntelliJ IDEA
.idea
*.iml
*.ipr
@castorflex
castorflex / URLUtils.java
Created September 5, 2013 13:39
Simple snippet building a docs.google URL if you have a webview with a pdf, doc, etc URL.
public class URLUtils {
private static final String fGOOGLE_DOC_URL = "http://docs.google.com/gview?embedded=true&url=%s";
private enum GoogleDocType{
PDF(".pdf"), DOC(".doc"), XLS(".xls"), DOCX(".docx"), XLSX(".xlsx");
private String mSuffix;
GoogleDocType(String suffix){
mSuffix = suffix;
public class CircularProgressDrawable extends Drawable
implements Animatable {
private static final Interpolator ANGLE_INTERPOLATOR = new LinearInterpolator();
private static final Interpolator SWEEP_INTERPOLATOR = new DecelerateInterpolator();
private static final int ANGLE_ANIMATOR_DURATION = 2000;
private static final int SWEEP_ANIMATOR_DURATION = 600;
private static final int MIN_SWEEP_ANGLE = 30;
private final RectF fBounds = new RectF();
@castorflex
castorflex / ASCIIFolding.java
Last active February 24, 2023 21:49
Java ASCII Folding
public class ASCIIFolding {
@NonNull
public static String foldToASCII(@NonNull String input) {
return foldToASCII(input, new StringBuilder(input.length()));
}
@NonNull
public static String foldToASCII(@NonNull String input, @NonNull StringBuilder sb) {
final int end = input.length();