Friday, October 1, 2010

Android Quick Search

Just discovered this feature on my Samsung Galaxy S – if you hold down the menu button on pretty much any screen (worked on all ive tried except the Wireless AP settings screen), Android will go straight to a ‘Quick Search’ mode allowing you to search your phone, internet, etc at a touch.  This is great since it saves me browsing through apps, contacts, etc and is similar to the awesome Windows search feature ive come to love in Vista and Windows 7.

More than likely every other Android user on the planet knows about this feature and if i had read the Android manual it would probably have been on page 1 …

Thursday, September 30, 2010

My First Android Feature Request

Frack Google search – the title has to be that statement because it has been a long time coming.  I just read this article that says the Samsung Galaxy S has the fastest GPU of any smartphone currently on the market (soon to change Im sure).  In short, by comparison:

    • Motorola Droid: TI OMAP3430 with PowerVR SGX530 = 7-14 million(?) triangles/sec
    • Nexus One: Qualcomm QSD8x50 with Adreno 200 = 22 million triangles/sec
    • iPhone 3G S: 600 MHz Cortex-A8 with PowerVR SGX535 = 7 million triangles/sec
    • Samsung Galaxy S: S5PC110 with PowerVR SGX540 = 90 million triangles/sec

    And for comparison a few consoles:

    • PS3: 250 million triangles/sec
    • Xbox 360: 500 million triangles/sec

Im currently developing a Live Wallpaper for my SGS and was surprised to find this because Android 2.1 only supports OpenGL ES 1.0, whereas the iPhone4 supports OpenGL ES 2.0.  All that power going to waste.  Hopefully in Android 3.0 they will address this with a simple software update, as i assume the almighty SGS GPU can handle it …

Tuesday, August 10, 2010

Entity Framework Cascade Delete Designer Gotcha

Came across YET another gotcha with the EF designer.  After updating my model i got the following error:

The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.

Turns out the designer had not picked up the cascading delete triggers on the foreign key relationships.  To fix it you have to go to the properties of each FK relationship and set the end1 action to cascade.  No doubt this will get overwritten everytime i update the model …

Thanks to Good-Ol Stack Overflow for setting me in the right direction.  Is there anything SO cant do?

Thursday, July 29, 2010

XAML Geometry Path Markup Syntax Summary

WPF/Silverlight has quite a nice syntax for defining paths in XAML.  The documentation explaining the syntax is quite verbose, which is a good thing, but i wrote this post to provide an at-a-glance summary of the various components:

Letter

Description

Syntax

Example

M

Move M startPoint M 0,0

L

Line L endPoint L 20,30

H

Horizontal line H x-coordinate H 90

V

Vertical line V y-coordinate V 90

C

Cubic Bezier curve C controlPoint1 controlPoint2 endPoint C 1,2 2,4 3,2

Q

Quadratic Bezier curve Q controlPoint endPoint Q 1,2 3,2

S

Smooth cubic Bezier curve S controlPoint2 endPoint S 1,2 3,2

T

Smooth quadratic Bezier curve T controlPoint endPoint T 1,2 3,2

A

Elliptical arc A size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint A 2 40 1 1 2,2

Z

Close the current figure Z Z

Notes

  • When sequentially entering more than one command of the same type, you can omit the duplicate command entry, eg - L 100,200 300,400 is equivalent to L 100,200 L 300,400
  • An uppercase command letter denotes absolute values
  • A lowercase command letter denotes relative values: the control points for that segment are relative to the end point of the preceding example
  • Instead of a standard numerical, you can also use the following special values: Infinity, –Infinity, NaN
  • You may also use scientific notation, eg - +1.e17

Tuesday, July 20, 2010

Differentiating MEF Metadata Using Custom Attributes

Discovered something interesting about MEF today when resolving exports and their associated metadata using custom attributes.  Lets say you have two different types of metadata you want to strongly type by using 2 custom attributes and associated metadata interfaces like so:

   1: public interface ILibrarySectionMetadata



   2: {



   3:     string Title



   4:     {



   5:         get;



   6:     }



   7: }



   8:  



   9: public interface ILiveViewMetadata



  10: {



  11:     string Title



  12:     {



  13:         get;



  14:     }



  15: }



  16:  



  17: [MetadataAttribute]



  18: [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]



  19: public class LibrarySectionAttribute : ExportAttribute, ILibrarySectionMetadata



  20: {



  21:     public LibrarySectionAttribute(string title) : base(typeof(UserControl))



  22:     {



  23:         this.Title = title;



  24:     }



  25:  



  26:     public string Title



  27:     {



  28:         get;



  29:         private set;



  30:     }



  31: }



  32:  



  33: [MetadataAttribute]



  34: [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]



  35: public class LiveViewAttribute : ExportAttribute, ILiveViewMetadata



  36: {



  37:     public LiveViewAttribute(string title) : base(typeof(UserControl))



  38:     {



  39:         this.Title = title;



  40:     }



  41:  



  42:     public string Title



  43:     {



  44:         get;



  45:         private set;



  46:     }



  47: }




