Google Android Development Agency SASS

Friday, 22 January 2010

Using C# 3.0 and LINQ with Kentico

I just encountered a weird problem with a custom webpart in Kentico CMS v4.

Our project is configured in VS.NET as a .NET 3.5 website; web.config references 3.5.0 assemblies and there's plenty of references to System.Linq in classes.

This morning I cane across an instance where I thought it might be useful to use a LINQ query to extract a filtered List from another List. I wrote my code

var filtered = (from m in data where m.DepartmentID = 1 select m)

VS.NET syntax highlighting was happy and showed no errors. However, when I browsed to the website I got the error "the type or namespace name 'var' could not be found" and varyingly various different "missing )" errors.

Clearly IIS wasn't treating this website as a 3.5 site. Easy to fix thankfully, I just added the following to web.config:


<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
>
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>

Wednesday, 20 January 2010

37 Signals - An unashamed testimonial

There's always a difficult balance in software engineering and the management thereof between choosing a toolset which is feature rich enough to be useful and lightweight and usable enough to make it, well, usable.

When it comes to project/development management I've tried everything from Microsoft Project Server to a whiteboard stuck to the development office wall.

Whilst Microsoft Project gives undeniable control over every minute detail of a project, it's not exactly lightweight and project plans can become cumbersome once you start adding progress tracking and expenditure.

On the flip side, a whiteboard on the wall is infinitely flexible, immediately visible and easily updated. Plus, you can draw all manner of rude things on it when you're bored and pin posters of your favourite Hotrod in my case to it. The downside is it's not inside one of them darned new-fangled computer machines so it can't send you a message to say you forgot to test yesterdays build on IE6 before releasing it you ningcompoop.

For the past year or so I've been trying to drag the easy-wipe marker from my hand and get everything electronic so that I can get reminders and such, and the toolset I've come to rely on is by those masters of lightweightness 37Signals.com.

We're now using their Basecamp product almost exclusively to manage our day to day tasks. Here's our setup:

We create Date-related Milestones for any deliverables. That way the deliveries appear on everyone's dashboard so noone can claim that they didn't know about it.

We create task lists for every milestone, tied to that milestone.
Now everyone knows what tasks need to be done to meet the milestone.

We add a due date to each task.
It's not exactly going to make a gannt chart, but now at least we've got some semblance of a plan. (That's a plerrrrrn if you speak geordie like me).

We turn on daily email digests
Now every morning at 9am we all get digest in our email of what's happened and what's coming up. Because everyone is too lazy to open Basecamp and check everyday and everybody opens their email in the morning to check for the latest hervia.com newsletter. Or is that just me?

We sync our Google Calendar with Basecamp
Praise be! Google Calendar syncs via iCalendar so all of our milestones appear in Google Calendar and we can add additional reminders if we think we're really going to forget about testing on IE6. (And god knows we're trying...)

So the moral of this outburst is, if you're not operating in a hardcore PM environment and are looking for some lightweight tools to manage your development activities, checkout http://basecamphq.com/ from 37Signals.

And no I don't work for them. But if you're listening Jason Fried I would not say no.

Wednesday, 9 December 2009

NUnit and App.config

Here's the problem: You have a project which you want to unit test with NUnit but the project relies on some appSettings or other config data normally loaded from app.config or web.config. You know the sort of stuff, connection strings, usernames etc.

When you run your code in NUnit you get a NullReferenceException when you try to access your config, it's like it's being ignored.

I come across this problem quite often but I always have to refresh my memory of how I fix it. Well there's two ways, but only one I can get to work reliably:

1) When you create your nunit project, rather than clicking Project-> Add Assembly, just drag your DLL from Windows Explorer onto NUnit. After doing this it'll pick up the assembly.dll.config file for your assembly. I couldn't get to work reliably though, it would work once and then fail.

2) You need to have a config file named the same as your nunit project and located alongside. So in my case I have com.sass.ecommerce.tests.nunit and alongside it my assembly (com.sass.ecommerce.tests.dll) and my renamed config file, com.sass.ecommerce.tests.config.

Doing it the second way gave me more reliable results and I could access my config file no problem from my unit tests.

