Android local service binding - quick howto

So you've decided you need a Service in your Android app.
The question is how to invoke its methods? How to interact with it?

In a nutshell, you define an interface to the service.
Upon request of such an interface (by an activity), the code binds an asynchronous implementation of the interface to the real service and returns that implementation.
The activity invokes methods on that implementation (interface) and they are later (async) propagated to the service.
The result will be two toasts fired by the service, but originated from the activity.

Below is the how code.
When you test the code, don't forget to add the activity and service to the manifest file.
Enjoy!

Manifest:


Code:

Ubuntu 10.10 Eclipse Java sun source code

Motivation: Saw a lot of misleading instructions on how to attach Java source code in Eclipse on Ubuntu 10.10 and even how to install Java.

First of all, It is best to install Java on Ubuntu as described here.
(I wanted to link to another place but can't find it, so the commands were taken from my commands history)

The source code will be attached automatically.

Android SDK source to be viewed in Eclipse

EDIT: (2011/11/22)
It seems that after upgrading the SDK, the source folders were deleted.
I found a nice tool as an Eclipse plugin that attaches the source code.
The problem is that it currently supports only up to Android v2.3.4.
Or you can do it the manual way, as stated in my original post below.


Original post:
Attached are the sources to:


Reference:
Attaching sources to android.jar in Eclipse


Unzip them to the appropriate platform ander the android SDK folder.
android-sdk-2.1_r1 -> android-7
android-sdk-2.2_r2 -> android-8
android-2.3.3_r1a -> android-10

If you use api level 7 or 8, just restart eclipse and you should be able to view the source code (F3 on the Activity class :)

Hope it helps and you don't need to start messing with git, scripts, etc. - not that I'm against them, just thought of saving some time to other Android developers.

Also, I migrated the script from Mac to any other Linux. You can download it here.

Java default date formats

java.util.Date:
EEE MMM dd HH:mm:ss z yyyy

Notes:
- Milliseconds are not shown thus get lost.
- The day is only for "show" - it doesn't really affect the parsing.

java.sql.Timestamp
yyyy-MM-dd HH:mm:ss.S

Unit tests to test the above can be found here.

Q&A:
Q: Why do I post this?
A: There are applications that output the default 'toString' of dates, thus need to be parsed if the date needs to be "understood".
Q: What does the format above mean?
A: The formats are the convention of Java's SimpleDateFormat.

SpringSource - a disappointment

Well, tried for several hours to install and use springsource STS.
NO SUCCESS.

springsource used "almost every" technology @ their disposal:
- Maven
- Spring
- gwt
- spring roo
- jpa
- log4j
- AOP - AspectJ
- JUnit

Well, this should be great but
they forgot to make it compile and run -
a very very big OOPS.

Downfall summary:
- They introduced a new scripting language (roo)
- New annotation API (roo annotations)
- Complex
- Created a whole different eclipse plugin management solution of their own. Why?
- Have an installation process that takes about several hours.
- Their hello world doesn't compile on Eclipse and no instructions on how to compile and run it outside of Eclipse.

Bummer. Sounded so good when I first read about it...

Little UI Progress And A Bright Future

The Progress
I made a little progress with the sample notes application I talked about in the previous post.
I created a header to the table using a CSS.
The old version can be found here.
The new version can be found here.

It was quite a fast experience for all I needed was to look at another application :)
What I learned was:
  • How to copy-paste CSS code :)
  • CSS syntax - Just scratched the surface
  • Few glitches in GWT

Ultimate Goal
The ultimate goal is to have a framework and knowledge to develop a web application from end to end where the development should be:
  • Fast
  • Easy
  • Business oriented
  • Interesting
What's next?
Lots of options:
  • GWT API - Experiments with tables, layouts and other API
  • Google's app-engine: Available APIs, DB(JPA), Google users API(open ID?), ...
  • GWT MVC(Model, View, Contoller)
  • GWT project organization - Client-Server shared code, projects reuse, projects dependencies, ...
Means
OK, so I now have a set of things to learn, but it would be nice to use them in a real useful application.

I would gladly continue my exploration with the notes application but similar exists by the tons, which kind of takes the edge out of it.

I'm looking for an application idea I could experiment with.

My current idea is a warehouse sorting application(will have a warehouse after we move to Modiin:) - I haven't yet googled to see if such exists.
The application would keep track on what exists where and help users find things when needed.
It can have several features like search capabilities. It could perhaps plug into a task application and pop up useful info when needed, for example: If i have a task to repair a bicycle puncture, the application would tell the user where his bicycle repair kit is located(with history).

What do you think?

Please feel free to suggest other application ideas....

Cheers,
Alik.

UI - A Personal Barrier



Hi all,