In other words, the two sets of metadata expose the same sets of properties, but are differentiated by their strongly typed class representations.  Now i expected that this meant i would be able to differentiate the two by requesting (importing) metadata of a certain type, for example the following would only retrieve library sections (ie UserControls decorated with the [LibrarySection] attribute):





   1: [ImportMany]



   2: public List<Lazy<UserControl, ILibrarySectionMetadata>> Sections



   3: {



   4:     get;



   5:     set;



   6: }


It turns out however, that MEF is still using reflection behind the scenes to resolve the metadata, because it will resolve ANY UserControl that is decorated with either attribute, as both have the necessary properties allowing them to be mapped to either metadata type.  This means that you need to differentiate the UserControls with a string identifier in both the attribute and the [Import] declaration to allow them to be differentiated when importing, like so:




   1: [MetadataAttribute]



   2: [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]



   3: public class LibrarySectionAttribute : ExportAttribute, ILibrarySectionMetadata



   4: {



   5:     public LibrarySectionAttribute(string title) : base("LibrarySection", typeof(UserControl))



   6:     {



   7:         this.Title = title;



   8:     }



   9:  



  10:     public string Title



  11:     {



  12:         get;



  13:         private set;



  14:     }



  15: }



  16:  



  17: [ImportMany("LibrarySection")]



  18: public ObservableCollection<Lazy<UserControl, ILibrarySectionMetadata>> Sections



  19: {



  20:     get;



  21:     private set;



  22: }


This is unfortunate (if not a minor problem) because it dirties the consumption class with a magic string, but i dont see another way of achieving the same result when the exported types use contracts that match (in this example, all items exported as UserControls).  This of course also holds true if you are trying to import types with metadata that is a subset of another metadata interface.  For example if live views also had a Description property, then importing library sections would still match with live view UserControls because they provide the Title property necessary for MEF to resolve the library section metadata.

Wednesday, July 14, 2010

Entity Framework CTP 4 Walkthrough

CTP 4 of the entity framework enhancements were released yesterday for review.  I have just started looking at the entity framework as a potential ORM solution for my latest project Worship.  I need an offline database and after looking at MS SQL CE and SQL Lite have opted for SQL Lite due to its smaller assembly size and larger feature set.  One problem i found with the original entity framework is that the designer did not support inheritance very well.  EF itself does support all 3 types of inheritance, but i found the designer lacking and had to resort to editing the XML manually to implement TPT inheritance which is what i wanted to use.  The new CTP of the entity framework has much better support for code driven development of the database model and much simplified use, so im pretty excited about trying it out and will write more on my experiences.  For now, read this post to get a nice overview of the improvements and how they can be used.

Tuesday, June 8, 2010

Changing The Windows Media Library Name in WMP12

Found an issue in Windows Media Player 12 that comes with Windows 7 today.  If you change the name of the media library (in the Media streaming options), it suddenly disappears from all other computers on the network and you can no longer stream media!  Turns out that Windows does not apply the change immediately and you need to restart the Windows Media Player Network Sharing Service to apply the change.  After this the renamed media library will again be immediately available from all other computers on the network.

Thursday, March 4, 2010

Windows Virtual PC: Network Between Host and VM Using Loopback Adapter

If you want to create a network between the host and VM using Windows Virtual PC in Windows 7 then this guide is for you.  This is especially useful if you need to communicate with the VM when not connected to a network.  WVPC offers a number of networking options:

  • None – no networking
  • Internal Network – Network between hosted VMs (but not the host)
  • NAT – Sets up a virtual NAT to allow the VM to access the internet
  • Bridge – Allows the VM to use one of the hosts network adapters to access the local network

I do all my work from my laptop, including hosting my VM so at home, when connected to my home network (LAN) i use the bridged mode – my laptop connects using the wireless adapter and the VM uses the Ethernet adapter.  This way i can see both the host (laptop) and VM on the network and they can talk to each other great.  The problem arises when i am travelling and not connected to a network – in this scenario bridged mode is no use because there is no network for the VM and laptop to communicate to each other.  What I want is a ‘host-only’ network mode, similar to what VMWare offers.  The following steps allow you to set up a local bridged network that allows the two to communicate on a private network:

Setup a loopback adapter on the Windows 7 host

  1. In the start menu type command, right-click Command Prompt and select Run As Administrator to open a command window with administrator privileges
  2. Type hdwwiz and press enter to start the Add Hardware Wizard
  3. Click Next
  4. Select Install the hardware that i manually select from a list (Advanced) and click Next
  5. Select Network Adapters from the list and click Next
  6. Select Microsoft in the Manufacturers list and then select Microsoft Loopback Adapter in the Network Adapter list and then click Next
  7. Click Next to install the loopback adapter

