Programming and general geekiness.

Archive for February, 2012

iPad 3 Announcement

The time of year has once again come that Apple reveal a new iPad and this time round we are set to see the iPad 3. Here’s what we know and what is likely:

  • Its going to have a Retina Display – when you compare the above image with an iPad 2 this one clearly has much higher definition
  • It’ll be thinner
  • It will run iOS5 until iOS6 comes out
  • It will be faster, use the A5X chip and possibly be quad-core (if not very fast dual core)
  • It might lose the home button – Gizmodo points out that the above image has to be in portrait because of the distance between tiles and the Calendar icon is below the right set of bubbles that should be above the home button

I can see that the iPad (and eventually iPhone and iPod Touch) will work quite well without a home button and app switching (along with reaching the home screen) will probably be achieved be some sort of flicking action. That or there is no physical home button but that the black border can detect touch.

Your Country Needs You v1.1


I’ve done an update for Your Country Needs You which brings it to version 1.1 on the Android Market. It now allows you to modify the background color which seemed to be a logical progression and the only reason that it wasn’t in the original version was because I completely forgot to add it in. In a future version I do intend that it will be possible for you to modify Lord Kitchener’s face however he is sticking around for the time being.

Your Country Needs You on the Android Market

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.

Keep Calm v1.2.2

This isn’t really a major update to Keep Calm for Android however it finally fixes the issue of posters not saving properly. It turns out that they were saving all along, however the Gallery app doesn’t refresh the picture list straight away. I’ve written up an explanation here.

Keep Calm for Android

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.

Prerequisites for Android Development

I really like doing Android development and over the past few months I’ve done quite a bit of it but I found at the beginning that some things didn’t seem to be entirely logical that were quite important despite the fact that I already had a vast programming knowledge. Here is a list of things I reckon are useful for learning Android development:

  • Java experience: I don’t think that you need to know loads of Java to develop Android apps but I would say it is important that you at least know the syntax and roughly how to do things. Experience in a similar language like C# or C++ would probably get you by, just so long as you know the difference between a package, class and that kind of thing
  • Experience in another object-orientated language: Some experience in another language would also be useful because despite the fact that most Android development is in Java it is useful to understand how other languages do things because a lot of the Android specific Java has had influence from C++
  • An understanding of how apps work: This would probably come with programming experience but you really aren’t going to get anywhere if you don’t get how the most basic apps. Reading a few tutorials can help fix this
  • Experience creating user interfaces via code and and a visual designer: Android uses both XML layouts and pure Java code to create User Interfaces so provided that you have done something in both before you’ll probably be fine. I should imagine that it would probably be OK if you’ve done JavaScript DOM and HTML
  • Basic knowledge of XML and SQLite: You won’t need to know how to do these perfectly but so long as you can create XML documents and edit them. I wouldn’t say SQLite knowledge is vital but it would be good to have some database knowledge
  • A basic understanding of other mobile platforms: I had done a tiny amount of iOS and Windows Phone development before starting Android which probably helped me a tiny bit because it gives you some knowledge of design. Windows Phone development is probably more different to Android than iOS, so even if you’ve just created a calculator in iOS you’ll be in a good position to start Android development
  • Good resources for testing: The emulator is good but I’ve found that it always useful to either have at least one Android device for testing. I also recommend setting up a few different devices in the emulator with different screen sizes and versions of Android because that will give you a chance to test in loads of different environments
  • You’ve read some stuff on Android development: It is worthwhile reading up on Android development before you get started. Android Design and the Android Guide are both good places to start and reading some blogs will probably help develop your ideas. If you get stuck, make sure that you go on Stack Overflow.

Once you are fairly confident with all of this I recommend going over to Lars Vogel’s site which has some great development tutorials.

Chrome will probably become the default browser on Android

At long last, as the above video details, Google Chrome will be coming to Android in version 4 upwards. Despite the fact that the current browser in Android is based off of WebKit and the V8 JavaScript engine it will probably bring a load of new features, most importantly Chrome Sync. I should imagine that ultimately it is just a re-branded version of the current browser, but slightly improved.

There is still some work to be done according to initial reviews however it seems that it is still very good and a major design improvement on the standard browser. Android has really needed Chrome for a while and it doesn’t surprised me that it has finally jumped ship and I am sure that in the future as it gets more users Chrome or Chromium will become the default browser for Android, perhaps with Android 5+ or even in an update to Ice Cream Sandwich.

Which is the best C++ variant?

It turns out that this month the Microsoft C++ compiler will turn 20 and it is probably my second favorite C++ compiler after G++. Microsoft are aiming to ship C++ 11 Beta that will, for the first time, include ARM support, Windows 8 support and better parralel computing support. At the end of the day it is still good old C++ it just happens to support a lot of extra features, but yet I still prefer G++ because most of my C++ work is on Linux and G++ produces much smaller executables on Linux compared to Windows.

Obviously some compilers automatically optimize code to a certain extent so that it is as efficient in both speed and memory usage as possible and this is generally the deciding factor in how big the produced executable is. Despite this, I reckon that how good a C++ variant is depends on how good its libraries are.

Microsoft C++ with the Microsoft Foundation Classes basically lets you do pretty much anything you could possibly want on Windows however the open source community has had to build up something similar for Linux. The GTK framework is basically fantastic and I personally prefer it to the Windows stuff because you don’t have to write as much code to build complex UIs.

The cool thing about C/C++ compilers and variants is that they are pretty much all standards compliant and have the same basic libraries. Because the languages were designed to work across multiple platforms tools such as SQLite just work without having to do complex configuration of the compiler. Ultimately at the end of the day there is no ‘best’ C++ variant because they are all pretty good, I just have a personal preference towards G++ and GTK.

Follow

Get every new post delivered to your Inbox.