Skip to content

Instantly share code, notes, and snippets.

@lecho
lecho / shadow.xml
Created September 7, 2013 07:01
Android shadow drawable xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
@lecho
lecho / SplineInterpolation.java
Created November 24, 2013 14:15
Spline interpolation in java.
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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
@lecho
lecho / ConvertToHex.java
Created February 21, 2013 20:37
Convert to HEX
public abstract class HexUtils{
pulbic static String convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
@lecho
lecho / ConnectDotsView.java
Created December 18, 2012 21:45
Connect dots android view.
public class ConnectDotsView extends View {
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mPaint;
private static final int TOUCH_TOLERANCE_DP = 24;
private static final int BACKGROUND = 0xFFDDDDDD;
private List<Point> mPoints = new ArrayList<Point>();
private int mLastPointIndex = 0;
import numpy
import matplotlib.pyplot as plt
def interpolateCatmulRomeSegment(P0, P1, P2, P3, nPoints=10):
"""
P0, P1, P2, and P3 should be (x,y) point pairs that define the Catmull-Rom spline.
nPoints is the number of points to include in this curve segment.
"""
# Convert the points to numpy so that we can do array multiplication
P0, P1, P2, P3 = map(numpy.array, [P0, P1, P2, P3])
public class TimePickerDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
private static final String DIALOG_HOUR = "my.package:INITIAL_HOUR";
private static final String DIALOG_MINUTE = "my.package:INITIAL_MINUTE";
//My custom listener
private OnTimePickedListener mListener;
private int mDialogRequestCode;
//Use dialogRequestCode to discriminate dialogs in OnTimePickedListener#onTimePicked method. I think you could also use dialog tag string instead of integer variable.
public static TimePickerDialogFragment newInstance(int hour, int minute, int dialogRequestCode, OnTimePickedListener listener) {
@lecho
lecho / PathCompat.java
Created August 21, 2014 17:40
PathCompat for android
package lecho.lib.hellocharts.renderer;
import lecho.lib.hellocharts.util.CasteljauComputator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
/**
* PathCompat uses Canvas.drawLines instead Canvas.drawPath. Supports normal lines and cubic Bezier's lines.
* Warning!: doesn't support breaks in line so line has to be continuous and doesn't support area chart.
@lecho
lecho / textview_marquee
Created August 20, 2013 08:12
Android TextView marquee.
TextView textView = new TextView(this);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setFocusableInTouchMode(true);
textView.setFreezesText(true);
textView.setSingleLine(true);
textView.setMarqueeRepeatLimit(-1);
textView.setFocusable(true);
textView.setSelected(true);
textView.setText("Sooooooooooooooome Loooooooooooooooooooooooong Teeeeeeeeeeeeeeeeeeeeeeeeeeext");
@lecho
lecho / actionbar_collapsed_tabs_hack.java
Created June 14, 2013 14:34
Hack around collapsed tab dropdown selection bug in ICS and ActionBarSherlock
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
selectInSpinnerIfPresent(position, true);
}
/**
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
public abstract class SimpleCursorLoader extends AsyncTaskLoader<Cursor> {
private Cursor mCursor;
public SimpleCursorLoader(Context context) {
super(context);
}