This is my second post and a more technology oriented one, though I tried putting in a personal touch.


UI
What do I mean by UI (User Interface) anyway (in the context of computer software of course)?
UI is how an application is presented to a human user, meaning:
- How a user sees data?
- How a user interacts with the application?
- What interests a user?
- etc.


Why UI?
As a person that feels deeply about sharing and collaboration, I try making myself as clear and "readable" as possible (not always succeeding).
When I write code, I try giving classes and methods meaningful names so that other developers can easily understand, reuse and maintain the code and application.
That means that for a server side developer, other developers are the primary users of code readability.
Customers, which are the application's end users don't really know or care about code readability - they just want the application to work!

Code readability is just one part of the game, which I kind of learned to master (there is always room for improvement).
Application readability is another part of the game, in which I have a bit of a clue - well, I am a user myself.
Naturally, I started getting more interested in the end user of my code - the application user.

Where does the the application user and I meet?
In the UI pub.


The Barrier
Recently, I have noticed that I have a UI barrier. Not just a temporary one - a big one that existed since a day I don't even remember.
Ever since I was a child, I had difficulty painting or sketching what I had in mind.
My dad told me that way back, when I was about 5 years old, my kinder garden teacher used to complain that I refuse to paint.
I don't remember her complaints, but I do get frustrated that I visualize one thing and sketch something horribly different :( - perhaps I will take some painting/sketching lessons in the future.
This defect follows me whenever I try making something visual - whether it is sketching a map for directions, choosing colors for presentations or developing UI.
I have lied to myself all these years that it is just a liking - I prefer server side development. The reality is that I have a developer's UI block.


The hammer
So, if I ever want to shutter my barrier, develop a start-up with UI or just broaden my knowledge, I would need to learn and use UI.
But what UI technology should I choose?
There are tons: Swing and SWT. GWT and Wicket. Spring MVC, HTML, CSS, JSP, ASP, Javascript, flex, javafx, and the list keeps on going.
All of them can be divided into 2 sections: Desktop and Web:
Desktop applications are applications that exists and installed locally on a person's machine.
Web application are browser based applications.
There are lots of differences between Desktop and Web application (there are also UI technologies that run on both).
Just search for web vs. desktop application and compare.
The big disadvantage of web applications was that they could not be as rich as a desktop application.
Well, this disadvantage belongs to the past. Just look at Gmail, Google Docs or Google Calendar - they are all very rich Web applications.

OK, so I chose to learn web UI development instead of desktop UI development.

Though this is the first time I'm writing about it, I did had some runs with desktop (Swing and SWT) and web (javascript& html) UI development - all failed miserably.

When I saw GWT(Google Web Toolkit) a few months ago, I thought: "Here is the hammer for my barrier".
GWT is a Web UI technology that is targeted to Java geeks like me.
It is an abstraction over the Web javascript language using the Java language and it gives an easy access to the server.
There were other technology rivals to GWT, like wicket.
Finally, I chose GWT, because no Web UI technology provided me with a 3 minute "hello world" web application that can be easily deployed on a server (Google app engine) and provide an easy client server interaction.


Raising the hammer
So I started using GWT and the first demo application is a Notes application.
The application should display users' notes in a table.
A user should be able to add/delete/edit/search notes.
Because my main goal was to learn UI development, the server just produces several hard coded notes and the UI should present them - for starters.


Failing miserably
Here is the first hammer strike.
It took me hours and still a long way from breaking the barrier.
How do I put the lines in the table?
How do I center the table?
How do I make the table stretch on all the screen?
How do I add column headers?

Well, now you know how my barrier looks like.
I visualized one thing and implemented a whole different one...


Purpose?
  • The trouble of many - half of the consolation.
  • A cry for help, by a UI developer, to the Web UI technology world. How come that there is no simple way for writing Web UI? Thanks to GWT, the client-server interaction is smooth and thanks to Google's app engine, the deployment is easy, but - Why is my UI still looks like $%^&?
  • A kind of a promotion to GWT.
  • A kind of a demotion to GWT - I expected something more easy.
  • Finally, because the only followers I have are my friends and family, this is an opportunity to share what's keeping me busy.

What's next? Retrospective!
I'll try to understand if it's me or GWT? (Why GWT doesn't have a Style class?) As Sting said: it's probably me :(
If it's me, I'll probably have the same problem with other Web UI technologies such as Wicket, so I'll probably stick with GWT.
I'll try to solve the problems I had above and continue broadening the application.
Perhaps choose a different application to develop? Something more useful. There are plenty of "kind of Notes" applications (who said Wave? :)
Feel free to suggest new ideas.
As soon as I start feeling more comfortable with Web UI, I'll share my insights.


This was a long one,
Hope you enjoyed,
Alik.