Tuesday, 1 December 2009

Tub Thumper Pro for Android out this week

At long last, we're looking at releasing Tub Thumper Pro for Android this week.

We've been into Android Development since day one and I've been constantly suprised at the amount of positive feedback we've had from the first version of Tub Thumper. We receive emails daily asking us about the pro version so I'm hoping it's going to be well received.

I'll put some more details online once it's live in the Android Market, but here's a screenshot of the sequencer interface in the meantime, which is one of the coolest new bits.


Tub Thumper Pro Sequencer Screenshot
You'll need at least Android 1.5 to run it and a touchscreen device. It's pushing the low-level audio features of Android with this tool, although I already have plans for Tub Thumper Pro 2! Watch this space...

At last! A good UML Editor for Visual Studio

For years I've been trying various different UML/CASE tools for designing .NET based solutions and until now I've always been left diasappointed. (I've not tried the new in-built tools of Visual Studio 2010 yet...)

This week I've been working on an e-commerce system for a client of ours who have chosen to use Sagepay as their payment gateway. Their site is built on the Kentico CMS platform and the Kentico E-commerce system doesn't support Sagepay out of the box, so basically I'm designing a payment provider for it.

I decided to try once again to find something decent to do Use Case diagrams, Activity diagrams, ST diagrams etc in so that I don't have to resort to Visio and Word as always.

Praise Jebus! Something good at last in the form of Tangible T4 Editor for Visual Studio. This is a plugin for VS.NET which allows you to create half-decent looking UML painlessly.

Here's an Activity diagram for the aforementioned e-commerce system I'm working on:




The only gripe I have so far is with the Use-case diagram tool; it would be really nice to be able to double-click on a use-case to open up a text-view of the actual use case allowing me to document the steps and pre and post conditions.

Here's the best bit: THERE'S A FREE VERSION!

Friday, 27 November 2009

Android AudioTrack source

I've been doing a lot of work optimising our audio playback on Tub Thumper Pro for Android this week and I constantly find myself referring back to the C++ source for the OS to help solve latency issues.

For anyone doing work with the AudioTrack object, it's worthwhile bookmarking the source online so that you can browse it whenever you hit a problem.

Here's two links I find really useful:

Incidentally, I've found that the best way of getting low-latency polyphonic audio is to subclass AudioTrack and call finalize() yourself after you're done playing; I was seeing more "write blocked for xx seconds" messages before I did this, although it may be co-incidental.

Thursday, 26 November 2009

Useful tool for building Android user interfaces

Android user interfaces are built using XML and the support for graphically laying these out in Eclipse is limited to say the least. (There are many things wrong with Visual Studio .NET but at least the UI builder is reasonably well sorted...)

A while back I came across DroidDraw - a third party tool for prototyping UIs. I think I must have had an early build back then because it had some issues, but I downloaded the latest build today and it's now hugely useful.

If you want to throw some Android user interfaces together head over to http://droiddraw.org/ and try it out. It's the tool Google should have included with the SDK!

Tuesday, 24 November 2009

Android Activity States and State Transitions

I wanted to tidy a bit of our Android code up recently to make sure that each Activity was handing it's state properly and to make sure that things were getting cleaned up when the Activity was done.

Before doing this it was important to fully understand the lifecycle of an Android Activity and to understand the state transitions that will and can occur within one.

An Android activity basically exists in one of four states:


Here's a bit more detail about each of these states:

Active
The Activity is in the foreground of the screen and is interacting with the user

Paused
The Activity has temporarily lost focus behind a new non-fullscreen or transparent Activity. In this state is retains all of it's state, however, if Android detects a low-memory situation it may be killed.

Stopped
The Activity is totally obscured behind another Activity. Again it retains it's state, but is much more likely to be killed at any point.

Finished
The Activity has been closed, either by Android or by calling finish(). The state it had dies at this point (unless you explicitly save it).


There are seven events in the Android Activity Lifecycle which give you a bit of control over what happens during each state transition.

onCreate(Bundle icicle)
Fires when the Activity is first launched. You would normally do all of your setup in this method. You can also retrieve any previously saved state from the supplied Bundle.

onStart()
Called when the Activity is becoming visible to the user, for example when another Activity higher in the stack has closed.

onRestart()
Called after the Activity has been stopped and is being restarted.

onResume()
Called when the Activity is becoming interactive to the user.

onPause()
Called when Android is about to start resuming another Activity. You would normally use this to stop anyting dynamic that is happening in your Activity, e.g sounds playing, animations happening.

onStop()
Called when the Activity is no longer visible, usually because another Activity has started over the top of it.

onDestroy()
This is the last breath of your Activity, called just before Android pulls the plug on it.

Here's a state transition diagram to show the sequence of states and the events in between:



isDaemon and Java Threads

Whilst pondering the best way to organise the threading structure of our upcoming Android app Tub Thumper Pro, it struck me that there is a smattering of confusion (at least in my head!) over whether a thread is a daemon or not.

In Java, there are two types of threads Daemon Threads and User Threads.

User Threads are the ones you'll most commonly use; these provide the mechanism of running parallel code in your applications. Most importantly - when the application is terminated, the JVM waits for all user threads to finish before quitting.

Daemon Threads are generally used for service-level processing rather than application-level code. The JVM will not wait for any daemons to finish before quitting your application, they will run behind the scenes until the JVM decides there's nothing else to do and terminates.



Monday, 23 November 2009

Low latency audio playback in Android

One of the things which bugged me immensely about Android was it's lack of low-latency audio playback and a low-level audio API.

Unlike the iPhone, Android developers were stuck with high-level media player objects which basically only allowed you to chuck an MP3/OGG/Wav their way and hope for the best.

Well not any more my robot loving amigos!

After pulling my hair out trying different designs and playback algorithms working on the sequencing function of Tub Thumper Pro for Android, I finally found what I'd been looking for; an object for working with sample-level data, just like we've been doing on the iPhone.

android.Media.AudioTrack

I mean, it's not perfect, but here's what we're doing to run samples directly to the hardware without all of that mediaplayer-esque overhead (I've edited it to make it make sense outside of our app, but the theory is there):


