Some ADB utility functions

Filed Under (android, bash) by Nathan Schwermann on 16-03-2013

Tagged Under : , ,

It is always such a pain debugging when you have multiple devices and emulators connected at the same time. I hate the dreaded “error: more than once device and emulator” message or “-waiting for device” when trying to view logcat.

So today I wrote some helper functions for my bash profile that will offer a menu to select what device to use when more than one is available. It is assumed that both adb and Jeff Sharkey’s coloredlogcat script are in your $PATH variable. If not, it shouldn’t be hard to modify the code to use direct paths.

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" 
		IFS=$'\n' devices=($devices)
		unset IFS
		local device
		PS3="Select a device # "
		select device in "${devices[@]}"; do
			if [ -n "$device" ]; then
				awk {'print $1'} <<< "$device"
function logcat(){
	local device
	if [ -z "$1" ]
		adb -s $device logcat |
      		local filters=""
      		for f in $@
			export filters="$filters $f:*"
      		echo "filters $filters"
		adb -s $device logcat $filters *:S |    

The usage goes as follow, after adding to your bash profile (add to ~./bash_profile on OSX or ~/.bashrc on linux) you can use the follow commands:


Full Source Here


An HTML5 Valentine

Filed Under (About Me, HTLM5, JavaScript) by Nathan Schwermann on 15-02-2013

Tagged Under : ,

I had some last minute inspiration (or was in panicking) to make an HTML5 Valentine’s Day game for my wife this year. Aside from the tiny bit of HTML required to post blog entries with my wordpress site here I hadn’t done any HTML since back in the time that <blink> was cool and everyone had those nifty little counters on the bottom of their site that said how many visiters had been there.

I was actually really astounded by how far things have come since then. I may have very well even caught the bug, I want to play around with this stuff some more and come up with something better when I don’t have such a time contraint. Anyways, I invite you to check out my short Valentines Day game, it can be found here.


Did a Year Just Go By?

Filed Under (About Me) by Nathan Schwermann on 03-01-2013

Wow, I just realized I went an entire year without a new blog post. It was quite a busy year for me, I worked a full time job doing Android development for Moblico and at the same time I was a full time student at KU trying to finish up my Bachelor’s in Computer Science.

I regret that I didn’t find time to do any more fun tutorials or blog posts, hopefully this year I will have some more time. This coming spring I will again be doing both school and a fulltime job, but luckily I only have 6 credit hours to go before graduation so it will be a light school load.

If time permits I hope to post some articles on functional programming, OpenGL and computer vision over the course of the year.


Using Scribe with Android

Filed Under (android, java, programming) by Nathan Schwermann on 13-04-2011

Tagged Under : , , , , ,

Recently I have been working on signing in with social networks with Android applications. I found a great article using Twitter4J to log in with twitter but I would like to expand on that article and rather than relying on an intent-filter and the default android browser I am adding a WebViewClient to handle the callback url.

Using an intent-filter and the default browser has two problems.  One, depending on what browser the user has set as their default browser there is a chance that the browser won’t initiate an ACTION_VIEW intent but rather just attempt to load the callback url. Secondly, when your app goes into the background and the default browser opens there is a chance that onDestory would be called on the Activity and then onNewIntent wouldn’t be called. Although that could be handled in a number of different ways. Finally, instead of using Twitter4J I opted for Scribe instead. Mainly because it is designed to work with and already has support for many other social networks besides Twitter.

It just about 80 lines of code we can have the user sign in and verify their account. Of course we have no error handling yet, and the next step would be to move this to the new Fragment API to so you can easily attach it to any Activity to sign in with Twitter.


package net.schwiz.oauth;

import org.json.JSONException;
import org.json.JSONObject;
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TwitterApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

 *Demonstrates how to use the scribe library to login with twitter.
public class Main extends Activity {
	final static String APIKEY = null;
	final static String APISECRET = null;
	final static String CALLBACK = "oauth://twitter";
    public void onCreate(Bundle savedInstanceState) {
        final TextView textView = (TextView)findViewById(;
        final  WebView webview = (WebView) findViewById(;
        if(APIKEY == null || APISECRET == null){
        	textView.setText("You must enter your own APIKEY and SECRET to use this demo.");
        //set up service and get request token as seen on scribe website 
        final OAuthService s = new ServiceBuilder()

		final Token requestToken = s.getRequestToken();
		final String authURL = s.getAuthorizationUrl(requestToken);
        //attach WebViewClient to intercept the callback url
        webview.setWebViewClient(new WebViewClient(){
        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
        		//check for our custom callback protocol otherwise use default behavior
        			//authorization complete hide webview for now.
        			Uri uri = Uri.parse(url);
        			String verifier = uri.getQueryParameter("oauth_verifier");
        			Verifier v = new Verifier(verifier);
        			//save this token for practical use.
        			Token accessToken = s.getAccessToken(requestToken, v);
        			//host twitter detected from callback oauth://twitter
	        			OAuthRequest req = new OAuthRequest(Verb.GET, "");
	        			s.signRequest(accessToken, req);
	        			Response response = req.send();
	        			try {
							JSONObject json = new JSONObject(response.getBody());
						} catch (JSONException e) {
        			return true;
        		return super.shouldOverrideUrlLoading(view, url);

        //send user to authorization page

Don’t forget to add the internet permission to your manifest! Also please note you will get a forceclose if you don’t add your own twitter API key. If you would like the full source code you can find it here.


Indeterminate Loading Text in Android

Filed Under (android, java, programming) by Nathan Schwermann on 01-08-2010

Recently I made a handy little Android widget that displays a message and animates 3 periods after it to indicate that work is being done. Its just another alternative to using a ProgressBar set to indeterminate. I used the timed UI updating technique described in the devguide

First we extend the TextView class and included some extra members.

public class LoadingTextWidget extends TextView {

        Handler mHandler;
        StringBuilder mBuilder;
        String mText;
        int mCount, mStringSize;
        final int DELAY = 400;

        public LoadingTextWidget(Context context, AttributeSet attrs) {
 	super(context, attrs);
		mText = (String)getText();
		mBuilder = new StringBuilder(mText);
		mCount = 0;
		mHandler = new Handler();
		mStringSize = (int) getPaint().measureText(mText + "...");

Next we implement a runnable to animate the periods every 400 ms.

Runnable AnimatePeriod = new Runnable() {

		public void run() {
			if(mCount == 4){
				mCount = 0;
				mBuilder.delete(0, mBuilder.length());
			mHandler.postDelayed(AnimatePeriod, DELAY);

Lastly remember to clean up after yourself.

	protected void onDetachedFromWindow() {

Now we just create the object in an Android layout file.

<?xml version="1.0" encoding="utf-8"?>

One thing to note about the style attributes is that the gravity is set to left. This way the actual text doesn’t move on the screen as the periods animate.

<?xml version="1.0" encoding="utf-8"?>
<style name="LoadingText">
        <item name="android:textSize">14dip</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">left</item>
        <item name="android:textStyle">bold</item>

GDC ’10

Filed Under (About Me, GDC) by Nathan Schwermann on 15-03-2010

Tagged Under :

What to Expect

I really wasn’t sure what to expect while attending the Game Developers Conference, as a first year attendee I had heard quite a bit about the conference but you can never really know for sure until you make it there.  I was actually expecting for the conference to be much more centered on heavy talks about programming, designing, etc but I was rather surprised to see that the GDC is more focused around networking and connecting with others in the industry.

Jack Palevich schools the crowd on how to port native code to Android.

I had bought the summits and tutorials pass because I am really interested in mobile phone development, especially Android and there was a handheld summit this year featuring speakers from Google’s Android team.  I wasn’t fully aware that the summits were over after the first two days and I would be locked out from any future sessions once the expo opened.  However it wasn’t a complete loss, while there were a handful of talks and tutorial offered only to those with a main pass I found there was still plenty to see, do and learn on the expo floor.


When traveling to GDC it is important to pack light, or better yet bring an extra empty suitcase. From what I understand this year had a relatively low amount of schwag density compared to previous years. Never the less I couldn’t walk more than 15 feet without someone, from somewhere, trying to give me something. I literally had to walk back to my hotel on the first day of the expo just to unload my bag so I could refill it with more glorious crap! It isn’t all crap as you can plainly see there were some gems mixed in with the various coasters, stickers, bad shirts and bottle openers.

The Schwag, not just the name for a crappy Grateful Dead coverband from the midwest.

When it came down to it though I had to make the decision of what stays and what goes. I left many soldiers behind in my hotel room after carefully and craftfully packing my bag to fit as much as humanly possible. My bag was literally bursting from the seams, and while it fit in the overhead compartment on the way to GDC and I was flying on the exact same model of jet on the way back my bag would sadly no longer fit in the overhead compartment. I embarrassingly had to lug it up to the front of the plane and ask the stewardess to stow it beneath. Actually, I wasn’t embarrassed but rather proud of my ability to pack a suitcase so full it actually grows in size.

Invaluable Advice

While the core benefit of attending GDC is centered on networking, for me as a student with a few years left to go I found the advice I received from those gracious enough to give me their time in the career pavilion to be the most valuable part of my trip.  While some of the constructive criticisms I received on my resume and portfolio may have been harsh I found them to be the most valuable part of my trip.

Christian Allen giving very valuable networking advice.

One industry veteran was kind enough to snatch a resume out of my hand saying “I’m sure it is crap but lets take a look” after a 5 second glance he said, basically said my resume was horrible, nothing on it was interesting.  He didn’t care what languages I knew or what schools I attended.  “What is it that you have done? You need to list your projects and say exactly what it is that you did on them.  You need something on your resume that is going to make me interested in you.”  I was quick to tell him I have a portfolio for that online, but he asked; why would he waste his time looking at my portfolio when there was nothing interesting on my resume to begin with.
Last but not least was the Game Career Seminar, I had really wished I had booked a later flight because I had to miss the last few sessions but I found each of those sessions to be extremely helpful as well as highly entertaining.

In the End

I can’t recommend enough for anyone interested in getting into the game industry to make the trip out to GDC every year. It is by far one of the best investments I have ever made in my future. You can spend all of the money in the world on a college education but it won’t make a difference if you don’t know what your future potential employers are looking for. I am glad I could make it out my first time this year and I look forward to my many returning trips in the future. Hopefully someday I’ll be giving the advice.


GDC 2010 Album

My GDC Schedule

Filed Under (About Me, GDC) by Nathan Schwermann on 08-03-2010

I have the summit pass this year so here is my schedule for Tue/Wen, on Thurs/Fri I will be exploring the career pavillion and expo. Hope to see some friendly faces, I will be checking twitter if you want to meet up!

Session Title Date Start Time End Time Location
Maximizing Sales and Downloads for Indie Mobile Game Developers 2010-03-09 11:15:00 12:15:00 Room 309, South Hall
Bootstrapping Games on Android 2010-03-09 13:45:00 14:45:00 Room 309, South Hall
Social Networks: The New Marketplace for Mobile Games? 2010-03-09 15:00:00 15:30:00 Room 309, South Hall
5TH Cell: From Mobile to Handheld & Beyond 2010-03-09 15:30:00 16:00:00 Room 309, South Hall
Application Stores: What You Should Know Before You Get Started 2010-03-09 16:15:00 16:45:00 Room 309, South Hall
Publishing Mobile Games in a Multi-store, Multi-platform Environment 2010-03-09 16:45:00 17:15:00 Room 309, South Hall
AI Developers Rant! 2010-03-09 17:15:00 18:00:00 Room 310, South Hall
Introduction 2010-03-10 09:45:00 10:00:00 Room 305, South Hall
Bring Your Games to Android 2010-03-10 10:00:00 11:00:00  
Step Into The Future Of Gaming: A Practical Approach to Design Handheld
Augmented Reality Games
2010-03-10 10:30:00 11:00:00 Room 309, South Hall
Get the Most Out of Android Media APIs 2010-03-10 11:15:00 12:15:00  
Profiling for Mobile GPUs 2010-03-10 12:15:00 12:45:00 Room 309, South Hall
Next-Generation Social Games 2010-03-10 13:30:00 14:15:00 Room 305, South Hall
Savvy Indie Solutions to Difficult Development Problems 2010-03-10 14:15:00 14:45:00 Room 135, North Hall
Android Office Hours 2010-03-10 15:00:00 16:00:00  
Grand Challenges for Game Developers 2010-03-10 16:15:00 17:15:00 Room 132, North Hall
MMO Retention – Learning from the First 25 Years 2010-03-10 16:15:00 17:15:00 Room 131, North Hall
A Sea Of Mobile Devices 2010-03-10 16:30:00 17:15:00 Room 305, South Hall
Who’s Got Game? 2010-03-10 17:15:00 18:00:00 Room 305, South Hall
Agile: No Silver Bullet 2010-03-12 09:00:00 10:00:00 Room 303, South Hall

Mac’s Ipad

Filed Under (apple, ipad) by Nathan Schwermann on 28-01-2010

Tagged Under : , ,

Apple did really push the envelope with the release of the iPhone and the iPod touch. At the time there was absolutely nothing at all like it on the market, sure we had seen touch screen PDAs and whatnot before but none quite as intuitive and responsive as the iPhone. Apple opened many doors, the most important in my opinion is that they showed other companies that allowing easy access to their SDK and allowing virtually anyone to post apps to their market, is actually a business model that works, and it works well.

How does Apple expect a giant to use this phone?

Sure the iPhone has its short comings but it was a ground breaking device laying the groundwork for future Apple products as well as competitors. However, the iPhone had one MAJOR flaw, it was entirely too small for giants.
Luckily after three long years of waiting Apple has finally remedied this problem with the release of the iPad. Finally a device that humans and giants alike can enjoy. At a cursory glance the iPad looks nothing short of amazing, it is like an iPhone but it is giant-sized!  As you can see Willie the giant looks quite intrigued, but will the device live up to the hype?

Could the iPad be the device giants have been waiting for?

Short answer, no.

After a few short minutes with the device Willie quickly realizes that all of the short comings from the original iPhone are still there. While these short comings were forgivable back in the day when Apple dominated and paved the way for the market. Today it is a different story, simply taking a device you market and making it larger is not what I would consider innovating. In fact, it is practically taking a step backwards as typically the goal is to make devices smaller!

I really like the idea of a tablet, perfect for relaxing on the couch (or the kitchen according to Steve Jobs) and browsing the web, checking emails, twitter, and what not. While this device is capable of those things I don’t see it pushing the envelope in the way like the iPhone originally did back in 2007. Yes it has cool software like the iWork and iBooks, but who honestly wants to make a spreadsheet on a tablet, and is the extra premium over the Kindle or Nook worth it? I personally don’t think so. While I would be happy if someone handed me one of these as a gift (hint hint) I just don’t see myself actually wanting to pay for one. I don’t like the proprietary connections, no flash is a huge mistake on Apple’s part, and the cost is just plain to high. Perhaps a future model will change my mind but for now I am sticking with a laptop.


Android – new line, shmew line

Filed Under (android, java, programming) by Nathan Schwermann on 26-01-2010

Tagged Under : , ,

In a previous blog post I talked about how to avoid having your users make a new line when the press enter on an EditText view in your Android applications. It was a hack way where you had to make your own EditText class and override onKeyDown. It works just fine but since then I have found a much easier way to achieve the same goal.

First your activity or dialog needs to implement OnEditorActionListener, set the onEditorActionListener in onCreate and…. thats it!!!! Right out of the box the implemented method automatically cancels sends a null character instead of a new line character when you press enter.

public class AdjustStringDialog extends Dialog  implements android.view.View.OnClickListener, OnEditorActionListener{

	private EditText editTextView;
	public AdjustStringDialog(Context context, UnderlinedView mV) {
		setTitle("My Dialog Box");
	protected void onCreate(Bundle savedInstanceState) {
	private void retisterViews() {
		editTextView = (EditText)findViewById(;
	public void onClick(View v) {
	private void closeDialog() {
		//do what you want with the entered text
		//update UI with new text if needed
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		return false;


Of course you can detect any key that is being pressed aside from the enter key with the event argument, and you can handle cases like the ‘Next’ button with actionId as well. Know any other ways to accomplish this, or care to share something you implemented with onEditorAction feel free to comment!
Cheers and happy 2010!


Android WolframAlpha Launcher

Filed Under (android, java, math, programming) by Nathan Schwermann on 16-09-2009

Tagged Under : , , , ,

Ahoy Ahoy it has been way to long I need to write you more often, but I have been busy with school, and before that I had video games to play. Being busy with school is what ultimately let to the project I want to talk about today. Recently, while studying for my Calculus 2 class I found this amazing website WolframAlpha which is what they call a computational engine. It can do all kinds of awesome stuff I have barely scratched the surface on playing with its different capabilities. I mainly use it to quickly look up integrals and sums while doing Calc homework.

Long story short, I ended up using my G1 daily to look up integrals on my phone and I wanted a faster way to do it. After applying for a code to access their online API and never hearing back I decided the next best thing was to just make a quick launcher similar to the one Wolfram released for Vista.

It came together pretty quickly I think its the first program I was able to finish in one day, and bug free to boot (it seems).
WolframAlpha Quicklaunch

It was pretty hassle free but I did run into a little snag I want to talk about. By default when pressing the enter key in the edit text box Android will make a new line, I wanted to launch the website. Getting this behavior was by far the most challenging thing to do in this project.

In order to pull this off you need to make your own EditText class that inherits from Android’s EditText class. Then, you have to override the onKeyDown function for the EditText class.

	public static class MyEditView extends EditText {
		//ref to the nesting the view
		walauncher launcher;
		public MyEditView(Context context, AttributeSet attrs) {
			this.launcher = (walauncher)context;
		public boolean onKeyDown(int keyCode, KeyEvent event) {	
			case KeyEvent.KEYCODE_ENTER:
			return super.onKeyDown(keyCode, event);
		public Editable getText() {
			// TODO Auto-generated method stub
			return super.getText();

Thats the easy part, what is tricky is how do you actually use it in your XML layout for the app? For starters notice how the class is static in the code above, also it has to be nested inside the Activity class that will be using it. Then in the XML file you need to add a View tag with an attribute called class which equals yourpackage.activityname$nameOfTheCustomClass

	class = "net.schwiz.wolfram.walauncher$MyEditView"
	android:maxLines="1" android:inputType="text|textImeMultiLine">

Well ok I guess that wasn’t so tuff but it took me a while to find out how to do this on the developers website, they do this in the notepad tutorial though if you want another example. If you want to install my app search for schwiz on the Android Market. I went ahead and released the source, it can be found here.

UPDATE: After over a year in the market WolframAlpha contacted me to let me know my app is in violation of their website’s TOS and forced me to remove it from the market. I updated the source to remove the WolframAlpha feature but keep the math keyboard for the system. I moved the source over to github with the updated codebase. It can be found here.