Skip to content

Instantly share code, notes, and snippets.

@Sefford
Sefford / CircularTransformation
Created May 22, 2014 19:46
Picasso transformation to achieve a circular crop of an image
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import com.squareup.picasso.Transformation;
/**
@Sefford
Sefford / RoundedBorderTransformation
Last active August 29, 2015 14:01
Picasso Transformation for creating images with rounded corners
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import com.squareup.picasso.Transformation;
@Sefford
Sefford / TriangleClipTransformation
Created May 22, 2014 19:52
Clips an image by the diagonal, creating just the right-bottom corner
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import com.squareup.picasso.Transformation;
@Sefford
Sefford / PartialRoundedTransformation
Last active January 12, 2024 17:30
Transformation for Picasso that rounds different edges of the screen
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import com.squareup.picasso.Transformation;
@Sefford
Sefford / BlurTransformation
Created May 23, 2014 11:42
Transformation for Picasso that applies a Blur effect to the image
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.util.Log;
import com.squareup.picasso.Transformation;
@Sefford
Sefford / AnagramPalindrome
Created June 10, 2014 10:50
A solution to the problem to find if a String is an anagram of a Palindrome
// In order to know if a String or char[] is an anagram of a palindrome we look up to the
// math definition of a palindrome: There must be an even number of every char except for the
// case there is a single letter in the middle, in which case we can afford only 1 instance of
// an odd character in the middle.
public boolean solution(char[] input) {
int[] letters = new int[26];
// We calculate frequencies to each of the letters
for (int i = 0; i < input.length; i++) {
// We lowercase the chars and compensate for the UTF-8 displacement to the right
@Sefford
Sefford / Switching
Created July 25, 2014 14:06
This method will switch minSDKVersion of RecyclerLibrary on compile time for version 13
applicationVariants.all{ variant ->
// This is a terrible hacky way of compile-time changing all the libraries
// minSDKs to SDK 13. This script has to be mantained everytime you update
// any of these libraries or the plugin updates.
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/intermediates/exploded-aar/com.android.support/recyclerview-v7/21.0.0-rc1/AndroidManifest.xml")
if (manifestFile.exists()) {
println("Replacing minSdkVersion of RecyclerView-V7 library")
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="L"/, 'minSdkVersion=\"13\"')
@Sefford
Sefford / ScrollAwareListView
Created August 28, 2014 15:41
ListView that knows how much has been scrolled downwards
public class ScrollAwareListView extends ListView {
/**
* Vertical offset listener
*/
OnVerticalScrollOffsetListener offsetListener;
/**
* Maximum vertical size
*/
int verticalRange = 0;
@Sefford
Sefford / Select Tabs
Created December 18, 2014 11:54
Helper method to gradually crossfade two tabs
void selectTab(Float scroll, int direction) {
float localOffset = scroll - scroll.intValue();
int intValue = scroll.intValue();
switch (direction) {
case 1:
views[intValue].setTextColor((int) argbEvaluator.evaluate(localOffset, selectedColor, unselectedColor));
if (intValue + 1 <= views.length - 1) {
views[intValue + 1].setTextColor((int) argbEvaluator.evaluate(localOffset, unselectedColor, selectedColor));
}
@Sefford
Sefford / CreditCardWatcher
Created January 27, 2015 11:15
Credit Card Watcher
package com.feverup.fever.ui.textwatchers;
/**
* Created by sefford on 14/02/14.
*/
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;