codefoster | May 2012
Jeremy Foster
@codefoster

Art Matters

by Jeremy Foster 31. May 2012 11:00

I'm in a Microsoft building today that I've not been in before. There are a lot of them since I'm a relatively new employee. This one houses a lot of the work that goes into the Windows Phone 7 operating system, and that's pretty cool.

I arrived early for my conference and decided to spend some time meandering. A 3rd floor native told me I should visit the Windows Phone design studio on the 2nd. The design studio looks like a bunch of art supplies, flowers, and rainbows blew up. It's very cool actually.

I'm a propeller head for sure, so it's important to me that a system functions correctly, but I want never to forget that art matters. It matters because it's human like your users. When I picked out my SCUBA gear, for instance, its ability to sustain my existence while I'm under water was certainly high on my priority list, but it was also an assumption for the most part. SCUBA gear wouldn't likely make it to the consumer shelf if it wasn't well tested. So I essentially set that aside and look for gear that I enjoy looking at - gear that makes me feel like  Navy Seal Ninja.

Know that your users are making the same assumptions that your application is going to function as it's intended, and they are going to choose it, keep it, and pay for it based on its art. Is it beautiful? Is it smooth like butter? Is it inspirational.

Tags: , , , , , , , ,

Windows 8 | Design

The Counter Principles of Metro Style Design

by Jeremy Foster 30. May 2012 10:36

Likely you’ve read the Metro style design principles, but you haven’t seen the counter principles yet (because I made them up). Here we go...

1. Show Shame in Mediocrity

To really show shame in mediocrity, just look at about 80% of the apps in any major app marketplace. These apps may get a users attention with a catchy title or a promise to solve some problem, but then they fail to add any value to anyone’s life. Even if they are not devoid of functional value they fail to provide any user joy.

  • Ignore the little things
  • Do something different in every little user interaction so you can keep them on their toes
  • Embrace chaos
  • Deviate slightly from the grid so the user knows something is wrong even though that can’t see it

2. Flow Like Peanut Butter

To be clear, peanut butter doesn’t flow. Even creamy peanut butter doesn’t flow. To meet this counter principle, perform actions synchronously, use while loops that peg the processor, and only use the UI thread.

  • Add some offset between the user’s finger and the registered touch point
  • No transitions or animations... all straight cuts
  • Add boring graphics and boring interactions.
  • Embrace lag and jitters

3. Be Faux Analog

It’s 2012, but give the user a solid 1994 experience by rendering an actual real-life scene and hope they’ll figure out which drawer their word processor is in. Even though there’s no actual need for a spiral binding, let’s add one. It’s nostalgic.

  • Show a desk or a lobby or some other loose analogy to your navigation model
  • Firmly draw your limits at real life paradigms and scenarios
  • Expand on the success of Microsoft Bob©

4. Do Less With More

Pack that screen. You have millions of pixels at your disposal. You can use some for navigation, some for commanding, and if there's room left over you can even include your user’s content.

  • Assure that users can orient themselves to your views within 7.5 minutes
  • Adhere to a strict 45 button limit per view
  • Give users a sense of adventure as they discover your application

5. Die Alone

  • Assume the user is only concerned with doing whatever it is that your app does.
  • Assume they don’t have friends to share your content with.
  • Assume they don’t need to find anything of your content
  • Assume the user what’s to do one thing at a time... always... ever... only

Tags: , , , , , , , , , , ,

Windows 8

I give you my word...

by Jeremy Foster 29. May 2012 12:38

I’m excited about what I just implemented. I’m always excited when I figure something out or learn something big. This one is big for me. Hopefully this post will add some value to your life as well.

First the problem statement...

Here’s what I wanted to do. I am working on a Windows 8 Metro app using HTML/JavaScript.

I have a data.js file that represents (for now, until I put the data in the cloud) my data service. I am loading data up from a roaming file that contains simple JSON data. Actually, is “simply JSON” redundant. JSON just IS simple, right?

My hub page then needs to make sure that the application data is loaded and then it needs to request some. I can’t just directly request the data as is though because it needs to be massaged into the right shape to back the hub view. My application has items of Type A and Type B and I need to essentially flatten that into a super type that my hub will represent in different groups.

So I need to fetch some data and it needs to happen in an async fashion.

