Marcos Placona Blog

Programming, technology and the taming of the web.

Category: Android

Android is an operating system for mobile devices such as cellular phones, tablet computers and netbooks. Android was developed by Google and based upon the Linux kernel and GNU software

Android: Where is my menu button?

Reading time: 2 – 2 minutes

So you’ve created your super polished android application and added a navigation menu to it, so your users can go from a place to another in your application without having top jump to the main application screen. It’s great, they can now simply press the menu button, and and a little menu pops up showing them all options available in your application. You’ve obviously made sure to select the correct images, and use icons that adhere to the Android style. Great! It’s time to start testing you application in as many devices as you can, and definitely make sure it works on any of the latest devices. Until you you see yourself facing a device that looks like this:

WhereIsTheMenu

Where is my flipping menu?

It turns out most devices now don’t even come with a menu button (iPhone’s never had them for example), and more and more, developers are being discouraged to build applications that actually rely on a physical menu button.

“So, does that mean you can’t use menu’s on your application?”

Continue reading

E4X and XML with namespaces

Reading time: 2 – 3 minutes

Here’s is something that got me scratching my head for a little while today while working on my new mobile application.

In my new application, I’ll be reading XML off various different providers, so I have an interface that gets implemented in various classes to make sure they all obey a certain contract, and I don’t need worry about what type they are (more on that later…)

With that in mind, I ended up implementing different logic on different classes since the XML returned will vary from provider to provider. I am using E4X to get the various information I need from the XML returned, and one of them would not work at all when selected.

I will put two XML examples here, and let you spot the difference:

var basket:XML =
	<foods>
	  <fruit>
		<name>Apples</name>
		<name>Bananas</name>
	  </fruit>
	</foods>;
trace(basket..fruit.name[0])

And that should return “Apples”.

Nothing new here, now for the second example:

var basket:XML =
	<foods xmlns="http://www.w3.org/TR/html4/">
	  <fruit>
		<name>Apples</name>
		<name>Bananas</name>
	  </fruit>
	</foods>;
trace(basket..fruit.name[0])

At a first glance, I have to admit I was expecting apples as well, but to my surprise, I got… nothing…

It took me a while to to go look on the XML again, and then it hit me. This provider would give me XML with a namespace, and in order to read that with E4X, I would need to declare that namespace. There is absolutely nothing wrong with the code above, but it simply won’t find anything since you’re not declaring what the namespace is, and the compiler gets completely lost.

What you need to do is declare the namespace on the top of my code like so:

namespace items = "http://ns.imageshack.us/imginfo/7/";
use namespace items;
trace(basket..fruit)

How you name it doesn’t matter, but it’s important that it’s unique, so in case you’re reading from multiple XML files on the same class, you should be using different names, otherwise you will get compiling errors.

Android and what I’ve been up to

Reading time: 1 – 2 minutes

Androids eat applesPhoto by: laihiu

I jumped into the Android bandwagon about two months ago, and so far I can’t cease to be impressed.

One of my favorite features is how easy it is to install new apps, as well as how open (source) the whole thing is. You can install and do whatever you like, without having to rely on closed platforms, or having to “sync as soon as I get home“. Do it anywhere, and whenever you please. It’s your phone, and you should be allowed freedom.

Continue reading