b-rad blog

adventures in technology

Follow me on TwitterRSS Feeds

  • Home
  • About
Android emulator

Hosts files and the Google Android emulator

Feb 13th

Posted by brad in Software

32 comments

Using the Google Android emulator is a good way to test how a website behaves on Android devices.

Connecting to your local computer

http://10.0.2.2 is the URL to connect to a website hosted on your local computer. localhost or 127.0.0.1 will not work! This is all defined in the documentation on Android emulator networking.

Using a hosts file

The Android emulator will not make use of your local hosts file. This is unfortunate when your website relies on host headers to work correctly (eg. SharePoint). What you need to do is edit the hosts file on the Android emulator image itself.

  1. start your Android Virtual Device (AVD):
    emulator -avd myAvdNameHere -partition-size 128

    Located in C:\Program Files (x86)\Android\android-sdk-windows\tools\ on Windows 64bit

    Note
    The partition-size parameter is needed to expand the image size to prevent an error in step 5. If you try and perform these steps after starting the emulator from the UI you will receive the following error:
    failed to copy ‘c:\temp\hosts’ to ‘/system/etc/hosts’: Out of memory

  2. remount the device image as writable:
    adb remount

    Located in C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\ on Windows 64bit

  3. save a copy of the existing hosts file to a temporary location on your host computer:
    adb pull /system/etc/hosts c:\temp
  4. edit the hosts file adding an entry pointing to your host computer:
    127.0.0.1     localhost
    10.0.2.2      mytesthost
  5. save the edited hosts file to your Android emulator:
    adb push c:\temp\hosts /system/etc

You can now browse to your entered hostname in the Android browser.
Android emulator

android, mobile, sharepoint, web
SharePoint 2010 JavaScript error

SharePoint 2010 jQuery compatibility errors – cmssitemanager.js

Jan 26th

Posted by brad in Software

6 comments

Recently I used a site collection scoped feature to add jQuery support to a SharePoint 2010 site collection. As documented on countless blogs, I used custom action XML similar to the following:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    ScriptSrc="JqueryCustomAction/jquery-1.4.2.min.js"
    Location="ScriptLink"
    Sequence="100">
  </CustomAction>
</Elements>

Everything seemed to work as intended. Only later did I notice strange JavaScript errors in the SharePoint interface. The most common errors were in a file called cmssitemanager.js when using the Asset Picker dialog as part of a publishing site:
SharePoint 2010 JavaScript error

It turns out that SharePoint 2010 has JavaScript that registers a global function named “$”. This conflicts with the same global function which is registered by jQuery and is used as shorthand for the various jQuery functions.

My very quick solution was to reference a second JavaScript file in my custom action. This JavaScript file disables the “$” shorthand function for jQuery. This fixes all the compatibility issues with the only downside being that you now have to replace “$” with “jQuery” when referring to jQuery globally.

Updated script references:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    ScriptSrc="JqueryCustomAction/jquery-1.4.2.min.js"
    Location="ScriptLink"
    Sequence="100">
  </CustomAction>
  <CustomAction
    ScriptSrc="JqueryCustomAction/jquery-noconflict.js"
    Location="ScriptLink"
    Sequence="105">
  </CustomAction>
</Elements>

No conflict JavaScript:

// this puts jquery into no conflict mode which will remedy conflicts caused by jQuery when used
// with certan publishing features
jQuery.noConflict();

Below is a minimal Visual Studio 2010 solution that contains a site collection scoped jQuery feature.

Visual Studio 2010 Solution – SharePoint 2010 & jQuery

c#, jquery, sharepoint
Fieldrunners HD

My iPad Experience

May 6th

Posted by brad in Gadgets

17 comments

I was lucky enough to get an iPad recently. I can truthfully say that it is my best ever gadget purchase. The iPad has not been designed as a general purpose computer and that is its biggest strength. It excels at web browsing, audio/video playback, as a book reader and at gaming. Below I’ll cover some of the apps I’ve been using to help me perform these tasks.

Safari

Safari is still the best mobile web browser I have used. The iPad version is basically the same as that of the iPhone. There are some tweaks to make better use of the screen real estate. This is most noticeable in the “tab” view for viewing multiple pages simultaneously. Although Flash is a noticeable absence from the iPad, I have not found it to be much of a problem. All of the video sites I frequent (YouTube, Vimeo, Funny or Die) support either HTML 5 or iPad compatible video. This results in a far better experience than even Flash video on the desktop. A simple pinch zoom brings an embedded video to full screen. It’s great.

