win8dev

all my win8dev posts

Dev Story Series (Part 1 of many): Creating a data class for both Windows 8 and Windows Phone app

Dev Story Series (Part 1 of many): Creating a data class for both Windows 8 and Windows Phone app

As I promised earlier on my application for the Intel App Innovation Contest on codeproject.com, I will do a series of blog posts for my application MSicc´s Blog for Windows 8 and Windows Phone.

This is the first article in my new Dev Story Series, where I describe the development process of the app. I am starting with the very first steps that you have to do if you plan such an application. To make the application useful, we first have to decide how we want to get the data from our blog/website into our application.

One hint that will make some of you crying out loud: At the moment I am not using the MVVM pattern. I am aware of the fact that most devs for Silverlight/C# swear on it, but I still decided to go without it – as well on Windows Phone as on Windows 8. I will continue to learn it in one of my future project, but for the moment I just want to get things done – also if that means that I have to create some – well, let us call it “compromises”.

Which way to choose?

If you consider to create a “blog reader”, you have to think about how you want to get the data from your blog into your app. There are different ways:

  • via a RSS/Atom feed (that was in the old version of my Windows Phone app for msicc.net)
  • via XMLRPC (if your blog supports that)
  • via JSON

I decided to go with JSON for the new version. There were several reasons to do so:

  • there is an app err… an plugin for that on WordPress
  • JSON is fast
  • JSON is set to be the new standard for data consumption
  • With JSON.NET you can deserialize your data with only one line(!) of code

How do we get the data in our app?

Of course, we will download it. But if you only download your JSON data, the only thing you will get is a very weird looking string that looks like this:

json_string_unserialized

That´s pretty ugly, right? Of course we could work us through all arrays and objects there. That would take hours and hours until we would have covered all data we need for our apps. Luckily, there are two tools that make the whole thing a lot easier.

Two handy tools to make a dev´s life easier

The first tool I want to show you is “Beautify JSON”. It is a web based tool that makes strings like the one above readable for a human. Find it here.

Just paste the string of your JSON API in there, and you will get a readable version of your JSON string:

beautify_json

If you want to use only some of the data that your API provides, you can now easily search the string for the objects and arrays that you need.

If you quickly want to create a data class for all data that is provided, you can do this by using json2charp.  It provides a ready-to-use code that can easily be copied and pasted into your class file in Visual Studio:

json2charp

Now let´s have a look to the class itself:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace WordPressDataClass
{
 public class Posts
    {
        [DataMember]
        public string status { get; set; }
        [DataMember]
        public int count { get; set; }
        [DataMember]
        public int count_total { get; set; }
        [DataMember]
        public int pages { get; set; }
        [DataMember]
        public List<Post> posts { get; set; }
    }
}

As you can see, I created a DataContract and DataMember based class by using System.Runtime.Serialization. If you want to know more about DataContracts and DataMembers I recommend you to read MSDN: using Data Contracts.

I am not posting the whole class, only the key DataContract Posts, which will get us our List of posts. You can download the whole class at the end of the post. It will be very helpful if you want to create an app for your WordPress based blog.

I use the class in both my Windows 8 and my Windows Phone app without any differences. As you can see, If you are familiar with Windows Phone Development, there is only a small step to Windows 8 development.

I hope this article is helpful for some of you. In my next post I will show you how easily you can use the provided JSON Data in your app/s.

source code: JsonDataClass

Posted by msicc in Dev Stories, win8dev, Windows, Windows Phone, wpdev, 4 comments

Smart little helper to clean HTML based strings for [WPDEV] and [WIN8DEV]

I thought I would share this small little class I created to clean out HTML based strings into readable strings. The class is both usable for your Windows Phone app as well as your Windows 8 app.

If you use cloud based or internet data, often strings contain “&ndash;” or “&#8211;” instead of their intended letter, like you can see on this image:

htmlstringuncleaned

