Tuesday 13 December 2011

Android - ProgressDialog without Dimming Screen

By default, when Android's ProgressDialog is shown, the rest of the screen is dimmed automatically. This is pretty useful in most cases, but sometimes you want to keep the content in the background clear and visible too.

This is possible albeit not overly obvious. It turns out that when ProgressDialog is constructed, it has a flag set specifying that behind the dialog should be dimmed. As passing in 0 to the constructor of the dialog as the chosen style doesn't work, you actually have to create the object, and then remove the offending flag manually.

An example follows, where this is an Activity:

Monday 12 December 2011

Android - Show Soft Keyboard When Activity Starts

This morning I needed to have a soft keyboard (AKA, the on-screen keyboard) showing when an activity launched. Why? Well it was login screen for my app, and the input text field would have focus by default so there was no need for the user to tap on the field prior to the keyboard appearing.

I came across code-based solutions which didn't work for me unfortunately.

The solution was thankfully available using a manifest-based approach.


Tuesday 6 December 2011

Android - Get body of HTTP Response as String


Making HTTP requests in Android often results in the same type of boiler plate code being produced. One in particular that annoys me is having to get the response body as in InputStream and using BufferedReader and the likes.


Bundled along with Android is the org.apache.http libraries, which provide classes for easy interaction for common HTTP-related activities.


The following snippet shows how to perform an HTTP GET on a URI, and turn the response body into a string. In my case, I take the string and turn into a JSON object, but you might parse as XML or whatever.


