Flurry Analytics Portable

We all know about Flurry Analytics, and we know how we can use this with Xamarin in iOS and Android, as well as on Windows Phone.

Well, now there is a portable version that allows the analytics to be implemented in portable class libraries! The portable API abstracts away all the platform differences, but keeps all the power of the Flurry!

This can be found on NuGet and on GitHub.

Features

The features of the portable API are the same as the native API’s, as the portable is more of an abstraction than anything else. So along with all the native features, there are a few nice new once that make the API easier to use.

This is the primary advantage of this library, it allows the analytics to be implemented in portable projects. This is especially useful if you are using a cross-platform framework, such as MvvmCross. There is a sample that you can check out that makes use of all the features.

Starting Sessions

Although the library is portable, each platform needs to start the analytics session natively/differently:

For iOS, it is very simple call StartSession from the AppDelegate:

    AnalyticsApi.StartSession("[API KEY]");

For Android, there are two ways to do this. Either by overriding the OnStart and OnStop methods from each Activity:

    // in OnStart
    AnalyticsApi.StartSession(this, "[API KEY]");

    // in OnStop
    Analytics.EndSession(this);

Or, by using the IActivityLifecycleCallbacks for the Application. This way allows you to start and end the session without having to implement the logic in each Activity. However it is only available from API Level 14 / Android 4.0 / Ice Cream Sandwich.

For Windows Phone, starting the session is done by attaching the StartSession method call to the Launching and Activated events:

    PhoneApplicationService.Current.Launching += (sender, args) => AnalyticsApi.StartSession();
    PhoneApplicationService.Current.Activated += (sender, args) => AnalyticsApi.StartSession();

For each of the platforms, there is also a way to pass the key in to the API, but only start the session later:

    // somewhere in the code
    AnalyticsApi.ApiKey = "[API KEY]";

    // and then a little later
    AnalyticsApi.StartSession();

There is also a boolean property, IsSupported, that will return true if the platform supports Flurry Analytics:

    if (!Analytics.IsSupported)
        Debug.WriteLine("PLatform does not support Flurry, nothing will be tracked.");

Setting Up Analytics

There are a few methods that hide the platform differences. Some examples of this are in the setting of user details, such as SetAppVersion, SetUserId, SetLocation, SetAge and SetGender.

Not only that, there are a few methods that specify how Flurry should communicate, such as SetSessionContinueTimeout and EnableSecureTransport.

Usually these methods should be called before starting the session.

Logging Events & Errors

Along with tracking basic analytics, events and errors can be tracked. There are a few methods that support this: LogPageView, LogEvent, LogTimedEvent, EndTimedEvent and LogError.

Logging timed events has been made much easier by implementing a new pattern for doing this. By calling LogTimedEvent in a using block, you can end the event in case of any exceptions as well as removing an extra call:

    using (AnalyticsApi.LogTimedEvent("EventId"))
    { 
        // perform a long running task
    } 

Before, you would have to ensure that you called EndTimedEvent to avoid any problems:

    try
    {
        AnalyticsApi.LogTimedEvent("EventId");
        // perform the long running task
    }
    finally
    {
        AnalyticsApi.LogTimedEvent("EventId");
    }

Parameters can also be passed with the events using a simple Dictionary:

    var parameters = new Dictionary<string, string> 
    {
        {"ParameterKey", "ParameterValue"}
        {"AnotherParameterKey", "AnotherParameterValue"}
    };
    AnalyticsApi.LogEvent("EventId", parameters);

MVVMCross Startup Crashes

Have you every used MvvmCross in your app, only for it to crash on startup when launching without the debugger? Well it happened for me quite a few times, and its because I was having a brain fart…

After launching the app many times and trying to somehow gain knowledge magically due to repeating the same thing over and over, I decided to add some “logging”:

    // Code to execute if a navigation fails
    private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
    {
        MessageBox.Show(e.Exception.ToString()); // <- LOGGING!
        if (System.Diagnostics.Debugger.IsAttached)
        {
            // A navigation has failed; break into the debugger
            System.Diagnostics.Debugger.Break();
        }
    }

    // Code to execute on Unhandled Exceptions
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        MessageBox.Show(e.ExceptionObject.ToString()); // <- LOGGING!
        if (System.Diagnostics.Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            System.Diagnostics.Debugger.Break();
        }
    }

This returns a nice little error message:

System.NullReferenceException: Object reference not set to an instance of an object.
  at Cirrious.CrossCore.Mvx.Resolve[TService]()
  at MvvmCrossSample.WindowsPhone.App.<RootFrameOnNavigating>b__0()

