Android Licensing

Over at the official Android Developers Blog the release of the licensing service for applications is being discussed.

The licensing service means you can better protect your applications from unauthorized use. Go and check it out if you need a model to lock down your applications.

I think its a good move and will encourage larger developers invest time and resources into the market if they can lock down usage and thus returns. Of course you need to make a great application that everyone is willing to pay for in the process!

Posted in Android | Leave a comment

We have decimals

So I tweeked the code to allow for decimals. Here are the changed lines.

Float 	t1,t2,t3,t4;	

t1 = Float.parseFloat(text1.getText().toString());
t2 = Float.parseFloat(text2.getText().toString());
t3 = Float.parseFloat(text3.getText().toString());
t4 = (t1 / 50) + (t2 / 12) - (t3 / 5);
text4.setText(Integer.toString(Math.round(t4)));
Posted in Android | Leave a comment

Swype is cool!

Just a test post from my Android phone using Swype and the open source WordPress application. Works pretty well and I am quite impressed how fast the Swype keyboard can be used.

Posted in Android | Leave a comment

My first app

Having run through some tutorials and also armed with some vague memories of coding Java 1.0 at university I plunged in to my own app.

I wanted to make something so my Girlfriend would understand why I had been battling with netbooks, usb drives and obscure command line coding these last few days. I decided on a simple calculator. My lovely lassy is undertaking some unnamed calorie controlled diet regime and I thought I could whip up a simple implementation of the mental arithmetic she had to go through when she encountered a food item that was not in her secret code book.

It was perfect for my first app. Simple interface, easy to code and something that she could actually use!

First things first with my android app I had to design an interface and this is what I came up with.

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:padding="10px">
	<TextView android:id="@+id/tv1"
 		android:layout_width="fill_parent"
  		android:layout_height="wrap_content"
  		android:text="Calories"/>
	<EditText android:id="@+id/text1"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/tv1"/>
	<TextView android:id="@+id/tv2"
 		android:layout_width="fill_parent"
  		android:layout_height="wrap_content"
		android:layout_below="@id/text1"
  		android:text="Fat"/>
	<EditText android:id="@+id/text2"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/tv2" />
	<TextView android:id="@+id/tv3"
 		android:layout_width="fill_parent"
  		android:layout_height="wrap_content"
		android:layout_below="@id/text2"
  		android:text="Fibre"/>
	<EditText android:id="@+id/text3"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/tv3" />
	<Button android:id="@+id/button1"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_below="@id/text3"
		android:layout_alignParentRight="true"
		android:layout_marginLeft="10px"
		android:text="Calculate" />
	<TextView android:id="@+id/tv4"
 		android:layout_width="fill_parent"
  		android:layout_height="wrap_content"
		android:layout_below="@id/button1"
  		android:text="Points"/>
	<EditText android:id="@+id/text4"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/tv4" />
</RelativeLayout>

So along with this beautiful layout I needed some code to drive it all. I came up with this. Its been a while since I coded Java and I had some trouble getting the data types to work correctly.

package com.example.pointCalc;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class pointCalc extends Activity {
	Button		button1;
	EditText 	text1,text2,text3,text4;
	Integer 	t1,t2,t3,t4;
    @Override
    public void onCreate(Bundle icicle){
    	super.onCreate(icicle);
    	setContentView(R.layout.main);
    	text1 = (EditText) findViewById(R.id.text1);
    	text2 = (EditText) findViewById(R.id.text2);
    	text3 = (EditText) findViewById(R.id.text3);
    	text4 = (EditText) findViewById(R.id.text4);
    	button1 = (Button) findViewById(R.id.button1);
    	button1.setOnClickListener(new clicker());
    }
    class clicker implements Button.OnClickListener{
    	public void onClick(View v){
    		if(v==button1){
    		        try {
    			t1 = Integer.parseInt(text1.getText().toString());
    			t2 = Integer.parseInt(text2.getText().toString());
    			t3 = Integer.parseInt(text3.getText().toString());
    			t4 = (t1 / 50) + (t2 / 12) - (t3 / 5);
    			text4.setText(Integer.toString(t4));
    			} catch (NumberFormatException nfe) {
    				text4.setText("Only Numbers!");
    			}
    	   	 }
    	}
    }
}

My next step will be to convert this code to allow for floating point. I would like users to be able to enter decimal numbers, however I only wish to return rounded positive integers as the result. Hmmmm any ideas?

