May, 2010


26
May 10

Book Review: Professional Android 2 Application Development

pa2ad

Reto Meier’s Professional Android 2 Application Development does a great job of educating the reader on what is necessary for developing Android applications. Core application fundamentals and advanced Android features are presented to the reader via a series of real-life application examples.  Readers who work the examples and leverage the breadth of coverage provided on the Android 2 framework will be well on their way towards establishing an excellent foundation for building compelling Android applications.

After giving the customary history lesson and tour of the toolsets and development environment, the first half of the book deals with the components that make up an application. Chapters are devoted to activities and life cycle, UI views, data and file access, and key Android concepts like intents (message-passing mechanisms) and content providers (ability to expose data to other apps).

Once the fundamentals have been covered, the remainder of the book is spent exploring the advanced and optional features available in the SDK. Android-centric concepts like background services, notifications and widgets are given the same in depth treatment given to the fundamentals so you get a lot of the “why” along with the how. Features and functionality that naturally lend them to being abstracted away via an API like media playback, GPS and Bluetooth are given adequate coverage of what is available via the framework and, where pertinent, the Android-specific behaviors are highlighted.

While the book is divided into fundamentals and advanced topics, continuity is maintained throughout via the example applications used to emphasize the concepts presented. By building the to-do list, compass, and earthquake monitoring service applications while reading through the book, passive learning is transformed into active, directed learning. Unlike some programming books I’ve read in the past, these examples do real work, accomplish specific real-life tasks, and provide some utility once completed. Readers are not just extending these applications one feature at a time, they are also adding one key concept to their proverbial tool belt while doing it.

The speed at which the Android platform is being evolved and improved upon is staggering. Since April 2009 there has been 4 major releases of the Android OS with a 5th release rumored for this fall. While the breadth of coverage provided for the APIs and framework is nice while it is still relevant, the real strength of this book comes building an understanding of the core Android fundamentals. Readers looking for a solid introduction to Android development need to look no further than Professional Android 2 Application Development.


6
May 10

Retargeting Visual Studio project files with PowerShell

I originally set out to write this post a little over a year ago. Back then I threw together a script to retarget all the project files from .Net 2.0 to .Net 3.5 for my previous company and recently I found myself having to a similar upgrade from .Net 3.5 to 4.0. I ended up using the same script again so I figured I’d go ahead and publish it.

The upgrade process done by Visual Studio on your current projects and solutions will only migrate the file format to the newest schema and will not retarget the framework to the latest version.  That is where the script I’ve included below comes in.  It will retarget all the C# project files found under the path provided to version 4.0 of the .Net framework

C# project files are XML based and navigating the DOM with Linq to XML is a cinch but there are a couple small but important steps that the script needed to include.  First, you need to append the namespace to the individual element names or else the elements will not be able to be found.  Second, when saving the modified XDocument, a XmlWriterSetting instance needs to be instantiated and the OmitXmlDeclaration property set to true.  Setting this property to true will make sure the XML that we save will be considered a valid project file by Visual Studio.

I’ve included the full script below as well as created a gist that can be found here.  It is important to note that this script will edit all the csproj files found under the directory specified in the path variable.  Make sure you backup these files or have them under source control prior to running the script.  Enjoy.

[UPDATE: Added change suggested in comments by Jeffery Snover]

[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null

#specify the root of your source tree below
$path = "C:\Code\chatsworth"

$ns = "http://schemas.microsoft.com/developer/msbuild/2003"
$xname = [System.Xml.Linq.XName]::Get("PropertyGroup",$ns)
$tfname = [System.Xml.Linq.XName]::Get("TargetFrameworkVersion",$ns)

$xws = New-Object System.Xml.XmlWriterSettings
$xws.OmitXmlDeclaration = $true
$xws.Indent = $true

function updatefx($filename)
{
    #Write-Host $filename
    $xml = [System.Xml.Linq.XDocument]::Load($filename)

     $result = $xml.Descendants($xname)

    foreach ($i in $result)
    {
        $fxelem = $i.Element($tfname)
        if($fxelem)
        {
            $i.SetElementValue($tfname,"v4.0")
        }
    }

    $xw = [System.Xml.XmlWriter]::Create($filename, $xws)
    $xml.Save($xw)
    $xw.Close()
}

$csprojs = Get-ChildItem $path *.csproj -Recurse

foreach ($file in $csprojs)
{
    updatefx $file.FullName
}