Skip to content

Instantly share code, notes, and snippets.

View tylerchesley's full-sized avatar

Tyler Chesley tylerchesley

View GitHub Profile
@tylerchesley
tylerchesley / CharacterCountErrorWatcher.java
Last active August 29, 2015 14:28 — forked from slightfoot/CharacterCountErrorWatcher.java
Material Design - Text field input - Over/under character or word count (android.support.design.widget.TextInputLayout) http://www.google.com/design/spec/patterns/errors.html#errors-user-input-errors
import android.graphics.Color;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.AlignmentSpan;
import android.text.style.ForegroundColorSpan;

Android Cheat Sheet

Developer tips

Record a video of your app

Developer options -> Check show touches
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4
@tylerchesley
tylerchesley / gist:0fbdf9c785727afef356
Created May 7, 2015 15:50
Control compileSdk and buildTools version from the root build.gradle
in the root project's build.gradle:
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.1"
}
in all the android modules:
android {
@tylerchesley
tylerchesley / TintableImageView.java
Created March 17, 2015 16:36
Backwards compatible TintableImageView
package com.example.widgets;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.example.R;
public abstract class CachedRefreshable<P, T> extends Refreshable<P, T> {
protected abstract Observable<T> getSourceObservable(P parameters);
/**
* Return the Observable that gets data from a cached source.
*
* @return Observable from cache item, or null if the cache misses.
*/
protected abstract Observable<T> getCachedObservable(P parameters);
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)) ;
//((textPaint.descent() + textPaint.ascent()) / 2) is the distance from the baseline to the center.
canvas.drawText("Hello", xPos, yPos, textPaint);
@tylerchesley
tylerchesley / gist:7582566
Created November 21, 2013 14:35
Android Studio .gitignore file
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@tylerchesley
tylerchesley / gist:6198074
Created August 9, 2013 23:10
Function to recursively copy files from an Android asset directory
public void copyFileOrDir(String path) {
AssetManager assetManager = this.getAssets();
String assets[] = null;
try {
assets = assetManager.list(path);
if (assets.length == 0) {
copyFile(path);
} else {
String fullPath = "/data/data/" + this.getPackageName() + "/" + path;
File dir = new File(fullPath);