//--load the sound file from the resource identifier into a byte array (c is Context)
InputStream s = c.getResources().openRawResource(resourceFile);
soundData = new byte[s.available()];
s.read(soundData);

//--setup an AudioTrack object, this one is running at 44.1Khz which worked best for us.
AudioTrack oTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT, intSize,AudioTrack.MODE_STREAM);

//--turn the audiotrack on
oTrack.play();
//--write something to the audio track, in this case the entire buffer
int playVal = oTrack.write(soundData,0,soundData.length);
//--we're turning it off here
oTrack.stop();

Our Android app in Top 100 Best Smartphone apps of all time!

Well oil my bike. Our first Android app, Tub Thumper, has just been listed in the "Hot 100 best apps" by T3 Magazine.

We still get plenty of feedback about the free version (mostly positive thankfully) and we're trying to get the Pro version out ASAP.

I'll be very interested in seeing how it runs on my Motorola Droid phone, when it arrives, given it has a multitouchscreen...

You can view the gallery here: http://www.t3.com/feature/t3s-hot-100-apps


Update - here's a shot of the app at number 1 in this months T3 magazine!

Google Chrome OS Beta first install

No posts for a few months, mainly due to the lack of mobile development action over here!

Just downloaded the first build of Google Chrome-OS and installed it on a VMWare virtual machine.

First impressions: Booted up very very quickly. I can definitely see the use for it in low-cost netbooks and for couch surfing. However, there are a couple of things which I can foresee might scupper it: No iTunes/Media playing and no image editing. All very well sticking your photos on Picasa or Flickr, but how are you supposed to get them off your device and edit them without any means of installing desktop editing software, or without provision for storing files locally?

I currently use a Macbook for surfing on the couch and for dragging photos off my cameras and onto Flickr. I would have considered Chrome-OS an alternative for this (farewell Apple at last...) but without just a few more niceties I can't make that switch.

Anyway, here's some screenshots of the login screen and the first screens you'll see.






All those apps you see above are of course just links to websites, although Google have mentioned in their design documents that they are hoping to use popups for sub-tasks, like the one shown below.



