So I’m doing some extremely simple operations here which requires a number that is between 0 and 9. If I am looking to decrement the number I want to ensure that I wrap around properly. The way I do this is by:

/**
 * Takes in a number between 0 and 9 and
 * ensures that the result is still a number
 * that is within that range.
 */
int decreaseValue(int value){
    int result = (value — 1) % 10;
        System.out.println("Result is: " + result);
    return result;
}

// This is just for demonstrations sake
// >> decreaseValue(0);
// "Result is: -1"

Now trying to be a good programmer, I’ve written up some unit tests that test code that essentially does this. Unfortunately, my code is stuck in an infinite loop. This makes absolutely no sense and I wanted to verify that I don’t fail at math as hard as I think I am so I pulled out my python interpreter and did essentially the same thing.

>>> def decreaseValue(value):
...     result = (value — 1) % 10
...     print "Result is: %d" % result
...     return result
...
>>> decreaseValue(0)
Result is: 9
9

Now the environment I’m running this code under is the Android 2.2 Simulator. I haven’t tried it on any devices yet, I’d just like to know if anyone else has had this issue or if I am indeed horrible at math and that is why my code isn’t working.

Edit:
It’s more of a misunderstanding of how the modulus operator operates in a Java environment. It’s very odd, and can catch you off guard.

 

So, the 26th of October has come and gone, and I’d just like to talk about my experience at AndroidTO. Before I start though, I’d just like to say I had a great time meeting with everyone and there is a very good chance I don’t remember your name. I’m not really a name person but if I see you again in public will probably recognize you, if not don’t be afraid to stop me and say hi.

The event itself was really well organized, and Puleen did a great job on keeping me on my toes (which I assume he did with the rest of the presenters as well). He’s a pretty persistent guy, but it always kept my presentation at the front of my mind.

The event ran very smoothly, besides a few technical hiccups such as the wireless; which honestly always happens at conferences. The choice of venue was really interesting; when I first heard that it was at the Polish Combattants Hall was thrown off a tad. This really wasn’t that big of a deal though, because it was right along a bunch of major TTC lines so getting there wasn’t a problem at all.

I was also really impressed with the androidTO app that was done by the great guys at http://mobicartel.com/. I was quite surprised at all the stuff they had done with making it a very polished Android application. From what I saw with Matt and Greg they are a great team, and I look forward to seeing what else they come up with in the future.

From what I’ve read around Twitter and from a few blogs, some of the presentations were a bit over peoples heads. They were pretty technical, especially the one by Manfred about the crazy stuff you can do with maven. Though, as a developer who’s been working with Android for several months now, I found the things he was talking about very intriguing. The tools he mentioned like Robotium and Roboguice look like amazing technologies that people should start looking into. If it were not for presentations such as Manfred’s I would’ve never heard about these tools, and that’s exactly what conferences like these are there for. Hopefully the things that were discussed will save everyone time from looking for these tools, especially when they don’t know what exactly to look for.

It was also nice to have seen Carmen going around taking photos of the event. I am not too sure if she was the official photographer, but it was awesome to see what she was doing. I brought my girlfriends point and shoot with me, but didn’t really want to disrupt some awesome conversations I was having with a lot of the people there. In case the organizers didn’t know, I’m also an amateur (read: wannabe) photographer and would totally be willing to go around an event in the future to take a bunch of shots at the next big Android thing going on. I also feel have some official photographers would help because then we would know in advance where to go to see all the pictures that were taken from the event.

The post event meetup was probably my favourite part of the event. This is always where everyone gets to actually learn more about people since there is actually time. There was of course even more great conversations that were going on, we got to talk about the technology even more as well as just getting to know each other more. I also found it great because I still find it difficult to tell how to know how someone is as a person, especially when most of the conversation I’ve gotten from them was on Twitter, where 2’s u’s and other various tragedies of the new millenium are required to actually say something.