I’ve consumed objects that follow the Promise pattern plenty, but here I need to create my own Promise and get all custom about when it is considered complete and what it returns as its payload.

So I have two methods that I need to make asynchronous: loadAppDataAsync() and getHubItemsAsync(). The former is internal to my data.js function, but the latter is “exposed” to the rest of the app using a WinJS.Namespace called “data”.

loadAppDataAsync

This method, as I said, is “internal” to my data.js file. That is, it’s defined inside the modular function that encapsulates everything on my data.js file and thus is not available anywhere else in the application. The purpose of the function is to read the applicationData.json file and populate some arrays with the results. Here’s the method definition...

function loadAppDataAsync() {
    return new WinJS.Promise(function (c, e, p) {
        if (loaded) c();
        else {
            appdata.roamingFolder.getFileAsync("applicationData.json")
                .then(function (file) {
                    Windows.Storage.FileIO.readTextAsync(file)
                        .then(function (content) {
                            //load the checklists
                            JSON.parse(content).checklists.forEach(function (i) {
                                checklists.push({
                                    title: i.title,
                                    template: i.template,
                                    description: i.description,
                                    backgroundImage: i.backgroundImage,
                                    items: i.items,
                                    type: "checklist"
                                });
                            });

                            //load the templates
                            JSON.parse(content).templates.forEach(function (i) {
                                templates.push({
                                    title: i.title,
                                    description: i.description,
                                    backgroundImage: i.backgroundImage,
                                    items: i.items,
                                    type: "template"
                                });
                            });
                        })
                        .then(function () { c();});
                });
        }
    });
}

I added the Async suffix to the method name because this method not only calls an async method, but also acts asynchronously itself. Here’s how that’s implemented.

If I just wanted to wrap up the getFileAsync method call, then I could simple return the result of that call, but I need to add a little bit of my own logic. I only want to make the getFileAsync call in the condition that my data has not already been loaded. So I return a new WinJS.Promise specifying its function (which receives complete, error, and progress attributes that I’ve called c, e, and p). In the function, if the data has already been loaded I call the complete method c (passing no attributes) immediately indicating that we’re done loading app data (because it’s already loaded). If the data has not been loaded, however, we have some work to do and we will not complete (by calling c) until we’re done with it (that’s why it’s in the .then).

This one is pretty simple. Let’s move on to the next method that we use to get the hub items after the application data has already been loaded. Here’s the code...

WinJS.Namespace.define("data", {
    getChecklists: function () { },
    getHubItemsAsync: function () {
        var hubItems = [];
        return new WinJS.Promise(function(c, e, p) {
            loadAppDataAsync()
                .then(function () {
                    checklists.forEach(function(cl) {
                         hubItems.push({
                             item: cl,
                             title: cl.title,
                             backgroundImage: cl.backgroundImage,
                             section: "My Checklists",
                             click: function (ev) {
                                  WinJS.Navigation.navigate("/html/checklistPage.html", { item: cl });
                             },
                             get subtitle() {
                                 return (cl.items.filter(function (i) { return i.checked; }).length / cl.items.length)
                                     + "% of " + cl.items.length + " items";
                             }
                         });
                    });
                    templates.forEach(function(t) {
                         hubItems.push({
                            item: t,
                            title: t.title,
                            backgroundImage: t.backgroundImage,
                            section: "My Templates",
                            click: function (ev) {
                                WinJS.Navigation.navigate("/html/template.html", { item: t });
                            },
                            get subtitle() { return t.items.length + " items"; }
                         });
                    });
                })
                .then(function () { c(hubItems); });
        });
    }
});

This one is defined in a Namespace so that we can call it from elsewhere in our app - namely from hub.js. What this method does is a little different from the former. Like before, we are returning a new Promise. Unlike before, after we populate our result (hubItems), we complete the promise with a result by calling c(hubItems).

Passing a value to the complete function makes that value available to the caller like this...

data.getHubItemsAsync().then(function(hubItems) {
    hubItems.forEach(function(i) { hubItemList.push(i); });
});

Simple, eh? That’s the way it’s supposed to be. I want to get then items and then I want to push each of the results into my WinJS.Binding.List (here called hubItemList).