The method uses Regex to replace all the wrong signs and clean out all of the unwanted signs. You can also add more to that if you need to replace wrong letters.

class CleanHTML
    {      
        public static string RemoveEncoding(string text)
        {
            try
            {
                string temp="";

                temp = 
                    Regex.Replace
                    (text.
                    Replace("&ndash;", "-").
                    Replace("&nbsp;", " ").
                    Replace("&rsquo;", "'").
                    Replace("&amp;", "&").
                    Replace("&#038;", "&").
                    Replace("&quot;", """).
                    Replace("&#039;", "'").
                    Replace("&#8230;", "...").
                    Replace("&#8212;", "—").
                    Replace("&#8211;", "-").
                    Replace("&#8220;", "“").
                    Replace("&#8221;", "”").
                    Replace("&#8217;", "'").
                    Replace("&#160;", " ").
                    Replace("&gt;", ">").
                    Replace("&rdquo;", """).
                    Replace("&ldquo;", """).
                    Replace("&lt;", "<").
                    Replace("&#215;", "×").
                    Replace("&#8242;", "′").
                    Replace("&#8243;", "″").
                    Replace("&#8216;", "'"),
                    "<[^<>]+>", "");

                return temp;
            }
            catch
            {
                return "";
            }
        }

        }

As we created a class for this little helper, you can call it from everywhere within you app to clean out the string. Here is one example I am using:

 item.title = CleanHTML.RemoveEncoding(item.title);

After calling this method, your string is plain text:

Screenshot (17)

I hope this post will be helpful for some of you.

Happy coding!

Posted by msicc in Dev Stories, win8dev, wpdev, 0 comments
Editorial – the relationship between developers and users

Editorial – the relationship between developers and users

I did not plan this post, but as I received an email yesterday from another developer, this changed. This post will be an Editorial about the relationship between developers and users.

Users and developers do have a problem. Users have expectations for our apps. We developers have to fulfill these expectations. Here is an image I found on the web, that describes the situation quite well:

Of course, this is a funny Picture. But in the last few weeks sadly this image turned out to be kind of  true. I talked also to other developers, and they made similar experiences. I will try to explain why feedback is important to us developers.

It all starts with an idea. The idea can come from a friend, a family member or from a situation your life. For my very first app the situation was simply the app I searched was not out there in the marketplace and it is no pleasure to use the mobile web in some situation (e.g. while fishing). For another app a discussion on my primary work was the reason.

If you are an app developer, you now sit down and create a concept. You have to think about a lot of things:

  • which features do I want in my application?
  • do I already know all to get this features into my app?
  • where can I learn about features that I want but do not know how to code them?
  • How does the UI have to look?
  • How much time will it cost to create a first running application?
  • what are the limitations of the OS I am coding for?
  • how can I promote my apps?
  • and certainly a few other things

Until now, we do not have written one line of code, but already spent a few hours if not days only in planning phase. At some point, of course we start coding. The coding and designing process is followed by ups and downs, where you have to reconsider features, sometimes even have to rethink your whole attempt on how to create the app.

I have a very good example for that. Initially I tried to use animated gifs in my app “fishing knots +” . It turned out that Windows Phone does not support this image format natively. So I searched a way to achieve my goal and let Windows Phone learn it within my app. There are some solutions out there, but I was not satisfied with the result. So I started to search for alternatives and found one that suites it very well: a storyboard for each animation. But then I had another problem: For a storyboard animation, you need single images, not a finished gif animation. Luckily one of my co-workers could help me out and created the images for me, so I was able to use it. But it took also some time for him to create the images (12 knots with at least 10 images). I created the basic images, and he did his magic. The result was great.

Now we have a very basic version of our app that runs, and can also be shown to some people. And of course, friends, coworkers and family are your first “customers” that give you some feedback. You should be grateful for the feedback they provide, as it often offers you sights on which you do not think while developing the app. Also if that means you have to rewrite a bunch of your code. They are no developers (in most cases). They are just users. Let them play around with your app (best on a real device!), and do write down every single point they tell you. Feedback is good, and helps you to evolve.

Now that we have done this, our app at some point reaches the state of being submitted to the Marketplace/Store. You should never start with a final version number like 1.0 for that. 1.0 suggests a user that it is a finished product with nearly no error. And they errors will come. I did not see a single app that was without issues on the first release, neither on the following updates. This counts for my apps as well as for apps of other developers. But that is not a bad thing. Once you have published your app, you have the possibility to obtain more feedback. This time from real end users.

To achieve this, you should offer a way to give feedback within your application. Here is my attempt that I have in every of my apps:

 

 

As you can see, I integrated a few ways to obtain feedback. I created a twitter handle, where users can give feedback and follow for actual announcements for my apps. Nowadays a Facebook page is also an advantage, and then users have the ability to send me an email to provide more detailed feedback. And one thing you never should miss: a direct link from your app to the review section of your app in Marketplace.

So from our part, we did all to get some feedback. Now to you, user of our app! We want you to give us some feedback! What we want is feedback that helps us to understand what you expect.

Sadly a lot of users are rating an app with less stars, providing no feedback or only harsh words for the app. A rating for an app was delivered with less than 5 stars because the app is not free. Another one gave me 1 start and as comment: “great”. That is not feedback that can be used to improve the app.

Another example is glƏƏk! for Windows 8. It is an really fast and fantastic twitter app. I use also their Windows Phone version, and I am absolutely happy with it.

The first versions of the Windows 8 app had some problems and was crashing a lot. Users, of course, wrote that into their reviews. But how many of them did give them feedback to improve the app? As I am in contact with the developers, I know that they did not get a lot of feedback to iron out all those issues. Feedback is important to us developers. We need to know in which cases you, the users, have the issues. We have to reproduce the error, but that is nearly impossible without your feedback.

I understand that you give a bad rating to an app if it crashes a lot or if you are constantly facing other problems. And we developers try to iron out every single point you tell us. If you see that the experience has improved, you also should honor the work we do for you and update your rating and review. glƏƏk! had some issues like all other twitter clients on Windows 8, too. In the meantime, glƏƏk! was updated nearly every day to iron out other issues, and finally we have a non crashing version.  But no one updated their reviews and ratings. Sure, some may have uninstalled the app, others are having it  still but do not updated their rating/review. This is frustrating for developers who do not get a lot of feedback via email or other channels but only via the ratings.

Please, do not take this as advice to not rate our apps. We want your ratings. But be fair. If something is wrong with one of our apps, please tell us! But I beg you to understand that we only can work with quality feedback, so please use twitter/Facebook/email, whatever we offer you. Give us as much information as you can, answer to our questions if we have them to you.  And please update your ratings after we have ironed out your issues.

Please not also that we are no aliens. We are humans like you after all. And we are  also users.

Posted by msicc in Dev Stories, win8dev, Windows, Windows Phone, wpdev, 0 comments
Microsoft shows what Windows 8 means for developers at CeBIT

Microsoft shows what Windows 8 means for developers at CeBIT

WP_000425

As I told you in my earlier post from CeBIT, I visited also an event for Developers at CeBIT.

Microsoft Developer Evangelist F. Rieseberg and G. Logemann were talking about some important things while developing for Windows 8.

Components of a modern IT

First Microsoft told us a few words about the new form factors, which both Microsoft and we Developer have to deal with. This was to show us how important it is to use the Grid. The Grid is a huge tool to accomplish our apps to look on all devices the same, regardless of the screen resolution. The told us some areas which we should not use, as the are reserved for gestures or the back button.

Windows RunTime (WinRT) and code languages

WP_000427

Microsoft explained us how easy it is to develop for the WinRT, using our already existing knowledge of our special languages. It is really easy to understand: Basic of the whole system is the kernel. On top of the kernel you have the WinRT APIs (for example communications, sensors). And with all supported languages you can call these APIs. You can develop Metro styled apps in C/C++, C# or VB (+ XAML), as well as in HTML/CSS or JavaScript.

Microsoft calls the WinRT APIs also the Metro style application APIs. These APIs are easy to understand.

WP_000429

  • First we have the fundamental APIs: Application Services, Threading/Timers, Memory Management, Authentication, Cryptography and Globalization
  • On top of that are APIs for Media, Devices as well as Communications & Data
  • Finally on top of that all we have the UI

Desktop apps

In two sentences: You can develop apps or programs also for the desktop, but without the advantages of the WinRT. You will have to decide if you want a desktop app or a Metro style app.

Async development!

Only async. full stop. No, seriously, Microsoft declared they only want async apps. The UI has to be “fast and fluid” at every time the user is in the app. This is relatively easy if you are an .NET/C# developer. You know it already. In Windows 8 we have a simple keyword for it: “await”. Example: calling the FilePicker to hand over an image to the photo app, you will call it with the simple word await in front.

Process states

WP_000434

Similar to Windows Phone, the used memory is controlled by the OS. This means when you app goes to background, you have to save the state of your app. Your apps has 5 seconds to handle all savings while going to suspended mode. While in suspending, your app runs no code.

You can create background tasks, but they need to be handled also for resuming. Imagine a download, you go to another app, return to your app. The background task has to resume while getting the right values from the download.

Another thing similar to Windows Phone: If the system runs to low memory, suspended apps will be terminated without any warning/notification. In this case all unsaved date is lost. It is up to us developers to save all data correctly within the 5 seconds until our app is suspended.

Q & A

At the end of the short event Microsoft took some questions. Two of them were interesting:

  • Q:  Is there a way to share data between a desktop app and a Metro styled app?
  • A:  Not locally. You have to use the cloud to do so.
  • Q: Will some of the features be available also for Windows Phone?
  • A: No comment.

What´s next?

Microsoft gave out feedback questions. Within this feedback questions we were asked whether we plan to develop Metro styled apps. If so, we should describe what app we are planning to. Microsoft will contact us developers before events which are suitable for our app ideas.

I tried to keep this post as short as possible. If you have any questions, do not hesitate to post a comment below.

Posted by msicc in Dev Stories, win8dev, 0 comments

Bing Maps SDK on Windows 8 (W8CP)

With the release of the Windows 8 Consumer Preview, it was only a matter of time that Microsoft releases some new SDKs to us developers. We are starting with the Bing Maps SDK.

Bing Maps SDK for Windows 8 Metro style apps

Screenshot (32)

Microsoft´s Bing Maps team released a new SDK for Windows 8. You can use the SDK free and unlimited during the preview period.

The new SDK supports Java by using the AJAX v7 controls, and provides all standard items like map types, pushpins, infoboxes and tile layers. Additionally there is now a venue Maps module. At the moment there are still some missing bits like directions, traffic and overlays. Your maybe previous used REST APIs will still work and help you to use more features. If you want to learn on an example, you can watch this site.

Of course you can also use C#, C++ or Visual Basic to create apps that are using the SDK. The SDK now supports client vendor rendering as well as full hardware acceleration.You can also use Aerial and  Bird´s eye view and traffic overlays  within you app. Some features are in this early stage US only. You can learn on an example on this MSDN page.

Getting started…

OC course, you need to download the SDK to get started overall:  http://visualstudiogallery.msdn.microsoft.com/0c341dfb-4584-4738-949c-daf55b82df58. You can also use the VS11 Extension Manager to download the SDK.

Secondly, you will net a special “Metro style  apps (BETA) key” to use the SDK within you apps. Get your key at www.bingmapsportal.com .

If you want to read a lot more about using Bing Maps within you Metro styled apps, head over to the documentation sites at MSDN.

Posted by msicc in Dev Stories, win8dev, 0 comments