I hope that everyone enjoyed my presentation, and I’ve encouraged you to begin using SQLite in your own Android projects as well. I was a bit nervous while I was up there, especially when my “Oh Shit” moment happened because I had forgotten to turn the wireless on my Macbook back on. Let me know what you liked, and how I could make the presentation better. I really love teaching people, and the only way I will know if what I’m teaching was good or not is if you let me know. Either send me an email, tweet or simply add a comment to this post. Also feel free to grab the code for use in your own projects. I warn you, the code does have it’s issues, and if you add some patches or clean some stuff up, feel free to send me the patch or or a pull request and I’ll be sure to bring it in.

I would like also like to thank my buddy Chris Millward for letting me crash at his place for my time down in Toronto for this conference. It was great to meet up with you again and talk about work, tech and everything else!

 

I’m a pretty decent fan of the Android platform. It’s fun to develop on, has an excellent community filled with tons of knowledge. Unfortunately, several items peripheral to Android such as the market are horrid and I despise being stuck with these. Sure, I can put my apps on the alternative markets, but I will still have my apps on the Android Market since this is the most likely place for people to go to get their apps.

Application Descriptions

This is probably the number one place I am having issues with. I now have to choose between informing my users about new features, how to fix problems or describe what the fuck the application actually does to get the interest of prospective users.

Now I have nothing wrong with limiting the walls of text you often see on other platforms, but I should be able to have enough room to write what it is my application does as well as provide a brief about what users can expect in the new version. It would also be nice since then I can inform users how to resolve issues they may be running in to; which takes me to my next point.

Android Market Errors Console

This is both awesome and a piece of crap at the same time.

I love it because now instead of having users bitch about the app and give it 1 star on the market, they can send me a stacktrace along with a brief description of what they were doing to cause the issue to happen. This is great for the easier bugs that you may run in to and helps you deal with them much more promptly.

Now for the hate

Where do I begin? I guess we can start off with the fact that it’s a unidirectional pipe and I cannot query users about what they were doing in more detail, or tell them to try something that may resolve the problem in the meantime. Sure there are suggestions such as using forums or google groups or some other kind of bullshit, but as far as I’m concerned that’s away from when the problem occurred. Hell, I’d prefer to see something like having the users send me a goddamn email as well so I can actually contact them.

Another issue I have is with the shall we call it… issue tracker? The tool is alright, I guess though I cannot flag items as completed or resolved, only as old. So, these issues stay in the tracker under the old section, and if you get new reports they don’t get re-bumped back up to new. I’d rather have a new or open section and a closed or resolved section for my bugs on this console. Now let’s say I’ve flagged an issue as closed but then another user brings the bug up again? Hmm… reopen the damn thing so that I notice I have new data and then clearly the problem hasn’t been solved.

Screenshots

Why only two? Why only the two specific resolutions? Why not the resolutions supported by the Android developer devices? At least then I could use my Nexus One for my screenshots instead of my HTC Magic which is typically turned off and in my messenger bag.

Unfortunately my application (and most likely several others) have more than 2 screens of interest in them. It would be nice to be able to give people more of a sneak peak into what is in the application before they download it or buy it.

In Closing

I figure I should vent these problems both as a form of stress relief and to hopefully get a hold of those responsible for this aspect of the Android platform inside of Google. I’ve found this tool feels very much like a half-baked 20% time project, and isn’t taken seriously at all.

I hope that these issues can get resolved so that the users of the Android platform can have a better experience with us; the developers and for this to happen we need to be happy as well.

 

Alright, so I’ve spent the morning working on getting a working version a HeadingAdapter and have pushed my changes to the csaundersAndroid project on github. This includes a simple demo of the HeadingAdapter working with a basic dataset.

I currently don’t have any tests written up for the adapter yet, but intend on getting some done soon. I simply wanted to get the code out so others can get their hands on it and provide feedback.

You can get more details about using this adapter from the project home page.

 

Open vs. Free

Well, another device has come out with hardware tools built in to prevent “unauthorized” Android images from being installed on it. The community has once again gone to arms about this. People are throwing around phrases like “goes against open source” or “Android is an open operating system”.

Yes, the source code for Android is Open Source, but vendors can take that code and modify it to their needs. They have just as much of a right to tighten the hatches on the device as we do to go out and create our own custom modifications.

