Skip to content

Instantly share code, notes, and snippets.

View alexfu's full-sized avatar

Alex Fu alexfu

View GitHub Profile
@alexfu
alexfu / TextViewCounter.java
Last active August 29, 2015 14:12
A counting View that counts from zero to N while animating each increment.
/*
* 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
alexfu / CheckableImageButton.java
Last active March 19, 2020 06:02
A simple checkable button that has all of the properties that comes with a Button but has checkable states. One thing all, if not most, Checkable views Android provides can't seem to do is center their own Drawables.
/*
* 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
alexfu / ProgressLayout.java
Last active October 25, 2017 16:06
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
alexfu / MyFragment.java
Created March 3, 2015 12:12
Change View styles on the fly with ContextThemeWrapper
public class MyFragment {
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
// Where the magic happens
context = new ContextThemeWrapper(getActivity(), R.style.Theme_Main_Inverse);
}
@alexfu
alexfu / AndroidSchedulerTransformer.java
Last active August 29, 2015 14:19
Transforms the given Observable into an Observable that runs asynchronously and emits items on the main thread.
/*
* 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
alexfu / StringUtils.java
Created May 23, 2015 14:27
A utility function to convert an InputStream to String.
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class StringUtils {
private StringUtils() { /* No op */ }
public static String from(InputStream is) {
byte[] buffer = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@alexfu
alexfu / ViewUtils.java
Last active September 26, 2015 13:53
View utility functions that I find myself using often.
/*
* 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
alexfu / CursorExtenstions.kt
Created June 30, 2015 11:56
Android database cursor extensions that simplify retrieval of typed values
import android.database.Cursor
/**
* CursorExtentions
*
* Android database cursor extensions that simplify retrieval of typed values
* @author alexfu
*/
fun Cursor.getInt(colName: String): Int {
return this.getInt(this.getColumnIndex(colName))
@alexfu
alexfu / AndroidAsync.java
Last active February 7, 2021 15:27
Helpful RxJava functions for daily use
/**
* Transforms an observable to run on a new thread
* and to be observed on Androids main thread.
*/
public static <T> Observable.Transformer<T, T> androidAsync() {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable
.subscribeOn(Schedulers.newThread())
@alexfu
alexfu / build-gradle-git-hockeyapp.gradle
Last active August 29, 2015 14:25
Examples of how to streamline releases with your Gradle based Android project
/**
* 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 {
jcenter()