Skip to content

Instantly share code, notes, and snippets.

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
}
}
//Automatically calculates Y axis values.
private Axis calculateYAxis(int numberOfSteps) {
if (numberOfSteps < 2) {
throw new
IllegalArgumentException("Number or steps have to be grater or equal 2");
}
List<Float> values = new ArrayList<Float>();
final float range = mData.getMaxYValue() - mData.getMinYValue();
final float tickRange = range / (numberOfSteps - 1);
final float x = (float) Math.ceil(Math.log10(tickRange) - 1);
@lecho
lecho / CohenSutherlandComputator.java
Created August 13, 2014 17:16
CohenSutherlandComputator - clipping algorithm
package lecho.lib.hellocharts.util;
import android.graphics.RectF;
/**
* Cohen-Sutherland algorithm implementation based on wikipedia article.
*
* {@link http://en.wikipedia.org/wiki/Cohen-Sutherland_algorithm}
*
*/
package lecho.lib.hellocharts.util;
import android.graphics.PointF;
/**
* Iterative implementation of de Casteljau's algorithm for cubic Bezier's curves.
*
*/
public class CasteljauComputator {
private static final int DEFAULT_CURVE_DEGREE = 3;// By default cubic.
@lecho
lecho / ColumnPreselectionText.java
Last active August 29, 2015 14:17
Column value pre-selection
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_line_column_dependency, container, false);
// *** TOP LINE CHART ***
chartTop = (LineChartView) rootView.findViewById(R.id.chart_top);
// Generate and set data for line chart
generateInitialLineData();
@lecho
lecho / RecyclerViewItemDevorator.java
Created July 10, 2015 19:51
Example decorator for RecyclerView form support library
package com.github.lecho.mobilization;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@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);
}