If you want to try it yourself, head over to http://discuss.gdgt.com/google/chrome-os/general/download-chrome-os-vmware-image/ and grab the VMWare image. (If you have trouble logging into the virtual machine, try the username "chronos" without a password).

Tuesday, 28 July 2009

Get Google Latitude on UK T-Mobile G1

I don't know why, but despite the regular firmware/OS updates for Android and the G1, Google has not yet released its Latitude feature for Google maps on the UK version of the device.

Thankfully, it's dead easy to get, without requiring root access to the hardware or replacing the T-Mobile shipped OS.

To get it, all you need to do is download the "Google Maps" app from Google Market; this will replace your current Maps app with a new version, which includes Latitude.

Thursday, 21 May 2009

Editing Umbraco in canvas mode gives error

I hit a slight quirk with Umbraco today. One of the features of Umbraco is its ability to edit a page in "Canvas mode". This means your page opens in a new window and is rendered as if it was a website, but with a content editor for you to edit your content in; much nicer than using that small white editor.

Today I fired up the canvas editor for one of the pages in a new site I'm working on, only to be met with:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Hmmf. It's because in the footer of the website I'm doing:

<%=DateTime.Now.Year%>

To output the current year. Umbraco is attempting to modify the controls collection of the page to create the editor, which is not allowed when using inline code blocks.

The workaround is a bit sneaky, but simple. All you need to do is change to the databinding syntax for echoing, like this:

<%# DateTime.Now.Year %>

Now all is well, the control collection can be modified and you can bask in the glory of the Umbraco canvas editor.

Tuesday, 19 May 2009

MIDI Playback in Android Cupcake

If, like me, you've been wondering why the audio support in Android was so poor, you'll be pleased to hear that Android 1.5 (Cupcake) addresses some of the issues.

I'll write a more in-depth post once I've gone through some real world examples, but one thing which I'm currently reading up on is the in-built MIDI support.

Rather than just stick a bog-standard MIDI engine in Android, the Google engineers have chosen to include a JET playback engine, which allows musical synchronisation of clips and seamless playback. It's mainly tailored towards game playing as it allows you to script the clips about to played back to tie in with the gameplay, but I'm already thinking up some cool musical ideas for it.

Have a read of the documentation on Android.com, at http://developer.android.com/guide/topics/media/jet/jetcreator_manual.html

New Tub Thumper Version

Today we released a minor update of our Google Android application Tub Thumper.

Tub Thumper is a touch screen drum machine for the Google Android platform and has proved immensely popular since its release last November.

This version is a minor release with a new hip-hop style drum kit, to wet people's apetites for our upcoming major release.

We've been hard at work developing Tub Thumper Pro, which will feature many new cool things. Notable assignable drum pads and the ability to sequence beats, similar to using a Roland TR-909 drum machine.

As it's not yet ready I'm not saying much more, but here's a sneak preview of assigning some drum sounds:



We're aiming this release for the Cupcake build of Android, which will have hit everyone's phones by the time we release it.

At SASS, we spend most of our time working on client projects; developing web and mobile applications for clients. It's nice to get a break from this to work on some of our own projects such as Tub Thumper and it gives us a great opportunity to try out new development ideas and increase our knowledge as developers. There does not seem to be a huge amount of Android developers around Manchester and Cheshire so it often feels like we're out on our own, but we'll continue to experiment and release new Android apps to showcase our ideas.

You can grab Tub Thumper from the Android Market. Just search, or check out the most popular Multimedia apps.

Friday, 8 May 2009

Changing the color of the iPhone navcontroller bar

You may have noticed some apps on the iPhone have different colored navigation bars. I didn't have any reason to play with this, but being an inquisitive iPhone developer I wanted to know how it's done. I hadn't even noticed that you could customise this in Interface Builder, but it turns out it's really simple.

Just open up your root view controller (MainWindow.xib) in interface builder. Now click on the NavController icon:



Now open up your inspector panel and look at the Top Bar drop down. You can select the color of the Nav Controller bar there, set it as either Normal (blue grey), Black or Translucent.



Now you can have a cool black nav controller too!

Thursday, 7 May 2009

UK G1 Owners - Get Android Cupcake early!

