Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / CustomGenerateViewId.java
Created April 9, 2015 13:49
A backport of generateViewId() to API 10+
public class CustomGenerateViewId {
private static final AtomicInteger nextGeneratedId = new AtomicInteger(1);
public static int customGenerateViewId() {
for (; ; ) {
final int result = nextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) {
newValue = 1; // Roll over to 1, not 0.
}
@hector6872
hector6872 / PriceTagSpan.java
Created March 10, 2015 13:54
Price Tag TextView
import android.text.TextPaint;
import android.text.style.SuperscriptSpan;
public class PriceTagSpan extends SuperscriptSpan {
@Override
public void updateDrawState(TextPaint tp) {
tp.baselineShift += (int) (tp.ascent() * 0.33f);
}
@Override
@hector6872
hector6872 / Log.java
Created February 25, 2015 11:41
Log
public class Log {
static final boolean isLoggable = BuildConfig.DEBUG;
static final String TAG = BuildConfig.APPLICATION_ID;
public static void i(String tag, String string) {
if (isLoggable) android.util.Log.i(tag, string);
}
public static void i(String string) {
if (isLoggable) android.util.Log.i(TAG, string);
@hector6872
hector6872 / ImageCenteredSpan.java
Created February 19, 2015 11:55
Image Centered Span
class ImageCenteredSpan extends ImageSpan {
public ImageCenteredSpan(Drawable d) {
super(d);
}
@Override
public void draw(Canvas canvas, CharSequence text,
int start, int end, float x,
int top, int y, int bottom, Paint paint) {
Drawable b = getDrawable();