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) {
			super(context,attrs);
			this.launcher = (walauncher)context;
		}
		
		@Override
		public boolean onKeyDown(int keyCode, KeyEvent event) {	
			switch(keyCode){
			case KeyEvent.KEYCODE_ENTER:
				launcher.launchWebsite();
				break;
			}
			return super.onKeyDown(keyCode, event);
		}
		
		@Override
		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

<view
	class = "net.schwiz.wolfram.walauncher$MyEditView"
	android:id="@+id/inputID" 
	android:text="" 
	android:layout_width="fill_parent" 
	android:layout_height="wrap_content"
	android:layout_weight="4"
	android:maxLines="1" android:inputType="text|textImeMultiLine">
</view>

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.

Share

Comments:

Make a comment

You must be logged in to post a comment.