12/15/12

Resharper and Xaml Spy

Two tools for .NET dev that you may want to consider:

The past several months I’ve started using Resharper – a productivity/code analysis/review plugin for Visual Studio. I know many .NET programmers have been using Resharper for awhile – for one reason or another I had never actually gotten around to it. With my current job, Resharper is required – and I’m really glad that it was. The improvements in Intellisense alone are worth the price of admission. Also having to learn a new set of coding conventions was a lot easier with the hints and code cleanup features. Highly recommended.

resharperresharper

Awhile ago, I had used this tool called Silverlight Spy – it allowed devs to do real time xaml inspection and editing – really useful for tweaking user interfaces to get that extra bit of polish. However, with the decline of Silverlight, I had basically forgotten about it a year ago. I recently discovered XamlSpy – the successor to Silverlight Spy (now targets WP/WPF/WinRT/SL). It’s been pretty helpful for tweaking Windows Phone UI’s to look exactly like designer specs. I wouldn’t say it’s essential, since you can do a lot of the tweaks with Blend & VS, but it definitely saves a lot of time and frustration of having to tweak-rebuild-tweak-rebuild. Recommended.

xaml spy screen shot

12/2/12

WinRT and Windows 8 Apps

It’s been awhile since I made a post – figured I’d give an update with what I’ve been working on.

For starters, I started my company, Three Screen Studios – an app development and consulting shop that focuses on Windows 8, Windows Phone, and Windows desktop apps. I’ve learned a ton so far, from estimated taxes and writing contracts, to Git and Gerrit.

I’ve really started getting in to Windows 8 app development, with WinRT. In general, I think it’s a good platform; coming from a WPF and Silverlight background definitely helps to be able to jump right in. There are a few gotchas though – no use of existing .NET code libraries (unless the author has ported it) is a pretty huge detriment to initial development. 3rd party control companies like Telerik have initial offerings out, but I’m hoping they’ll start fleshing out their control suites soon.

The first app I’ve created for Windows 8 is called FoodGraphic! I was able to tie for 1st place in a Windows 8 Hackathon up in Chevy Chase with the prototype, and so I decided to continue fleshing out the idea. FoodGraphic hooks into the Yelp api, and allows you to find great restaurants around the world. The value add is that it is presented in a nice UI, and I create some nice graphs of the search data to help you make a dining decision. For example, you can view a graph of ratings vs distance, which will help you find the best rated restaurant that also isn’t 20 miles away.

 

06/9/12

My Home Workstation

Where you work is definitely an important part of productivity – we just moved, so I setup my workstation (which is relatively clean for the time being).

My friends say I’m living in a forest because of the various plants around, but I feel like it helps make the area a little nicer (and maybe helps the air quality http://www.ted.com/talks/kamal_meattle_on_how_to_grow_your_own_fresh_air.html).

Also dual monitors are always nice to have (refurbished HP LP3065 30″ still goin strong & Chimei 22″).

Finally, I use a Microsoft Ergonomic 4000 Keyboard – everyone who isn’t used to ergonomic keyboards hates it, but no carpal tunnel for me!

05/13/12

A couple applications I’ve made – InstantReddit and WeatherPeek

One of the things I’d like to start doing on this blog is showing a few of the apps I’ve created, and then writing up a tutorial on the things I’ve learned while creating them. Since tutorials take a little while, I figured I’d first start just by posting a few pages and then going back and adding the rest in :)

The first is InstantReddit – a WP7 reddit client that I’ve been developing with 25K Digital. You can check the page here for more details. I’m still actively developing this application, so please also feel free to send any suggestions or comments my way!

The next app is called WeatherPeek – it’s a WPF based weather application for Windows 7. The gist of it is that you hover over the icon, and it gives you the forecast for the next several days in the preview thumbnails. Check out the page here for more details and some code snippets (and eventually the source code when I get around to it).

05/4/12

My Essential .NET Toolkit

Despite not wearing carpenter jeans, I still feel like I need to have my tools whenever I start a new project. VS2010 is pretty much a must of course – I’ve started dabbling with VS11, but the XAML intellisense in the beta is a little flaky, and the lack of color is a little disorienting.

(seriously, it’s really hard to glance and find the right button anymore)

Anyhow, my library toolkit always includes the excellent Json.NET and Hammock libraries. Json.NET is exactly what it sounds like – a framework for serializing/deserializing/parsing json. Hammock is a framework for consuming REST services. Between those two, dealing with web apis have become immensely easier. Other than those, it really depends on the project what other libraries I use – the silverlight/wpf/wp7 official toolkits are always nice (though sometimes lacking) to round out the UI side. SignalR is one of the coolest projects I’ve seen in awhile, but I’m still trying to find a good use that will do it justice.

If anyone has suggestions of libraries that make their life easier, I’d love to hear them!

05/3/12

Optimizing Performance for WP7 Bing Maps Control

One of the first apps I created for Windows Phone with 25K was one called Maps+. It’s still available, but it definitely has some flaws – namely the Bing Soap API was finicky (yes I should have used the REST API), and didn’t seem to work depending on where you were in the world.