The rumour mill has been in full swing with regards to the early push out of Android 1.5 "Cupcake" to UK T-Mobile G1 users. Whether or not they really have started the push remains to be seen (I've not had it) but the folks over at Andblogs.net have posted how you can get it early.

First things first, grab the update: UK 1.5 Cupcake Update (CRB17) (5)


Save it to the sd card, named “update.zip”. (If you use windows, be sure you aren’t naming it something like “update.zip.zip”.) Reboot your phone in recovery mode (hold down ‘home’ while booting until you see the diamond warning.)


Now time to update! Press Alt-L. (This will turn on logging, so you can see what is going on.) Then Alt-S will apply the update.zip from the sd card. When it finishes, it’ll reboot.



I'm just trying, fingers crossed!

Oh, and don't blame me if you brick your phone, like I said - I've not tried it yet! Don't know if this works for countries other than the UK either, I'd suspect not but feel free to comment if you know otherwise.

Update!



My phone exploded in a huge fireball! Just kidding, after a nerve wracking few reboots with some cryptic logos I finally got a shiny new animating silver Android logo and I'm now smothered in delicious Cupcake.

Here are a couple of money shots:

The much-talked about touchscreen keyboard.


New homescreen icons (and check out my sweet (get it?) NIN Downward Spiral wallpaper, in your face iPhone!):


In the inimitable words of fake James Hetfield, sprinkles GOOD!

Wednesday, 6 May 2009

iPhone GPS programming is easy

Before I looked at GPS development for iPhone I was bracing myself for an onslaught of complicated hardware commands, old school C data structures and binary arithmetic. Queue a flashback to the CoreAudio learning curve...

Almost unbelievable it's not the case though; Apple have made things pretty straightforward for a change!

The first thing to do, and the key to it all, is to create a class which conforms to the CLLocationManagerDelegate specification:


@interface MyLocationManager : NSObject <CLLocationManagerDelegate> ...


The CLLocationManager delegate needs to contain a method which is called to notify it that the location has been updated. Basically, this:


- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
...


Now within your method implementation you can access the coordinates of the old and new locations with:


newLocation.coordinate.latitude;
newLocation.coordinate.longitude;
newLocation.altitude;


Obviously you'll need to do a bit of jiggery pokery to get those raw figures into a useful state, but that's down to your own app logic. In terms of getting the GPS coordinates nothing could be easier!

Apple have a very good sample project in the developer library called LocateMe. I'd suggest you download it and study the code to learn the ins and outs of GPS programming. It took me literally 10 minutes to get the basics going.

Next stop - Android GPS development!

Tuesday, 5 May 2009

Lots of weird errors with iPhone 3.0 SDK Beta

Today is the first day I've been doing iPhone 2.2.1 development alongside the iPhone 3.0 beta and I can tell you that things have not gone to plan.

The first nightmare I encountered was to do with the naming of my 2.2.1 app. The name has a space in it (which is not technically allowed I now understand although nothing has ever moaned before). When I tried to compile the app using the 2.2.1 framework I get the error:

com.apple.tools.product-pkg-utility: error: CFBundleIdentifier 'com.yourcompany.Project_name' contains illegal character '_'


The first thing to note here is that the only thing that's changed on this Mac since the last time I compiled the app is that I've installed the iPhone 3.0 beta SDK.

The only way I've found to get around this so far is to manually edit the "Identifier" field in the project settings to remove the space, and hard code to package identifier (not good).

The next weird thing happened when I tried running the app on a connected iPhone. (In fact the iPhone that I've been using for all of the development up until now).
When I first ran the app from XCode I received the error "The application is already installed on the device".

Obviously the app is already installed, I've been developing it for months! Normally XCode would just overwrite the app and keep all of your application settings and data, but now it seems I have to manually delete the app from the phone before hitting build and go. Extremely frustrating!

This last problem seems a little unpredictable too - I've just ran the app twice from XCode without uninstalling it and it hasn't popped up the error yet. We shall see...

I should state that all of this is with me targetting 2.2.1, I haven't ran it under 3.0 yet.

If I come up with anymore solutions or problems, I'll update this post but for now I'd better get back to making it work!