diff --git a/README.md b/README.md index 4b4ce0dc1f..c7dcb16c91 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ + + # Universal Windows app samples This repo contains the samples that demonstrate the API usage patterns for the Universal Windows Platform (UWP) in the Windows Software Development Kit (SDK) for Windows 10. These code samples were created with the Universal Windows templates available in Visual Studio, and are designed to run on desktop, mobile, and future devices that support the Universal Windows Platform. @@ -84,15 +88,16 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github. Basic face tracking + Playlists Simple imaging - Spatial audio + Spatial audio System media transport controls Transcoding media - Video playback + Video playback Windows audio session (WASAPI) Windows media import @@ -314,15 +319,16 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github. Application resources and localization + Date and time formatting Japanese phonetic analysis - Language font mapping + Language font mapping Linguistic services Number formatting and parsing - Text segmentation + Text segmentation Text suggestions Unicode string processing @@ -332,18 +338,19 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github. Graphics and animation + Animated GIF (XAML) + Animation library (HTML) Animation metrics + + Direct2D custom image effects Direct2D gradient mesh + Efficient animations (HTML) - HTML animation library Transform3D animations Transform3D parallax - - Efficient HTML animations - diff --git a/Samples/Accelerometer/README.md b/Samples/Accelerometer/README.md index fc88df7d5c..c294292611 100644 --- a/Samples/Accelerometer/README.md +++ b/Samples/Accelerometer/README.md @@ -1,5 +1,6 @@  # Accelerometer sample diff --git a/Samples/Accelerometer/cpp/Accelerometer.vcxproj b/Samples/Accelerometer/cpp/Accelerometer.vcxproj index 06afcf347e..efa0c1e474 100644 --- a/Samples/Accelerometer/cpp/Accelerometer.vcxproj +++ b/Samples/Accelerometer/cpp/Accelerometer.vcxproj @@ -146,19 +146,19 @@ - Scenario1_DataEvents.xaml + ..\shared\Scenario1_DataEvents.xaml - Scenario2_ShakeEvents.xaml + ..\shared\Scenario2_ShakeEvents.xaml - Scenario3_Polling.xaml + ..\shared\Scenario3_Polling.xaml - Scenario4_OrientationChanged.xaml + ..\shared\Scenario4_OrientationChanged.xaml - Scenario5_DataEventsBatching.xaml + ..\shared\Scenario5_DataEventsBatching.xaml @@ -168,11 +168,11 @@ Designer - - - - - + + + + + Styles\Styles.xaml @@ -199,19 +199,19 @@ - Scenario1_DataEvents.xaml + ..\shared\Scenario1_DataEvents.xaml - Scenario2_ShakeEvents.xaml + ..\shared\Scenario2_ShakeEvents.xaml - Scenario3_Polling.xaml + ..\shared\Scenario3_Polling.xaml - Scenario4_OrientationChanged.xaml + ..\shared\Scenario4_OrientationChanged.xaml - Scenario5_DataEventsBatching.xaml + ..\shared\Scenario5_DataEventsBatching.xaml diff --git a/Samples/Accelerometer/cpp/Accelerometer.vcxproj.filters b/Samples/Accelerometer/cpp/Accelerometer.vcxproj.filters index dbb5bd5576..9c425d626b 100644 --- a/Samples/Accelerometer/cpp/Accelerometer.vcxproj.filters +++ b/Samples/Accelerometer/cpp/Accelerometer.vcxproj.filters @@ -53,11 +53,11 @@ - - - - - + + + + + Styles diff --git a/Samples/Accelerometer/cpp/Package.appxmanifest b/Samples/Accelerometer/cpp/Package.appxmanifest index 7302b04421..b337dcb817 100644 --- a/Samples/Accelerometer/cpp/Package.appxmanifest +++ b/Samples/Accelerometer/cpp/Package.appxmanifest @@ -7,14 +7,14 @@ IgnorableNamespaces="uap mp"> - AccelerometerCPP + Accelerometer C++ Sample Microsoft Corporation Assets\StoreLogo-sdk.png @@ -30,12 +30,12 @@ + EntryPoint="Accelerometer.App"> diff --git a/Samples/Accelerometer/cs/Accelerometer.csproj b/Samples/Accelerometer/cs/Accelerometer.csproj index ce818bc4f2..acdee0a749 100644 --- a/Samples/Accelerometer/cs/Accelerometer.csproj +++ b/Samples/Accelerometer/cs/Accelerometer.csproj @@ -7,8 +7,8 @@ {DC30CE66-DAEE-4CCF-BD02-8837FE918B6F} AppContainerExe Properties - AccelerometerCS - AccelerometerCS + SDKTemplate + Accelerometer en-US UAP 10.0.10240.0 @@ -125,23 +125,28 @@ MSBuild:Compile Designer - + + Scenario1_DataEvents.xaml MSBuild:Compile Designer - + + Scenario2_ShakeEvents.xaml MSBuild:Compile Designer - + + Scenario3_Polling.xaml MSBuild:Compile Designer - + + Scenario4_OrientationChanged.xaml MSBuild:Compile Designer - + + Scenario5_DataEventsBatching.xaml MSBuild:Compile Designer diff --git a/Samples/Accelerometer/cs/Package.appxmanifest b/Samples/Accelerometer/cs/Package.appxmanifest index c24cea491e..87dad868ec 100644 --- a/Samples/Accelerometer/cs/Package.appxmanifest +++ b/Samples/Accelerometer/cs/Package.appxmanifest @@ -7,7 +7,7 @@ IgnorableNamespaces="uap mp"> @@ -15,7 +15,7 @@ - AccelerometerCS + Accelerometer C# Sample Microsoft Corporation Assets\StoreLogo-sdk.png @@ -31,12 +31,12 @@ + EntryPoint="Accelerometer.App"> diff --git a/Samples/Accelerometer/cs/SampleConfiguration.cs b/Samples/Accelerometer/cs/SampleConfiguration.cs index cb1dff2671..6889a33f13 100644 --- a/Samples/Accelerometer/cs/SampleConfiguration.cs +++ b/Samples/Accelerometer/cs/SampleConfiguration.cs @@ -12,21 +12,20 @@ using System; using System.Collections.Generic; using Windows.UI.Xaml.Controls; -using AccelerometerCS; namespace SDKTemplate { public partial class MainPage : Page { - public const string FEATURE_NAME = "AccelerometerCS"; + public const string FEATURE_NAME = "Accelerometer"; List scenarios = new List { - new Scenario() { Title = "Data events", ClassType = typeof(AccelerometerCS.Scenario1_DataEvents) }, - new Scenario() { Title = "Shake events", ClassType = typeof(AccelerometerCS.Scenario2_ShakeEvents) }, - new Scenario() { Title = "Polling", ClassType = typeof(AccelerometerCS.Scenario3_Polling) }, - new Scenario() { Title = "OrientationChange", ClassType = typeof(AccelerometerCS.Scenario4_OrientationChanged) }, - new Scenario() { Title = "Data events batching", ClassType = typeof(AccelerometerCS.Scenario5_DataEventsBatching)} + new Scenario() { Title = "Data events", ClassType = typeof(Scenario1_DataEvents) }, + new Scenario() { Title = "Shake events", ClassType = typeof(Scenario2_ShakeEvents) }, + new Scenario() { Title = "Polling", ClassType = typeof(Scenario3_Polling) }, + new Scenario() { Title = "OrientationChange", ClassType = typeof(Scenario4_OrientationChanged) }, + new Scenario() { Title = "Data events batching", ClassType = typeof(Scenario5_DataEventsBatching)} }; } diff --git a/Samples/Accelerometer/cs/Scenario1_DataEvents.xaml b/Samples/Accelerometer/cs/Scenario1_DataEvents.xaml deleted file mode 100644 index 3dfa10c9be..0000000000 --- a/Samples/Accelerometer/cs/Scenario1_DataEvents.xaml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - +

+

+ + + diff --git a/Samples/DateTimeFormatting/js/html/scenario2-stringTemplate.html b/Samples/DateTimeFormatting/js/html/scenario2-stringTemplate.html new file mode 100644 index 0000000000..0a9292fcc7 --- /dev/null +++ b/Samples/DateTimeFormatting/js/html/scenario2-stringTemplate.html @@ -0,0 +1,31 @@ + + + + + + + +

+

Description:

+
+

+ Formats the current date and time using + custom formats that are specified using a template string. + This can be used when the requirements for the + date presentation do not match the “short” or “long” form. +

+

+ For example, if the app requires only a month and a day + or a month and a year, + or needs to combine date and times with time zone information, + this method allows the app to present only those date elements + in a format that respects the user's preferences. +

+
+

+ +

+

+