See here for the above instructions including images of each step.

Configure the loopback adapter

  1. Go to the Network & Sharing Centre (from the start menu)
  2. Click Change Adapter Settings from the list on the left
  3. Go to the properties of the Microsoft Loopback Adapter
  4. Disable all items, except Client For Microsoft Networks, Virtual PC Network Filter Driver and Internet Protocol Version 4 (TCP/IPv4).  If the Virtual PC Network Filter Driver is not enabled, the VM will not see the adapter
  5. Go to the properties of the IPv4 protocol and set the IP to a reserved private IP, such as 192.168.x.x or 10.x.x.x, that does not conflict with any other network you will connect to.  Ensure that the gateway is left BLANK otherwise it may cause issues with other networking
  6. Click OK until the dialogs are all closed
  7. Open regedit and browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
  8. Find the subkey (0001 … 00xx) that corresponds to the loopback adapter (DriverDesc = Microsoft Loopback Adapter)
  9. Add a DWORD called *NdisDeviceType (don’t forget the asterisk at the start) with a value of 1
  10. Go to the start menu and type View Network Connections to open the list of network adapters
  11. Disable then enable the Microsoft Loopback Adapter to apply the registry changes.  The loopback adapter will no longer appear in the Network and Sharing Centre but will operate as a network endpoint on a private network, which is exactly what we want.  See here for more information.

See here for a thread discussing the registry change

Configure the VM to use the loopback adapter

  1. Ensure the VM is shutdown (not hibernated) to simplify the following steps
  2. Right click the virtual machine .vhd file and select Settings
  3. Change the network adapter to use the new loopback adapter (if you cant see it in the list, check that the filter driver mentioned above is definitely enabled on the host)
  4. Save the settings and run ipconfig from the command-line to check the IP has been successfully set
  5. Start the VM

Configure the loopback adapter in the VM

  1. Go to the properties of the Local Area Network connection in the VM
  2. Go to the properties of the IPv4 protocol and use an IP on the same subnet as the host (eg if the host is 192.168.1.1, use 192.168.1.2 for the VM)
  3. Save the settings and run ipconfig from the command-line to check the IP has been successfully set

Note that pinging does not appear to work using this configuration, even when IP addresses are specified.  However i have been able to successfully perform all other network operations without problem.  The drawbacks with this approach are that the VM cannot communicate to the hosts network when it is connected.  In this scenario, either change the VM to bridge via a different, connected adapter on the host as outlined above, or setup a proxy on the host that can forward requests from the VM to the network.

Monday, February 8, 2010

Setting up Windows 7 VPN Server

A few notes on setting up a VPN server in Windows 7 i have found while doing so on my home computer.

Setup the VPN server by following this guide

Test the VPN server from a computer outside the network (ie dont try and connect from a local computer – some consumer routers wont let this happen and can confuse the issue)

Note that TCP port 1723 must be forwarded as well as IP port 47 (GRE) traffic, details of which are explained here

If the VPN connection is not working, then there are some tools from Microsoft to debug the issue.  Download the tools from here, start pptpsrv.exe on the VPN server and then run the pptpclnt.exe tool on the client.  This will allow you to determine if the traffic is getting through as required.

NOTE: You need to stop the Routing and Remote Access () service so that the server exe can bind to port 1723, otherwise this will not work!

It can also be useful to put your PC in the DMZ in your router temporarily to eliminate blocked traffic as a potential issue.

Hopefully at this point you have a working secured VPN.

Thursday, January 21, 2010

Official BlueSoleil Driver Support For Macbook Pro Unibody Bluetooth Coming Soon!

Some exciting news for MBPU users running Windows – I raised an issue with BlueSoleil support and they have contacted me RE supporting the BT hardware in the Macbook Pro Unibody laptop line-up.  I have been corresponding with them and sending stack traces, etc so that they can officially add the hardware to an upcoming release.  This means no more hacking required to get BT to work – yay!  I’ll let you know when i know more as they have promised to contact me for testing before it is released.

Bootcamp 3.1 Update Released

So Apple finally got around to releasing the update to the Bootcamp drivers which officially support Windows 7.  I have them installed now and as expected there is basically nothing to write home about.  Nothing has been improved or added that couldn’t be achieved before.  I guess the difference now is that instead of having to manually extract and install a bunch of drivers, they are all packaged correctly so that everything is fixed in this latest release.  Oh did i say everything?  I mean everything except the fact that the sound levels are still screwed.  My gosh how hard is it Apple!  Sure the SPDIF light does not stay on when in use but the sound volume level through the speakers is very low and the centre speaker does not appear activated.  Anyway its a step forward – download them here (64-bit) and here (32-bit).