Skip to content

Instantly share code, notes, and snippets.


Alex Fu alexfu

View GitHub Profile
alexfu / TouchSlopDelegate.kt
Last active Apr 24, 2018
Android TouchSlopDelegate
View TouchSlopDelegate.kt
import android.content.Context
import android.view.MotionEvent
import android.view.MotionEvent.*
import android.view.ViewConfiguration
class TouchSlopDelegate(context: Context) {
private val targetTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
private var touchSlop: Int = 0
private var lastTouchX: Float = 0f
private var lastTouchY: Float = 0f
alexfu / app_build.gradle
Created Nov 30, 2017
Grouping shared dependencies
View app_build.gradle
* This file would be located under /path/to/project/app/build.gradle
apply plugin: ''
android {
// Usual stuff
alexfu / Demo.kt
Last active Mar 21, 2019
Making (Android) Spannable great again with Kotlin
View Demo.kt
val world = "World"
val mySpannedText = SpannableString("Hello ${world}!")
mySpannedText.spanWith(world) {
what = BackgroundColorSpan(Color.RED)
alexfu /
Last active Dec 25, 2017
A FrameLayout that can show different states one at a time.
* A {@link FrameLayout} that can show different states one at a time.
public class StateFrameLayout extends ViewAnimator {
public static final String STATE_LOADING = "loading";
public static final String STATE_EMPTY = "empty";
public static final String STATE_ERROR = "error";
private static final String STATE_DEFAULT = "default";
private SimpleArrayMap<String, View> stateViewMap;

Keybase proof

I hereby claim:

  • I am alexfu on github.
  • I am alexfu ( on keybase.
  • I have a public key whose fingerprint is 2AB9 0B76 0A73 7277 00C2 42FB 92A7 CCF0 9D47 5005

To claim this, I am signing this object:

alexfu / UIErrorTextField.swift
Last active May 12, 2016
A UITextField with error text support. Draws error text underneath UITextField.
View UIErrorTextField.swift
import Foundation
import UIKit
class UIErrorTextField : UITextField {
private let bgView = UIView()
private var textFieldHeight = CGFloat(40)
private var errorTextHeight = CGFloat(12)
private let errorTextPadding = CGFloat(2)
var errorFont = UIFont.systemFontOfSize(12) {
alexfu /
Last active Jul 27, 2021
Add equal spacing to RecyclerView items automatically. Can handle horizontal, vertical, and grid display modes
import android.view.View;
public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int spacing;
private int displayMode;
public static final int HORIZONTAL = 0;
alexfu / ripple_item_background.xml
Created Jan 12, 2016
v21 checkable selector with ripples
View ripple_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android=""
<item android:id="@+id/mask">
<color android:color="@android:color/white" />
View versioning.gradle
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
ext.VersioningPlugin = VersioningPlugin
class VersioningPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create("versioning", VersioningPluginExtension)
alexfu / build-gradle-git-hockeyapp.gradle
Last active Aug 29, 2015
Examples of how to streamline releases with your Gradle based Android project
View build-gradle-git-hockeyapp.gradle
* This example demonstrates how to create a build task
* for publishing a beta to HockeyApp in addition to
* tagging and pushing a beta release to your remote git
* repo using the gradle-git plugin.
buildscript {
repositories {