+ + diff --git a/Samples/DateTimeFormatting/js/html/scenario3-parameterizedTemplate.html b/Samples/DateTimeFormatting/js/html/scenario3-parameterizedTemplate.html new file mode 100644 index 0000000000..fbcf7381ff --- /dev/null +++ b/Samples/DateTimeFormatting/js/html/scenario3-parameterizedTemplate.html @@ -0,0 +1,36 @@ + + + + + + + +
+

Description:

+
+

+ Formats the current date and time using + custom formats that are specified using a parameterized template. + This + method for formatting dates or times can be used when the requirements + for the date presentation do not match the "short" or "long" form. For + example, if the app requires only a month and a day or a + month and a year, this method allows the app to present only + those date elements in a format that respects the user's + preferences. +

+

+ By default the dates and times are formatted + according to the conventions of the current application language. + (In the case of this sample, only a single default language is supported.) + For a localized application, + the current language is determined by the user's language preferences. +

+
+

+ +

+

+

+ + diff --git a/Samples/DateTimeFormatting/js/html/scenario4-override.html b/Samples/DateTimeFormatting/js/html/scenario4-override.html new file mode 100644 index 0000000000..2286715b30 --- /dev/null +++ b/Samples/DateTimeFormatting/js/html/scenario4-override.html @@ -0,0 +1,25 @@ + + + + + + + +
+

Description:

+
+

+ Formats dates and times by overriding the + user's default global context. This method is used when an app + presents dates or times that reflect + settings different from the user's current defaults. You can + specifying overrides for language(s), region, clock, and calendar. +

+
+

+ +

+

+

+ + diff --git a/Samples/DateTimeFormatting/js/html/scenario5-unicodeExtensions.html b/Samples/DateTimeFormatting/js/html/scenario5-unicodeExtensions.html new file mode 100644 index 0000000000..914159ca9b --- /dev/null +++ b/Samples/DateTimeFormatting/js/html/scenario5-unicodeExtensions.html @@ -0,0 +1,26 @@ + + + + + + + +
+

Description:

+
+

+ Format dates and times by using Unicode + extensions in specified languages, overriding the user’s default global + context if applicable. This method is used when an app + presents dates or times that reflect different + settings from the user’s current defaults by specifying the overrides + directly as extensions in language tags. +

+
+

+ +

+

+

+ + diff --git a/Samples/DateTimeFormatting/js/html/scenario6-timeZone.html b/Samples/DateTimeFormatting/js/html/scenario6-timeZone.html new file mode 100644 index 0000000000..fa8017d137 --- /dev/null +++ b/Samples/DateTimeFormatting/js/html/scenario6-timeZone.html @@ -0,0 +1,22 @@ + + + + + + + +
+

Description:

+
+

+ Converts and formats the current date and + time using the time zone support available in the Format method. +

+
+

+ +

+

+