It isn’t all good though. I am often left waiting for sections of a page to render even if it has already been recently rendered. This occurs when you are panning around a large website. This may be related to the small amount of memory given to the iPad (256MB). I also find the iPad redownloading a lot of content that you might expect to be cached. This often occurs when you navigate back and may also be due to the small amount of memory.

Air Video – $3.99

Air VideoMy media setup is made up of a Thecus NAS with TwonkyMedia server serving to my PS3. This works great for all of the many media formats that can be natively played by the PS3. For other files I use the fantastic PS3 Media Server which serves the same files on my NAS but adds a seamless transcoding function.

I wanted this same experience on my iPad so that it could act as another “screen” for local content. I first investigated DLNA/UPNP clients which would allow me to browse my Twonky server. There are a few of these but the main limiting factor is the iPad and its inability to play content in anything other than its preferred format. After some brief investigations into PS3 Media Server support for iPad, I eventually turned to another iPad app and matching software called Air Video. This works in a similar way to PS3 Media Server by providing a seamless transcoding experience especially for the iPhone and iPad. It isn’t free and it isn’t UPNP compatible but it has successfully transcoded every video I have thrown at it thus far.

Kindle – Free

KindleI was already a Kindle owner, so for me the Amazon Kindle application for iPad was a must. This app seamlessly turns your iPad into another Kindle compatible device. All of your books will automatically appear on your iPad just as they did on your Kindle. The iPad is a solid book reader. For large format books or for books with detailed illustrations the iPad is far better than my Kindle (international, non DX). For reading basic novels I prefer the smaller and lighter Kindle. One thing I did notice was that I seemed to get less drowsy when reading from the iPad versus the Kindle. This can be good in some situations but is obviously not preferable before bedtime. Another issue which became apparent was that the iPad provided unlimited sources of distraction from the books I was attempting to read.

Wyse PocketCloud Remote Desktop & RDP Client – $17.99

WYSEI use this reasonably priced piece of software to remotely control my Windows 7 machines via RDP. This software is simple to use and quite fast over my wireless-G network. The good thing about this application when compared with others is that it allows for direct interaction. By this I mean that to click a button you simply touch it. Other RDP/VNC tools first make you move the mouse cursor to a position before you can click it. One example of this iTeleport.

iTeleport: Jaadu VNC for iPhone / iPad – $29.99

iteleportThis is a rather pricey app that can be used for accessing your computers via VNC. The creators of this app also provide a number of additional OSX/Windows tools for helping you configure your firewall settings, port forwarding/UPNP. These may be useful for beginners but I found they just got in the way. As expected VNC was not as fast as RDP on a Windows machine. Also, the non-direct way of interacting with the host system (via the movement of a virtual mouse pointer) was quite annoying.

iNet Pro – $5.99

iNet provides a number of useful networking tools. This application is actually an iPhone application. I can put up with the iPad’s awful 2x scaling of iPhone apps because i use the wake on LAN function of this app to turn on my computers from my couch.

F1 2010 Timing App – $39.99

f1timingAlthough ridiculously priced, this app should be good. There a number of other sports apps in the AppStore that are designed to augment your TV viewing experience. As my sport of choice is F1 I coughed up the money for this app which should provide live timing and track position during practice sessions, qualifying and grand prixs. My first use should be at next week’s Spanish grand prix.

Dungeon Hunter HD – $8.99

Dungeon Hunter HDThis game will appeal to anyone who likes Diablo or Torchlight. This game has all of the right ingredients and is fun to play but it is let down by its horrible leveling/balancing. It gets easier as you progress through the game to the point that you don’t really feel the need for new gear or attributes. I hope someone can fix this as the iPad is awesome for this style of game.

Real Racing HD – $12.99

Real Racing HDThis is my favorite racer on the iPhone and it’s even better on the iPad. Although it pretends to be a simulation style racer, the car dynamics are far from realistic. This is probably for the best given the limited control inputs available. Heaps of tracks and great graphics make this game worthy of its premium pricing.

Minigore HD – $5.99

Minigore HDThis is a fun arcade shooter with a great visual style and even better comical sound effects. I recommend it.

Fieldrunners HD – $9.99

Fieldrunners HD

Tower defense games are brilliant on iPad. Field runners is one of the best. It has great graphics and is highly addictive.

Zombieville USA HD – $2.49

Zombieville HDThis game is amazingly simple. You move either left or right and tap as fast as you can to shoot the never-ending herd of zombies that are trying to eat your brains. Great artwork and well priced.

Geometry Wars – $12.99