Now the grid on my hub is bound to a List that gets populated with data after the application data has been loaded and after the getHubItemsAsync method has projected the application data to look how we want it to look.

Phew! This JavaScript stuff is pretty crazy. It’s pretty awesome though.

Happy promise keeping!

Tags:

Windows 8 | JavaScript

Update on ReSharper 7 EAP

by Jeremy Foster 28. May 2012 17:48

I opted out of the ReSharper 7 EAP beta for a little while just because it was throwing a lot of exceptions and I had to get some code written, but now I’m back and it appears they’ve made a lot of improvements to it. I am noticing a lot more support in JavaScript code in Windows 8 development, so that’s awesome.

Also, they made it work with VS 2005, 2008, and 2010. Although, if you’re still using VS2005, can I please ask you why? :)

Go here and  download the latest build now and try it out. ReSharper makes you more productive.

 

Tags:

ReSharper | Visual Studio | Windows 8

Long Weekend

by Jeremy Foster 25. May 2012 21:49

It's the long weekend!

Time to breath a sigh of relief and take some time off. If you're a tech head and love your job like me then it might be a bit of a discipline to shut down all the systems, unplug, and relax. But it's worth it.

Surely you've had this experience a hundred times... you are fighting a bug or a seemingly insurmountable technical issue and you feel like you must... just... keep... working. Then you finally give up and step away for some length of time. Upon returning to the issue then, you have it fixed in 10 minutes. That happens to me all the time. So much in fact that I've learned to just walk away and try again later. I think it's a good use of time.

Consider how productive you'll be upon returning from this long weekend then.

I guess if I'm blogging then I'm not unplugged, so here goes. Over and out.

Tags:

Productivity

iPazzPort Giveaway

by Jeremy Foster 25. May 2012 09:43

A what?! It’s an iPazzPort. I ordered one recently and I was sent two. Not a bad deal, but I really only need one, so I decided to give one away to one of my Twitter followers. It’s new in the box. Read on for details. First, what is it...

I have a media center PC. Actually, it’s just a PC that I hooked up to my 37” LCD TV and installed Windows 8 on. I like the start screen tiles on my tablet and my PC, but they’re awesome for a media PC too! I put all of my media related programs on the start screen and now it’s super easy to launch whatever I want.

The device...

Well, I had a little remote control for the PC, but it decided to quit working a few weeks ago, and my wife asked if I could find a good solution. I think I did!

I found and ordered this iPazzPort. On one side it’s a full Windows keyboard including the win key (which is important), arrow keys, and all of the symbols and function keys. Next to the keyboard are buttons to control a gyro mouse, so you can just swing the device around in the air to move your mouse. You can hit a key to switch mouse modes so that you can either hold it the long way or the short way (when you’re using the keyboard). Then if you flip the device over, it has a few basic television remote buttons that you can train with your real TV remote. Finally, there are buttons on the side that act as page up and down which comes in extremely handy for web browsing and such. It has a rechargeable battery, so you just plug it into your computers USB port every few days to charge it up.

The giveaway...

So I sent out a tweet. You can find it here. If you retweet that and follow me on Twitter then you’ll be entered to win. I’ll keep it open until Thursday, May 31. I’ll draw a winner at random on that day and announce them on this blog post and on Twitter by noon Pacific time. If you’re the lucky winner and you live in the United States, I’ll mail you the iPazzPort.

Tags:

Windows 8: Top 10 Reasons Why I Choose HTML5 Over XAML

by Jeremy Foster 23. May 2012 10:26

My colleague and friend Jerry Nixon recently wrote an article on the top 10 reasons why he chooses XAML over HTML5 and it begged me for a reply. Alas, here it is...

Following are the top 10 reasons why I’m in the HTML/CSS/JS space right now.

I should qualify. I completely adore C# and XAML. I geek out on the nuances of the C# language, lambda expressions give me joy, and LINQ is like dreams and starlight. But that’s not where I am right now. I’m moving on but not moving away. I want both bullets in my belt... the sheer power of C# and the wit and fancy of JavaScript.

More qualification. I love JavaScript and at the same time I hate JavaScript. Sometimes it makes me feel like a coding cowboy and other times like I’m in its gallows.

So here we go...

1. Skill Ready