I can understand why a vendor or telco would want to lock down a device. This could be for their own security, to sell their “value added services” (which drive me up the wall) or to make it harder for a user to accidentally brick their device. I honestly believe the last issue is the probably a big motivator for them to introduce these technologies on their devices. If a vendor gets a return from a user who’s device won’t boot they can immediately know if it was because of tampering. This will have drastic effects on their bottom line, so I don’t blame them for making such a decision.

There is only one part of the Android system that is truly free; the kernel since it was a Linux derivative which is released under the GPL. Aside from that, the rest of the source code is under an Apache license. As such, vendors only really need to release the source code for any modifications or extensions to the kernel they have made.

I believe Google chose to develop Android with such a system on purpose. The kernel is honestly a minor part of the system when compared to everything else, and vendors want to own the code that is running on their devices. We don’t know what their source contains, but it could have “trade secrets” or whatever that they want to keep to themselves with an advantage over the competition. If you want a truly free device, then an Android device by manufacturers such as Motorola, HTC, or Samsung isn’t for you.

I feel that the terms free and open often get mixed up by people, which is unfortunately very misleading. In my references I have included an article by Richard Stallman who (biasedly) describes the difference between free and open.

Consumers have the Power

This really comes down to us as consumers to show that we will not allow vendors and telcos to sell us devices that have such mechanisms built into them. It is very simple, don’t buy the device. Instead go with one from a more forgiving vendor or if you want to be absolutely sure you have a device you can mod go with an Android Developer Phone that you can get from with a developer account from the Android market.

Now I know the cyanogenmod guys will get around these issues, but sometimes we have to ask ourselves is this necessary? It negatively reinforces the decisions made by the brass at these companies into believing consumers are fine with what they are doing because the hardware is flying off the shelves. Personally, I would prefer to see a device like the G2 do horribly. This would perhaps convince those responsible for such decisions to not include such hardware mechanisms.

The market will have the ability to change this trend of caging the Android OS, we just need to learn when to say no those shiny pieces of technology.

References:

 

So the majority of the code for my presentation at AndroidTO is up and hosted on Github.

If you are looking for a tutorial on how to interact with SQLite on Android, check out my code. It’s fairly straightforward though almost completely undocumented. I’ll go through in the next few weeks while working on the presentation and add comments to the code both for JavaDocs as well as explaining the nuances of what I was thinking while writing the stuff.

This is probably my fourth or fifth time writing code to interact with databases on Android and I must say that it is a huge pain in the ass. Having to write much of the SQL by hand is error prone, tedious, and downright annoying. It would be nice if the Android SDK came with a built in persistence layer like how iOS comes with CoreData baked into it. It would allow you to focus on the problem at hand instead of wasting that time on the boilerplate copypasta.

I have looked into some ORMs for Android and so far it appears fairly sparse. There are Java libraries you can bring over, though I’m not entire sure how compatible or efficient they are. Hibernate is clearly out of the picture. I have found one project Active Android that seems to be kinda neat, which I am working on using for an app I’m working on. Unfortunately it’s commercially licensed, though it’s rather inexpensive.

If you are looking for an open source tool there is one project called sqlitegen that uses Java annotations and code generation to build to data access classes for you. I haven’t used it personally since I’d prefer to use a solution that doesn’t rely on Eclipse.

 

Since I’m going to be presenting at AndroidTO next month, I figured now would be a good time to start working on the source code that I will be using in my presentation. If you want to watch the progress of the project as I work on it, you can check it out at github.

The presentation I will be doing will be about using the SQLite Database that comes with the Android platform. For the demo what we will be doing is pulling down images from a Picasa album, storing the data in a database so that you can view them on the phone without a data connection. I only have the XML parser done for the feed but it will print out some information to the log to prove that it is indeed parsing the information correctly.

Feel free to check out the code and get a hold of me if there is something that is a bit weird in the source that could possibly be clarified with some more comments or whatnot. The code is under an MIT license so go ahead and use it in your projects if you want.

 

For a new feature I’m adding to Runr I needed to get access to audio files. Now, I don’t want to really have some buggy implementation that is dependent on placing files in specific folders on the SD Card. I just want to get all the Audio Files off the card then display them in a spinner or something.