So what does that mean? Well, over there I am trying to resolve the IMvxAppStart type:

RootFrame.Dispatcher.BeginInvoke(() => { 
    Mvx.Resolve<IMvxAppStart>().Start();
});

So for some reason, my Setup object wasn’t getting initialized… This is what I had:

    // Show graphics profiling information while debugging.
    if (System.Diagnostics.Debugger.IsAttached)
    {
        // ...

        Setup setup = new Setup(RootFrame);
        setup.Initialize();
    }

Hmm… Maybe the app should start up for the users without debuggers as well? All I needed to do was to move the startup object out of the scope of the if block:

    // Show graphics profiling information while debugging.
    if (System.Diagnostics.Debugger.IsAttached)
    {
        // ...
    }

    Setup setup = new Setup(RootFrame);
    setup.Initialize();

After that, the app worked fine.

In short, don’t just copy-and-paste when using templates, at least read the snippet you are pasting.

GoMetro App

App Icon
GoMetro is an app designed for your travel needs. It brings together announcements, timetables, maps and more. Also it provides an easy-to-use journey planner that will give you more flexibility when commuting.

Main Screen Results Screen

New Features

  • Metrorail timetables
  • Favourites
  • Fare calculator
  • Railway line maps
  • Announcements
  • OS theme aware
  • Fast and easy-to-use

Privacy Policy

The GoMetro app takes your privacy very seriously and does not, in any way, share, store information about your phone or identity number.

Department of Home Affairs App

App Icon

Ever wanted to see the progress of your South African ID or Passport application? Have you ever wanted to check to see if someone is married, or if someone is still alive? This app allows you to discover public information on South African residents.

I created this app to have a nice, quick and easy way to check my status of my application for my passport.

Main Screen Results Screen

How To Use

This app is very simple and only has one step: enter your ID number and press “check status now”.

The results that are put together and displayed include:

  • ID application progress
  • Passport application progress
  • Marital status
  • Alive or deceased
  • Duplicate ID status
  • Permit application progress

Privacy Policy

The Department of Home Affairs app takes your privacy very seriously and does not, in any way, share, store information about your phone or identity number.

My Personal Data

None of your details are stored or shared on any server, anywhere except for:

  • Anonymous approximate age for in-app analytics and cannot be used to associate anything to you.
    This is purely for statistics and is only used for determining the average age groups of the app’s users.
  • Anonymous gender for in-app analytics and cannot be used to associate anything to you.
    This is purely for statistics and is only used for determining the average gender of the app’s users.
  • Anonymous approximate location for in-app analytics and cannot be used to associate anything to you.
    This is purely for statistics and is only used for determining the average (general country/state area, nearest to a city) location of the app’s users.

My Phone Data

App doesn’t access to sms history, browsing history or other data from your phone other than a general location, see above, used specifically for anonymous statistics.

Permissions

  • Geolocation Data – All information is totally anonymous and only used for app usage statistics
  • Networking – Only used to retrieve the results of your search and to send anonymous app usage statistics

Department of Home Affairs Data Servers

All information used by the app are all available on the official website of the Department of Home Affairs for the Republic of South Africa.

The same results generated by the app can be retrieved on the official status page: http://www.dha.gov.za/status/.

For Windows Phone, By Surface Pro

Surface Pro and Windows Phone

I was just reading through my usual news feeds, one of them being Windows Phone Central when I came across a cool post from Microsoft, “Geek out with Surface and win!“. So I started thinking about what I could do. I am one of the very few people in South Africa that has a Surface. The shipping is what kills, but I had to get one. I am also a developer, so it seemed natural to get a tablet that ran Visual Studio. Only the tablets running Windows 8 Pro was of any real value, so after a bit of thought, I got myself a Surface Pro – and have been loving it ever since.

Just to show how great this tablet really is, I can say that I gave my PC away and never once regretted that decision. I have developed an app for Windows Phone 8 exclusively on the Surface. It is available on the Store: GoMetro | Windows Phone Apps+Games Store. I am proud of this app as it is my first for Windows Phone as well as it being developed on my favourite device – my Surface.

Some time ago, before I started the app, I wrote a post on what I was going to do: “GoMetro for Windows Phone 8

I love my phone and my tablet, and I develop apps for both. I am working on several projects ranging from websites, Windows Phone and desktop. C# is my main language, but I do do extensive JavaScript and CSS development for those wbsites.

As you can see, my Shift and Ctrl keys are a bit worn from my continuous use! I won’t recommend the touch cover for extensive use, certainly not for development, but it can be done – you just hve to get used to typing.