I and about a kazillion other people in the world have gathered a ton of experience on the HCJ stack. Websites became applications as some point, and they became essential in the enterprise. I would guess that the web stack has drastically more developers than any other stack... but that’s a guess.

2. Triptych

HTML, CSS, and JavaScript form what I like to call the happy triptych. Instead of separating code into two roles, HCJ has three. HTML defines the structure, CSS defines the layout and style, and JavaScript defines the logic. This makes things like modifying the layout and style for different view states or devices as simple as swapping out the style sheet.

3. Dynamic

I know that C# has the DLR and I’ve used it in numerous real scenarios, and it’s some awesome functionality added to the language. JavaScript, however, is truly dynamic. If I want to add a property to my app like lastLaunched, I just type app.lastLaunched = “5/1/2012” and voila I have a new property. If I want to add a function called detectLastLaunched, I just type app.detectLastLaunched = function() { ... }. That’s way cool.

4. JSON

JavaScript has JSON. I know that C# can speak JSON too, but not like JavaScript. JavaScript and JSON go together like peas and carrots.

5. Light

JavaScript is light. Super light. The absence of some of C#’s heavy artillery (I’m thinking polymorphism, inheritance, type safety, etc.) leaves it light and agile. The fancier things like inheritance and even asynchronicity are implemented as patterns instead of as language features. This means they’re not baked in so they can be adapted to suit.

I was newing up some sample data in both languages the other day. I had to declare all of my types in C# and then even with object and collection initializers, the code to create the sample data was quite large and repetitive. In JavaScript on the other hand, it’s a matter of declaring a variable and setting it with very terse object initializer syntax... thing of beauty.

Just compare the default Metro style Grid Application in XAML/C# and then in HTML/JS and you’ll see how light JavaScript is.

 

6. Libraries

Again, there are a ton of web stack developers out there and consequently there are a ton of web stack libraries and helpers. Bing something like “javascript face detection” and you’ll find an open source library that’s ready to go. Glance at microjs.com to see what I mean about JavaScript library support.

7. Query Selection

In XAML, it’s easy enough to give a control an ID and then select it in the code. But how do you select all of every third paragraph, the third element in the grid, or something like that. The answer is imperative code. There’s no part of the object model that you can’t access, but with query selectors in CSS and JS, you can use simple strings like “div#myDiv p:nth-child(3n)” to select every third paragraph in the div with the ID of myDiv.

8. CSS

CSS is amazing. With a collection of style rules, I can style, animate, layout, add images, position things, and a ton more. With declarative CSS code I can make the same HTML view look entirely different. Style rules cascade down to the eventual screen element and allow a developer to set a style globally and then override that style locally given the need.

There’s a JS library called LESS that extends CSS’s capabilities and allows me to set style variable and even do variable math. So I can set the base color of my app to red and then create a number of derived colors (darker or lighter for instance). That way, the change of a single color variable will result in a complete change to my app’s color palette.

9. Blend

The nature of HTML/JS apps means that Blend for Visual Studio can dynamically execute the application while you’re designing it. Expression Blend (the XAML designer for classic Windows apps, Silverlight, Windows Phone, etc.) has some robust support for sample data and designer data because it’s not able to drag in the application data at runtime. With Blend, however, when working on a Metro style app using JavaScript, the entire need for sample data goes away. Instead, you look at your real app data... even if you’re pulling it down from the sky (I’m a little tired of the word cloud, so I choose to use the word sky).

10. Name

I live in Seattle. I drink coffee. Fancy coffee. The people that make coffee in this town are insane about their technique, the quality of their bean, and the nanosecond precision of their brew pull. So I’m enjoying JavaScript because it goes so well with the french press of Ecuadorean joe I hold before me.

Sorry, C#. Your name is sharp, but it’s so technical and boring compared to JavaScript.

Nail. Coffin. JavaScript wins hands down! Oh, whatever. It’s all in fun.

Tags: , , , , , ,

C# | CSS | JavaScript | Windows 8 | XAML

Windows 8: Building Up to Blank

by Jeremy Foster 22. May 2012 11:51

When you’re learning a new platform or development stack or seeing something for the first time, it’s an exercise in concept building. If you don’t get the concepts down then you may as well be a monkey walking through steps. And sometimes when you start with a project template, so much has been done for you that grasping concepts involves separating what is fundamental to the technology and what has been done for you by the tooling.

