I’m getting along pretty nicely with my first PhoneGap-app for iPhone/iPad/Android. Just thought that I should share a few screenshots of the first view on the targeted devices. It works pretty well on the iPhone and in the Android emulator though it really shines on the iPad. The Android version should be ready for release pretty soon (via PhoneGap Build if I just can find the time to polish it a bit more whilst the iOS-versions will have to wait a bit (I have a functional build environment setup on my iMac though I haven’t enrolled as a developer yet).

Android

iPad

iPhone
I just got an email with a signup key to join the beta of PhoneGapBuild! For those who doesn’t know what PhoneGap is; It’s a really sweet wrapper application that let you build advanced mobile applications for iOS, Android, webOS and more using html/css/js. I’m currently building a small app for Någonting Större mainly aimed at the iPhone but with the idea to someday compile it for Android aswell. With PhoneGapBuild that part just turned really easy. I zipped my contents, uploaded the zip-file, waited a few minutes and then I could download my app for Android aswell!
When my app(s) are ready I’ll be sure to post a note here (and for Android, a download link) so stay tuned!
More info about PhoneGapBuild (and a form to apply for the beta) can be found at http://build.phonegap.com/. More information about PhoneGap is available at http://www.phonegap.com/
Just got a new monitor here at work, a really sweet 24″ Samsung, which came with a few really annoying application. The applications does the usual stuff, allow you to change gamma and color hues etc. but they also allow me to rotate my screen 0, 90, 180 or 270 degrees. A really sweet function if you happen want to rotate your monitor for some reason. The developers also thought that people would like to do this really often and therefore included a contextmenu extension to allow you to rotate your screen by rightclicking on a folder background or on your desktop.

I can’t really see how many people that will have any use of this particular feature but I sure don’t need it. It also seems to be poorly coded since it can conflict with other extensions (in my case TortoiseSVN, see this post for more information).

So how can we avoid this problem? The someone on the TortoiseSVN mailing list suggested that we simply remove the icons from the TortoiseSVN contextmenu which solved the problem easily. Open regedit and go to “HKEY_CURRENT_USER\Software\TortoiseSVN” and add a new DWORD named “ShowContextmenuIcons” with a value of 0 and you are done, the changes should be in effect immediately.
Another solution that feels a lot better if you ask me though is to get rid of the horrible MagicRotate extension. To do this we open regedit and navigate to the “HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers” key. The subkeys/folders shown under this key represents the contextmenus currently registered. If you as me have TortoiseSVN installed you will see a key named TortoiseSVN there. If you have Samsung MagicRotate installed you will see a key named SimpleBkgndExtension (google the name and you will find a reference to “The Complete Idiot’s Guide to Writing Shell Extensions”
). The easy way from here is to just remove the key SimpleBkgndExtension and it won’t show up any more.

I just got around to publish my latest project. It’s a site for a christian festival/conference called Någonting Större (Something Greater or Something Larger in English). It has taken a while but it turned out really great (mainly because I didn’t have to do to much work with the design) and hopefully many other great things will come out of the codebase (called BeaverSite, a CMS built with ASP.Net MVC which works GREAT!). A lot of code in this project is also shared with other projects such as BeaverShop and Imager Gallery.Net which both speed up this project and at the same time progressed the others. You can see the page in its full glory at http://www.någontingstörre.se/.
I just finished uploading my geodesy library (CrazyBeavers.Geodesy) to CodePlex. It has some various functions for working with coordinates (converting between coordinate systems and calculating distances and such). It can be found here: http://beavergeodesy.codeplex.com/.
Give me a shout if you want to help me with this project (just adding more grid projections would be awesome!) or if you just want to thank me for it
.
It has been many months since I posted something here so finally today I wrote a small function that I thought I could share to get this blog going again. It’s a small snippet that takes an address and tries to geocode it (convert it to coordinates) using the Google Maps API.
public class Coordinate
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public static Coordinate[] GeocodeAddress(string address)
{
List<Coordinate> coordinates = new List<Coordinate>();
string response = new WebClient().DownloadString(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", HttpUtility.UrlEncode(address)));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
string status = xmlDoc.DocumentElement.SelectSingleNode("status").InnerText;
switch (status.ToLowerInvariant())
{
case "ok":
// Everything went just fine
break;
case "zero_results":
return coordinates.ToArray();
case "over_query_limit":
case "invalid_request":
case "request_denied":
throw new Exception("An error occured when contacting the Google Maps API."); // Should probably be refined to something more useful like throwing specific exceptions for each error
}
XmlNodeList nodeCol = xmlDoc.DocumentElement.SelectNodes("result");
foreach (XmlNode node in nodeCol)
{
double lat = Convert.ToDouble(node.SelectSingleNode("geometry/location/lat").InnerText, CultureInfo.InvariantCulture);
double lng = Convert.ToDouble(node.SelectSingleNode("geometry/location/lng").InnerText, CultureInfo.InvariantCulture);
Coordinate wgs84 = new Coordinate() { Latitude = lat, Longitude = lng };
coordinates.Add(wgs84);
}
return coordinates.ToArray();
}
}
For more info on the Google Maps Geocoding API you can visit http://code.google.com/apis/maps/documentation/geocoding/.
I’ve been working heavly with Google Maps and transforming coordinates at work this summer and when I get the time I’m going to make a nice package of the things I’ve created. I have a few helper functions in .Net for transforming between grid-based coordinates (X, Y) and geodesic coordinates (latitude, longitude) using the GaussKruger-formula as well as some snippets for Google Maps to handle large amounts of markers on a map (by hiding markers outside of the viewport) and some basic layer support for the markers.
A new version of jQuery Tag Editor is out. This time it’s up to version 1.4 and gladly enough I didn’t have to put almost any work into it. A huge thanks goes out go to Joost Elfering who made most of the changes and improvements in this release.
As usual, the demo and project page can be found at the urls below.
http://blog.crazybeavers.se/wp-content/Demos/jquery.tag.editor/
http://plugins.jquery.com/project/jQueryTagEditor
It has been quiet around here (as usual unfortunately) so I thought I should get every one up to speed on what I’ve been doing lately.
First out is ImagerGallery.Net which is still being worked on sporadicly. Latest additions is a Silverlight plugin to accompany the SeaDragon implementation for users with Silverlight 3.0 or later installed. More and more features are being added all the time and its getting better and better. I have no timeline for a public release of it though the current progress can be followed at http://svn.crazybeavers.se:81/trac/CrazyBeavers.ImagerGallery/roadmap and a live demo of the current version is available at http://www.kallesbildarkiv.se. I hope to be able to share some more code samples from this project some time soon, just need to extract it and document it a bit better.
My second project the past months is a site for a friend of mine called Händiga Män (Swedish for “Handy men”) located at http://www.handigaman.com/. It was designed by me and built using almost no server code at all but fills its purpose just fine.
Third out is a webshop I’ve been working on for a local shop though it isn’t public yet so I can’t give out a link to it. Will see if I can upload an image later when I get my portfolio updated with my latest projects.
A part from the above listed I’ve also worked in a few internal projects at work which have been winform applications to ease some of the administrative work at the fire department. Will try to update my portfolio with a few screenshots and better descriptions later on.
I’m currently experiencing some problems with the syntax highlighting script after upgrading to WordPress 2.9.1. I will try to sort it out tonight but I’m afraid it might come to going back through all posts and editing them. Stay tuned!
I’ve been working on two fairly large MVC-projects lately. ImagerGallery.Net and a webshop-application suitably named BeaverShop. While working on those projects I’ve realized that I just love being able to use ActionFilters in MVC. Basically, they are attributes that you append to action-methods. They can be used to validate input, parse data into more suitable structures, check security and lots more.
One of my most used filters in both ImagerGallery and BeaverShop is one I named PagingAttribute which I thought I should show to you today.
Any ActionFilter need to inherit the ActionFilterAttribute and implement at least one of the following methods: OnActionExecuting, OnActionExecuted, OnResultExecuting or OnResultExecuted. They are all called during different stages of the execution of an action-method and can be used for various things. The one I’ll be using is OnActionExecuting since it is executed before the action so that I can pass extra arguments to the action.
The code is quite easy to understand. There is only one property to be set (except for the default property Order which is defined in ActionFilterAttribute) which is which field to be parsed. I check if the field is null or empty, if not ten I use a regular expression to see check if the selected field ends with “page” and a numerical value. The numerical value is then returned as a argument for the action called “pageNo”. This value is defaulted to 1 to make sure that we always get a number for our page (and not specifying anything should mean the first page). In my case I also want the field to be modified so it doesn’t contain the “page” part but that might not be suitable for everyone. If not, then you can easily remove that part by commenting the line looking like this: filterContext.ActionParameters[Field] = id;
using System;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
namespace BeaverShopMvc.Attributes
{
/// <summary>
/// An ActionFilter to parse a page number from a field value
/// </summary>
public class PagingAttribute : ActionFilterAttribute
{
/// <summary>
/// The name of the field to parse
/// </summary>
public string Field { get; set; }
// A compiled regular expression to speed things up
private static Regex _pageRegex = new Regex("page(?<PageNo>\\d+)$", RegexOptions.CultureInvariant | RegexOptions.Compiled);
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string id = filterContext.ActionParameters[Field] as string;
Int32 pageNo = 1;
// We never need an ending / so remove it
id = id.TrimEnd('/');
// Check so that the field isn't empty and while at it also that it
// contains "page"
if (!string.IsNullOrEmpty(id) && id.ToLowerInvariant().Contains("page"))
{
Match match = _pageRegex.Match(id);
if (match.Success)
{
pageNo = Convert.ToInt32(match.Groups["PageNo"].Value);
if (id.Contains("/"))
id = id.Substring(0, id.LastIndexOf('/'));
else
id = string.Empty;
}
}
filterContext.ActionParameters["pageNo"] = pageNo;
// The line below replaces the old field value with a
// new one without the "page" part
filterContext.ActionParameters[Field] = id;
base.OnActionExecuting(filterContext);
}
}
}
Using the attribute is really simple and the great thing about this is that it is easily reusable on any actions you need it to. Below is a little sample of it in action.
[Paging(Field = "id")]
public ActionResult ListProducts(string id, Int32 pageNo)
{
return View();
}
I have a few more filters that I really like as well (AkismetValidatorAttribute for example) that I might share some other day. I’m still learning a lot about working with MVC and will keep you posted with what other interesting things I can find.
Recent Comments