Skip to content

Instantly share code, notes, and snippets.

Avatar

Antoine Merle castorflex

View GitHub Profile
@castorflex
castorflex / ASCIIFolding.java
Last active Dec 10, 2018
Java ASCII Folding
View ASCIIFolding.java
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();
View CircularProgressDrawable.java
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 / URLUtils.java
Created Sep 5, 2013
Simple snippet building a docs.google URL if you have a webview with a pdf, doc, etc URL.
View URLUtils.java
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;
@castorflex
castorflex / .gitignore
Last active May 10, 2016
android .gitignore
View .gitignore
# Eclipse
.project
.classpath
.settings
.checkstyle
# IntelliJ IDEA
.idea
*.iml
*.ipr
View 1Description.md

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)
View CustomBounceInterpolator.java
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));
@castorflex
castorflex / FlipImageView.java
Created Mar 9, 2013
Added possibility to set drawables programmatically
View FlipImageView.java
public void setFlippedDrawable(Drawable flippedDrawable){
mFlippedDrawable = flippedDrawable;
if(mIsFlipped) setImageDrawable(mFlippedDrawable);
}
public void setDrawable(Drawable drawable){
mDrawable = drawable;
if(!mIsFlipped) setImageDrawable(mDrawable);
}
@castorflex
castorflex / NearestPowerOf2.java
Last active Dec 12, 2015
Get the nearest power of 2 of your number
View NearestPowerOf2.java
public static int nearestPowerOf2(int number) {
--number;
number |= number >>> 1;
number |= number >>> 2;
number |= number >>> 4;
number |= number >>> 8;
number |= number >>> 16;
return ++number;
}
You can’t perform that action at this time.