I’m not one to throw the tools and templates out the window. Once you get the concepts down they’re awfully handy. But let’s throw them away temporarily while we learn the concepts and then we’ll run out to the curb before the garbage guy gets here and retrieve them.

I’m going to use Visual Studio 11 (Consumer Preview) and start with a truly blank HTML/JavaScript project and work us up to the blank project - that is - work us up to the project template that you get with VS11, which although it’s called blank is not quite.

Here we go...

Start with the blank template... then kill it...

Open VS11. Create a new Windows Metro Style JavaScript project using the Blank Application template.

Here’s what your Solution Explorer should look like...

image

Notice that you already have a bunch of stuff. So let’s kill it. Delete everything in there except for the images folder (because we’d just have to recreate those anyway). Also, go to the References folder and remove the reference to Microsoft Windows Library for JavaScript SDK.

Your Solution Explorer should now look like this...

image

Ah... clean slate. That’s better. Now it’s time to get started.

Add a default.html file

If you’re going to make an HTML application, you’re going to need an HTML file for sure. So right click on your project and choose Add New Item, then choose a simple, old, plain, no frills, basic, classic HTML file. Actually, it will be HTML5 so I guess that’s not so classic yet. Call it default.html and be done with it.

Type “Hello, World!” inside the body and you should have something like this...

image

At this point, it seems the app would be executable, but if you try you’ll get a message that you’re required to have an application manifest file. That’s one of the few ways in which an HTML/JS app in Metro is different from a website. So we’ll add that now.

Add an application manifest file...

Add a new blank XML file to your project. Call it package.appxmanifest.

There are a few things required in this file. Let’s enumerate.

Below the XML declaration add the Package element...

<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
</Package>

Then inside the Package element add...

<Identity
    Name="dfc9ddf8-dde8-4460-8967-1dbb70b653fa"
    Version="1.0.0.0"
    Publisher="CN=Jeremy" />

The Name value is a unique identifier for your application. You should be safe using the GUID from my example above since I don’t have any plans of publishing this application to the store :) Obviously you can put your name in there as the publisher.

Then add this after the Identity element...

<Properties>
    <DisplayName>Application1</DisplayName>
    <Description>Application1</Description>
    <PublisherDisplayName>Jeremy</PublisherDisplayName>
    <Logo>images\storelogo.png</Logo>
</Properties>
<Prerequisites>
    <OSMinVersion>6.2</OSMinVersion>
    <OSMaxVersionTested>6.2</OSMaxVersionTested>
</Prerequisites>
<Resources>
    <Resource Language="x-generate" />
</Resources>

You can imagine what each of these elements does, so I won’t bore you with the details.

The next section is more interesting. Add this...

<Applications>
    <Application Id="App" StartPage="default.html">
        <VisualElements
            DisplayName="Application1"
            Logo="images\logo.png"
            SmallLogo="images\smalllogo.png"
            Description="Application1"
            ForegroundText="light"
            BackgroundColor="#000000">
        <DefaultTile ShowName="allLogos" />
        <SplashScreen Image="images\splashscreen.png" />
        </VisualElements>
    </Application>
</Applications>

This is almost entirely intuitive, so I won’t explain. Notice all the links to the images that I had you leave in the project.

Finally, add...

<Capabilities>
    <Capability Name="internetClient" />
</Capabilities>

... which declares a single capability - internetClient. This capability declares that this app will want to be able to access the internet. Without it, HTTP calls outside the application would be blocked. In this blank app, we don’t actually need to access internet, but we’ll leave this in there since the blank project template does.

That’s it for the package.appxmanifest file.

Now try running your app! You should see Hello World on a big white screen. Exciting isn’t it. You have two files in your project and already you have a working, albeit boring application.

Let’s keep moving though and work up to what the blank project template offers. It’s not a lot further we have to go.

Sign your application...

The blank template contains a .pfx file. That is a Personal Information Exchange file that allows for release signing. To generate it double click on your package.appxmanifest file. Then go to the Packaging tab. Then hit Choose Certificate next to the Publisher field. Then I just chose to create a test certificate. As you can see the .pfx file is automatically created for you.