Geometry WarsThis game is pretty much the same as it is on every other platform. It still provides some pretty intense arcade style fun. The virtual analogue controllers mean you won’t be as accurate as you would be on other platforms. Still this is worh the money especially if you are yet to try this great game.

Flight Control HD – $5.99

Flight Control HDThis is the iPad version of the best selling iPhone game. In this game you direct planes and helicopters into runways and helipads in an attempt to avert inevitable fiery disasters. In this version they have added some splitscreen multiplayer modes and 3D?!? This game spawned a host of other “path drawing” games and is probably still the best.

Angry Birds HD – $5.99

Angry Birds HDThis is another very popular game which has come from the iPhone. In it you shoot angry birds at mean pigs in all kinds of breakable environments. I don’t think the iPad has added anything to the enjoyment of this game but it was pretty fun to start with so that’s ok.

So, are there any other apps I should be using? I have omitted the Apple provided apps like iBooks and iWork as these are not yet available to Australians. In fact the iPad AppStore app itself is unavailable. For the moment i am forced to get all my apps through iTunes and then sync via USB. It’s a good thing the iPad is an incredible device because iTunes is rubbish.

ipad, tablet
Windows Phone 7 - Prototype Hardware

Windows Phone 7 Series – notes from launch

Feb 16th

Posted by brad in Gadgets

1 comment

Microsoft announced Windows Phone 7 today. It looks pretty amazing. The only negative point is that it won’t be out until the fourth quarter of 2010.

Windows Phone 7 - Prototype Hardware

Below are my notes from the launch:

Approach

  • WP7 changed approach, focused on end users, business and otherwise
  • visual design is called “metro” graphical intense, high motion ui
  • home screen is called the “start bar”
  • focuses on tasks rather than apps – tasks form a hub
  • Syncing to social networks seems to be a hands-off experience, sign in and it does the rest
  • Microsoft want to maintain stricter control of the look & feel of the device while still allowing for third-party innovation

Hardware

  • three hardware buttons (back, start, search)
  • require capacitive touch (minimum 4 point touch)
  • WVGA screen
  • FM (or digital?) radio

Search

  • context sensitive – different results based on where you are in the phone (contacts, email etc.)
  • automatically uses GPS
  • search can be of three types, attempts to choose the most appropriate one automatically (local, news, web)

Web Browser

  • based on PC code for maximum compatibility
  • pinch zoom
  • tap to zoom (zoom to column on page)
  • sub pixel positioning for text)
  • recognizes phone numbers and addresses and makes them linkable
  • supports tabs

People Hub

  • Aggregates all your contacts from social networks (no twitter yet by the looks, I imagine this will change)
  • Shows people you have communicated with recently
  • “What’s new” feed: feed from all your social networks

Office Hub

  • Access to Microsoft Office apps like OneNote, Excel, Word etc.

Games hub

  • Syncs with Xbox live
  • Focus on social gamer experience
  • earn gamer score, achievements

Me tile

  • Simultaneously update your social networking status to multiple sites

Email

  • Supports all common providers including gmail, yahoo as well as Exchange (of course)
  • Never see a loading bar, works against a local cache (very fast experience)

Text

  • Supports SMS, MMS
  • Supports portrait/landscape typing modes

Calendar

  • Automatically merges your personal and work calendars

Pictures

  • gallery lets you browse all pictures
  • “mosaic” shows recent or favourite pictures
  • “What’s new” feed shows latest pictures from your social networking sites (Facebook, Windows Live etc)
  • Album view combines folders from photos synced from Zune software on your PC with albums from Facebook, Windows Live
  • Social networking comments are displayed when you view a picture

Music and Video

  • Full Zune HD experience
  • Supports Zune pass/subscription

Other

  • toolbar is always available at the bottom to access “enhanced” commands
  • UI is not completely done (especially some of the buttons you see)
  • one press to correct words you’ve messed up in keyboard mode

More information:

http://channel9.msdn.com/posts/LauraFoy/First-Look-Windows-Phone-7-Series-Hands-on-Demo/

http://www.windowsphone7series.com/

mobile, wp7

Windows 7 tablets versus the Apple iPad

Feb 7th

Posted by brad in Gadgets

2 comments

There’s plenty of things not to like about the iPad. However the user experience isn’t one of them. I think the Windows 7 crew have a fair way to go in this respect.

See the videos and make up your own mind.

HP Slate – Windows 7

Archos 9 – Windows 7

Apple iPad – iPhone OS

ipad, tablet, windows 7
The Document Template

