My android Hello World

I was very curious on the Android development stuff recently.  I looked up for “Android tutorial” on google and this thing came up. It’s a very comprehensive guide for the Android newbie. I only read the first section called “Building your first app”. Some of the topics covered here are mostly the basics, how to setup your Android SDK, widgets, layouts, how Android is XML driven and the most important, how to assign Intents to objects.

Some time ago I wanted to do some basic operations with dates such as adding weeks, years, months. It sounds pretty easy, but the truth is completely the opposite. Dealing with dates is very difficult, because of the time measurement complexity itself, and tedious, because of the human historical inaccurate methods and schemas we have. I created my own date engine, but the most I pushed to be accurate, the most complicated it was to get a good answer.

So I gave up and used GregorianCalendar object in the Java API, it is a really fast way to do all the stuff described above. Somebody else suffered with those problems and solved them very well.

This is my first application on Android, couple of years ago I used to develop J2ME programs oriented to solve medical calculations, pretty basic stuff. It’s amazing how the API has changed, now we have hundreds of ways to get advantage of those supercomputers in our pockets. I really liked to do this app. If you ask me I would say this was quite a better experience than it was for iOS.

Now, about the application. It’s actually very basic in terms of, I should say, everything. An array of buttons trying to mimic a calculator. It performs basic calculations of dates. You can add or subtract days, months, weeks or years using a DatePicker to “pick the desired date”.

At the end I liked the way it parses the calculation string:


Pattern myregex = Pattern.compile("([\\+-]\\s\\d+[dwmy])");
Matcher matcher = myregex.matcher(operation);
while (matcher.find())

{
operationElements = matcher.group(1).split(" ");

That fragment of code will bring warmth to this night. That’s for sure.

Screenshot_2014-01-30-00-22-09

How the application works? It’s very intuitive. It can be tricky to get the date because the button at the bottom is actually a slider you swipe upwards to bring up the DatePicker object.

Grammar can be determined by using below regex:

mm/dd/yyyy\s([+|-]\s[0-9]+[dwmy]) +

This means

10/20/2010 + 24d + 3w – 5y

October the twentieth of 2010 plus 24 days, plus 3 weeks, minus 5 years.

IT WON’T FALL INTO PARSING ISSUES, AND IF IT DOES, LET ME KNOW.

Enjoy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s