Here’s a snapshot of your Solution Explorer again...

image

Add the WinJS styles and scripts to make it a Metro app...

Our app runs and shows “Hello, World!”, but it looks more like a web page than like a Windows 8 Metro style app. We just need to bring in some script and style sheet references in order to make this look and act like a Metro app. Those references are inside of the WinJS library package. To add a reference to that package, just right click on References and Add Reference. Under Extensions, you’ll see Microsoft Windows Library for JavaScript SDK (at version 0.6.0.0 as of this post). Add that.

There are three references we want to make.

  1. ui-dark.css - gives us the black background color, white foreground color, and a lot of Metro style rules
  2. base.js - gives us a lot of core functionality in WinJS like classes and namespaces and such
  3. ui.js - gives us a ton of UI functionality like animations and visibility control

Keep in mind that these dependencies are not entirely necessary. If you bring a web application into Metro it obviously won’t have them and it won’t need them until the first time you want to use something from WinJS. In fact you can still even call into the WinRT without these references, but if you’re making an application for Windows 8. then you probably want to use WinJS. There’s no real reason not to.

To add references to these three files, here’s what we do. Just add these three lines inside the <head> element of your default.html file...

<link href="//Microsoft.WinJS.0.6/css/ui-dark.css" rel="stylesheet">
    <script src="//Microsoft.WinJS.0.6/js/base.js"></script>
    <script src="//Microsoft.WinJS.0.6/js/ui.js">
</script>

Note that the values for the href and src attributes start off with “//”. If you leave the scheme off of the URL here then the assumed scheme is “ms-appx” which means “this package”. So “//” is equivalent to “ms-appx://”. Then when specifying the domain, you have the option of using the name of a package (in this case “Microsoft.WinJS.0.6”). So these lines are referring to the ui-dark.css, base.js, and ui.js files from the WinJS package.

Now run your application and note that it looks very Metro indeed.

Add your own style and script files and references...

If you are going to style anything on the default.html page, you’ll need a style sheet. By convention, we put the .css files into a css folder and we create one for each page. So let’s create a css folder and create a default.css file in it. Also, you’re going to want to write some JavaScript as well. Again, by convention we put .js files into a js folder and create one for each page. So we’ll also create a js folder and create default.js in it. Here we are...

image

The CSS style sheet that we created came with a single style tag for the body. The blank template has something more, so lets add and explain. Add this to the default.css after the body style rule...

@media screen and (-ms-view-state: fullscreen-landscape) {
}

@media screen and (-ms-view-state: filled) {
}

@media screen and (-ms-view-state: snapped) {
}

@media screen and (-ms-view-state: fullscreen-portrait) {
}

These are called media queries, and they are super nice. Media queries allow us to specify different styles for the different view states our application might be in. If you can control the look and layout of your app with CSS alone, then you don’t even need to write any code for when the user rotates his tablet or snaps your app. There is an event for when the layout changes, however, for when you need to write code.

We’ll need  references to our new .css and .js files in default.html too. Adding this to the <head> element (under where you have the WinJS references) should do it...

<link rel="stylesheet" type="text/css" href="css/default.css" />
<script type="text/javascript" src="js/default.js"></script>

Write the application lifecycle and event script...

The last thing we need to do is write some JavaScript to handle the basic application lifecycle and events. We don’t have a separate App entity in HTML/JS like you would have in a XAML/C# app. Instead, this logic goes into the default.js file and it’s quite simple. We’ll take it one step at a time.

First, open default.js. It’s completely empty. Here’s a snapshot of what a completely empty file looks like...

image

Nice, eh? Like a polar bear in a snow storm.

Now, in order to stick with a fundamental JavaScript pattern called the modular pattern, we’re going to start by writing an anonymous function...

function() {}

This function has no name. That’s why we call it anonymous. And so far its body is empty. We want the code in this function to execute though. We don’t want to just declare a function. We want it to go. So we do this...

(function() {

})();

Note that we have simply wrapped the function in parentheses and then put a football (the two calling parentheses) at the end... plus a semicolon for good measure. This effectively declares and calls our function all at once. Actually, first it declares it and then it calls it.