Despite the issues, one of the parts that I was rather proud of was the map optimization and performance. If you’ve used mapping apps on WP7 before, you’ve most likely run into lag and stuttering. Not to say my app was perfect in this regard, but I feel like I found a few good tricks to eek out some more frames.

1. Use CacheMode=”BitmapCache” on map markers for the love of god

If you don’t enable this setting on any controls (ie pushpins or other markers) that you add to the map, the gpu will redraw each control every time you zoom or pan the map. This is one of the main causes for lag in map apps, and it pains me because it’s so easy to fix! Just add CacheMode=”BitmapCache” to controls you add to the Map control. Of course too many controls and you start eating into GPU memory, but that’s another story. A good article about this here.

2. If you are plotting directions (using MapPolyLine) – use the Douglas Peucker Line Approximation algorithm to reduce the amount of  points that you have to render. At lower zoom levels, you should only need to render a fraction of the points given in order to display an accurate path, so why waste cycles on the extras you can’t even see? Craig Selbert has a great implementation of the DPAA here. I used this and adapted it slightly to work with the WP7 Map control:

public class Utility
    {

        /// <summary>
        /// Uses the Douglas Peucker algorithim to reduce the number of points.
        /// </summary>
        /// <param name="Points">The points.</param>
        /// <param name="Tolerance">The tolerance.</param>
        /// <returns></returns>
        public static List<Location> DouglasPeuckerReduction(List<Location> Points, Double Tolerance)
        {

            if (Points == null || Points.Count < 3)
                return Points;

            Int32 firstPoint = 0;
            Int32 lastPoint = Points.Count - 1;
            List<Int32> pointIndexsToKeep = new List<Int32>();

            //Add the first and last index to the keepers
            pointIndexsToKeep.Add(firstPoint);
            pointIndexsToKeep.Add(lastPoint);

            //The first and the last point can not be the same
            while (Points[firstPoint].Equals(Points[lastPoint]))
            {
                lastPoint--;
            }

            DouglasPeuckerReduction(Points, firstPoint, lastPoint, Tolerance, ref pointIndexsToKeep);

            List<Location> returnPoints = new List<Location>();
            pointIndexsToKeep.Sort();
            foreach (Int32 index in pointIndexsToKeep)
            {
                returnPoints.Add(Points[index]);
            }

            return returnPoints;
        }

        /// <summary>
        /// Douglases the peucker reduction.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="firstPoint">The first point.</param>
        /// <param name="lastPoint">The last point.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <param name="pointIndexsToKeep">The point indexs to keep.</param>
        private static void DouglasPeuckerReduction(List<Location> points, Int32 firstPoint, Int32 lastPoint, Double tolerance, ref List<Int32> pointIndexsToKeep)
        {
            Double maxDistance = 0;
            Int32 indexFarthest = 0;

            for (Int32 index = firstPoint; index < lastPoint; index++)
            {
                Double distance = PerpendicularDistance(points[firstPoint], points[lastPoint], points[index]);
                if (distance > maxDistance)
                {
                    maxDistance = distance;
                    indexFarthest = index;
                }
            }

            if (maxDistance > tolerance && indexFarthest != 0)
            {
                //Add the largest point that exceeds the tolerance
                pointIndexsToKeep.Add(indexFarthest);

                DouglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance, ref pointIndexsToKeep);
                DouglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance, ref pointIndexsToKeep);
            }
        }

        /// <summary>
        /// The distance of a point from a line made from point1 and point2.
        /// </summary>
        /// <param name="pt1">The PT1.</param>
        /// <param name="pt2">The PT2.</param>
        /// <param name="p">The p.</param>
        /// <returns></returns>
        public static Double PerpendicularDistance(Location Point1, Location Point2, Location Point)
        {
            //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)|   *Area of triangle
            //Base = √((x1-x2)²+(x1-x2)²)                               *Base of Triangle*
            //Area = .5*Base*H                                          *Solve for height
            //Height = Area/.5/Base

            Double area = Math.Abs(.5 * (Point1.Latitude * Point2.Longitude + Point2.Latitude * Point.Longitude + Point.Latitude * Point1.Longitude - Point2.Latitude * Point1.Longitude - Point.Latitude * Point2.Longitude - Point1.Latitude * Point.Longitude));
            Double bottom = Math.Sqrt(Math.Pow(Point1.Latitude - Point2.Latitude, 2) + Math.Pow(Point1.Longitude - Point2.Longitude, 2));
            Double height = area / bottom * 2;

            return height;

        }
    }

3. Another point about using MapPolyLine, is that it draws the entire line, even if parts of the line are off the screen. This can be quite painful for a large route, especially if you are zoomed in pretty close. I found that clipping the route to the screen helped in reducing the rendering hit. This one is pretty easy to implement as well:

MapPolyLine routeLine = new MapPolyLine();
routeLine.Clip = new RectangleGeometry() {  Rect = new Rect(0,0,480,800) };

Anyways, hope those tips helped!

- Tommy