Programming and general geekiness.

Archive for the ‘Code’ Category

Update to Keep Calm

I updated Keep Calm on Google Play today to version 2.2.5. This new update fixes a couple of bugs and makes poster generation a lot more efficient which should, in theory, mean that the app is a lot less likely to crash – an error reported due to a memory error.

The reason that the app had been crashing for some users (especially those with older phones with less RAM and older versions of Android) was because the background of the poster was being regenerated every time something was changed on the poster. This was a necessary because Keep Calm Pro allows for a greater variety in the backgrounds (solid color, linear gradient, radial gradient and an image) however was completely unnecessary for Keep Calm and therefore lead to an unnecessary Bitmap object hogging up memory.

The two apps share the same class to generate the poster (its called Dunkirk and the majority of variables, functions and classes in the app get their namesake from various WWII battles to keep me entertained whilst coding) so an extra function has been added to this that generates higher quality posters. I also adjusted the resolution the preview as rendered at – by default it is 600 by 900 (this is the export resolution) however if the screen resolution is lower than that it will be rendered at the lower resolution.

Hopefully this update has fixed any bugs that were in Keep Calm which is now within in three/four days of 50,000 downloads :) .

Keep Calm on Google Play

Keep Calm Pro v1.2

Earlier today I launched the third update to Keep Calm Pro since its initial release which brings the app up to version 1.2. This new update officially introduces 100 icons (which brings the total up to 150 icons). Whilst these were technically introduced in version 1.1.5 there were a number of bugs in this version that I hadn’t considered so therefore this new version fixes these bugs.
The most peculiar bug that I had to fix was that on some devices the app was not correctly loading images from the phone’s Gallery app. Thankfully I was able to fix this bug (if anyone is interested it was a threading issue) and I have therefore improved the the way that images are loaded better so that the look great heading the poster.

Keep Calm Pro on Google Play

HTML5 Canvas Stick figure animator

This morning I remembered a program that I haven’t used in years: Pivot Stickfigure. The program was a pretty simple animation tool for making 2D stickfigure based animations and it was fairly popular a few years back and there are many thousands of videos that have been made with it on YouTube. I thought it would be interesting to make a similar tool to Pivot Stickfigure that allowed me to create simple animations, however I figured it would be more interesting if I made it with HTML5 Canvas.

Before I started I decided that rather than having individual frames I would have a keyframes system. This would allow me to create smoother animation (even though I’m not that great at it). I put together a load of JavaScript that stores the animation in JSON format (and also displays it so that you can ‘save’ your animation). Unfortunately my version doesn’t really allow for more than one stick figure however it could, in theory, be added at a later date. I also added in a bunch of sliders so you could manipulate each frame and choose at what time point you wanted it at.

The above video shows my shocking first attempt at making an animation. Unfortunately my computer’s least favorite activity is screen capture so its a bit slow but if you want to check out the web app please click here and if you want the JSON for my animation click here (you can just copy and paste it in).

Things I’d like from Android

Android is a good platform – not a great platform, but a good one. I’ve been doing a lot of Android development recently and it certainly has many good features and it is easy (and cheap) to make an app for the system. There are, however, a great number of problems with Android from a developer’s point of view. This is a rough list of things I would like to see from the Android project. I don’t think that it necessarily needs them, but I think it would be a good thing for the platform if it had a few of them:

  • SVG support everywhere: A major problem with Android at the moment is that you have to create at least three different copies of the same icon for use in app because Android apps can run on many different devices at different resolutions. If all icons were changed to SVG it would be possible to just include one copy of the icon and know that it would be shown at maximum quality on all screens. This would also be useful when Android displays eventually get to a higher pixel density (as in the iPhone and iPad) as icons would never appear pixelated. SVG font support would also be handy but not a requirement.
  • Better font support: Android currently comes with three fonts whereas Windows Phone and iOS come with over fifty. You can include fonts in your app however if you wish to do this you have to change the font of each View pragmatically rather than via styling or XML which can increase the size of the app and also make it slower. Again, SVG font support would be useful.
  • Higher PPI displays: When the iPhone got a Retina Display the only way that Android devices could get a similar resolution was to get bigger screens because Android wouldn’t run as well on higher density displays. There should be some big system changes to get this support.
  • One Android: It amazes me how phone manufacturers have fragmented Android by adding new UIs and alternative apps. Whilst some of these are really great it often means that some devices won’t receive a major update for months after it has been released because the UI is being developed. If Android could go back to being pure Android it would make it a lot easier for developers and require less testing of apps.
  • Google Play gift cards: This seems like a painfully simple thing to do but it is one of many reasons why iOS developers make a lot more than Android developers. It is a well known fact Android users ‘don’t like buying apps’ however the problem is that most of them can’t. When you set up an iTunes account you either have to type in your bank details or set it so that you will use gift cards however this is not required for Google Play registration. As most Android users have not created a Google Wallet account they can’t buy Android apps. By selling gift cards everywhere (as iTunes does) more people are likely to start buying apps.
  • Better integration between Eclipse and Google Play: Currently you can create an app in Eclipse, export it and then upload it to Google Play. It makes a lot more sense, however, to integrate the two so that developers sign into Eclipse and then press one button to upload an app to Google Play. This would also simplify the process of creating in-app purchases.
  • OTA updates: Most iOS devices are now running iOS 5.x and many are already running iOS 5.1, which came out in the last month. On Android most devices are still stuck with a two year old version of Android because phone manufacturers (who are responsible for updates) have not chosen to update to Ice Cream Sandwich. If Google were to take over the updating of Android devices it would probably mean that more people were using the latest version of the software.
  • Better emulator: The Android emulator is very good however it can be incredibly slow when trying to emulate Android 3.x and Android 4.x devices.

