Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / ImageZoomView.java
Created February 24, 2013 13:00
Image view with zoom and pan functions.
public class ImageZoomView extends ImageView {
Matrix matrix = new Matrix();
// Three possible states.
static final int NONE = 0;
static final int PAN = 1;
static final int ZOOM = 2;
static final int CLICK = 3;
int mode = NONE;
@lecho
lecho / CustomScrollView.java
Created February 24, 2013 13:06
Vertical ScrollView that allows for horizontal scrolling children.
public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@lecho
lecho / sqlite_export.txt
Created March 2, 2013 19:42
Command for exporting sqlite database for debuggable app on android device. Api 8+, no root required.
adb -d shell 'run-as com.yourpackage cat /data/data/com.yourpackage/databases/dbname > /sdcard/dbname'
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);
}
@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);
}
/**
@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 / 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