Tag Archive for 'Android'

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 com.android.internal 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 http://code.google.com/p/adthiddentweak/ 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 (http://dotnetzip.codeplex.com/) 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