New Android app: Keep Calm Pro

It’s been just over two months since I originally published Keep Calm on Google Play and the time has come to upgrade it to introduce new exciting features. Keep Calm Pro is now officially available and introduces the following new exclusive features:

  • Updated rendering engine so that text always appears on the poster and so that it appears at the maximum size possible
  • New menu that makes the app easier to use and reduces time between loading the app and saving/sharing the finished poster
  • The option to use the standard sans-serif font or Open Sans Light
  • Change the text color
  • Change the icon to one of 50 included icons or any image from the your Gallery which is automatically resized, cropped and recolored so that it looks great at the top of the poster
  • Change the background color and choose whether it is a solid color, linear gradient or radial gradient
  • Change the background to an image of your choice from your Gallery
  • Improved wallpaper rendering for higher quality

Unfortunately camera integration didn’t work too well initially so in version 1.0 you will need to select the ‘Gallery’ option before pressing ‘Menu’ which then gives you the option to take a new photo. Please note the image of the teacup used in the screenshots is licensed under Creative Commons license from Wikimedia Commons. All other images used by the app are in the public domain.

Keep Calm Pro is by far the best Keep Calm and Carry On app available for Android at just 50p/99c.

Pricing apps

App development is becoming increasingly common and everyday hundreds – if not thousands – of new apps are released each day. Mobile platforms, along with the web, are the most popular deployment bases. The main mobile OSes all offer an online app store of some sort that allows developers to either give away their apps for free of force users to pay for them.
A large number of apps are now ad-supported so that developers can still profit from free apps. The only problem with this model is that ads often really damage the user experience, especially in games because they just get in the way of what the user is trying to do.
The biggest alternative to ads without charging for the app is to have in-app purchases so that users have to pay for additional features in the app. This is a lot more efficient than ads because it maintains a contained user experience that is solely focused on the app itself. My belief is that these in-app purchases should add to the user experience rather than not having them making the app worse. An app with in-app purchases should function perfectly reasonably without the user having to pay to make it better – instead they have the choice. At the same time I’ve got absolutely no objections to users being encouraged (but only subtly) to purchase additional features.
At the end of the day if you’ve made a really great app you should charge for it but if you feel you can reach more users by making it free and letting them pay for some extra features in-app purchases are probably an equally good if not better option.
After that I’ve made a mental note not to try posting from the WordPress iOS app.

Converting phone apps to tablet apps

There are probably hundreds of thousands of great smart phone apps out there that are still waiting to be made for tablets. This year (more than 2010 and 2011) will be the year of tablets as millions of people buy iPads, Android tablets and Windows 8 tablets. The first two will happily run iPhone and Android phone apps respectively however there will be a little more conversion between Windows Phone 7 apps and Windows 8 apps but I should imagine that the process will be roughly the same.

The current problem is that phones are generally a lot smaller than tablets and also have different aspect ratios. For instance, the iPhone has a resolution of 960 by 640 and an aspect ratio of 3:2 whereas the iPad has a resolution (currently) of 1024 by 768 and an aspect ratio of 4:3 thus meaning that apps’ layout can’t really be the same on both.

The first method of converting an app is to literally scale up the layout so it looks exactly the same on both screens. It may be that some zooming is required on a phone whereas it isn’t on a tablet as in Safari. This method will work for some apps, but it won’t work with all apps. Here is an alternative method where you get two screens of phone information on one tablet screen:

An alternative option that works similar to the above is to split the single column that you have on the phone layout into two columns on a tablet. The above example wouldn’t really work but if you had a biography app you could do the following:

In this example the content on the phone has to scroll whereas on the tablet some of the information can be put on the left hand side in such a way that it would never need to scroll however the remainder of the information could be placed on the right of the screen and would, if necessary, scroll.

Obviously it may be necessary to reverse engineer this process and convert a tablet app to a phone app. This is probably a little more challenging as you are naturally given more space, as a developer, to work with on a tablet whereas that space becomes limited on a phone. I would recommend taking advantage of scrolling/flipping, tabs, menus and other specific phone features to ensure that the information is still on the screen.

How Apple proved the importance of app permissions