Overall the tablet is very good, it can play the average game as well without a real problem. Excellent for surfing the web and social networking, emails and other light use. I read my digital comics on this device and they are clear, crisp and vivid.

On more serious tasks, it is also oustanding, development is slightly harder due to the small screen, but I developed an app without any external monitors so it can be done. I have done some photo editing and 2D drawings without any problems. I run a virtual machine using Hyper-V for one of my projects, and have not noticed a real problem.

The OS is snappy an the apps that I use are very good: Mail, People, Facebook, Internet Explorer, Skype, Nokia Music, Adera (game), Fresh Paint and Autodesk Sketchbook. There have been some tremendous improvements since Windows 8.1.

The USB port in the charger is used to charge my phone and the stylus is used for my assignments and note taking in both OneNote and Word. I have done some nice drawings and the stylus is pretty accurate. The USB port is used mainly to connect my external HDD, but is used for other things, even for emergency charging of my phone when I don’t have my charger around.

The sound quality is good, sometimes a bit soft, but that doesn’t really affect me as I use it mostly after hours and late into the night. Movies are awesome, colours are good and there is no lag in the images that I can see.

I find the battery life is fairly substantial, setting my brightness to about 75% usually extends it for several hours – I have never actually measured, but it is more than 5 hours. Often, in my bed at night I can read my comics, setting the brightness right dow and it’ll last for hours even from below 50%.

One more thing, SkyDrive. This is integrated into the OS, but that is just cool. The most totally awesome feature is the photo file management: I have got over 8GB on SkyDrive, but it only takes up 170MB on disk. This is the greatest and coolest of all those cloud guys. Especially as the tablet has limited storage of 128GB. I have just clocked at 50% on my HDD, so the space is not being swamped, even with Office, Visual Studio and its SDKs. Although, I do have an external drive for my music, movies and other large games such as Battlefield.

I look forward to trying and maybe buying the Surface Pro 2…

GoMetro for Windows Phone 8

I was just recently given the opportunity to work on a Windows Phone 8 app for the GoMetro system. Currently they have the mobile website and are working on a new-and-improved version, but not yet a Windows Phone 8 native app. As I have a shiny new Nokia Lumia 820, its no good going to the web browser each time I need to take a train.

They have a REST API that I will be using, but I hope to use some caching and personalization on the user’s device. The next version of the GoMetro engine will have more features like these, but until then, it will have to remain local only. Of course, once the next version is out, I should just be able to import them into the online database.

I have been working on some concept designs for this app, which I show below. I am using ProtoShare instead of manually drawing each screen. This is a cool tool for quick screen creation, although it is not free. I will give it a try and see what happens.

This application so far has 3 main areas of importance:

  1. Announcements
    This is the area where we will be able to display any notifications about the lines, Metrorail and the app.
  2. Favourites / Shortcuts
    This is probably the most important feature for me as I often don’t commute to work on a specific train, but rather the one around 8:30, sometimes before and sometime after. So instead of going through the whole workflow to get the next time, I can quickly see the scheduled arrival. As the current API does not support storing this on the cloud, I will keep it in a small SQLite DB on the actual device, to be synced at a later date.
  3. Train Timetables
    This is the usual workflow for getting the times of the next train. The next image follows on from after the user selects a province that he/she is interested in.

Main Screen 

The next main chunk of application is the actual finding of the train timetable. This is going to be the same as the website in structure.

We get to this level after the user selects a province from the main screen. He/she then selects a line and then proceeds to select the departure and arrival stations. I would like to be able to specify the day and time of the trip as well, but I need to do some more research on the availability of this first. When the user is ready, all is needed is to tap the arrow button. The final screen is a list of the departure times with a few options:

  • Switch the direction of travel
  • Go to the earlier times
  • Go to the next set of times
  • Add this route to favourites

Timetable Workflow

This is just the preliminary designs and probably will change. If you have any comments, then just leave a comments below. Or you can vote.

I am a contributor to Mono

I just remembered that I had previously made a pull request in the Mono project, and when I went to have a look today, I saw that it was accepted! Yay! Now I can say I have contributed to the coolest project in the world. I don’t know if those two lines really count, but at least I am part of the Mono team (at least I like to think so).

I suppose this is a way to realise that no matter how small a contribution to a project, endevour or anything, a contribution is really helping others. Maybe I will contribute some more in future, but at least now I will have that one line moved for the better.

I came accross this when I was creating my port for the Windows Phone / Silverlight.