Document and report generation using XAML, WPF data binding and XPS

Feb 6th

Posted by brad in Software

10 comments

Generating printable documents or reports containing dynamic data is a common requirement of most business systems. In this post I will show you how to create XPS documents dynamically using WPF templates loaded from the file system and populated with data binding. This technique is especially powerful when the output document needs to be either highly dynamic or has lots of design elements. The example document we will create looks something like this:

The document template

For a fixed format document the <FixedDocument/> is a logical starting point. The template needed to make our document is as follows:

<FixedDocument
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xml:lang="en-au">
   <FixedDocument.Resources>
      <BooleanToVisibilityConverter x:Key="visConverter"/>
   </FixedDocument.Resources>
   <PageContent>
      <FixedPage Width="793.76" Height="1122.56">
         <!-- Page 1 Begins Here -->
         <StackPanel Margin="50">
            <Border BorderThickness="5" BorderBrush="Gray" CornerRadius="10"
               Padding="20" Width="690">
               <StackPanel Orientation="Horizontal" Margin="0 0 0 0">
                  <Image Source="truck.jpg" HorizontalAlignment="Left"/>
                  <TextBlock Margin="30 0 0 0" FontSize="50"
                     Text="{Binding Path=Heading}" VerticalAlignment="Center"/>
               </StackPanel>
            </Border>
            <TextBlock Margin="0 30 0 0"
               Text="{Binding Path=CurrentDate, StringFormat='{}{0:d MMMM yyyy}'}"/>
            <TextBlock Margin="0 30 0 0"
               Text="{Binding Path=Name, StringFormat='Dear {0},'}" />
            <ItemsControl Margin="30 20 0 0" ItemsSource="{Binding Path=DotPoints}"
               HorizontalAlignment="Left">
               <ItemsControl.ItemTemplate>
                  <DataTemplate>
                     <StackPanel Margin="0,8,0,0" Orientation="Horizontal" >
                        <TextBlock Text="• " />
                        <TextBlock Text="{Binding}" TextWrapping="Wrap" Width="400"/>
                     </StackPanel>
                  </DataTemplate>
               </ItemsControl.ItemTemplate>
            </ItemsControl>
            <TextBlock Margin="0 30 0 0"
               Text="Congratulations, you are entitled to a 50% discount!"
               Visibility="{Binding Path=GiveDiscount,
                                        Converter={StaticResource visConverter}}"/>
         </StackPanel>
      </FixedPage>
   </PageContent>
   <PageContent>
      <FixedPage Width="793.76" Height="1122.56">
         <!-- Page 2 Begins Here -->
         <TextBlock Margin="50" Text="Nothing to see here."/>
      </FixedPage>
   </PageContent>
</FixedDocument>

This includes the namespace imports that should be familiar to any WPF developer. One thing of interest in this template is the hard coded width and height of the <FixedPage/>. These values have specified an A4 page in portrait orientation. These have been based on the DPI of WPF (96) and the dimensions of an A4 page.

The XAML template includes standard WPF binding expressions which will be used to populate the document with dynamic data. It also makes use of the BooleanToVisibilityConverter to make easy show/hide functionality through data binding.

Loading the template from the file system

System.Windows.Markup.XamlReader provides an easy way of parsing XAML markup into objects:

public static object LoadTemplate(string templatePath)
{
   object template;

   // get the needed template paths
   string absolutePath = Path.GetFullPath(templatePath);
   string directoryPath = Path.GetDirectoryName(absolutePath);

   using (FileStream inputStream = File.OpenRead(absolutePath))
   {
      var pc = new ParserContext
      {
         // It is critical to have the trailing backslash here
         // will not work without it!
         BaseUri = new Uri(directoryPath + "\\")
      };

      template = XamlReader.Load(inputStream, pc);
   }

   return template;
}

It’s critical here to setup the ParserContext so that resources can be referenced from the XAML. In our example we reference an image, but you can also reference things like fonts and other XAML files.

Injecting data into the document with data binding

For our example we will use basic object data binding. However this technique would work equally well with other WPF binding sources such as XML. The object we will bind to has properties which correspond to the binding expressions in the template:

public class Data
{
   public string Heading { get; set; }
   public DateTime CurrentDate { get; set; }
   public string Name { get; set; }
   public string[] DotPoints { get; set; }
   public bool GiveDiscount { get; set; }
}
public static void InjectData(FixedDocument document, object dataSource)
{
   document.DataContext = dataSource;

   // we need to give the binding infrastructure a push as we
   // are operating outside of the intended use of WPF
   var dispatcher = Dispatcher.CurrentDispatcher;
   dispatcher.Invoke(
      DispatcherPriority.SystemIdle,
      new DispatcherOperationCallback(delegate { return null; }),
      null);
}