The reason we do this (and this is why the modular pattern exists) is because then the stuff we do inside our function is scoped to the function. If we declare a variable, it is only available inside that function. This is good because otherwise any other part of the application (including 3rd party libraries you might want to bring in) that tried to use the same variable name would have a collision and would get really angry.

One more thing we add is a “use strict” directive to tell Visual Studio we want a little help making sure we don’t accidentally to silly JavaScript wizardry like use a variable we having yet declared or the like. Here’s that...

(function() {
    "use strict";

})();

Inside that function now, we want to handle some application events. The blank template actually defines just two, but I’m going to do a third for your benefit.

We’re going to be referring to the application by using WinJS. We do that by using WinJS.Application. But we don’t want to have to type that out every time, so we can effectively give it an alias by adding...

var app = WinJS.Application;

Now we can just use app instead of the whole thing. I guess you could sort of compare it to a using in C# except that it doesn’t import a namespace. It only gives one an alias.

We’re ready to write our application events. These go inside the function we’ve been talking about...

app.onactivated = function (eventObject) {

};

app.oncheckpoint = function (eventObject) {

};

app.onready = function (eventObject) {

};

You can probably guess about onactivated and onready. onactivated fires when the app is started from scratch or when it revived from a suspended state. onready fires whenever you request the default page. And then we need to add one more line...

app.start();

This... um... well, it starts the app. :)

So all together, you’re default.js should look like this...

(function() {
    "use strict";

    var app = WinJS.Application;
    app.onactivated = function (eventObject) {

    };

    app.oncheckpoint = function (eventObject) {

    };

    app.onready = function (eventObject) {

    };

    app.start();
})();

And if you want to test the onready event for instance, try adding this line inside...

new Windows.UI.Popups.MessageDialog("ready").showAsync();

The blank application further breaks down the onactivated event with this code...

var a = Windows.ApplicationModel.Activation;

if (eventObject.detail.kind === a.ActivationKind.launch) {
    if (eventObject.detail.previousExecutionState !==
        a.ApplicationExecutionState.terminated) {
        // TODO: This application has been newly launched. Initialize
        // your application here.
    }
    else {
        // TODO: This application has been reactivated from suspension.
        // Restore application state here.
    }

    WinJS.UI.processAll();
}

Actually, I added the var a = ... there just to make it shorter, but the point here is to detect whether the application is being launch anew or resuscitated.

And there you have it. You should now be at the functional equivalent of the blank application, but you’ve done it all yourself. You can’t claim ninja status yet, but you can have a yellow belt.

Copyright (c) Microsoft. All rights reserved. The code provided in this post is licensed under the MS-Limited Public License

Tags:

Windows 8

Good Design for App Bar Button Placement

by Jeremy Foster 21. May 2012 08:44

I’ve watched a few developers port their existing apps over to Windows 8.

The first thing they do is drop all of their UI into their new app and run it to see it work. It’s nice to see things work, but Windows 8 is more than just a new API for accessing modern computer hardware. It’s a completely new design for user experience as well. So after you drop all of your buttons into your new app and see it work, you should migrate most of those buttons to the app bar.

The app bar, for the uninitiated, is the bar that slides up from the bottom of the screen whenever the user swipes up from off screen (and sometimes it appears all on its own). That app bar is nice. It avoids bothering the user by appearing only when the user requests it.

Here are some questions that developers raise when they’re learning to design and develop for Windows 8...

  1. Why can’t I put my buttons on the screen like I always have?
  2. Okay, fine, but which buttons should I put in the app bar and which should remain on the canvas?
  3. Do I put the buttons on the left, the right, or what?
  4. What if they don’t all fit?
  5. How do I control when buttons appear?

I’ll take these one at a time...

Why can’t I put my buttons on the screen like I always have?

It’s because it’s 2012 now! The modern trend has been to cram as much information into a user’s screen as possible, but we’ve had enough! When I see so may things I cease to see anything. It’s time to take a step back, take a deep breath, and think about what the user is actually doing right now and dedicate every pixel on the screen to it, immersing the user.

Look at the website versus the Metro versions of the Times of India...

image

image

Most of the space in the website version is taken up with navigation commands (hyperlinks), which is a good example of an app telling you about “where you might go” instead of telling you where you are and letting the user navigate with the content.

Okay, fine, but which buttons should I put in the app bar and which should remain on the canvas?