There has been a lot of outrage in the past week after it was uncovered that some iOS apps have been ‘stealing’ the data in your Address Book and sending it all to private servers. The apps, such as Path, Instagram and possibly Twitter, then presumably use this data to help to obtain new users or to guide you how to follow based on people that are already in your Address Book. I can’t really imagine that they would really need to use the data for anything else and it makes sense that you could utilize the various APIs to send lots of addresses at once so that the server could then reply with the usernames of the users in your address book. However, some of the data may be stored on the servers.

Most people’s (or Congress’) problem with this is that all of this has been happening without the direct permission of the users. Any iOS app that you install is able to access pretty much anything on the system but on the basis that Apple has already approved the app it should be OK. Because Apple obviously can’t check through all the code that an app uses it is hardly a surprise that they didn’t spot that the apps were submitting this data.

In the future apps will now have to post a message to the user telling them that the app would like to access Address Book data however it will still be technically possible to access the data anyway.

What this incident has essentially highlighted is a major flaw in the iOS security system. Android apps require specific permissions to allow code to run to do things like write to the SD card, change the wallpaper, use the camera, use the Internet and access the Address Book. Examining the Android app for Path we can see that it does request some of these permissions which are granted by the user when they install the app. This means that Google have to do a lot less work reviewing apps and it also means that Android apps are a lot more sandboxed on the device.

I should imagine that this will leave Apple in a position where they need to start implementing permissions to ensure that users remain safe because at the end of the day they can’t pick up everything by using humans to review apps.

Free Android app: Your Country Needs You

As a natural follow up to my Keep Calm and Carry On app it made sense to develop another similar app based on another famous British wartime poster. This new app allows you to modify the text of the poster however you will soon be able to change Lord Kitchener’s face to your own face and also change the background color (this update will probably ship in the next week).

The app also fixes the saving error in the Keep Calm app* – it turns out that your posters were saving but not always appearing in the gallery. This was a technical error in that the gallery app doesn’t check for new images when it loads and so adding one extra line of code in my app automatically refreshes the gallery. As well as saving you are also able t0 share, set as wallpaper and choose from three fonts – Alfa Slab One, Enriqueta, PT Sans.

This slideshow requires JavaScript.

Your Country Needs You on the Android Market

*Don’t worry, I’ll be updating Keep Calm so you can save your pictures properly in that too.

Sharing and saving Bitmaps in Android

If you’ve ever worked with Android development before you’ll probably know that once you get it right it can be incredibly rewarding however if you get it wrong it can be a real pain to fix. Sometimes the development also demonstrates the fragmentation of Android and how it can be a great challenge to do something relatively simple because it works differently on different devices.

I recently developed the Keep Calm app for Android that allows users to create Keep Calm and Carry On style posters. The app has been a reasonable success (20,000 downloads in a month) however there has been one major issue: not everyone could save properly. At first I didn’t really understand why this was because all of the testing I had done indicated that the Bitmap object that the image was stored in was being correctly saved to the SD card and it would then appear in the Gallery app. However, this was not the case for everyone.

I soon discovered that it wasn’t a technical issue with my app entirely. The default Gallery app gets a list of files in the various images folders on the SD card each time it loads but the Android system doesn’t always refresh this list of files very often – sometimes only when the device is restarted. Clearly it would have been a major issue for my users to have to restart their phone each time they wanted to view a file so I came up with this solution:

String saved = Images.Media.insertImage(this.getContentResolver(), bitmap, title, description);
Uri sdCardUri = Uri.parse("file://" + Environment.getExternalStorageDirectory());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, sdCardUri));

The bitmap object is of type Bitmap whereas title and description are both Strings. The sendBroadcast function (your activity inherit it as the class extends Activity, where the function is) then forces the OS to remount the SD card as it would do when the device starts up meaning that your picture will appear in the Gallery app. If you want to prove this to your users you can load up the file in the app:

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(saved), "image/*");
startActivity(intent);

This then loads the image up, using an Intent, in whatever the default Gallery app is. Remember that you’ll need to add the android.permission.WRITE_EXTERNAL_STORAGE to your Android Manifest otherwise the app will fail. The obvious progression of saving is, of course, sharing and Android makes this incredibly easy to do without having to use the APIs of all the various social networks that exist – instead the app can just utilize services provided by other social network apps on the phone. Here is how to do it:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(saved));
startActivity(Intent.createChooser(sharingIntent, "Share image"));

This loads up a menu (unless no options are available other than email) headed with the “Share image” text asking the user what service they would like to share it with. The appropriate app will then launch. Another cool thing I’ve done using a Bitmap is to set the wallpaper. You’ll need to ensure that the Bitmap is double the width of the user’s device and the same height (explained in this Lifehacker article) – this could be done using a Canvas. Here is the code you can use:

WallpaperManager wallpaperM = WallpaperManager.getInstance(this);
wallpaperM.setBitmap(newBitmap);

Like with saving, you’ll need to ensure that you add the android.permission.SET_WALLPAPER t0 your manifest otherwise, again, the app will fail. Hopefully this article has helped you with your projects and if you have any other problems leave me a message in the comments.

Follow

Get every new post delivered to your Inbox.