+ + diff --git a/Samples/DateTimeFormatting/js/images/placeholder.txt b/Samples/DateTimeFormatting/js/images/placeholder.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Samples/DateTimeFormatting/js/js/sample-configuration.js b/Samples/DateTimeFormatting/js/js/sample-configuration.js new file mode 100644 index 0000000000..fd0cbf42b2 --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/sample-configuration.js @@ -0,0 +1,58 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var sampleTitle = "Date and time formatting"; + + var scenarios = [{ + url: "/html/scenario1-longAndShortFormats.html", + title: "Format date and time using long and short" + }, { + url: "/html/scenario2-stringTemplate.html", + title: "Format using a string template" + }, { + url: "/html/scenario3-parameterizedTemplate.html", + title: "Format using a parameterized template" + }, { + url: "/html/scenario4-override.html", + title: "Override the current user's settings" + }, { + url: "/html/scenario5-unicodeExtensions.html", + title: "Formatters using Unicode extensions" + }, { + url: "/html/scenario6-timeZone.html", + title: "Format using different time zones" + }]; + + function clearFormattingResults() { + document.getElementById("output").innerText = ""; + } + + function appendSection(text) { + var section = document.createElement("p"); + section.innerText = text; + document.getElementById("output").appendChild(section); + } + + function appendCurrentLanguage() { + var currentLanguage = Windows.Globalization.ApplicationLanguages.languages[0]; + appendSection("Current application context language: " + currentLanguage); + } + + function appendFormattingResults(title, formatters, generator) { + var results = title + "\n"; + formatters.forEach(function (formatter) { + results += generator(formatter) + "\n"; + }); + appendSection(results); + } + + WinJS.Namespace.define("SdkSample", { + sampleTitle: sampleTitle, + scenarios: new WinJS.Binding.List(scenarios), + clearFormattingResults: clearFormattingResults, + appendCurrentLanguage: appendCurrentLanguage, + appendFormattingResults: appendFormattingResults + }); +})(); \ No newline at end of file diff --git a/Samples/DateTimeFormatting/js/js/scenario1-longAndShortFormats.js b/Samples/DateTimeFormatting/js/js/scenario1-longAndShortFormats.js new file mode 100644 index 0000000000..99b5fc2b25 --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario1-longAndShortFormats.js @@ -0,0 +1,45 @@ +//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +//// PARTICULAR PURPOSE. +//// +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var DateTimeFormatter = Windows.Globalization.DateTimeFormatting.DateTimeFormatter; + + var page = WinJS.UI.Pages.define("/html/scenario1-longAndShortFormats.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + + // This scenario uses the DateTimeFormatting.DateTimeFormatter class + // in order to display dates and times using basic formatters. Note that the pattern of + // the date returned is determined by the current language and region value of the application context + + SdkSample.clearFormattingResults(); + SdkSample.appendCurrentLanguage(); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + SdkSample.appendFormattingResults("Formatted results:", [ + // Formatters for dates. + new DateTimeFormatter("shortdate"), + new DateTimeFormatter("longdate"), + + // Formatters for times. + new DateTimeFormatter("shorttime"), + new DateTimeFormatter("longtime") + + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + } +})(); diff --git a/Samples/DateTimeFormatting/js/js/scenario2-stringTemplate.js b/Samples/DateTimeFormatting/js/js/scenario2-stringTemplate.js new file mode 100644 index 0000000000..826447df45 --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario2-stringTemplate.js @@ -0,0 +1,68 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var DateTimeFormatter = Windows.Globalization.DateTimeFormatting.DateTimeFormatter; + + var page = WinJS.UI.Pages.define("/html/scenario2-stringTemplate.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + // This scenario uses the DateTimeFormatter class + // to format a date/time via a string template. Note that the order specifed in the string pattern does + // not determine the order of the parts of the formatted string. The current language and region value will + // determine the pattern of the date returned based on the specified parts. + + SdkSample.clearFormattingResults(); + SdkSample.appendCurrentLanguage(); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + SdkSample.appendFormattingResults("Dates:", [ + new DateTimeFormatter("month day"), + new DateTimeFormatter("month year"), + new DateTimeFormatter("month day year"), + new DateTimeFormatter("month day dayofweek year"), + new DateTimeFormatter("dayofweek.abbreviated"), + new DateTimeFormatter("month.abbreviated"), + new DateTimeFormatter("year.abbreviated") + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + + SdkSample.appendFormattingResults("Times:", [ + new DateTimeFormatter("hour minute"), + new DateTimeFormatter("hour minute second"), + new DateTimeFormatter("hour") + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + + SdkSample.appendFormattingResults("Time zones:", [ + new DateTimeFormatter("timezone"), + new DateTimeFormatter("timezone.full"), + new DateTimeFormatter("timezone.abbreviated") + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + + SdkSample.appendFormattingResults("Date and time combinations:", [ + new DateTimeFormatter("hour minute second timezone.full"), + new DateTimeFormatter("day month year hour minute timezone"), + new DateTimeFormatter("dayofweek day month year hour minute second"), + new DateTimeFormatter("dayofweek.abbreviated day month hour minute"), + new DateTimeFormatter("dayofweek day month year hour minute second timezone.abbreviated") + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + } +})(); diff --git a/Samples/DateTimeFormatting/js/js/scenario3-parameterizedTemplate.js b/Samples/DateTimeFormatting/js/js/scenario3-parameterizedTemplate.js new file mode 100644 index 0000000000..a5309cf37e --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario3-parameterizedTemplate.js @@ -0,0 +1,76 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var DateTimeFormatting = Windows.Globalization.DateTimeFormatting; + var DateTimeFormatter = DateTimeFormatting.DateTimeFormatter; + + var page = WinJS.UI.Pages.define("/html/scenario3-parameterizedTemplate.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + // This scenario uses the DateTimeFormatter class + // to format a date/time by specifying a template via parameters. Note that the current language + // and region value will determine the pattern of the date returned based on the + // specified parts. + + SdkSample.clearFormattingResults(); + SdkSample.appendCurrentLanguage(); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + SdkSample.appendFormattingResults("Dates:", [ + new DateTimeFormatter( + DateTimeFormatting.YearFormat.full, + DateTimeFormatting.MonthFormat.abbreviated, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.abbreviated), + + new DateTimeFormatter( + DateTimeFormatting.YearFormat.abbreviated, + DateTimeFormatting.MonthFormat.abbreviated, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.none), + + new DateTimeFormatter( + DateTimeFormatting.YearFormat.full, + DateTimeFormatting.MonthFormat.full, + DateTimeFormatting.DayFormat.none, + DateTimeFormatting.DayOfWeekFormat.none), + + new DateTimeFormatter( + DateTimeFormatting.YearFormat.none, + DateTimeFormatting.MonthFormat.full, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.none) + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + + SdkSample.appendFormattingResults("Times:", [ + new DateTimeFormatter( + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.default, + DateTimeFormatting.SecondFormat.default), + + new DateTimeFormatter( + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.default, + DateTimeFormatting.SecondFormat.none), + + new DateTimeFormatter( + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.none, + DateTimeFormatting.SecondFormat.none) + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": " + formatter.format(dateToFormat); + }); + } +})(); diff --git a/Samples/DateTimeFormatting/js/js/scenario4-override.js b/Samples/DateTimeFormatting/js/js/scenario4-override.js new file mode 100644 index 0000000000..d6894d7be5 --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario4-override.js @@ -0,0 +1,66 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var DateTimeFormatting = Windows.Globalization.DateTimeFormatting; + var DateTimeFormatter = DateTimeFormatting.DateTimeFormatter; + var CalendarIdentifiers = Windows.Globalization.CalendarIdentifiers; + var ClockIdentifiers = Windows.Globalization.ClockIdentifiers; + + var page = WinJS.UI.Pages.define("/html/scenario4-override.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + // This scenario uses the Windows.Globalization.DateTimeFormatting.DateTimeFormatter class + // to format a date/time by using a formatter that provides specific languages, + // geographic region, calendar and clock + + SdkSample.clearFormattingResults(); + SdkSample.appendCurrentLanguage(); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + // Formatters for dates, using basic formatters, string templates and parametrized templates. + SdkSample.appendFormattingResults("Dates:", [ + new DateTimeFormatter("longdate", ["ja-JP"], "JP", CalendarIdentifiers.japanese, ClockIdentifiers.twelveHour), + new DateTimeFormatter("month day", ["fr-FR"], "FR", CalendarIdentifiers.gregorian, ClockIdentifiers.twentyFourHour), + new DateTimeFormatter( + DateTimeFormatting.YearFormat.abbreviated, + DateTimeFormatting.MonthFormat.abbreviated, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.none, + DateTimeFormatting.HourFormat.none, + DateTimeFormatting.MinuteFormat.none, + DateTimeFormatting.SecondFormat.none, + ["de-DE"], "DE", + CalendarIdentifiers.gregorian, ClockIdentifiers.twelveHour) + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": (" + formatter.resolvedLanguage + ") " + formatter.format(dateToFormat); + }); + + // Formatters for times, using basic formatters, string templates and parametrized templates. + SdkSample.appendFormattingResults("Times:", [ + new DateTimeFormatter("longtime", ["ja-JP"], "JP", CalendarIdentifiers.japanese, ClockIdentifiers.twelveHour), + new DateTimeFormatter("hour minute", ["fr-FR"], "FR", CalendarIdentifiers.gregorian, ClockIdentifiers.twentyFourHour), + new DateTimeFormatter( + DateTimeFormatting.YearFormat.none, + DateTimeFormatting.MonthFormat.none, + DateTimeFormatting.DayFormat.none, + DateTimeFormatting.DayOfWeekFormat.none, + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.default, + DateTimeFormatting.SecondFormat.none, + ["de-DE"], "DE", + CalendarIdentifiers.gregorian, ClockIdentifiers.twelveHour) + ], function (formatter) { + // Perform the actual formatting. + return formatter.template + ": (" + formatter.resolvedLanguage + ") " + formatter.format(dateToFormat); + }); + } +})(); diff --git a/Samples/DateTimeFormatting/js/js/scenario5-unicodeExtensions.js b/Samples/DateTimeFormatting/js/js/scenario5-unicodeExtensions.js new file mode 100644 index 0000000000..3d27650049 --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario5-unicodeExtensions.js @@ -0,0 +1,72 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var DateTimeFormatting = Windows.Globalization.DateTimeFormatting; + var DateTimeFormatter = DateTimeFormatting.DateTimeFormatter; + + var page = WinJS.UI.Pages.define("/html/scenario5-unicodeExtensions.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + // This scenario uses the Windows.Globalization.DateTimeFormatting.DateTimeFormatter class + // to format a date/time by using a formatter that uses unicode extenstion in the specified + // language name + + SdkSample.clearFormattingResults(); + SdkSample.appendCurrentLanguage(); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + SdkSample.appendFormattingResults("Dates and times:", [ + // Create formatters using various types of constructors specifying Language list with Unicode extension in language names + + // Default application context + new DateTimeFormatter("longdate longtime"), + + // Telugu language, Gregorian Calendar and Latin Numeral System + new DateTimeFormatter("longdate longtime", ["te-in-u-ca-gregory-nu-latn", "en-US"]), + + // Hebrew language and Arabic Numeral System - calendar NOT specified in constructor + new DateTimeFormatter( + DateTimeFormatting.YearFormat.default, + DateTimeFormatting.MonthFormat.default, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.default, + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.default, + DateTimeFormatting.SecondFormat.default, + ["he-IL-u-nu-arab", "en-US"]), + + // Hebrew language and calendar - calendar specified in constructor + // also, which overrides the one specified in Unicode extension + new DateTimeFormatter( + DateTimeFormatting.YearFormat.default, + DateTimeFormatting.MonthFormat.default, + DateTimeFormatting.DayFormat.default, + DateTimeFormatting.DayOfWeekFormat.default, + DateTimeFormatting.HourFormat.default, + DateTimeFormatting.MinuteFormat.default, + DateTimeFormatting.SecondFormat.default, + ["he-IL-u-ca-hebrew-co-phonebk", "en-US"], + "US", + Windows.Globalization.CalendarIdentifiers.gregorian, + Windows.Globalization.ClockIdentifiers.twentyFourHour) + ], function (formatter) { + // Perform the actual formatting. + return "Result: " + formatter.format(dateToFormat) + "\n" + + " Language List: " + formatter.languages.join(", ") + "\n" + + " Template: " + formatter.template + "\n" + + " Resolved Language: " + formatter.resolvedLanguage + "\n"; + " Calendar System: " + formatter.calendar + "\n"; + " Numeral System: " + formatter.numeralSystem + "\n"; + }); + return; + + } +})(); diff --git a/Samples/DateTimeFormatting/js/js/scenario6-timeZone.js b/Samples/DateTimeFormatting/js/js/scenario6-timeZone.js new file mode 100644 index 0000000000..1283e6049f --- /dev/null +++ b/Samples/DateTimeFormatting/js/js/scenario6-timeZone.js @@ -0,0 +1,56 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario6-timeZone.html", { + ready: function (element, options) { + document.getElementById("displayButton").addEventListener("click", doDisplay, false); + } + }); + + function doDisplay() { + // This scenario illustrates time zone support in DateTimeFormatter class + SdkSample.clearFormattingResults(); + + // Additional time zones we will show. + var timeZones = ["UTC", "America/New_York", "Asia/Kolkata"]; + + // Create formatter object using longdate and longtime template + var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate longtime"); + + // Obtain the date that will be formatted. + var dateToFormat = new Date(); + + // Show current time. + var results = "Current date and time\n"; + results += "In Local time zone: " + formatter.format(dateToFormat) + "\n"; + timeZones.forEach(function (timeZone) { + results += "In " + timeZone + " time zone: " + formatter.format(dateToFormat, timeZone) + "\n"; + }); + results += "\n"; + + // Show a time on 14th day of second month of next year. + // (Note that month numbers start at zero in JavaScript, so month 1 is the second month.) + // Note the effect of daylight saving on the results. + results += "Same time on 14th day of second month of next year\n"; + dateToFormat = new Date(dateToFormat.getFullYear() + 1, 1, 14, dateToFormat.getHours(), dateToFormat.getMinutes(), dateToFormat.getSeconds()); + results += "In local time zone: " + formatter.format(dateToFormat) + "\n"; + timeZones.forEach(function (timeZone) { + results += "In " + timeZone + " time zone: " + formatter.format(dateToFormat, timeZone) + "\n"; + }); + results += "\n"; + + // Show a time on 14th day of tenth month of next year. + // Note the effect of daylight saving on the results. + results += "Same time on 14th day of tenth month of next year\n"; + dateToFormat.setMonth(9); + results += "In local time zone: " + formatter.format(dateToFormat) + "\n"; + timeZones.forEach(function (timeZone) { + results += "In " + timeZone + " time zone: " + formatter.format(dateToFormat, timeZone) + "\n"; + }); + results += "\n"; + + // Display the results. + document.getElementById("output").innerText = results; + } +})(); diff --git a/Samples/DateTimeFormatting/js/sample-utils/placeholder.txt b/Samples/DateTimeFormatting/js/sample-utils/placeholder.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Samples/DateTimeFormatting/shared/Scenario1_LongAndShortFormats.xaml b/Samples/DateTimeFormatting/shared/Scenario1_LongAndShortFormats.xaml new file mode 100644 index 0000000000..730fb52129 --- /dev/null +++ b/Samples/DateTimeFormatting/shared/Scenario1_LongAndShortFormats.xaml @@ -0,0 +1,42 @@ + + + + + + + Formats the current date and time using + the Long and Short formats. These formats represent conventional + presentation forms for date and time and are useful when presenting + standard date and times. The available formats are shown in Settings + under Time & Language. + + + By default the dates and times are formatted according to the conventions + of the current application language. + (In the case of this sample, only a single default language is supported.) + For a localized application, the current language is determined by + the user's language preferences. + + +

