Android Drawable Resources

Doing some work on testing SmsDroidway on different Android SDK/Platform levels and I noticed that some of the nice default icons were missing from my UI. A quick google showed that this was not uncommon and that the best practice was to import the resources to your project locally to make yourself platform agnostic, though you then don’t necessarily match in with the platform.

The Android Eclipse project folder structure has a ‘res’ folder that contains Drawables, layouts, menus and values. However, the Drawables tend to be split by High, Medium and Low DPI folders, in fact some of the ADT tools create icons for you into these folders. This means that to import from the SDK folders you have to go and grab the the images from the folders individually, this just struck me as too much effort/pain.

So… I weighed up creating an Eclipse plugin to steal them from the SDK folders and push them into your project, and, to be honest, this would have been my preferred method. But I don’t have time to get up to speed with the plugin framework to create a UI, to access the ADT preferences and all the other stuff it should do.

However, I do have time to write a quick (and admittedly bit dirty) C# Winforms application that can do this.

So that is what I did, this is the wonderfully named “Android Resource Transferer”. I could probably brand it better 🙂

At the top you select your destination eclipse android folder, the Shell browse dialog is validated on exit to confirm the folder looks android like. This is a pain, the FolderBrowseDlg doesn’t support custom validation or subclassing, so I had to just put it in a loop with some delegate validation function passed.

Next you can choose to either use the SDK as the source or a Donor Project. The Tab selection is your active method.

The SDK Browse process includes some checks to make sure it looks like the SDK root folder. The SDK includes a platform level on the left, you can see my Android internals platforms listed there. You can then use whatever icon you think looks best.

A big difference from the eclipse ADT tool here is that the search box uses your search string as a  “contains” method, so you can focus on keywords and not if it starts with ic_ or whatever like you must in ADT.

The list of resources includes a nmeonic of [HMLN] to indicate which DPI are available for a particular resource, being [H]igh, [M]edium, [L]ow, [N]eutral. The selected resource is previewed at the highest DPI on the right.

The final step is to hit import and the drawable will be put in your project, it will even create the right folder if it doesn’t exist.

Back in Eclipse you will have to refresh to see you results and might have to do a clean to get the drawable IDs propagating through the project.

You can download the tool here. I can probably downgrade it from .NET 4 if needed, and I expect it to run under Mono, since there isn’t anything too complex in there. We won’t be releasing the source to this tool as it isn’t to the standard we normally work, being a quick tool to aid our development work, on the other hand, we haven’t obfuscated it at all, so if you run reflector over it you will see that it isn’t deliberately malicious 🙂

Accessing the Android Internal Classes

As part of our mobile work I have been peering into the Android source and Kernel, which is great, but we also wanted to see what we could get access to without making our own ROM and/or Kernel.

This provides a middle ground between more functionality and less compatibility when we want to offer some of our items for download to any old phone.

I found this posting Using classes from DevMaze. It was way helpful and in the final sections he discusses how the ADT Eclipse plugin restricts use of the internal classes, even if you can access them via the custom platform creations.

Well, I manually carried out the hex edit and it is all working, but I was concerned that if I let eclipse update I have to go and do it again. So, I give you a very simple application that carries out the ‘hard work’ of doing the modification.

It just:

  • Copies the plugin to a folder under your documents to work on
  • Unpacks using DotNetZip ( to a folder
  • Maps the file that needs to be modified into memory (first time using memory mapped files in .NET, frankly not as useful as in C/C++) for alteration
  • Copies the plugin as <file>.bkp just in case
  • Creates the Jar (a zip file)
  • Copies back over the original Jar plugin file

Nothing really amazing but it did allow me to mess with two things.

Visual Studio 2012.

Yesssss….. Not bowled over by this experience. I wasn’t asked what developer profile I prefer, so ended up with a .NET profile, I’ve always used C++ (I’ve been using VS since v6) and got used to the layout.

Color scheme, blinded by the light, though thankfully I found the dark mode.

Icons.. I’ve only had 15 years to get used to the old ones, so I guess making me learn new ones might cause a bit of frustration…

I don’t feel especially disposed to upgrading right away.

Memory Mapped Files

I was keen to see these in .NET as the application here was a text book example of their use.

In C++ you map the file, get a pointer and get to treat it like a big block of memory. It makes the C programmer in me happy :).

In C# I thought I would get a massive array of bytes that I could mess with, instead I got what really looked like a stream. I might as well have just opened the file R/W via File IO and worked on it.

Today was a day to want my pointers back :-p

Why software engineers are bad for electronics

Since I’m responsible for the hardware side of CASL I thought I’d share this article from Rugged Circuits about how easy it can be to kill one of the Arduino boards we use for happy prototyping. As we say about each other, we each know enough of the others expertise to be dangerous!
This is why I try to make sure our designs can withstand software engineers, after that users should be the easy ones…

10 Ways to Destroy an Arduino


CASL has been working on Atmel AVR programming using the excellent Arduino rapid prototype platform. Conveniently we’ve been using supplied boards as we could source them at Jaycar, just a few minutes drive away.

My own previous experience has been some PIC solutions,and a bit of FPGA work (I’ve also got some really old stuff like 6800 and MCS48…) , so this was interesting trying out another processer architecture and the provided development environment, the Arduino IDE.

I liked the boards, I liked the prevalance of libraries but hated the IDE… I’m coming from a Visual Studio background or Emacs, so I’m used to actually seeing my errors and having some extra control.

It wasn’t long until I had Visual Micro Arduino installed in VS2010, but even that wasn’t great (good plugin, but still using the FDH toolchain of the IDE). So I downloaded AVR Studio.

Now, we were talking I was seeing warnings, errors and lots of new stuff. I’ve spent a bit of time now configuring up templates for Arduino development, cleaned up the libraries and made new additions to the core (fancy subsrcribing to Pin Change Interrupts? How about multiple subscribers to Interrupt handlers?).

I should be going back and doing a QA on the code, when that’s done CASL will release an AVR Studio template for Arduino boards and also look to push the architecture changes back into the mainline of the Arduino sources.

Hello world!

We’ve set up a blog here on the website so that we add in more dynamic technical articles, hopefully we should be sharing information on bits of technology we have been working on and what we are thinking about.

We’ve used wordpress, since that was offered easily with our hosting, and hopefully it is the content, not the meidum (and perhaps even some of the presentation) that is important.

We look forward to sharing some of our work with you!