My thoughts are to:

  • Change t1,t2,t3,t4 from an Integer to a Float
  • Use Float.toString(t4) instead of Integer.toString
  • Include some sort of Math.round()

I have had some initial tinkers with this but so far have been met with failure. I might get it working as a Java applet first and then port it back to Android to speed up the development process.

Posted in Android | Leave a comment

Bring on the Toshiba

I caved in and picked up a Toshiba L655D-011. Its a Canadian model. Athlon 2 P320 4GB Ram, 640GB HD and an integrated ATI HD 4250. Its running Windows 7 Home Premium 64 bit.

Toshiba L655D-011

I am sure this will do most of what i want. It’s not top of the line. In fact its right down there towards the bottom, but it was cheap as hell and I considered it good value.

Posted in General | Leave a comment

Bending the rules

I was struck by a new thought. Perhaps I could use my work issued laptop to do a bit of coding on the side. It’s heavily locked down by group policy and various other forms of protection but that’s no reason to stop me.

So I downloaded Eclipse, the Android SDK and I copied the JDK install directory from my netbook. I then set up a batch file as so:

@SET CLASSPATH=.
@SET JAVA_HOME=%~d0\development\jdk6
@SET PATH=%~d0\development\jdk6\bin\;%~d0\development\android-sdk-windows\tools\;%PATH%
@%~d0\development\eclipse\eclipse.exe -vm "%~d0\development\jdk6\jre\bin\javaw.exe" -data "%~d0\development\workspace"

Now that seemed to work for a while, but Eclipse kept on crapping out with out of memory problems and just was not stable. I tried adding some arguments:
-vmargs -XX:MaxPermSize= -Xmx

I tried a few different values for memory size and it made it a bit more stable, but it was still crapping out.

Next step was to try and find a live cd of Ubuntu with the development kits and tool already deployed. I found some links but they all wanted me to pay. It really should be easier.

I then tried a to make a persistent Ubuntu Live USB. Nope that wasn’t working either. I managed to have it boot on one Ubuntu Live USB and store the Casper:RW persistant partition/filesystem on another. That allowed me to book into Ubuntu and install all the parts I needed including OpenJDK.

I finally manged to get it all up and running and compiled my first Android app. Yes the hello world tutorial was coming in handy now.

The bad news passing the app to the emulator was horrendously buggy and would only work around 1 out of every 5 times. I think its time to face the reality that I am going to need a my own laptop.

Posted in Android | Leave a comment

SyntaxHighlighter Plus

Testing the SyntaxHighlighter Plus. This looks like a decent plugin to demonstrate my code.

class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
Posted in Android | Leave a comment

Netbook madness

Hi and welcome to my blog. A collection of notes, examples and rants related to me learning to develop on Android.

I didn’t need a smartphone, or particularly want a smartphone but I bought one anyway because I was curious.  So I am the proud owner of a HTC Legend running Google Android.  It cost me $349 plus another 12% thanks to the Canadian wonder that is HST.

I wanted to know if I could develop on this thing so no messing around I googled “android dev” and dove right in.

I am running with a Lenovo s10e, its a pretty sweet little netbook, running an Intel Atom with 2gb of ram and Windows 7.  The only gripe I have with this little box is the vertical screen resolution is only 576.  If only they added a measly 24 more lines there would be no problem. Most of the online blogs, forums mentioned that it could be done but it was going to be painful to develop on this platform.

Meh, I say.  I am only planning to develop some small simple apps, surely I can compile some java and emulate a phone. I installed Eclipse, the JRE and the Android SDK.  Then I promptly coded up the hello world example.  It was OK other than eclipse ran horribly slow and then I tried to run it.

It didn’t work, the emulator just sat for ages on the Android boot screen.  I waited as patiently as I could, which for me can be a challenge, but this emulator it just wasn’t going to cut it.

I remembered reading that the Android Live CD could be booted in VirtualBox.  I tried that and it worked, I just now needed a way to add some HD space so I could install some apps and not loose them every time I rebooted the virtual machine. I failed, i just couldn’t get fdisk to see the HD that I had allocated in VirtualBox.

I was using this guide:
http://workinginavirtualspace.blogspot.com/2010/01/android-app-development-on-netbooks.html
and others like it.  It must be said that the live CD ran a whole magnitude faster than the SDK version.

I lost this time.  I think I need a better development platform.

Posted in Android | Leave a comment