In this code we set the DataContext for the FixedDocument to be the object containing the data. The strange thing is the dispatcher code. In a normal WPF application the dispatcher is used to marshal calls from worker threads to the UI thread. It seems that data binding outside of the UI context is not triggered unless the dispatcher is woken from its sleepy state. To do this we give it an arbitrary task.

Save our document to XPS

The ugliest code is left for last.  Below is what is required to convert a FixedDocument to an XPS format file ready to be viewed and printed by the user:

public static void ConvertToXps(FixedDocument fixedDoc, Stream outputStream)
{
   var package = Package.Open(outputStream, FileMode.Create);
   var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
   XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

   // xps documents are built using fixed document sequences
   var fixedDocSeq = new FixedDocumentSequence();
   var docRef = new DocumentReference();
   docRef.BeginInit();
   docRef.SetDocument(fixedDoc);
   docRef.EndInit();
   ((IAddChild)fixedDocSeq).AddChild(docRef);

   // write out our fixed document to xps
   xpsWriter.Write(fixedDocSeq.DocumentPaginator);

   xpsDoc.Close();
   package.Close();
}

When working with XPS files you will find that you always have to work within a Package. The other interesting part of this code is the cast to IAddChild which is needed to add the DocumentReference as content within the FixedDocumentSequence.

Exception: the calling thread must be STA

WPF controls can only be used in STA threads. This isn’t usually something you have to consider when you are using WPF in a GUI application. However, if you are attempting to use this XPS code deep within some class library then the apartment state of the calling thread cannot be guaranteed. Instead of putting this requirement onto the consumer of your class you can use code like the following:

if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
{
   var t = new Thread(() =>
      {
         // do work here when calling thread is not STA
      });
   t.SetApartmentState(ApartmentState.STA);
   t.IsBackground = false;
   t.Start();
   t.Join();
}
else
{
   // do work here when calling thread is STA
   // this removes the overhead of creating
   // a new thread when it is not necessary
}

Final comments

This XPS generation technique is extremely flexible. Some key strengths:

  • Allows for the full power of WPF, enabling attractive documents
  • You can use user controls as well as third party components such as charting libraries
  • Your own custom ValueConverters in combination with data triggers can be used for almost any dynamic requirement (this is probably worth another post)
  • Conversion to PDF is possible with third party libraries

Visual Studio 2008 Solution – XpsDocumentGenerator.zip

c#, wpf, xaml, xps
  • Latest tweets

    Loading tweets...
    Follow me on Twitter!
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Software (3)
    • Gadgets (3)
    android c# ipad jquery mobile sharepoint tablet web windows 7 wp7 wpf xaml xps
    • February 2011 (1)
    • January 2011 (1)
    • May 2010 (1)
    • February 2010 (3)
    • Hosts files and the Google Android emulator (32)
    • My iPad Experience (17)
    • Document and report generation using XAML, WPF data binding and XPS (10)
    • SharePoint 2010 jQuery compatibility errors – cmssitemanager.js (6)
    • Windows 7 tablets versus the Apple iPad (2)
    • Windows Phone 7 Series – notes from launch (1)
    • Ethan: The downside of "have to replace “$” with “jQuery” when referring to jQuery globally" can be avoid i...
    • Girish: Hi, Is there a way to add exceptions to the proxy?
    • Jalpa Bhaliya: I followed above steps, But I am still not able to connect with the website that is hosted on local...
    • Mmarshad: Nice article. I'm trying to create multipage xps document using datatemplate. But soon I add a...
    • Higo Cidario: Also make sure you place an [enter] after your entry!
    • István Ujj-Mészáros: This process works, but the hosts file resets after restarting the emulator, so you need to make...
    • New Offer from Sony BDP-S590 3D Blu-ray Disc Player, watch video demo inside: [...] Sony BDP-S590 3D Blu-ray Disc Player with Wi-Fi (Black) 3D Blu-ray Disc Full HD 1080p...
    • Egy Freight: [...] Water sports, boating, sailing, fishing, yachts, cruising and much more news and events. You...
  • Friends

    • 10dogs.net
    • Chaitanya Gurrapu
    • OJ's Rants
    • Share and Enjoy
    • Smarter Geek
    • The Cowch
Mystique theme by digitalnature | Powered by WordPress
RSS Feeds Top