Skip to content

Instantly share code, notes, and snippets.


Alex Fu alexfu

View GitHub Profile
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 /
Last active Nov 10, 2017
A ContextWrapper that provides a custom Drawable for overscroll egde and glow.
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
alexfu /
Last active Oct 25, 2017
A simple FrameLayout that hides/shows an indeterminate ProgressBar over top of your UI
* The MIT License (MIT)
* Copyright (c) 2015 Alex Fu
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
alexfu /
Last active Oct 4, 2017
Example that shows how to determine if the ActionBar is currently in overlay mode.
public class MyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
if(windowActionBarOverlay()) {
// Do something

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 / 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" />
alexfu /
Last active Dec 31, 2015
An attempt at reversing the stack ordering of a simple FrameLayout.
* Copyright (C) 2006 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
* Unless required by applicable law or agreed to in writing, software
alexfu /
Created Apr 5, 2013
Downloading an image from the network using HttpURLConnection
private void fetchImageFromNetwork() {
InputStream input = null;
OutputStream output = null;
HttpURLConnection urlConnection = null;
byte[] buffer = new byte[100*1024];
try {
URL url = new URL(imageUrl);
urlConnection = (HttpURLConnection) url.openConnection();
input = urlConnection.getInputStream();
output = new FileOutputStream(path);
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)