Jul 2, 2009
p&p Acceptance Test Engineering Guide
See here.
Jul 1, 2009
Windows Mobile 6 with C# (compass control)
Let's hack some dirty user control drawing code:
/// <summary>
/// Paints the control.
/// </summary>
/// <param name="e"></param>
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
int penWidth = 5;
using (Graphics g = this.CreateGraphics())
using (Pen penBlackThin = new Pen(Color.Black, penWidth - 3))
using (Pen penBlack = new Pen(Color.Black, penWidth))
using (Pen penDarkGray = new Pen(Color.DarkGray, penWidth))
using (Pen penRed = new Pen(Color.Red, penWidth + 3))
using (Pen penWhite = new Pen(Color.WhiteSmoke, penWidth + 3))
using (Brush brushDarkGray = new SolidBrush(Color.DarkGray))
using (Brush brushWhite = new SolidBrush(Color.White))
using (Brush brushLightGray = new SolidBrush(Color.LightGray))
using (Brush brushRed = new SolidBrush(Color.Red))
{
double radius = (this.ClientRectangle.Width - 50) / 2;
double radiusInner = (this.ClientRectangle.Width - 70) / 2;
int xcenter = this.ClientRectangle.Width / 2;
int ycenter = this.ClientRectangle.Height / 2;
float halfFont = this.Font.Size / 2;
// g.Clear(this.BackColor);
// draw circles
g.FillEllipse(brushLightGray, penWidth, penWidth, this.ClientRectangle.Width - 2 * penWidth, this.ClientRectangle.Height - 2 * penWidth);
g.DrawEllipse(penDarkGray, penWidth, penWidth, this.ClientRectangle.Width - 2 * penWidth, this.ClientRectangle.Height - 2 * penWidth);
g.DrawEllipse(penBlack, 2 * penWidth, 2 * penWidth, this.ClientRectangle.Width - 4 * penWidth, this.ClientRectangle.Height - 4 * penWidth);
// draw separator lines
for (int l = 0; l < 16; l++)
{
double angle = l * 22.5 + this.Heading;
double xout = Math.Sin(this.ToRadian(angle)) * radiusInner;
double yout = Math.Cos(this.ToRadian(angle)) * radiusInner;
double xin = Math.Sin(this.ToRadian(angle)) * (radiusInner - 2 * this.Font.Size);
double yin = Math.Cos(this.ToRadian(angle)) * (radiusInner - 2 * this.Font.Size);
g.DrawLine(penBlackThin, (int)xout + xcenter, (int)yout + ycenter, (int)xin + xcenter, (int)yin + ycenter);
}
// draw N, W, E, S
double x = Math.Sin(this.ToRadian(this.Heading)) * radius;
double y = Math.Cos(this.ToRadian(this.Heading)) * radius;
g.DrawString("N", this.Font, brushRed, (float)(xcenter - x) - halfFont, (float)(ycenter - y) - halfFont);
g.DrawString("S", this.Font, brushRed, (float)(xcenter + x) - halfFont, (float)(ycenter + y) - halfFont);
g.DrawString("W", this.Font, brushRed, (float)(xcenter - y) - halfFont, (float)(ycenter + x) - halfFont);
g.DrawString("E", this.Font, brushRed, (float)(xcenter + y) - halfFont, (float)(ycenter - x) - halfFont);
// draw needle
g.DrawLine(penWhite, xcenter, ycenter, xcenter, this.ClientRectangle.Height - 50);
g.DrawLine(penRed, xcenter, 50, xcenter, ycenter);
// draw digital heading
g.FillRectangle(brushWhite, (int)(xcenter - 11 * halfFont), (int)(ycenter - 5 * halfFont), (int)(22 * halfFont), (int)(11 * halfFont));
g.DrawString(string.Format("{0,3:000}°", this.Heading), this.Font, brushRed, xcenter - 4 * halfFont, ycenter - 5 * halfFont);
// draw height above sea level
g.DrawString(string.Format("{0,4:0000.0}m", this.Height), this.Font, brushRed, xcenter - 10 * halfFont, ycenter);
}
}
which looks about this on the device:
Needs some adjustments, especially to look great on other screen resolutions too. Maybe later ...
Windows Mobile 6 with C# (GPS)
As I am new to this platform I first browsed through the Mobile SDK samples to get an idea about the slighty restricted framework capabilities. An initial MyApp application was easily created using the older Visual Studio 2005. Changing the main form to my special 800x480 screen resolution did not work properly, so the designer does not represent my device screen.
The fact that my HTC has a built-in GPS device fascinated me very much. So I had a closer look at the GPS application GPS sample and copied some classes into MyApp. Instantiating goes like this:
55 this.gps = new Gps();
56 gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
57 gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
getting a GpsPosition class instance with the following major fields:
//** Position + heading related
internal double dblLatitude = 0.0; // Degrees latitude. North is positive
internal double dblLongitude = 0.0; // Degrees longitude. East is positive
internal float flSpeed = 0.0f; // Speed in knots
internal float flHeading = 0.0f; // Degrees heading (course made good). True North=0
internal double dblMagneticVariation = 0.0; // Magnetic variation. East is positive
internal float flAltitudeWRTSeaLevel = 0.0f; // Altitute with regards to sea level, in meters
internal float flAltitudeWRTEllipsoid = 0.0f; // Altitude with regards to ellipsoid, in meters
After a couple of seconds running the application I got my first position. Output formatted as string was fine ... for the first day ;-)