+ + + + \ No newline at end of file diff --git a/Samples/Playlists/js/html/scenario2-display.html b/Samples/Playlists/js/html/scenario2-display.html new file mode 100644 index 0000000000..a9c49bf6a6 --- /dev/null +++ b/Samples/Playlists/js/html/scenario2-display.html @@ -0,0 +1,27 @@ + + + + + + + + + + + +
+

Description:

+
+ Take an existing playlist (WPL, ZPL, M3U) and display its contents. +
+

+ +

+

+

+
+ + + \ No newline at end of file diff --git a/Samples/Playlists/js/html/scenario3-add.html b/Samples/Playlists/js/html/scenario3-add.html new file mode 100644 index 0000000000..7387bcccc9 --- /dev/null +++ b/Samples/Playlists/js/html/scenario3-add.html @@ -0,0 +1,28 @@ + + + + + + + + + + + +
+
+

Description:

+
+ Add items to the end of an existing playlist (WPL, ZPL, M3U). +
+
+

+ + +

+
+ + + \ No newline at end of file diff --git a/Samples/Playlists/js/html/scenario4-remove.html b/Samples/Playlists/js/html/scenario4-remove.html new file mode 100644 index 0000000000..6651fe9e85 --- /dev/null +++ b/Samples/Playlists/js/html/scenario4-remove.html @@ -0,0 +1,27 @@ + + + + + + + + + + + +
+
+

Description:

+
+ Remove an item from the end of an existing playlist (WPL, ZPL, M3U). +
+
+

+ +

+
+ + + \ No newline at end of file diff --git a/Samples/Playlists/js/html/scenario5-clear.html b/Samples/Playlists/js/html/scenario5-clear.html new file mode 100644 index 0000000000..471b03888e --- /dev/null +++ b/Samples/Playlists/js/html/scenario5-clear.html @@ -0,0 +1,27 @@ + + + + + + + + + + + +
+
+

Description:

+
+ Remove all items from an existing playlist (WPL, ZPL, M3U). +
+
+

+ +