First off, most of the buttons should be in the app bar. It won’t take long for a user to learn that that’s where the interactions are and start to swipe that bar up automatically. Since the app bar is hidden at first (usually), many wonder if their command won’t be apparent enough to the user. Keep in mind, however, that when a user draws up the app bar, they are specifically searching for a command. It takes away the need for discoverability and arguably makes your command more apparent - not less.

Some buttons should be on the canvas though. You would decide to put a button on the canvas when it’s part of the workflow a user is traversing. A case could be made that the workflow itself is the content at that point. If I’m adding products to my cart and checking out, I’m not here to browse content anymore. I’m engaged in the purchasing workflow. If you’re a retailer making a Windows 8 app, I would recommend that you diligently immerse the user in your products and their supporting media to make them love the browsing experience. Then when they decide to checkout, transition them to a slightly more utilitarian mode with canvas buttons and progress feedback.

Do I put the buttons on the left, the right, or what?

In general, the right side is for global commands, and the left side is for contextual commands. There are exceptions, however.

Global commands are those that apply to the entity represented by the current page. If you’re on the friend page, then add to favorites is a global command because it applies to the friend.

Contextual commands are those that apply to the entity or entities the user has selected. If you’re on the my friends page, then add to favorite is going to require that you swipe select one or more friends and would then be a contextual command.

One exception to this is when you don’t have any (and aren’t going to have any) contextual commands because you have nothing for the user to select. In this case, the entire app bar can be dedicated to global commands and the left and right sides should be used to separate the most disparate functions. You could, for instance, put your filtering commands on the left and your sort commands on the right.

What if they don’t all fit?

If you have more commands then you have app bar, then go vertical by combining commands into menus. For instance, if this is what you have on your app bar...

image

...then combine all of your filters into one menu and your sorts into another. That would bring 9 buttons down to only 4!

How do I control when buttons appear?

If you’re using HTML/JavaScript for your app, the recommended way to add app bar buttons and control when they appear is to declare them all on the default.html file and then in the .js file for each page just control their visibility. This avoids having to manipulate the DOM each time a page is loaded. There are easy functions for doing this such as...

appbar.showOnlyCommands(["add-template-item","delete-global"]);

If you’re using XAML/C# then (from what Jerry Nixon tells me), you will actually create the app bar buttons on the page where they’ll appear.

Finally, don’t forget to account for snap view. When your app is snapped, you only have room for 5 app bar command buttons. If you have more then they will wrap up to a second row and it will look funny and your users will laugh at you. And that’s not the response you’re likely looking for.

Happy commanding!

Tags:

Windows 8

App Accelerator Resources

by Jeremy Foster 17. May 2012 16:44

To everyone who joined @mjconnection and I (@codefoster) at the Windows 8 App Accelerator the last 3 days, thanks for bringing all the energy, questions, and app ideas! I know I had a great time.

I promised everyone that I would provide a list of resources that we brought up in class. If you think of any more that I missed, feel free to leave it in a comment and I’ll merge it into this list.

Keep me posted on the progress of your apps!

Metro Tile Sources

The Noun Project  - this is a great collection of icons that represent things… you know nouns
Icon Finder  - find icons on the web and get either the PNG or the ICO file
Icons8.com - a cache of free glyphs that work well with Windows 8 Metro style tiles and art
The XAML Project  - more
SyncFusion Metro Studio - more
http://raphaeljs.com/icons/ - more

Visual Studio Add-Ins

Debugger Canvas  - use this to visualize your code and your call stack while you’re debugging. It even supports visualization of multi-threaded stacks and recursive functions.
Bug Aid  - some more great help visualizing C# entities while you’re debugging
ReSharper 7 EAP - perhaps the biggest source of developer joy you can ask for

Art Tools

Inkscape.com - this is an awesome vector based graphics tool. If you’re still using a bitmap based image editing tool for generating app art, you should stop in your tracks and learn to use vector.
Kuler - a color palette picker.
ColourLovers.com   - again
colorschemedesigner.com - again

App Stats

None of these support Windows 8 yet of course, but they were mentioned in class so I thought I should include them…

App Annie
Distimo

Other

txt2re.com 

Tags:

Windows 8

Feed Subscribe