23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

var tileContent = NotificationsExtensions.TileContent.TileContentFactory<br />

.createTileWideImageAndText01();<br />

tileContent.image.src = "ms-appx:///images/redWide.png";<br />

tileContent.image.addImageQuery = true;<br />

In all of these cases, the appended string will be of the form<br />

?ms-scale=&ms-contrast=&ms-lang=<br />

where is 80, 100, 140, or 180, is standard, black, or white, and is a<br />

BCP-47 language tag such as en-US, jp-JP, de-DE, and so forth. All of these are described on the<br />

Globalization and accessibility for tile and toast notifications in the documentation, including how to<br />

localize update text.<br />

Sidebar: PNG vs. JPEG Image Sizes<br />

When considering tile images for the larger 140% and 180% scales, the encoding you use for your<br />

images can make a big difference and keep them below the 200K size limit. As we saw in<br />

“Branding Your App 101” in Chapter 3, a wide tile at 180% is 558x270 pixels and a square is<br />

270x270 pixels. With the wide tile, a typical photographic PNG at this size will easily exceed 200K.<br />

I encountered this when adding tile support to Here My Am! in this chapter, where it makes a<br />

smaller version of the current photo in the local appdata folder and uses ms-appdata:///-local<br />

URIs in the tile XML payload. At first, I borrowed code from Scenario 10 of the App tiles and<br />

badges sample, as we’ve been working with here, to create a PNG from the img element using a<br />

temporary canvas and the blob APIs. This worked fine for a 270x270 tile image (a 180% scale that<br />

can be downsized), but for a 558x270 the file was too large. So I borrowed code from Scenario 3<br />

of the Simple Imaging sample to directly transcode the StorageFile for the current image into a<br />

JPEG, where the compression is much better and we don’t need to use the canvas. This code is in<br />

the transcodeImageFile function in pages/home/home.js, a routine that we’ll also rewrite in<br />

Chapter 17 using C# in a WinRT component.<br />

Such considerations are certainly important for services that handle the addImageQuery<br />

parameters for scale. For larger image sizes, it’s probably wise to stick with the JPEG format to<br />

avoid going over the 200K limit.<br />

Branding<br />

If you’re the kind of person who likes to read XML schema specs (like the Tile schema reference I<br />

pointed to a few moments ago), you might have noticed another attribute of the visual and binding<br />

elements called branding. This can be set to none, logo (the default), or name to indicate whether to<br />

include the app’s small logo or short name on the tile, both of which are provided in the app’s manifest.<br />

Scenario 5 of the App tiles and badges sample lets you play with these variations.<br />

584

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!