+
+ + + \ No newline at end of file diff --git a/Samples/Playlists/js/images/placeholder.txt b/Samples/Playlists/js/images/placeholder.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Samples/Playlists/js/js/sample-configuration.js b/Samples/Playlists/js/js/sample-configuration.js new file mode 100644 index 0000000000..f600805af9 --- /dev/null +++ b/Samples/Playlists/js/js/sample-configuration.js @@ -0,0 +1,25 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var sampleTitle = "Playlists"; + + var scenarios = [ + { url: "/html/scenario1-create.html", title: "Create a playlist" }, + { url: "/html/scenario2-display.html", title: "Display a playlist" }, + { url: "/html/scenario3-add.html", title: "Add items to a playlist" }, + { url: "/html/scenario4-remove.html", title: "Remove an item from a playlist" }, + { url: "/html/scenario5-clear.html", title: "Clear a playlist" }, + ]; + + var audioExtensions = [".wma", ".mp3", ".mp2", ".aac", ".adt", ".adts", ".m4a"]; + var playlistExtensions = [".m3u", ".wpl", ".zpl"]; + + WinJS.Namespace.define("SdkSample", { + sampleTitle: sampleTitle, + scenarios: new WinJS.Binding.List(scenarios), + audioExtensions: audioExtensions, + playlistExtensions: playlistExtensions + }); +})(); diff --git a/Samples/Playlists/js/js/scenario1-create.js b/Samples/Playlists/js/js/scenario1-create.js new file mode 100644 index 0000000000..6196f602ec --- /dev/null +++ b/Samples/Playlists/js/js/scenario1-create.js @@ -0,0 +1,41 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario1-create.html", { + ready: function (element, options) { + document.getElementById("PickAudioButton").addEventListener("click", pickAudio, false); + } + }); + + function pickAudio() { + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.audioExtensions); + + picker.pickMultipleFilesAsync().done(function (files) { + if (files.size > 0) { + var playlist = new Windows.Media.Playlists.Playlist(); + + files.forEach(function (file) { + playlist.files.append(file); + }); + + var folder = Windows.Storage.KnownFolders.musicLibrary; + var name = "Sample"; + var collisionOption = Windows.Storage.NameCollisionOption.replaceExisting; + var format = Windows.Media.Playlists.PlaylistFormat.windowsMedia; + playlist.saveAsAsync(folder, name, collisionOption, format).done(function (file) { + WinJS.log && WinJS.log(file.name + " was created and saved with " + playlist.files.size + " files.", "sample", "status"); + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } + else { + WinJS.log && WinJS.log("No files picked.", "sample", "error"); + } + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } +})(); diff --git a/Samples/Playlists/js/js/scenario2-display.js b/Samples/Playlists/js/js/scenario2-display.js new file mode 100644 index 0000000000..39546006ca --- /dev/null +++ b/Samples/Playlists/js/js/scenario2-display.js @@ -0,0 +1,46 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario2-display.html", { + ready: function (element, options) { + document.getElementById("PickPlaylistButton").addEventListener("click", displayPlaylist, false); + } + }); + + function displayPlaylist() { + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.playlistExtensions); + + var playlist; + picker.pickSingleFileAsync().then(function (item) { + if (item) { + return Windows.Media.Playlists.Playlist.loadAsync(item); + } + return WinJS.Promise.wrapError("No file picked."); + }).then(function (result) { + playlist = result; + + // Request music properties for each file in the playlist. + var promises = playlist.files.map(function (file) { + return file.properties.getMusicPropertiesAsync(); + }); + + // Wait for all the properties to be retrieved. + return WinJS.Promise.join(promises); + }).done(function (results) { + var output = "Songs in playlist: " + playlist.files.length + "\n"; + results.forEach(function (musicProperties, index) { + output += "File: " + playlist.files[index].path + "\n"; + output += "Title: " + musicProperties.title + "\n"; + output += "Album: " + musicProperties.album + "\n"; + output += "Artist: " + musicProperties.artist + "\n\n"; + }); + WinJS.log && WinJS.log("", "sample", "status"); + document.getElementById("OutputStatus").innerText = output; + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } +})(); diff --git a/Samples/Playlists/js/js/scenario3-add.js b/Samples/Playlists/js/js/scenario3-add.js new file mode 100644 index 0000000000..762c7bc31a --- /dev/null +++ b/Samples/Playlists/js/js/scenario3-add.js @@ -0,0 +1,65 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var pickPlaylistButton; + var pickAudioButton; + var playlist; + + var page = WinJS.UI.Pages.define("/html/scenario3-add.html", { + ready: function (element, options) { + pickPlaylistButton = document.getElementById("PickPlaylistButton"); + pickPlaylistButton.addEventListener("click", loadPlaylist, false) + + pickAudioButton = document.getElementById("PickAudioButton"); + pickAudioButton.addEventListener("click", addSong, false); + } + }); + + function loadPlaylist() { + pickAudioButton.disabled = true; + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.playlistExtensions); + + picker.pickSingleFileAsync().then(function (file) { + if (file) { + return Windows.Media.Playlists.Playlist.loadAsync(file); + } + return WinJS.Promise.wrapError("No file picked"); + }).done(function (result) { + playlist = result; + pickAudioButton.disabled = false; + WinJS.log && WinJS.log("Playlist loaded.", "sample", "status"); + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } + + function addSong() { + if (playlist) { + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.audioExtensions); + + var numFilesPicked = 0; + picker.pickMultipleFilesAsync().then(function (files) { + if (files.size > 0) { + numFilesPicked = files.size; + + files.forEach(function (file) { + playlist.files.append(file); + }); + + return playlist.saveAsync(); + } else { + return WinJS.Promise.wrapError("No files picked."); + } + }).done(function (file) { + WinJS.log && WinJS.log(numFilesPicked + " files added to playlist.", "sample", "status"); + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } + }})(); diff --git a/Samples/Playlists/js/js/scenario4-remove.js b/Samples/Playlists/js/js/scenario4-remove.js new file mode 100644 index 0000000000..f50986167b --- /dev/null +++ b/Samples/Playlists/js/js/scenario4-remove.js @@ -0,0 +1,30 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario4-remove.html", { + ready: function (element, options) { + document.getElementById("PickPlaylistButton").addEventListener("click", removeSong, false); + } + }); + + function removeSong() { + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.playlistExtensions); + + picker.pickSingleFileAsync().then(function (file) { + if (file) { + return Windows.Media.Playlists.Playlist.loadAsync(file); + } + return WinJS.Promise.wrapError("No file picked."); + }).then(function (playlist) { + playlist.files.removeAtEnd(); + return playlist.saveAsync(); + }).done(function (file) { + WinJS.log && WinJS.log("Item removed from end of playlist.", "sample", "status"); + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } +})(); diff --git a/Samples/Playlists/js/js/scenario5-clear.js b/Samples/Playlists/js/js/scenario5-clear.js new file mode 100644 index 0000000000..205efff6cd --- /dev/null +++ b/Samples/Playlists/js/js/scenario5-clear.js @@ -0,0 +1,30 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario5-clear.html", { + ready: function (element, options) { + document.getElementById("PickPlaylistButton").addEventListener("click", clearPlaylist, false); + } + }); + + function clearPlaylist() { + var picker = new Windows.Storage.Pickers.FileOpenPicker(); + picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary; + picker.fileTypeFilter.replaceAll(SdkSample.playlistExtensions); + + picker.pickSingleFileAsync().then(function (file) { + if (file) { + return Windows.Media.Playlists.Playlist.loadAsync(file); + } + return WinJS.Promise.wrapError("No file picked."); + }).then(function (playlist) { + playlist.files.clear(); + return playlist.saveAsync(); + }).done(function (file) { + WinJS.log && WinJS.log("Playlist cleared.", "sample", "status"); + }, function (error) { + WinJS.log && WinJS.log(error, "sample", "error"); + }); + } +})(); diff --git a/Samples/Playlists/js/sample-utils/placeholder.txt b/Samples/Playlists/js/sample-utils/placeholder.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Samples/Playlists/shared/Scenario1_Create.xaml b/Samples/Playlists/shared/Scenario1_Create.xaml new file mode 100644 index 0000000000..92fa133847 --- /dev/null +++ b/Samples/Playlists/shared/Scenario1_Create.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + Create and save a playlist from a set of audio files. + + + + + An app can request that the system not allow + the user to resize the view below a certain size. + For this to succeed, + the windowing model of the operating system must allow views to be resized freely. + If the requested size is outside the range permitted by the operating system, + the nearest permissible values are used. + + + + + + + diff --git a/Samples/BackgroundTask/cs/BackgroundTask/Scenario3_ServicingCompleteTask.xaml b/Samples/ResizeAppView/shared/Scenario2_Launch.xaml similarity index 51% rename from Samples/BackgroundTask/cs/BackgroundTask/Scenario3_ServicingCompleteTask.xaml rename to Samples/ResizeAppView/shared/Scenario2_Launch.xaml index 4be17471c2..4917237b35 100644 --- a/Samples/BackgroundTask/cs/BackgroundTask/Scenario3_ServicingCompleteTask.xaml +++ b/Samples/ResizeAppView/shared/Scenario2_Launch.xaml @@ -1,4 +1,4 @@ - - + - - - Registers a background task for the Servicing Complete event. The - background task runs when the application is updated with a newer - version. + Launching at a custom size - - diff --git a/Samples/SpeechRecognitionAndSynthesis/cs/PauseAsyncScenario.xaml.cs b/Samples/SpeechRecognitionAndSynthesis/cs/PauseAsyncScenario.xaml.cs index 357b0acd45..572af8fa88 100644 --- a/Samples/SpeechRecognitionAndSynthesis/cs/PauseAsyncScenario.xaml.cs +++ b/Samples/SpeechRecognitionAndSynthesis/cs/PauseAsyncScenario.xaml.cs @@ -268,7 +268,7 @@ public async void EmailButton_Click(object sender, RoutedEventArgs e) { // Update UI, disabling buttons so the user can't interrupt. updateUI(false); - var newButtonText = ""; + string newButtonText = ""; long start = DateTime.Now.Ticks; @@ -295,7 +295,7 @@ public async void EmailButton_Click(object sender, RoutedEventArgs e) } // Recompile with the new constraints and resume the session again. - var result = await speechRecognizer.CompileConstraintsAsync(); + SpeechRecognitionCompilationResult result = await speechRecognizer.CompileConstraintsAsync(); if (result.Status != SpeechRecognitionResultStatus.Success) { // Disable the recognition buttons. @@ -334,7 +334,7 @@ public async void PhoneButton_Click(object sender, RoutedEventArgs e) { // Update UI, disabling buttons so the user can't interrupt. updateUI(false); - var newButtonText = ""; + string newButtonText = ""; long start = DateTime.Now.Ticks; @@ -361,7 +361,7 @@ public async void PhoneButton_Click(object sender, RoutedEventArgs e) } // Recompile with the new constraints and resume the session again. - var result = await speechRecognizer.CompileConstraintsAsync(); + SpeechRecognitionCompilationResult result = await speechRecognizer.CompileConstraintsAsync(); if (result.Status != SpeechRecognitionResultStatus.Success) { // Disable the recognition buttons. diff --git a/Samples/SpeechRecognitionAndSynthesis/cs/SpeechAndTTS.csproj b/Samples/SpeechRecognitionAndSynthesis/cs/SpeechAndTTS.csproj index 552e7e5beb..bbd0708eec 100644 --- a/Samples/SpeechRecognitionAndSynthesis/cs/SpeechAndTTS.csproj +++ b/Samples/SpeechRecognitionAndSynthesis/cs/SpeechAndTTS.csproj @@ -240,8 +240,8 @@ SRGS\it-IT\SRGSColors.xml - - SRGS\zh-CN\SRGSColors.xml + + SRGS\zh-Hans-CN\SRGSColors.xml
diff --git a/Samples/SpeechRecognitionAndSynthesis/js/SpeechAndTTS.jsproj b/Samples/SpeechRecognitionAndSynthesis/js/SpeechAndTTS.jsproj index d83a9c6526..84c02c771c 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/SpeechAndTTS.jsproj +++ b/Samples/SpeechRecognitionAndSynthesis/js/SpeechAndTTS.jsproj @@ -57,6 +57,7 @@ + @@ -91,6 +92,7 @@ + diff --git a/Samples/SpeechRecognitionAndSynthesis/js/html/scenario10_PauseAsync.html b/Samples/SpeechRecognitionAndSynthesis/js/html/scenario10_PauseAsync.html new file mode 100644 index 0000000000..6f105dc38d --- /dev/null +++ b/Samples/SpeechRecognitionAndSynthesis/js/html/scenario10_PauseAsync.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + +
+
+

Description:

+
+

This sample showcases how to switch grammars during a continuous recognition session.

+
+
+
+

+

+

+ + Listening for:
+ Send email
+ +

+

+

+
+
+ + + \ No newline at end of file diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/sample-configuration.js b/Samples/SpeechRecognitionAndSynthesis/js/js/sample-configuration.js index b32af45229..16391fbb20 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/sample-configuration.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/sample-configuration.js @@ -23,7 +23,8 @@ { url: "/html/scenario6_SRGSConstraint.html", title: "Custom SRGS Constraint" }, { url: "/html/scenario7_ContinuousDictation.html", title: "Continuous Dictation" }, { url: "/html/scenario8_ContinuousRecognitionListGrammar.html", title: "Continuous List Commands" }, - { url: "/html/scenario9_ContinuousRecognitionSRGSGrammar.html", title: "Continuous SRGS Commands" } + { url: "/html/scenario9_ContinuousRecognitionSRGSGrammar.html", title: "Continuous SRGS Commands" }, + { url: "/html/scenario10_PauseAsync.html", title: "PauseAsync to Change Grammar" } ]; WinJS.Namespace.define("SdkSample", { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario10_PauseAsync.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario10_PauseAsync.js new file mode 100644 index 0000000000..dba0eb6902 --- /dev/null +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario10_PauseAsync.js @@ -0,0 +1,449 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +(function () { + "use strict"; + var page = WinJS.UI.Pages.define("/html/scenario10_PauseAsync.html", { + ready: function (element, options) { + AudioCapturePermissions.requestMicrophonePermission().then(function (available) { + if (available) { + initializeRecognizer(); + + btnRecognize.addEventListener("click", continuousRecoFn, false); //speak button click + btnEmailGrammar.addEventListener("click", emailGrammarFn, false); //email grammar button click + btnPhoneGrammar.addEventListener("click", phoneGrammarFn, false); //phone grammar button click + } + else { + btnRecognize.disabled = true; + errorMessage("Microphone Unavailable, check microphone privacy settings."); + } + }, + function (error) { + var messageDialog = new Windows.UI.Popups.MessageDialog(error.message, "Exception"); + messageDialog.showAsync(); + }); + + }, + + unload: function (element, options) { + if (recognizer != null) { + recognizer.removeEventListener('statechanged', onSpeechRecognizerStateChanged, false); + recognizer.continuousRecognitionSession.removeEventListener('resultgenerated', onSpeechRecognizerResultGenerated, false); + recognizer.continuousRecognitionSession.removeEventListener('completed', onSpeechRecognizerSessionCompleted, false); + + recognizer.close(); + } + } + }); + + var recognizer; + + // These speech recognition constraints will be added and removed from the recognizer. + var emailConstraint; + var phoneConstraint; + + function initializeRecognizer() { + /// + /// Initialize speech recognizer and compile constraints. + /// + /// + /// For more information about grammars for Windows apps and how to + /// define and use SRGS-compliant grammars in your app, see + /// https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn596121.aspx + /// + recognizer = Windows.Media.SpeechRecognition.SpeechRecognizer(); + + // Provide feedback to the user about the state of the recognizer. + recognizer.addEventListener('statechanged', onSpeechRecognizerStateChanged, false); + // Handle continuous recognition events. Completed fires when various error states occur or the session otherwise ends. + // ResultGenerated fires when recognized phrases are spoken or the garbage rule is hit. + recognizer.continuousRecognitionSession.addEventListener('resultgenerated', onSpeechRecognizerResultGenerated, false); + recognizer.continuousRecognitionSession.addEventListener('completed', onSpeechRecognizerSessionCompleted, false); + + emailConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(["Send email"], "email"); + phoneConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint(["Call phone"], "phone"); + + recognizer.constraints.append(emailConstraint); + + recognizer.compileConstraintsAsync().done( + function (result) { + // Check to make sure that the constraints were in a proper format and the recognizer was able to compile them. + if (result.status != Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.success) { + btnRecognize.disabled = true; + // Let the user know that the grammar didn't compile properly. + speechRecognizerUnsuccessful(result.status); + } + else { + btnRecognize.disabled = false; + } + } + ); + } + + function continuousRecoFn() { + /// + /// Begin recognition or finish the recognition session. + /// + + // Check if the recognizer is listening or going into a state to listen. + if (recognizer.state != Windows.Media.SpeechRecognition.SpeechRecognizerState.idle) { + disableUI(true); + btnRecognize.innerText = "Stopping recognition..."; + + recognizer.continuousRecognitionSession.cancelAsync(); + } + else { + btnRecognize.innerText = "\uE1d6 Stop recognition"; + errorMessage(""); + + disableUI(false); + + // Start the continuous recognition session. Results are handled in the event handlers below. + try { + recognizer.continuousRecognitionSession.startAsync(); + } + catch (e) { + disableUI(true); + + } + } + } + + function emailGrammarFn() { + /// + /// Adds or removes the 'email' constraint from the recognizer. + /// + + // Update UI, disabling buttons so the user can't interrupt. + disableUI(true); + var newButtonText = ""; + var start = performance.now(); + + try { + recognizer.continuousRecognitionSession.pauseAsync().then( + function (result) { + // Update the grammar appropriately. + if (btnEmailGrammar.innerText == "Remove 'email' grammar") { + btnEmailGrammar.innerText = "Updating..."; + + var index = recognizer.constraints.indexOf(emailConstraint); + if (index.index != -1) { + recognizer.constraints.removeAt(index.index); + } + + newButtonText = "Add 'email' grammar"; + emailInfoTextBlock.style.visibility = "hidden"; + } + else { + btnEmailGrammar.innerText = "Updating..."; + recognizer.constraints.append(emailConstraint); + newButtonText = "Remove 'email' grammar"; + emailInfoTextBlock.style.visibility = "visible"; + } + + return recognizer.compileConstraintsAsync(); + } + ).then( + function (result) { + // Check to make sure that the constraints were in a proper format and the recognizer was able to compile them. + if (result.status != Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.success) { + disableUI(true); + + // Let the user know that the grammar didn't compile properly. + speechRecognizerUnsuccessful(result.status); + + recognizer.continuousRecognitionSession.cancelAsync(); + } + else { + recognizer.continuousRecognitionSession.resume(); + + var end = performance.now(); + var elapsed = end - start; + msTextBlock.innerText = "Grammar update took " + elapsed + " ms"; + + // Restore the original UI state. + disableUI(false); + btnEmailGrammar.innerText = newButtonText; + } + } + ); + } + catch (e) { + var messageDialog = new Windows.UI.Popups.MessageDialog(e.message, "Exception"); + messageDialog.showAsync(); + } + } + + function phoneGrammarFn() { + /// + /// Adds or removes the 'phone' constraint from the recognizer. + /// + + // Update UI, disabling buttons so the user can't interrupt. + disableUI(true); + var newButtonText = ""; + var start = performance.now(); + + try { + recognizer.continuousRecognitionSession.pauseAsync().then( + function (result) { + // Update the grammar appropriately. + if (btnPhoneGrammar.innerText == "Remove 'phone' grammar") { + btnPhoneGrammar.innerText = "Updating..."; + + var index = recognizer.constraints.indexOf(phoneConstraint); + if (index.index != -1) { + recognizer.constraints.removeAt(index.index); + } + + newButtonText = "Add 'phone' grammar"; + phoneInfoTextBlock.style.visibility = "hidden"; + } + else { + btnPhoneGrammar.innerText = "Updating..."; + recognizer.constraints.append(phoneConstraint); + newButtonText = "Remove 'phone' grammar"; + phoneInfoTextBlock.style.visibility = "visible"; + } + + return recognizer.compileConstraintsAsync(); + } + ).then( + function (result) { + // Check to make sure that the constraints were in a proper format and the recognizer was able to compile them. + if (result.status != Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.success) { + disableUI(true); + + // Let the user know that the grammar didn't compile properly. + speechRecognizerUnsuccessful(result.status); + + recognizer.continuousRecognitionSession.cancelAsync(); + } + else { + recognizer.continuousRecognitionSession.resume(); + + var end = performance.now(); + var elapsed = end - start; + msTextBlock.innerText = "Grammar update took " + elapsed + " ms"; + + // Restore the original UI state. + disableUI(false); + btnPhoneGrammar.innerText = newButtonText; + } + } + ); + } + catch (e) { + var messageDialog = new Windows.UI.Popups.MessageDialog(e.message, "Exception"); + messageDialog.showAsync(); + } + } + + function onSpeechRecognizerResultGenerated(eventArgs) { + /// + /// Handle events fired when a result is generated. This may include a garbage rule that fires when general room noise + /// or side-talk is captured (this will have a confidence of rejected typically, but may occasionally match a rule with + /// low confidence). + /// + /// + /// Details about the recognized speech. + /// + + // The garbage rule will not have a tag associated with it, the other rules will return a string matching the tag provided + // when generating the grammar. + var tag = "unknown"; + if (eventArgs.result.constraint != null) { + tag = eventArgs.result.constraint.tag; + } + + // Developers may decide to use per-phrase confidence levels in order to tune the behavior of their + // grammar based on testing. + if (eventArgs.result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.high || + eventArgs.result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.medium) { + + resultTextBlock.innerText = "Heard: " + eventArgs.result.text + ", (Tag: '" + tag + "', Confidence: " + convertConfidenceToString(eventArgs.result.confidence) + ")"; + } + else { + resultTextBlock.innerText = "Sorry, I didn't catch that. (Heard: " + eventArgs.result.text + ", Tag: '" + tag + "', Confidence: " + convertConfidenceToString(eventArgs.result.confidence) + ")"; + } + } + + function onSpeechRecognizerSessionCompleted(eventArgs) { + /// + /// Handle events fired when error conditions occur, such as the microphone becoming unavailable, or if + /// some transient issues occur. This also fires when the session completes normally. + /// + /// + /// The state of the recognizer. + /// + if (eventArgs.status != Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.success) { + speechRecognizerUnsuccessful(eventArgs.status); + } + btnRecognize.innerText = "\uE1d6 Continuous Recognition"; + btnRecognize.disabled = false; + } + + function displayMessage(text) { + /// + /// Sets the status area with the message details and color. + /// + /// + /// The text to be displayed in the status box. + /// + statusMessage.innerText = text; + statusBox.style.backgroundColor = "green"; + } + + function errorMessage(text) { + /// + /// Sets the specified text area with the error message details. + /// + /// + /// The error text to be displayed to the user. + /// + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } + } + + function disableUI(newState) { + /// + /// Enables/disables the UI based on the passed in boolean. + /// + /// + /// The new disabled state for the UI. + /// + btnRecognize.disabled = newState; + btnEmailGrammar.disabled = newState; + btnPhoneGrammar.disabled = newState; + } + + function onSpeechRecognizerStateChanged(eventArgs) { + /// + /// Looks up the state text and displays the message to the user. + /// + /// + /// The state of the recognizer. + /// + switch (eventArgs.state) { + case Windows.Media.SpeechRecognition.SpeechRecognizerState.idle: { + displayMessage("Speech recognizer state: idle"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.capturing: { + displayMessage("Speech recognizer state: capturing"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.processing: { + displayMessage("Speech recognizer state: processing"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.soundStarted: { + displayMessage("Speech recognizer state: soundStarted"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.soundEnded: { + displayMessage("Speech recognizer state: soundEnded"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.speechDetected: { + displayMessage("Speech recognizer state: speechDetected"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognizerState.paused: { + displayMessage("Speech recognizer state: paused"); + break; + } + default: { + break; + } + } + } + + function speechRecognizerUnsuccessful(resultStatus) { + /// + /// Looks up the error text and displays the message to the user. + /// + /// + /// The status of the speech recognition result. + /// + switch (resultStatus) { + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.audioQualityFailure: { + errorMessage("Speech recognition error: audioQualityFailure"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.grammarCompilationFailure: { + errorMessage("Speech recognition error: grammarCompilationFailure"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.grammarLanguageMismatch: { + errorMessage("Speech recognition error: grammarLanguageMismatch"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.microphoneUnavailable: { + errorMessage("Speech recognition error: microphoneUnavailable"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.networkFailure: { + errorMessage("Speech recognition error: networkFailure"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.pauseLimitExceeded: { + errorMessage("Speech recognition error: pauseLimitExceeded"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.timeoutExceeded: { + errorMessage("Speech recognition error: timeoutExceeded"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.topicLanguageNotSupported: { + errorMessage("Speech recognition error: topicLanguageNotSupported"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.unknown: { + errorMessage("Speech recognition error: unknown"); + break; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionResultStatus.userCanceled: { + errorMessage("Recognition canceled by the user."); + break; + } + default: { + break; + } + } + } + + function convertConfidenceToString(confidence) { + /// Converts numeric confidence value into text representation of + /// Windows.Media.SpeechRecognition.SpeechRecognitionConfidence for visualization. + /// + /// + /// The numeric confidence returned by SpeechRecognitionResult.Confidence. + /// + switch (confidence) { + case Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.high: { + return "high"; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.medium: { + return "medium"; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.low: { + return "low"; + } + case Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.rejected: { + return "rejected"; + } + default: + return "unknown"; + } + } +})(); diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario3_PredefinedDictationGrammar.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario3_PredefinedDictationGrammar.js index 7f0e78d2b9..f2fd310c32 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario3_PredefinedDictationGrammar.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario3_PredefinedDictationGrammar.js @@ -111,9 +111,11 @@ ).done( function (result) { // Reset UI state. - btnListen.disabled = false; - btnListenUI.disabled = false; - btnListen.innerText = "\uE1d6 without UI"; + if (typeof btnListen !== "undefined") { + btnListen.disabled = false; + btnListenUI.disabled = false; + btnListen.innerText = "\uE1d6 without UI"; + } } ); } @@ -176,7 +178,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario4_PredefinedWebSearchGrammar.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario4_PredefinedWebSearchGrammar.js index 66c72d82e3..c47be14f95 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario4_PredefinedWebSearchGrammar.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario4_PredefinedWebSearchGrammar.js @@ -116,9 +116,11 @@ ).done( function (result) { // Reset UI state. - btnListen.disabled = false; - btnListenUI.disabled = false; - btnListen.innerText = "\uE1d6 without UI"; + if (typeof btnListen !== "undefined") { + btnListen.disabled = false; + btnListenUI.disabled = false; + btnListen.innerText = "\uE1d6 without UI"; + } } ); } @@ -182,7 +184,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario5_ListConstraint.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario5_ListConstraint.js index ef0ba7a7a5..6c49287414 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario5_ListConstraint.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario5_ListConstraint.js @@ -115,9 +115,11 @@ ).done( function (result) { // Reset UI state. - btnListen.disabled = false; - btnListenUI.disabled = false; - btnListen.innerText = "\uE1d6 without UI"; + if (typeof btnListen !== "undefined") { + btnListen.disabled = false; + btnListenUI.disabled = false; + btnListen.innerText = "\uE1d6 without UI"; + } } ); } @@ -181,7 +183,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario6_SRGSConstraint.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario6_SRGSConstraint.js index b3ace4dd58..dff53f1d58 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario6_SRGSConstraint.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario6_SRGSConstraint.js @@ -143,9 +143,11 @@ ).done( function (result) { // Reset UI state. - btnListen.disabled = false; - btnListenUI.disabled = false; - btnListen.innerText = "\uE1d6 without UI"; + if (typeof btnListen !== "undefined") { + btnListen.disabled = false; + btnListenUI.disabled = false; + btnListen.innerText = "\uE1d6 without UI"; + } } ); } @@ -328,7 +330,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario7_ContinuousDictation.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario7_ContinuousDictation.js index 618baa4906..15d81f4de1 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario7_ContinuousDictation.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario7_ContinuousDictation.js @@ -168,7 +168,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario8_ContinuousRecognitionListGrammar.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario8_ContinuousRecognitionListGrammar.js index 857f8f75c2..c03f4bd314 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario8_ContinuousRecognitionListGrammar.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario8_ContinuousRecognitionListGrammar.js @@ -150,7 +150,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario9_ContinuousRecognitionSRGSGrammar.js b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario9_ContinuousRecognitionSRGSGrammar.js index a91ea7a8a1..f29cc4373e 100644 --- a/Samples/SpeechRecognitionAndSynthesis/js/js/scenario9_ContinuousRecognitionSRGSGrammar.js +++ b/Samples/SpeechRecognitionAndSynthesis/js/js/scenario9_ContinuousRecognitionSRGSGrammar.js @@ -283,7 +283,9 @@ /// /// Sets the specified text area with the error message details. /// - errorTextArea.innerText = text; + if (typeof errorTextArea !== "undefined") { + errorTextArea.innerText = text; + } } function onSpeechRecognizerStateChanged(eventArgs) { diff --git a/Samples/SpeechRecognitionAndSynthesis/shared/SRGS/zh-CN/SRGSColors.xml b/Samples/SpeechRecognitionAndSynthesis/shared/SRGS/zh-Hans-CN/SRGSColors.xml similarity index 100% rename from Samples/SpeechRecognitionAndSynthesis/shared/SRGS/zh-CN/SRGSColors.xml rename to Samples/SpeechRecognitionAndSynthesis/shared/SRGS/zh-Hans-CN/SRGSColors.xml diff --git a/Samples/SplashScreen/README.md b/Samples/SplashScreen/README.md index 2837b15607..a3bed905ce 100644 --- a/Samples/SplashScreen/README.md +++ b/Samples/SplashScreen/README.md @@ -1,5 +1,6 @@ # Splash screen sample diff --git a/Samples/StreamSocket/README.md b/Samples/StreamSocket/README.md index f4fdc9c541..62716a024a 100644 --- a/Samples/StreamSocket/README.md +++ b/Samples/StreamSocket/README.md @@ -1,5 +1,6 @@  # StreamSocket sample @@ -100,7 +101,7 @@ This sample requires that network capabilities be set in the *Package.appxmanife **Client:** Windows 10 -**Server:** Windows Server 2016 Insider Preview +**Server:** Windows Server 2016 Technical Preview **Phone:** Windows 10 diff --git a/Samples/Syndication/README.md b/Samples/Syndication/README.md index 32cb1de717..f623a5bf72 100644 --- a/Samples/Syndication/README.md +++ b/Samples/Syndication/README.md @@ -1,5 +1,6 @@  # Syndication sample @@ -67,7 +68,7 @@ For more information on network capabilities, see [How to set network capabiliti **Client:** Windows 10 -**Server:** Windows Server 2016 Insider Preview +**Server:** Windows Server 2016 Technical Preview **Phone:** Windows 10 diff --git a/Samples/SystemMediaTransportControls/README.md b/Samples/SystemMediaTransportControls/README.md index 6b1d360d80..ae42113726 100644 --- a/Samples/SystemMediaTransportControls/README.md +++ b/Samples/SystemMediaTransportControls/README.md @@ -1,5 +1,6 @@ # System media transport controls sample @@ -29,10 +30,9 @@ https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.systemmediat System requirements ---------------------------- -Client: -Windows 10 -Windows Phone 10 +**Client:** Windows 10 +**Phone:** Windows 10 Build the sample ---------------------------- diff --git a/Samples/TextSegmentation/README.md b/Samples/TextSegmentation/README.md index d4f111349d..87d885f7dd 100644 --- a/Samples/TextSegmentation/README.md +++ b/Samples/TextSegmentation/README.md @@ -1,5 +1,6 @@ # Text segmentation sample diff --git a/Samples/TextSuggestion/README.md b/Samples/TextSuggestion/README.md index fcbc0f052d..c261087132 100644 --- a/Samples/TextSuggestion/README.md +++ b/Samples/TextSuggestion/README.md @@ -1,5 +1,6 @@  # Text suggestions sample diff --git a/Samples/TitleBar/README.md b/Samples/TitleBar/README.md index dbb57906c7..305d84ab97 100644 --- a/Samples/TitleBar/README.md +++ b/Samples/TitleBar/README.md @@ -1,5 +1,6 @@  # Title bar sample diff --git a/Samples/Unicode/README.md b/Samples/Unicode/README.md index 152ab3173f..d7ad29f9e9 100644 --- a/Samples/Unicode/README.md +++ b/Samples/Unicode/README.md @@ -1,5 +1,6 @@  # Unicode string processing sample diff --git a/Samples/UserConsentVerifier/README.md b/Samples/UserConsentVerifier/README.md index 7c58f26bd0..930da0fc5d 100644 --- a/Samples/UserConsentVerifier/README.md +++ b/Samples/UserConsentVerifier/README.md @@ -1,5 +1,6 @@  # UserConsentVerifier sample diff --git a/Samples/UserDataAccountManager/README.md b/Samples/UserDataAccountManager/README.md index 9174b696a7..f468fb77bd 100644 --- a/Samples/UserDataAccountManager/README.md +++ b/Samples/UserDataAccountManager/README.md @@ -1,5 +1,6 @@ # UserDataAccountManager sample diff --git a/Samples/UserInfo/README.md b/Samples/UserInfo/README.md index 3d4a470daf..30b807bcec 100644 --- a/Samples/UserInfo/README.md +++ b/Samples/UserInfo/README.md @@ -1,5 +1,6 @@  # User information sample diff --git a/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.cpp b/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.cpp index b1a760b1f9..b94e35d9ab 100644 --- a/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.cpp +++ b/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.cpp @@ -35,43 +35,34 @@ void Scenario1_FindUsers::OnNavigatedTo(NavigationEventArgs^ e) // Populate the list of users. create_task(User::FindAllAsync()).then([this](IVectorView^ users) { - if (users != nullptr) + // Get the display name of each user. + std::vector> tasks(users->Size); + std::transform(begin(users), end(users), begin(tasks), [](User^ user) { - auto current = begin(users); - AddNextUserAsync(current, users).then([this, users]() + return create_task(user->GetPropertyAsync(KnownUserProperties::DisplayName)); + }); + return when_all(begin(tasks), end(tasks)).then([this, users](std::vector results) + { + // For each user and display name... + for (size_t index = 0; index < users->Size; index++) { - if (users->Size > 0) + auto displayName = safe_cast(results[index]); + // Choose a generic name if we do not have access to the actual name. + if (displayName->IsEmpty()) { - UserList->SelectedIndex = 0; + displayName = "User #" + nextUserNumber.ToString(); + nextUserNumber++; } - }); - } - }); -} -task Scenario1_FindUsers::AddNextUserAsync(VectorViewIterator current, IVectorView^ users) -{ - if (current != end(users)) - { - auto task = create_task((*current)->GetPropertyAsync(KnownUserProperties::DisplayName)); - return task.then([this, current, users](Platform::Object^ result) - { - auto displayName = safe_cast(result); - // Choose a generic name if we do not have access to the actual name. - if (displayName->IsEmpty()) + // Add it to our collection. + models->Append(ref new UserViewModel(users->GetAt(index)->NonRoamableId, displayName)); + } + if (users->Size > 0) { - displayName = "User #" + nextUserNumber.ToString(); - nextUserNumber++; + UserList->SelectedIndex = 0; } - models->Append(ref new UserViewModel((*current)->NonRoamableId, displayName)); - - return AddNextUserAsync(current + 1, users); }); - } - else - { - return create_task([] {}); - } + }); } void Scenario1_FindUsers::ShowProperties() diff --git a/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.h b/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.h index c0fdebd603..addf81c7db 100644 --- a/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.h +++ b/Samples/UserInfo/cpp/Scenario1_FindUsers.xaml.h @@ -28,7 +28,5 @@ namespace SDKTemplate MainPage^ rootPage = MainPage::Current; Platform::Collections::Vector^ models = ref new Platform::Collections::Vector(); int nextUserNumber = 1; - - concurrency::task AddNextUserAsync(Platform::Collections::VectorViewIterator current, Windows::Foundation::Collections::IVectorView^ users); }; } diff --git a/Samples/UserInfo/cpp/Scenario2_WatchUsers.xaml.h b/Samples/UserInfo/cpp/Scenario2_WatchUsers.xaml.h index 20a88155e0..76733b83f7 100644 --- a/Samples/UserInfo/cpp/Scenario2_WatchUsers.xaml.h +++ b/Samples/UserInfo/cpp/Scenario2_WatchUsers.xaml.h @@ -22,6 +22,13 @@ namespace SDKTemplate public: Scenario2_WatchUsers(); + property Windows::Foundation::Collections::IVector^ Users + { + Windows::Foundation::Collections::IVector^ get() + { + return models; + } + } protected: virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; void StartWatching(); diff --git a/Samples/UserInfo/cs/Scenario1_FindUsers.xaml.cs b/Samples/UserInfo/cs/Scenario1_FindUsers.xaml.cs index 0b5e33780c..01899ea797 100644 --- a/Samples/UserInfo/cs/Scenario1_FindUsers.xaml.cs +++ b/Samples/UserInfo/cs/Scenario1_FindUsers.xaml.cs @@ -58,7 +58,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e) } } - private async void Show_Click(object sender, RoutedEventArgs e) + private async void ShowProperties() { var selectedUser = (UserViewModel)UserList.SelectedValue; if (selectedUser != null) diff --git a/Samples/UserInfo/js/js/scenario1-findUsers.js b/Samples/UserInfo/js/js/scenario1-findUsers.js index 7b3e000c5c..fb6c7ddd30 100644 --- a/Samples/UserInfo/js/js/scenario1-findUsers.js +++ b/Samples/UserInfo/js/js/scenario1-findUsers.js @@ -31,28 +31,24 @@ function fillUsersAsync() { nextUserNumber = 1; User.findAllAsync().then(function (users) { - return addNextUserAsync(0); - - function addNextUserAsync(i) { - if (i < users.length) { - var user = users[i]; - return user.getPropertyAsync(KnownUserProperties.displayName).then(function (displayName) { - // Choose a generic name if we do not have access to the actual name. - if (displayName == "") { - displayName = "User #" + nextUserNumber; - ++nextUserNumber; - } - - var newOption = document.createElement("option"); - newOption.text = displayName; - newOption.value = user.nonRoamableId; - newOption.selected = false; - userList.add(newOption); - - return addNextUser(i + 1); - }); + WinJS.Promise.join(users.map(function (user) { + return user.getPropertyAsync(KnownUserProperties.displayName); + })).then(function (results) { + for (var i = 0; i < users.length; i++) { + // Choose a generic name if we do not have access to the actual name. + var displayName = results[i]; + if (displayName == "") { + displayName = "User #" + nextUserNumber; + ++nextUserNumber; + } + + var newOption = document.createElement("option"); + newOption.text = displayName; + newOption.value = users[i].nonRoamableId; + newOption.selected = false; + userList.add(newOption); } - } + }); }); } @@ -113,19 +109,10 @@ // issuing a series of single-property queries. function simulateGetPropertiesAsync(user, desiredProperties) { var values = {}; - return addNextPropertyAsync(0); - - function addNextPropertyAsync(i) { - if (i < desiredProperties.length) { - var propertyName = desiredProperties[i]; - return user.getPropertyAsync(propertyName).then(function (result) { - values[propertyName] = result; - return addNextPropertyAsync(i + 1); - }); - } else { - return values; - } - } + return WinJS.Promise.join(desiredProperties.map(function (propertyName) { + return user.getPropertyAsync(propertyName).then(function (result) { + values[propertyName] = result; + }); + })).then(function () { return values; }); } - })(); diff --git a/Samples/UserInfo/shared/Scenario1_FindUsers.xaml b/Samples/UserInfo/shared/Scenario1_FindUsers.xaml index 4a76dacf6e..29c991cd0b 100644 --- a/Samples/UserInfo/shared/Scenario1_FindUsers.xaml +++ b/Samples/UserInfo/shared/Scenario1_FindUsers.xaml @@ -30,7 +30,7 @@ Find users and display user properties -