Skip to content

Instantly share code, notes, and snippets.

View nschwermann's full-sized avatar
:shipit:

Nathan Schwermann nschwermann

:shipit:
View GitHub Profile
/*
* Copyright (C) 2014 Chris Banes
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2014 Google Inc.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/**
* Creates a 'ghost' bitmap version of the given source drawable (ideally a BitmapDrawable).
* In the ghost bitmap, the RGB values take on the values from the 'color' argument, while
* the alpha values are derived from the source's grayscaled RGB values. The effect is that
* you can see through darker parts of the source bitmap, while lighter parts show up as
* the given color. The 'invert' argument inverts the computation of alpha values, and looks
* best when the given color is a dark.
*/
private Bitmap createGhostIcon(Drawable src, int color, boolean invert) {
int width = src.getIntrinsicWidth();
@nschwermann
nschwermann / .bash_profile
Last active December 14, 2015 19:19 — forked from jimothyGator/.bash_profile
Display current Git branch and root directory in Mac OS X Terminal title bar.
# Add to .bash_profile
cd () {
builtin cd "$@"
update_title
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
@nschwermann
nschwermann / .bashrc
Last active December 15, 2015 01:09
Helper functions for adb. Offers a selection menu for multiple devices and makes logcat filtering easier.
#add to your .bash_profile / .bashrc
adbd () {
adb -s $(get_device) "$@"
}
function get_device() {
local devices=$(adb devices | grep device$)
if [ $(wc -l <<< "$devices") -eq 1 ]; then
awk {'print $1'} <<< "$devices"
@nschwermann
nschwermann / manifest.json
Created April 8, 2013 00:43
Chrome plugin to hide reddit sidebar when window is too small.
{
"name" : "Hide Reddit Sidebar",
"version" : "1.1",
"manifest_version" : 2,
"description" : "hides the sidebar when the media is too small",
"content_scripts" : [
{
@nschwermann
nschwermann / gist:5632785
Created May 23, 2013 04:44
refresh media player on android when new music added to device but not showing up
adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard/music
@nschwermann
nschwermann / ExampleAdapter.java
Last active December 22, 2016 15:16
GridViewPager example
package schwiz.net.example;
import android.content.Context;
import android.graphics.Color;
import android.support.wearable.view.GridPagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@nschwermann
nschwermann / ClipRevealFrame
Created December 19, 2014 06:34
CircularReveal backport
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.FrameLayout;
public class ClipRevealFrame extends FrameLayout{
private Path mRevealPath;
@nschwermann
nschwermann / IonDataSource.java
Created October 2, 2014 22:16
Custom DataSource for ExoPlayer that uses ION/AndroidAsync
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DataSpec;
import com.google.android.exoplayer.upstream.HttpDataSource;
import com.google.android.exoplayer.upstream.TransferListener;
import com.google.android.exoplayer.upstream.UnexpectedLengthException;