This is where Content Providers come in; more specifically, those provided by the Android OS itself. I won’t go into too much detail of making a content provider, but they essentially allow you to make access to certain data public so other can use it. In my case, I want to know what audio files are on disk but don’t care about where they are and having to find them. Android has taken care of this for us, and we are going to take advantage of it.

In order to use the content provider we need to set establish a few things first:

  • We need to make a call to the appropriate URI to get access to the right content provider
  • We will need to specify what data we want from our request (which columns we want)
  • If there is any limitation on what kind of selection we are doing
  • What kind of ordering we want our data to be in
/*
 * We only care about content that is stored on the SD Card, so we will only query
 * the content provider that provides us with external audio files.
 */
URI audioURI = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

// Set up the projection so that we reduce the data we fetch to only the stuff we need
// In our case we only want to get the Title, Author and the audio data
String[] projection = new String {
        MediaStore.Audio.Media.TITLE,
        MediaStore.Audio.Media.ARTIST,
        MediaStore.Audio.Media.DATA
};

String selectionString = "WHERE " + MediaStore.Audio.Media.ARTIST + "=?";
String[] selectionArgs = new String[] {"Lady GaGa"};
String sortOrder = MediaStore.Audio.Media.ARTIST + " ASC";

// Run the query
Cursor cursor = managedQuery(audioURI, projection, selectionString, selectionArgs, sortOrder);

// Make sure we have data to actually iterate through
if( cursor.moveToFirst() ){
    while( !cursor.isAfterLast() ){
        // Have the cursor determine what index the Title and Artist information is stored at
        String title = cursor.getString( cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
        String artist = cursror.getString( cursor.getColumnIndex( MediaStore.Audio.Media.ARTIST));
        Log.i("ContentProviderExample", "Found: " title + " by " + artist);
    }
} else {
    Log.i("ContentProviderExample", "No Audio files!");
}

This code would be running in an activity of course which gives you access to the managedQuery function.

Anyway, I hope this little blog post provides a bit of information on how to determine what audio files are available on the users Android device.

References:

 

I’ve been mulling over the idea of using alternative app stores as the main way of selling my Android software but I feel that there is one issue with them. Not all users will know that they exist.

Now, I personally feel that App stores are pretty bad to begin with but users are becoming accustomed to them for getting software for their platform of choice. This works out great, that is as long as you can actually sell software on those distribution channels. So far for something like the Android market you can only sell if you are from the US, UK, France, Spain and a few other countries.

So what else is there to do? Well go on the alternative app store if you want to sell your software or come up with licensing and give it away for free on the Android market and get users to buy licenses from you which will give them more features.

My problem with the licensing issue is that you need to set up all that infrastructure to get it going. As a developer it would be nice to just tie into something very simple that does all the licensing for you.

I’ve been mulling on the idea of providing a service like that. Have no clue exactly how I would run in and how I would make money from it. I think the first thing I would be interested in knowing is if any developers (on any platform) would be interested in this.

Please feel free to leave comments, send me a DM on Twitter or send me an email about this.

 

For some work I need to do, I’m displaying some remote images from a web server as icons. Initially this really slowed down my UI as I needed to pull the images down each time when I scrolled to a new icon*. To help deal with the issue where I was constantly pulling down icons, I have created an in memory cache which solves the problem as long as the application is running. Unfortunately this solution will only work, as long as the user is connected to the Internet.

This is where I’ve decided that I need to have a 3-tiered system that will deal with the caching for me. It is going to work in the following manner:

  1. Check the in memory cache, if the item is there use that.
  2. If the item is not in the cache, check on disk to see if we can get it from there.
  3. Finally, if we have not found the item from disk, try to grab it from the server add it to disk then return the item and add it to the in memory cache in case we need to use it again.

This will hopefully speed up the application, reduce the amount of data the application will use and will have uses in other applications as well. I’ve only started working on it, but should have it done in the next few days. Once I have it all tested out and I’ll probably push it up onto bitbucket as an open source project.

*Note — Yes, yes, I know that pulling down the images should be done in a separate thread, which I will do once I get everything else working properly.

© 2011 Christopher Saunders Suffusion theme by Sayontan Sinha