Making Keep Calm more memory efficient

Over the past couple of days I’ve been making some improvements to both Keep Calm and Keep Calm Pro to ensure that they are now significantly more memory efficient and require a lot less CPU power meaning that they can more comfortably run on older and slower devices.

The first thing that I’ve gone through and done is get rid of useless functions and variables that were just clogging up memory – this has reduced the amount of code by about half and should make the app a little faster.

A major problem that I’ve always resented with the app is that previously a bitmap was generated off screen before being displayed in an ImageView meaning that it was effectively stored and drawn twice (stored once by the main activity and drawn once by the drawing class before being stored and drawn again by the image view). I therefore decided to build a custom view which handles the drawing (along with saving, sharing and setting as wallpaper which all happen in different threads now meaning the app should run a bit faster). The custom view is a lot more lightweight and I’ve noticed fantastic performance effects in the emulator and I should imagine that it will run even better on real devices.

I’ve also updated some of the Keep Calm Pro code so that background images don’t have to be reloaded quite so often (helping to reduce memory/CPU usage). I’ve also ensured that aside from UI specific stuff both apps share as much code as possible which should make it easier for me to adjust them in the future. On a side note I’ve also halved the number of lines of code on both apps.

Both apps have had their default background changed as well – before it was a red gradient however I have now changed this to a simple grey for three reasons:

  • It’s going to look a lot better on Keep Calm 3.x*
  • Drawing the UI is a little faster
  • It means that hopefully people will pick better background colors for their posters – I’ve noticed that with the red gradient I tended to pick quite nasty colors whereas now with the grey the UI becomes less distracting so hopefully people will be able to better judge the color they want

Another minor adjustment I’ve made is exporting to PNG rather than JPEG which means that the images are of better quality when shared via the web.

Here’s a quick summary of all the improvements that I’ve made and how they affect the user experience:

  • Less memory in use means that the app can more comfortably run (and other apps can run faster when Keep Calm isn’t in use)
  • Less CPU power required for drawing
  • Reduction in amount of UI drawing done by half
  • Smaller executable
  • Simpler UI that will look better in current and future versions of the apps
  • Export to PNG rather JPEG to ensure higher quality posters are produced

*I’m currently planning what will be Keep Calm 3.x and Keep Calm Pro 2.x. I’m not sure if I’ll ever release them but they will be pretty cool if I do.