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.

function pinSecondaryTile() {<br />

var Scenario1TileId = "SecondaryTile.Logo";<br />

var uriLogo = new Windows.Foundation.Uri(<br />

"ms-appx:///images/SecondaryTileDefault-sdk.png");<br />

var uriSmallLogo = new Windows.Foundation.Uri(<br />

"ms-appx:///images/smallLogoSecondaryTile-sdk.png");<br />

// Create activation arguments...<br />

var currentTime = new Date();<br />

var newTileActivationArguments = Scenario1TileId + " WasPinnedAt=" + currentTime;<br />

var tile = new Windows.UI.StartScreen.SecondaryTile(Scenario1TileId,<br />

"Title text shown on the tile",<br />

"Name of the tile the user sees when searching for the tile",<br />

newTileActivationArguments,<br />

Windows.UI.StartScreen.TileOptions.showNameOnLogo, uriLogo);<br />

// Setting other options<br />

tile.foregroundText = Windows.UI.StartScreen.ForegroundText.dark;<br />

tile.smallLogo = uriSmallLogo;<br />

var selectionRect = document.getElementById("pinButton").getBoundingClientRect();<br />

}<br />

tile.requestCreateForSelectionAsync(<br />

{ x: selectionRect.left, y: selectionRect.top, width: selectionRect.width,<br />

height: selectionRect.height },<br />

Windows.UI.Popups.Placement.below)<br />

.done(function (isCreated) {<br />

if (isCreated) {<br />

// The tile was successfully created<br />

} else {<br />

// The tile was not created<br />

}<br />

});<br />

Note As mentioned in Chapter 7, the system flyout displayed when creating a secondary tile (and when<br />

removing it, see “Managing Secondary Tiles” below), will cause the app to lose focus and will dismiss a<br />

nonsticky app bar as a result. For this reason, Scenario 7 of the Secondary tiles sample keeps the app<br />

bar visible by setting its sticky property to true before calling the secondary tile API.<br />

App Activation From a Secondary Tile<br />

Secondary tiles provide a way to activate an app to something other than its default state, similar to<br />

how command-line arguments work with desktop or console apps. This process depends entirely on the<br />

contents of the secondary tile’s arguments property. When a secondary tile is tapped or clicked, the<br />

app’s activated event is fired with an activation kind of launch and the tile’s arguments value in<br />

eventArgs.detail.arguments. The app then takes whatever action is appropriate for that data, such as<br />

navigating to a particular page of content, retrieving a piece of content from an online source, and so<br />

on. In the Secondary tiles sample, the activation code in js/default.js navigates to its Scenario 5 page,<br />

where we pass arguments as the options parameter of WinJS.Navigation.navigate:<br />

574

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

Saved successfully!

Ooh no, something went wrong!