Monday, November 12, 2012

Installing Java for Applets

I've blogged before about the fact that Sun (and now Oracle) like to make it as difficult as possible to get Java working, especially for applets.  You can spend hours trawling the new for soutions, but often they don't work due to differing versions of your OS, of Java and your browser.

However, for future reference I've found this page which seems to wort and is incredibly simple:-

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html


Wednesday, November 07, 2012

Julian Gollop Announces New Chaos

If you're a fan of Chaos then you probably already know this, but Julian Gollop, famed developer of strategy games, has announced he's working on a new version of Chaos.

Chaos is indeed a brilliant game; that's just one reason why I copied it so faithfully for my own Sorcerers for Android.  I hope Julian won't mind if I treat this as a bit of competition between us as to who can create the best game.  I'm bound to lose, but it's the kind of impetus I need to keep working on a game.  And there can be no losers!

Friday, November 02, 2012

Speed Warning

Here's a new app which will hopefully save me money from those annoying speed cameras.

Without wanting to get too political on this blog, what really gets me about being caught for speeding is that it's too easy to creep over the speed limit.  Staying on the right side of the law shouldn't be a test of skill, and the more time you spend looking at your speed dial, the less time you spend looking out the window to check you're not going to crash, which can't be right.

Anyhoo, either way, my new Speed Warning app for Android should help and save people from the usual speeding fines.  It sits on your dashboard and will show you your current speed, in either Miles per Hour or Kilometres per Hour, depending on what your country uses. 

The main feature however, is to give you a visual and audible warning should your speed creep over the limit you have set, which can be easily adjusted with the '+' or "-" icons.  So now you can keep your eyes on the road at all times without worrying if you're breaking the law.

Wednesday, October 24, 2012

Podcast Manager