DefaultHttpClient http = new DefaultHttpClient();
HttpGet httpMethod = new HttpGet();
httpMethod.setURI(new URI(SERVER_URI_GOES_HERE));
HttpResponse response = http.execute(httpMethod);
int responseCode = response.getStatusLine().getStatusCode();
switch(responseCode)
{
    case 200:
        HttpEntity entity = response.getEntity();
if(entity != null)
{
String responseBody = EntityUtils.toString(entity);
                 
        }
        break;

Thursday 1 December 2011

Android - Creating a new Activity in Eclipse

The method of creating new Activities in Eclipse is somewhat counter-intuitive if you ask me.

Open your manifest file, which is likely called "AndroidManifest.xml" if you've stuck with defaults. You should see multiple tabs at the bottom, which will give you different views on the one manifest file. Choose the "Application" tab.

You'll see a horribly cluttered screen here, with one of the sections named as "Application Nodes"; this lists all of your existing Activities and allows you to add new ones. Nodes...? C'mon Google!! Anyway, hit the "Add..." button.

You'll see the following prompt:


Choose "Activity" from this list. This will create a new section named as "Attributes for Activity" to the right of "Application Nodes". Don't be tempted to go filling in values yet. See the hyperlinked text, "Name*", yup, click on that:



This will launch the "New Class Wizard" with the superclass already set appropriately for you. Name your class, choose your package as you normally would.

The last step is to add a new layout XML for the Activity (assuming you need one). Under your project, there will be a folder named "res", and under that a folder named "layout". Right click on "layout", and choose "New", then "Other...". Select "Android XML Layout File" from the list.



Give it a name that corresponds to your Activity in some meaningful way, but you are limited as to what characters you can use:
 File-based resource names must contain only lowercase a-z, 0-9, or _
Once created, open your new Activity class up, and you'll see the onCreate method has been templated for you. After the line, super.onCreate(savedInstanceState); add the following:
setContentView(R.layout.name_of_activity_layout_file);
If Eclipse fails to autocomplete once you have typed R, it could be because it has imported android.R automatically and not your own R class. Simply the delete the following line if it exists:
import android.R;
After that, organize your imports  (CTRL+SHIFT+O) and if prompted, choose your own R class and not the default android.R.

Saturday 12 November 2011

Typing into Windows Phone 7 Emulator

Little tip that can save a ton of time for when typing using the emulator. The on-screen keyboard will jump up by default and allow you to use the mouse to click on the keys you are after. However, by default, it will not allow you to use your computer's keyboard to input text.

A very counter-intuitive way around this, is when the on-screen keyboard is shown on the emulator, simply hit the PAGE UP button on your machine's keyboard. This will dismiss the keyboard and let you type at full speed.

And yes, PAGE DOWN will allow you to restore the on-screen keyboard.

Monday 31 October 2011

Setting up Synology DS411J NAS Drive

I recently made the big decision of buying a NAS drive. I have previously relied upon external USB drives and they have been fine up until recently. My previous system was to buy a hard drive, use it until it neared being full, buy a bigger one, copy everything over, stop using the old hard drive (too small by comparison now) and rely fully on the new hard drive. This is madness. If you do this, and you like your data, this is madness. Why? Well, you have everything you own on one hard drive. One drive, which could fail at any moment. Not to scaremonger too much, but I began feeling pretty uneasy about this.

My solution was to buy a NAS box which can hold up to 4 drives. I only bought two hard drives (each 2TB) to go inside the NAS, but the box itself can support up to 12TB. I decided to set this up in a mirroring setup, meaning whatever is added to one drive is automatically written to the other. Obviously then, my 2x2TB hard drives only allow for 2TB storage (and not 4TB) but with the huge and potentially live-saving advantage that if any of the drives failed, there would be a perfect mirror still with all my data intact.

For the NAS drive, I opted for the Synology DS411J (read details on Amazon) and for the hard drives themselves, I opted for Samsung HD204UI Spinpoint 2TB SATA 3.5" Hard Drives (read details on Amazon). Or scroll to the bottom for the Amazon links widget.

Not the ugliest box

Thursday 27 October 2011

iPhone Development - Turn On Automatic Reference Counting (ARC) on a Single File in a Project


Off the back of my other post, Turn Off ARC, which instructs you how to configure Xcode to disable ARC for individual files, this post is the polar opposite; how to enable ARC for individual files.

To enable ARC for a single class, you should go to the "Project Navigator", click on your project, and then select the "Build Phases" tab. From the "Compile Sources" dropdown, find your class on which you wish to enable ARC. Note, you enable this on the .m implementation files, not the .h header files.

Notice that there are two columns here, "Name" and "Compiler Flags". Double click in the relevant "Compiler Flags" column for your desired class, and the following:

-fobjc-arc

Clean and Rebuild your project to pick up these changes. Note, as far as I know, you cannot apply this to whole directories in one go, and have to apply it one file at a time.

Wednesday 26 October 2011

iPhone Development - Turn Off Automatic Reference Counting (ARC) on a Single File in a Project

Xcode has introduced ARC from version 4.2 and above (compatible with iOS 4.0 and above) and it is excellent. All new projects you create will have it enabled by default (you can uncheck this during the new project wizard if you so desire) and that is just lovely.

But what if you need to import legacy code, or another party's source code that hasn't been coded with ARC enabled? You need to remove all manual memory management commands such as release, retain, autorelease etc... if you want to enable ARC. So if your legacy or third party code has these in it and you can't or don't want to edit the code, then you'll have to tell Xcode that ARC is disabled for these files.

Thankfully, Xcode allows you to have ARC enabled for the whole project, but disabled on a select number of files.

To disable ARC for a single class, you should go to the "Project Navigator", click on your project, and then select the "Build Phases" tab. From the "Compile Sources" dropdown, find your class on which you wish to disable ARC. Note, you disable this on the .m implementation files, not the .h header files.

Notice that there are two columns here, "Name" and "Compiler Flags". Double click in the relevant "Compiler Flags" column for your desired class, and the following:

-fno-objc-arc


Clean and Rebuild your project to pick up these changes. Note, as far as I know, you cannot apply this to whole directories in one go, and have to apply it one file at a time.


For details on how to enable ARC for individual files, see my other post, Turn On ARC.

Monday 24 October 2011

Custom HTTP Headers in iPhone UIWebView


If you've done much coding for iPhones, you'll likely have come across the UIWebView class. It is what allows you to use an embeddable web browser component, within your app. It's a useful component that lets you view web pages straight from within your app, using the very capable rendering capabilities granted to the iPhone's full Safari browser.

The problem I faced today, however, was that I needed to customise some of the HTTP headers that are sent to servers, when using the UIWebView component. Turns out that this is possible, although not as straight forward as I first expected. Why might you want to do this? Well you might want to alter the HTTP User Agent string, add some custom headers that your server requires, alter the language supported by the Accept header or you might well just be really curious.

Read the solution after the break.

Thursday 20 October 2011

I Ran a Marathon!

Yes I did. It's true, I have pictures to prove it and everything. On 2nd October, 2011, I participated in the Loch Ness Marathon, some 26.2 miles (~ 42km) of gruelling, undulating, unrelenting hills, unmercifully wearing me down, damaging and breaking my body and spirit. My final time was 5hrs 21mins.

Proof, that certainly couldn't possibly have been photoshopped



A few weeks on though and I've managed to block out exactly how difficult it was. But hopefully in writing this post and looking back at the pictures, I will remember.


Last mile!


Read more after the break.

Sat Nav App for WP7

I recently went looking for a good sat nav software for my Windows Phone. Even with mango, Bing Maps is nothing more than "all right".

Sure it can get me from A to B. But doing so in an easy, safe and convenient manner whilst driving seemed to cause it issues. I mean really, it doesn't update the instructions as you pass them, so the onscreen information is still showing you how to get out your street when you've hit roadworks half way through your journey and need a plan B. And don't even get me started on a lack of turn by turn voice directions.

So I went looking. And sadly found no good free apps. However, I did find a rather spiffingly good app that comes at a cost.

Tuesday 27 September 2011

Windows Phone Update - Mango ISV Beta Bundle: Cleanup

My HTC HD2 is a trusty phone. It's been around for about 2 years now. Upon release, it was a monster and was one of the first - and even to this day one of only a dozen or so handsets - to support such a massive screen.

One of the reasons it's still popular in certain circles (the hackers/tinkerers/hobbyists) is how well it has supported modification over the years. I have seen it personally run Windows Mobile 6.5 (and many variants therein), Android (again, many versions) and Windows Phone 7 and Mango. I have also seen the interwebs do amazing(ly geeky) things with it too, like putting Meego and Windows 95 on it!

I run WP7 on it though, a Mango RTM version specifically. How excited I still am though to get the 'proper Mango' version, and hopefully before the more legitimate handsets receive it. The smugness one can have, honestly, you'd think I'd just bought an Apple product and was keen to argue about how amazing it is even though no one really cares only to find that I'd really just been trying to convince myself of its worth... woah, where'd that come from? Moving on....

Today I received the indication that a software update was due... oooh, could this be it? Certainly about the right time, no? Zune indicates the update is for "Mango ISV Beta Bundle: Cleanup" which made my heart sink a little. Probably not the release I'm waiting on then, but almost certainly a precursor to the update.



Monday 26 September 2011

BlackBerry Development - JVM Error 104

During BlackBerry development, there are literally hundreds of hurdles that will get in your way.

One of which I noticed recently was the seemingly random error, which causes the "White Screen of Death" you can see below. This is caused by the dreaded JVM Error 104, which is a sort of catch-all something-went-wrong-and-you-didn't-handle-it kind of problem.


Sunday 18 September 2011

Playstation 1 Emulator on Android Tablet

Recently I got my tablet (Motorola Xoom) playing old Playstation 1 games, using my PS3 controller as an input device. Please do not underestimate how happy I was to see Final Fantasy VII up and running!



In this post, I'll detail the steps needed to get an emulator installed, how to download the games and how to convert the games into a suitable format and what you'll need to use your PS3 controller as input device should you desire such a thing. The emulator has a small cost (currently it is £2.61 or $4.10)

Be warned, it isn't all that straight forward so a certain amount of geekery is recommended! If you have any problems, just ask in the comments section.

Also, be warned, emulators and the games you play on emulators (called ROMs) can be a bit of a grey area, legally speaking. My best understanding is that you have the best shot at staying legal if you own the console you are emulating and own the games that are being emulated. I'm no lawyer by any means, so seek your own legal advice and conscience before diving straight in.

Thursday 15 September 2011

BlackBerry - Eclipse Error - Invalid Regex in BlackBerry_App_Descriptor.xml

If you ever see this error from Eclipse whilst doing BlackBerry development,

InvalidRegex: Pattern value '([a-zA-Z_]{1,63}[\s-a-zA-Z_0-9.]{0,63}[;]?)*' is not a valid regular expression


you should of course follow the hint in the error and check that none of your values in your BlackBerry_App_Descriptor.xml will fail the regex.

However, there is a very strange case whereby you will see this error regardless of your values. In fact, creating a new project straight from Eclipse will still show the error.

Turns out this could be caused by having Java JRE 7 installed on your machine. The BlackBerry plugin doesn't support this yet, Eclipse might be trying to use that.

The fix? You simply have to edit the eclipse.ini that will live in the same directory as your eclipse.exe that you use to start the IDE. Closing Eclipse and making a backup of eclipse.ini before you do this would be a good idea.

Find the line "openFile" and immediately after, add the following:

-vm
C:/Program Files/Java/jre6/bin/javaw.exe [or wherever your jre6 directory might be]

Cross your fingers and restart Eclipse.
Rebuild your projects.

Wow I hate programming for BlackBerry. Is it not dead yet? Seriously any platform that needs a site like this (http://isthesigningserverdown.com/) needs to get itself sorted.

Sunday 7 August 2011

Ear won't pop

I'm currently experiencing a very odd medical condition. Whilst I'm not typically one to broadcast all my embarrassing ailments; I feel this is suitably odd/not embarrassing enough to worry about people knowing. Additionally, in my Googling for people with the same problem, there seems to be a fair few out there, but with no real suitable conclusion to the problem, so if nothing else, I'd like to raise my hand in the air and shout me too! Shouting because I probably won't hear myself doing so.

The problem you ask? Well as the title hints at, my ear won't pop. I was on a plane home 8 days ago (returning from a week in the Algarve, Portugal) and during the flight, my ears were constantly requiring popping. For anyone interested, I favour the fairly standard popping technique, of holding my nose and attempting to blow my nose, resulting in some pressure relief via the ears. My right ear was responding to this as normal, but my left ear just didn't seem to want to give. And a week and a bit on, it still hasn't.

Monday 13 June 2011

Playing Videos on the Xoom

I recently took my girlfriend on a weekend away up to Loch Tay. It was to celebrate our 2 year anniversary and she had previously mentioned she would like to go camping. I like the idea of camping, but also kinda like having my phone above 90% charge at all times. Not to mention liking to keep my beers cooled! So we decided to go camping; the premium edition. We stayed in a wooden wigwam. It was a tremendously relaxing weekend which was long overdue given the amount of stress I was going through prior to leaving.

Obviously, a weekend away in the almost outdoors (the indoor heating, fridge/freezer, TV, microwave, kettle and shower qualifies the 'almost' I feel) is a good time to fill up the Xoom with some high quality videos to wile away the hours as the Scottish summer rains down outside! But what a nightmare getting videos to copy onto the Xoom. Read on for the problem and the seemingly bizarre solution.

Tuesday 10 May 2011

XBMC control for Motorola Xoom

Been a while since my last post, so thought I'd try resume with a quick and fairly non-technical post.

Bought myself a Motorola Xoom the other week (month?) there and have been loving it. It's one of these things which enters your life with such subtlety that one would be forgiven as branding it a needless luxury. It's not how much it changed my life when I got it that surprised me, rather, how much I can't now seem to function without it.

There have been many poor attempts at justifying me spoiling myself to some shiny luxury. However, one of the big ones I reckoned would be to have this portable browser in my hands one second, allowing me to play on Facebook research the social dynamics of my generation, then quickly switch to a remote for my PC, enabling me to control the background, yet necessary, TV show I inevitably watch whilst doing other things. I'm a fiddler. Worse, I like to fiddle as a background task.

Thursday 31 March 2011

WP7 - URI Mapper

Overview
I am always on the lookout for ways to improve code; short term benefits are nice but there is a great feeling in identifying potential problems way in advance, and putting in the framework early to make life easier later. Using a UriMapping when developing WP7 apps is one of the many ways you can help eliminate annoyances later.


So first of all, a brief description of how page navigation works in WP7, what a UriMapper is, and why it pays to use it. Scroll down passed these descriptions if you'd rather just see how to implement one.

Tuesday 8 March 2011

Micro Payments, Major Annoyance

Since when does paying £50 for a game mean you are only renting it nowadays?

The world has changed a lot in the last two decades, and probably in no greater way than in technology. Whilst the advent and subsequent popularisation of the internet is probably the single, greatest thing which has changed the way people live their lives in recent years, it has some damn subtle annoyances that come with it.

Friday 4 March 2011

WP7 Web Browser

After spending some time working with WP7 now, I really must comment on the embeddable web browser, the WebBrowser component. As a recent convert to WP7 as a user, I can't say I've too many complaints about the phone's main browser (Internet Explorer, as you may have guessed) and it usually does the job fine. In my heart, I know it could be much better, much smoother, support many standards better, be... much more like a Webkit browser really!

However, having found a requirement which could have been satisfied with either native components, or the use of the embeddable web browser, I opted straight for the web browser route. The reason for this, mainly, is that this solution has been used across iPhone, Android and BlackBerry with little or no tweaks needed on the server side when integrating the new platforms. Take all the content needing shown, use HTML to handle the layout (optimised for the requesting device, of course), wrap it all up and send to the device which can store it locally for offline viewing. Elegant, efficient, flexible... perfect. And best of all, changes to this layout requires no code changes, so can be edited even after the apps have went live. Beautiful, I must say, even though I can't take the credit for the original idea. Cue WP7 deciding to be a bit special.

Monday 28 February 2011

Windows Phone 7 Development

That's been almost a whole day now working with WP7 so long overdue to start making notes on it.

Getting the right packages downloaded isn't quite as obvious as I would have expected, but certainly didn't take too long to find. (http://create.msdn.com/en-us/home/getting_started). The site recommended getting the January update on top of the default tool set, advertising the much discussed copy-paste functionality. I had to sigh remembering it wasn't actually available on any WP7 devices. Anyway, too soon for negativity, stuck it on to download and install. Grateful there is no messing around with path variables etc... (something I'm entirely comfortable with, but still resent having to do with the comparable java set up).

Hello world app rattled out nice and quick, always a good sign. Found the compiled app (in .xap format) nestled nicely in my bin folder too, which allowed for easy testing on my WP7-hacked handset (a story for another time perhaps).

So everything seems reasonably nice enough to code in. My only issue at the moment is that because C# is fairly similar to Java, at the syntactic layer at least, I expect to be able to code much faster than I am. It is deceptively similar, much to my folly as I keep finding out. And because it is indeed so similar, I refuse to do much reading on the language itself, focusing exclusively on reading about the mobile platform which utilises it. There's also a distinct lack of smugness at getting something to work. Something you have a-plenty after figuring out just how many dozen ] to add to the end of my Objective C lines of code, but that is probably a good thing. One can have too much smugness.

The single biggest issue I have with the development cycle at the moment is caused by Visual Studio. Again, so deceptively like my IDE of choice (Eclipse), and yet the devil really is in the details. All those features, all those little shortcuts my fingers remember (despite contemplating it now, my brain forgetting) are gone. But that's ok right, just need to learn the new shortcuts. And then I find out that Eclipse isn't just an average IDE, it's a blooming great one! Anyone who develops in Eclipse exclusively; take a break from it for a while, and try something else. Not because there are better ones out there, but because you will almost certainly be taking it for granted. Makes me swoon for returning to Android apps, sadly. Sadly as I really want WP7 to be a success amongst developers and, therefore, Joe Public. If Visual Studio had been given the same love and care as Eclipse has had, it would be half the battle won in luring Android or iPhone developers. Mind you, it's still miles better than XCode.

First post

I've been meaning to start writing in some form for a while, so I figure now, whilst waiting on my flatmate getting off his phone, would be a good time to at least add the functionality to the site. As soon as I start typing this, I'm already thinking that it would be good to have an app to use to write my blogs up so I may have to add that to the investigate/build to-do list.