I listen to a lot of podcasts.  They make driving much more fun; now, when I hit a traffic jam, I think "Great, I can listen to more comedy before I get to work!".  (This probably sounds sarcastic, but it's true).

I was yet to find a decent podcast manager on Android, so I decide to create one.  All the other ones seemed too complicated; all I wanted was one that would let me easily find the podcasts on my phone and play them, but have lots of convenience features like let me return to the same point in a previously played podcast as it was when I last stopped playing it.

With this in mind, let me present Podcast Manager, and android Podcast player with all these features and more:-

* Scans your SD Card for all mp3s.
* Voice search
* Reads and displays the details of your podcasts (artist, album, etc...)
* Remembers previously played podcasts and the last position, so you can pick up exactly where you left off.
* Delete listened-to podcasts.
* Easily browse your phone's memory for podcasts.
* Easy to use interface for skipping through podcasts.

If you have to get it, let me know what you think and I'm always open to feature suggestions.  But at the moment it does everything I want from a Podcast player.

Tuesday, October 23, 2012

Minecraft + 3D Printer?

You read it here first - I predict that in the future you will be able to connect Minecraft to a 3D printer and print out a model of the worlds that have been created.  And I predict the first person to do this will get very rich.  And there will be a shortage of 3D paper since everyone insists on printing out the Mines of Moria.

(I also predict that someone will tell me this has already happened).

Friday, July 27, 2012

New App: Sorcerers

Like every other human being on the planet, I am a big fan of most Julian Gollop games, and the pinnacle of these are obviously Laser Squad and Chaos.  I've "tributed" Laser Squad with Stellar Forces, and now it's time for some Chaos.

My new app is called Sorcerers.  Like Chaos, it's a multi-player game where each player takes control of a wizard.  Each wizard has some spells which they must use to destroy the other wizard, and the winner is the last wizard left standing.  The spells range from fantasy creatures like a Wraith or Golden Dragon, to Magic Fire and of course Turmoil and the dreaded Gooey Blob.




There are a few changes to the original: there are more variety of spells, and turmoil doesn't crash the game.  It's currently 2-player, but will be increased soon to up to 4 player.

Thursday, July 26, 2012

Jellybean Graphics Bug - Help!

There's a really annoying bug in Jellybean, and I can't work out how to get round it, so I'm posting it here in case someone else has come across it and knows a solution:-

I've got two .png images in my app, both identical except for the name and I've changed one of them to be "bluer" (using Gimp). However, Jellybean refused to draw the bluer one. (I'm having trouble with other random images as well). There are no errors, and it loads the file okay, but nothing appears. I've tried swapping their names. They're both only 57x57 pixels, so it's not a memory issue.

Someone else has posted the same problem on Stack Overflow, but as of now there are no replies.

It's driving me mad!  How can something broken like this end up being released onto millions of mobile phones?


UPDATE: I've found a workaround!  Copying my images into /drawable-nodpi, seems to have solved it.

Wednesday, July 25, 2012

Free Service?

One thing that is starting to annoy me is the number of services that start out free, but then as soon as they become popular they introduce paid-for features while slowly reducing the free features until they are virtually useless.

The stock response to this is "well, it's free, what do you expect?".  However, this oversimplifies the issue and ignores all the other aspects of the problem.  Most important of these is that I've recommended these services to others, thus giving the free service its userbase.  My comments on these services are still on the internet, but I wouldn't recommend them now.  I've also spent my own time incorporating their service into my apps and my time isn't free.  Their services are now so entwined in my apps that it's going to take me lots more time to remove them and find alternatives.

I've got no problem with these services charging for extra features, but reducing the features that were there originally is almost tantamount to blackmail.

Friday, June 01, 2012

Your First Java Library Function

The first thing to do when you start creating your own library of Java functions is to write a wrapper for Integer.ParseInt() (and any of the other similar built-in functions).

Integer.ParseInt is, maybe deliberately, the most pedantic piece of code ever written.  Pass it a string like "2" and it works fine.  Pass it a string like " 2" and it goes "waoh!  A space?  What the f*ck is that?? Error!  Crash the system, we're going down!!".  Is it too much to ask to be able to handle a space?

In fact, almost any non-numeric character (the main exception being a "minus") in the string will cause it to throw a wobbly.  Even a decimal point: "2.0" is beyond its capabilities. 

My suggestion is as follows, although it's not the hardest piece of code to write:-

    public static int ParseInt(String s) {
        try {
            if (s == null) {
                s = "0";
            } else if (s.length() == 0) {
                s = "0";
            }
            return Integer.parseInt(s.trim());
        } catch (java.lang.NumberFormatException ex) {
            return 0;
        }
    }

Monday, May 28, 2012

MySQL Replication Challenges

If you've got a server running MySQL that's creaking under the weight of database reads, the obvious solution is to set up replication.  MySQL replication seems to work fine, but one thing I didn't appreciate at first is the changes that probably need to be made to your code (and not just changing which server it reads data from).

I imagine that most web pages, if they're anything like mine (oh dear) implicitly rely on the database being updated immediately.  My web pages usually have a similar structure:-

1: Read any get/post values and update the database
2: Display the new updated data as part of the web page

This seems fine, and it is if your database is updated immediately (since stage 2 is reading the data that has just been changed by stage 1).  If you're using replication, then you'll be updating the master database in stage 1, but then reading the data from a slave for stage 2.  However, if the slave hasn't updated itself from the master by the time stage 2 is running (and we're probably only talking millionths of a second) then stage 2 will display old data, and your users will cock their head to side wondering what's going on and why the system has ignored their commands.

Another similar problem I experienced is with an automatic routine that transfered data from one table to another.  For various good reasons, this routine would read the first 100 records (from the slave, obv), append them to another table, and then delete the originals (on the master).  And this worked fine until there was a small glitch in the communication between the master and slave.  Glitches in communication aren't normally a problem since you can specify how long the master retains logs for, so you can turn a slave off for a few days, turn it on, and it will (eventually) update itself.

However, due to the glitch, the slave wasn't updating itself.  It read the first 100 records from one table (on the slave), wrote them to another table (on the master), and then deleted the records from the original table (on the master).  Since it was reading the records from the (non-updating) slave, the next 100 records it read were the same 100 records as last time, because they were still there.

Being an automatic routine that runs overnight, this process was duplicating identical records at a hysterical rate, eventually eating up all the disk space and so the whole system went down within just a few minutes.  Oh dear.

So, in summary, replication technically works very well, but you can't just plug it in and turn it on and expect all your problems to be solved.  You probably need to think carefully about when to read from the slave or master, and what will happen if the slave is too far behind the master.

Thursday, May 17, 2012

Recording Videos of my Android Apps

If there's one thing I've learnt (or learned - which is it?) over the last month, it's that people like to be able to see what an Android app looks like before they hand over any hard cash.  I recently created a video of a few of my apps: Chromakey Photo Edit, Worldcrafter and Stellar Forces.  And blow me down with a feather if sales and/or downloads didn't increase!

So how did I create the videos?  I do have access to two phones, both of which are capable of recording videos, so the obvious answer was to use one phone to record another.  However, keeping both phones steady while recording and playing was harder than I thought; the phone that is recording doesn't need to be held by a person, but it does need to be positioned between the player ("hello") and the phone I'm playing on.  Asking a fellow human to hold the recording-phone tends to feel a bit ridiculous as they have to reach around you and keep the phone super-steady, which isn't that easy.

The solution hit me like a birthday present when, for my birthday, I got a present that turned out to be a phone holder for my car.  Perfect!  Its suction cup held it securely to a table while I played the games around it.  The only challenge now is to make a vaguely entertaining video that's short but also shows off the best features of the games.  And also where my thumb isn't always in the way.

Here's the Worldcrafter one:-



Since the game involves tilting the phone, that provided an extra challenge for keeping the phone in-view.

Friday, March 30, 2012

More Eclipse Update Frustrations

I use Eclipse all the time for coding, but every time I want to add a new add-on to it, it turns into a nightmare making me want to strangle whoever came up with the Eclipse update system.  Todays living hell is all about trying to add MAT (Memory Analysis Tool), just so I can read a "hprof" file.


Okay, where to start?  It was easy enough to find the MAT homepage (http://www.eclipse.org/mat/).  How do I actually get it?  There's a link called "Download the latest version as RCP application" (whatever RCP means), but I know I want to add it using the Eclipse Update Manager.  There is a "Getting Started" link, so I'll try that.

This is looking good.  There is a link called "Read the Eclipse Memory Analyzer Tutorial to see how to start the program. "

We must be there soon.  The tutorial says "Install Eclipse MAT via the Eclipse Update manager . Select "General Purpose Tools " and install "Memory Analyser (Incubation)" and "Memory Analyser (Charts)"."


Okay.  I assume by Eclipse Update Manager they mean the Install New Software option.


That asks me for a site to update from.  Erm, any clues Mr. Tutorial?  No?  Gee, thanks.

Okay, lets go back to the downloads page.  It's better than nothing.


Watch out!  It has an update site!  Okay, let's go back into Eclipse and put that in.

Hmm, it lets me put in the text, but OK is greyed out.  It seems that this is a "Duplicate Location", even though it's not in the dropdown list of locations.  Great.  Another dead end.

What next?  After fumbling about for half an hour I try the Eclipse Marketplace (which takes about 2 minutes for the window to appear as it insists on loading data from the internet every time).  I'll just do a search for MAT.


It's here!  This must be the solution then.  Okay, what do I click on?  The only links are "Share" and "Learn more", neither of which sound like "End all this messing about and just get it now", so I guess I'll try "Learn More".


This link just takes me to the website of MAT on the marketplace.  The only link I can see on the page that might be of use is the one that gives the update site.  What?  I thought this was the update site!  And the link to the Home Page returns a 404.


Fucking Hell this is ridiculous.  It seems that the Marketplace only has v1.0 of MAT, which has been replaced with a seemingly non-existent v1.1.  Maybe.  I don't know and am rapidly losing interest in this piece-of-shit life-wasting process (Apologies for the swearing but I've lost count how many days of my life I've wasted trying to find my way through the maze of Eclipse updates only to give up).



UPDATE

I finally got MAT by discovering a "Available Software Sites Preferences", adding MAT and then doing the update (this sentence makes it sound far easier than it was).  With MAT installed, I opened the HPROF file:


[Sound of programmer stabbing himself]


Friday, March 23, 2012

Java URL class is Buggered to Buggery

Take this bit of code:

URL url = new URL("http://www.somesite.com/forums/test.php");

What should "url.getFile()" return?  I would have guessed the string "test.php".  But it returns "/forums/test.php", which seems to be including the path as far as I can see.

The javadoc actually says "Gets the file name of this URL", but then goes on to contradict itself in the very next sentence with "The returned file portion will be the same as getPath().".  Is it me or Oracle[/Sun] that needs to go back to programming school and learn about the difference between a path and a filename?  Or maybe there is a subtle but massive difference between a "file name" and a "filename".

Also, AFAICT there's no way to get the (what I would call) filename, i.e. "test.php" in the example above.

Thursday, March 15, 2012

XML is a Step Backwards

XML has its place, like when transferring data between disparate systems.  But I can't help wondering if using it for things like the Android Manifest is a step backwards.  Why not use a programming language?  With XML, you lose a lot of the useful features of a programming language, like code-completion and interaction with the main code.

Taking the Android Manifest as an example, I have to refer to a list of the specific permissions that I require, since without code-completion it won't tell me the possible options.  These also have to be spelled exactly right.  Also, I'd like to change the icon based on some flags in the code.  Can I do this?  No, the XML is static.  Great!

Friday, March 09, 2012

New Android App: Speech Browser

I can now unveil my latest app: Speech Browser!  It's a voice-controlled web browser with all the usual functions that a web browser has, such as going to a website, doing a search, going forwards/back through history, following links, searching for text etc..  

However, being voice-controlled, there are a lot of extra functions: repeating a page, going forward/back through the page, controlling the speed of the voice.  There are also 3 voices available: British, American and Canadian (although being British myself I can't tell the difference between the last two :) ).

It should hopefully be quite useful for blind Android users (and if any find it useful or otherwise I'd be please to know), but I also wrote it for people to be able to listen to a website like Wikipedia without having to stare at a screen.

Wednesday, February 29, 2012

Thunderbird Deleted all my Deleted Items!

It's not the double-negative that it sounds like.  I "delete" all my emails (that have been actioned) so they go into my Deleted Items folder in Outlook, for reference at a future date.

However, I then started using Ubuntu at work meaning Outlook was no longer an option.  There is the Outlook web view, but as far as I can tell there's no search feature.  Being the modern techno-geek radical that I am, I thought Thunderbird would be a good idea, at least for the search facility.

Initially it went well, but then I noticed that the contents of my deleted items had disappeared: 5 years worth of emails (about 9,000 emails in all)!

The problem seemed to stem from the fact that I had "Empty Trash on Exit".  I naively thought that this meant it would empty the Trash folder on exit, but Thunderbird, presumably trying to be clever and helpful, decided that my "Deleted Items" folder was my trash, not the actual Trash folder.  Er, thanks.  Back to Outlook it is then.  I just hope I can recover them all.

Thursday, February 23, 2012

Good Review!

While it's nice to make a bit of cash from my apps, getting a good review is always great; I don't think many users appreciate how much effect they can have on a developer; a crap review (especially nonconstructive ones) can be a real downer.  Even the most basic app takes days of work, and when they are given away free but a user still leaves a crude review like "this is rubbish", it makes you think "What is the point?".

Conversely, getting a good review is great and really makes it all worthwhile.  Here's a humdinger that I received a few days ago for UK Traffic Alerts.  I've taken a screenshot since it could well get superseded by (hopefully) just as gushing reviews.


Whoever Peter is, I thank you!.

Thursday, January 19, 2012

Android Bitmap Idiosyncrasies

Whilst improving my Android app Chromakey Photo Edit, I've come across a few idiosyncrasies with Android Bitmaps which I thought I'd share for reference:-

  • Bitmap.createScaledBitmap() always returns a bitmap of type RGB_565, regardless of the source bitmap.  See http://code.google.com/p/android/issues/detail?id=13038
  • ARGB_4444 is now depreciated, so you'll always need to use ARGB_8888 if you want to store transparency information.
  • When using BitmapFactory.decodeFile(), always try to pass a BitmapFactory.Options().inPreferredConfig to ensure you get a bitmap in the format you need.  By default, bitmaps loaded this way are always immutable (uneditable), so you'll need to do a Bitmap.copy() if you need to make it mutable.
  • Bitmap.recycle() is ALWAYS required; if you create a bitmap but don't recycle when you're finished with it, expect to run out of memory eventually.  Setting bitmaps to null isn't necessary.