My first Windows 8.1 game!

by sunil ravulapalli /27. April 2014 04:30 /windows8 /Comments (0)

 

Defend the planet from a continues barrage of asteroids. You control a ship which moves around a planet and has an unlimited supply of laser cannons to destroy the incoming asteroids. Don't let the asteroid come too close to the planet or your ship. How many levels can you go without getting destroyed? 

WinJS.UI.AppBar icons

by sunil ravulapalli /28. March 2012 04:32 /windows8 /Comments (0)
previous: \uE100
next: \uE101
play: \uE102
pause: \uE103
edit: \uE104
save: \uE105
clear: \uE106
delete: \uE107
remove: \uE108
add: \uE109
cancel: \uE10A
accept: \uE10B
more: \uE10C
redo: \uE10D
undo: \uE10E
home: \uE10F
up: \uE110
forward: \uE111
right: \uE111
back: \uE112
left: \uE112
favorite: \uE113
camera: \uE114
settings: \uE115
video: \uE116
sync: \uE117
download: \uE118
mail: \uE119
find: \uE11A
help: \uE11B
upload: \uE11C
emoji: \uE11D
twopage: \uE11E
leavechat: \uE11F
mailforward: \uE120
clock: \uE121
send: \uE122
crop: \uE123
rotatecamera: \uE124
people: \uE125
closepane: \uE126
openpane: \uE127
world: \uE128
flag: \uE129
previewlink: \uE12A
globe: \uE12B
trim: \uE12C
attachcamera: \uE12D
zoomin: \uE12E
bookmarks: \uE12F
document: \uE130
protecteddocument: \uE131
page: \uE132
bullets: \uE133
comment: \uE134
mail2: \uE135
contactinfo: \uE136
hangup: \uE137
viewall: \uE138
mappin: \uE139
phone: \uE13A
videochat: \uE13B
switch: \uE13C
contact: \uE13D
rename: \uE13E
pin: \uE141
musicinfo: \uE142
go: \uE143
keyboard: \uE144
dockleft: \uE145
dockright: \uE146
dockbottom: \uE147
remote: \uE148
refresh: \uE149
rotate: \uE14A
shuffle: \uE14B
list: \uE14C
shop: \uE14D
selectall: \uE14E
orientation: \uE14F
import: \uE150
importall: \uE151
browsephotos: \uE155
webcam: \uE156
pictures: \uE158
savelocal: \uE159
caption: \uE15A
stop: \uE15B
showresults: \uE15C
volume: \uE15D
repair: \uE15E
message: \uE15F
page2: \uE160
calendarday: \uE161
calendarweek: \uE162
calendar: \uE163
characters: \uE164
mailreplyall: \uE165
read: \uE166
link: \uE167
accounts: \uE168
showbcc: \uE169
hidebcc: \uE16A
cut: \uE16B
attach: \uE16C
paste: \uE16D
filter: \uE16E
copy: \uE16F
emoji2: \uE170
important: \uE171
mailreply: \uE172
slideshow: \uE173
sort: \uE174
contactpresence: \uE181
priority: \uE182
uploadskydrive: \uE183
gototoday: \uE184
font: \uE185
fontcolor: \uE186
contact2: \uE187
folder: \uE188
audio: \uE189
placeholder: \uE18A
view: \uE18B
setlockscreen: \uE18C
settile: \uE18D
cc: \uE190
stopslideshow: \uE191
permissions: \uE192
highlight: \uE193
disableupdates: \uE194
unfavorite: \uE195
unpin: \uE196
openlocal: \uE197
mute: \uE198
italic: \uE199
underline: \uE19A
bold: \uE19B
movetofolder: \uE19C
likedislike: \uE19D
dislike: \uE19E
like: \uE19F
alignright: \uE1A0
aligncenter: \uE1A1
alignleft: \uE1A2
zoom: \uE1A3
zoomout: \uE1A4
openfile: \uE1A5
otheruser: \uE1A6
admin: \uE1A7  

Windows 8 Grid application data.js sample to get data asynchronously from multiple sources

by sunil ravulapalli /20. March 2012 19:58 /windows8 /Comments (0)

This code was tested on Windows 8 consumer preview and may be outdated by the time future versions are released.

(function () {
    "use strict";

    var lightGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY7h4+cp/AAhpA3h+ANDKAAAAAElFTkSuQmCC";
    var mediumGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY5g8dcZ/AAY/AsAlWFQ+AAAAAElFTkSuQmCC";
    var darkGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY3B0cPoPAANMAcOba1BlAAAAAElFTkSuQmCC";

    var groups = [
        { key: "group1", title: "Featured products", subtitle: "Featured", backgroundImage: lightGray, description: "Bedding products" },
        { key: "group2", title: "Towel", subtitle: "Featured", backgroundImage: lightGray, description: "Towel products" },
        { key: "group3", title: "Knife", subtitle: "Featured", backgroundImage: lightGray, description: "Knife products" }
    ];

    function groupKeySelector(item) {
        return item.group.key;
    }

    function groupDataSelector(item) {
        return item.group;
    }

    function getItemsFromGroup(group) {
        return list.createFiltered(function (item) { return item.group.key === group.key; });
    }

    var list = new WinJS.Binding.List();
    var groupedItems = list.createGrouped(groupKeySelector, groupDataSelector);

    function downloadError() {

    }

    function processProducts(requests) {

        for (var i = 0; i < requests.length; i++) {
            var xml = requests[i].responseXML;
            var records = xml.selectNodes("//SearchRecord");

            for (var postIndex = 0; postIndex < records.length; postIndex++) {
                var record = records[postIndex];

                var description = record.selectSingleNode("description").text;
                var priceRange = record.selectSingleNode("priceRange").text;
                var itemImage = record.selectSingleNode("itemImage").text.replace("/130/", "/230/");
                var sku = record.selectSingleNode("sku").text;
                var collection = record.selectSingleNode("collection").text;

                list.push({
                    group: groups[i],
                    title: description,
                    subtitle: priceRange,
                    description: description,
                    itemDescription: description,
                    content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                    backgroundImage: itemImage
                });
            }
        }
    }

    var dataPromises = [];

    var promise1 = WinJS.xhr({ url: "http://www.samplesite.com/search/searchservice.asmx/Search?searchString=bedding&from=0&blockSize=10" });
    dataPromises.push(promise1);

    var promise2 = WinJS.xhr({ url: "http://www.samplesite.com/search/searchservice.asmx/Search?searchString=towel&from=0&blockSize=6" });
    dataPromises.push(promise2);

    var promise3 = WinJS.xhr({ url: "http://www.samplesite.com/search/searchservice.asmx/Search?searchString=knife&from=0&blockSize=6" });
    dataPromises.push(promise3);

    WinJS.Promise.join(dataPromises).then(processProducts, downloadError);

    WinJS.Namespace.define("data", {
        items: groupedItems,
        groups: groupedItems.groups,
        getItemsFromGroup: getItemsFromGroup
    });
})();

Windows 8 Grid application data.js sample to get data asynchronously

by sunil ravulapalli /20. March 2012 19:54 /windows8 /Comments (0)

This code was tested on Windows 8 consumer preview and may be outdated by the time future versions are released.

(function () {
    "use strict";

    var lightGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY7h4+cp/AAhpA3h+ANDKAAAAAElFTkSuQmCC";
    var mediumGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY5g8dcZ/AAY/AsAlWFQ+AAAAAElFTkSuQmCC";
    var darkGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY3B0cPoPAANMAcOba1BlAAAAAElFTkSuQmCC";

    var groups = [
        { key: "searchResultsGroup", title: "Search Results", subtitle: "Results", backgroundImage: lightGray, description: "Search Results" }
    ];

    function groupKeySelector(item) {
        return item.group.key;
    }

    function groupDataSelector(item) {
        return item.group;
    }

    function getItemsFromGroup(group) {
        return list.createFiltered(function (item) { return item.group.key === group.key; });
    }

    var list = new WinJS.Binding.List();
    var groupedItems = list.createGrouped(groupKeySelector, groupDataSelector);

    function downloadError() {

    }

    function processProducts(request) {
        var xml = request.responseXML;
        var records = xml.selectNodes("//SearchRecord");

        for (var postIndex = 0; postIndex < records.length; postIndex++) {
            var record = records[postIndex];

            var description = record.selectSingleNode("description").text;
            var priceRange = record.selectSingleNode("priceRange").text;
            var itemImage = record.selectSingleNode("itemImage").text.replace("/130/","/230/");
            var sku = record.selectSingleNode("sku").text;
            var collection = record.selectSingleNode("collection").text;

            list.push({
                group: groups[0],
                title: description,
                subtitle: priceRange,
                description: description,
                itemDescription: description,
                content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                backgroundImage: itemImage
            });
        }
    }

    WinJS.xhr({ url: "http://www.samplesite.com/search/searchservice.asmx/Search?searchString=bed&from=0&blockSize=20" }).
            then(processProducts, downloadError);

    WinJS.Namespace.define("data", {
        items: groupedItems,
        groups: groupedItems.groups,
        getItemsFromGroup: getItemsFromGroup
    });
})();

Windows 8 Consumer Preview on Samsung Series 7 Chronos laptop

by sunil ravulapalli /9. March 2012 17:58 /windows8 /Comments (2)

I have a Samsung Series 7 Chronos laptop with the Express cache feature(8GB on board SSD) for faster boot. For several days I wasn't able to load set up a dual boot on a VDH, using this technique from Scott Hanselman.

 http://www.hanselman.com/blog/GuideToInstallingAndBootingWindows8DeveloperPreviewOffAVHDVirtualHardDisk.aspx

I always got this errror

"Setup was unable to create a new system partition or locate an existing system partition. See the Setup log files for more information".

I think it has to do with the fact that this laptop is considered to have two hard disks and there is some discussion on the internet that recent versions of windows has a problem with two hard disks attached to the computer at the same time. The resolution was to just detach one of them before installing windows. However, this was not an option on the laptop.

So, I used VirtualBox and loaded Windows 8 Preview as Virtual Machine.But, it killed the joy of the new UI. It was okay to do some Window 8 Application Coding. But the UI was very jerky. I hated it.

Then one fine day, on my quest to resolve this issue, I bumped into this aticle

http://www.howtogeek.com/75286/how-to-dual-boot-windows-7-and-8-without-re-partitioning-using-vhd/

It involves some powereshell, but it is just running some commands.

Now, I am dual booting Wndows 8 Consumer Preview and it is FAST and BEAUTIFUL.

 

Error DEP1000

by sunil ravulapalli /28. February 2012 03:38 /windows8 /Comments (0)

Error DEP1000 : Cannot copy file "C:\Users\Username\Grid\Debug\resources.pri" to layout "resources.pri" for the following reason: The requested operation cannot be performed on a file with a user-mapped section open.

How to get rid of it?
Uninstall the app from the metro desktop, and rerun the app. This will get rid of this error.

Windows 8 How to Write to a File

by sunil ravulapalli /13. January 2012 20:17 /windows8 /Comments (0)

This code was tested on Windows 8 developer preview and may be outdated by the time future versions are released.

Following is the function which takes filename and content and writes content into the file.

 function saveStuff(fileName, contentText) {

        var sampleFile;

        // Create file in user's Document library, overwriting the existing file if there is one
        Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(fileName,
         Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
            sampleFile = file;

            // Have file and text to write
            if (sampleFile != null && geoCode != null) {
                // Open file as stream with read/write access
                sampleFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (stream) {
                    // File opened

                    // Prepare and write to the file stream
                    var outputStream = stream.getOutputStreamAt(stream.size);
                    var writer = new Windows.Storage.Streams.DataWriter(outputStream);
                    writer.writeString(contentText);

                    // Save stream to file
                    writer.storeAsync().then(function () {
                        outputStream.flushAsync().then(function () {
                            writeContent('Geocode saved.');
                        });
                    });
                });
            }
        });
    }

You can call it as following:

saveStuff('settings.txt', 'blue');

Windows 8 How to Join Promises

by sunil ravulapalli /13. January 2012 19:53 /windows8 /Comments (0)

This code was tested on Windows 8 developer preview and may be outdated by the time future versions are released.

Currently I am using promises[0]._value.responseText to access by response. But it doesn't feel right at all. I could not yet find any documentation to do it correct way.

 var urls = [
                    "http://dev.virtualearth.net/REST/v1/Locations?q=07008&key=abcdef",
                    "http://dev.virtualearth.net/REST/v1/Locations?q=08830&key=abcdef"
                ];
        
 var promises = urls.map(function (url) {
            return WinJS.xhr({ url: url });
 });
    
 WinJS.Promise.join(promises).then(function () {
                contentPara.innerHTML += promises[0]._value.responseText+ '
'; contentPara.innerHTML += promises[1]._value.responseText+ '
'; }, handleError); function handleError() { writeContent('Error geocoding, please try again later.'); }

Windows 8 Fragment Navigation

by sunil ravulapalli /13. January 2012 17:57 /windows8 /Comments (0)

This code was tested on Windows 8 developer preview and may be outdated by the time future versions are released.

The contents of default.html are as show below. Just include a div called "contentHost".

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>TTips</title>
    <!-- WinJS references -->
    <link rel="stylesheet" href="/winjs/css/ui-dark.css" />
    <script src="winjs/js/base.js"></script>
    <script src="winjs/js/ui.js"></script>
    <script src="winjs/js/binding.js"></script>
    <script src="winjs/js/controls.js"></script>
    <script src="winjs/js/animations.js"></script>
    <script src="winjs/js/wwaapp.js"></script>
    <!-- TTips references -->
    <link rel="stylesheet" href="/css/default.css" />
    <script src="/js/default.js"></script>
</head>
<body>
    <h1>Traffic Tips</h1>
    <div id="contentHost">
        
    </div>
  
</body>
</html>

In default.js, include the navigated as it is. Don'f forget to include this line WinJS.Navigation.addEventListener('navigated', navigated); as shown. When onmainwindowactivated all you have to do is call WinJS.Navigation.navigate('main.html').

(function () {
    'use strict';
    // Uncomment the following line to enable first chance exceptions.
    // Debug.enableFirstChanceException(true);

    document.addEventListener("DOMContentLoaded", function () {
        WinJS.UI.processAll();
    }, false);

    WinJS.Application.onmainwindowactivated = function (e) {
        if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
                    WinJS.Navigation.navigate('main.html');
        }
    }

    function navigated(e) {
        WinJS.UI.Fragments.clone(e.detail.location, e.detail.state)
            .then(function (frag) {
            var host = document.getElementById('contentHost');
            host.innerHTML = '';
            host.appendChild(frag);
            document.body.focus();

            WinJS.Application.queueEvent({
                type: 'fragmentappended',
                location: e.detail.location,
                fragment: host,
                state : e.detail.state
                });

        });
    }

    WinJS.Navigation.addEventListener('navigated', navigated);
    WinJS.Application.start();
})();

Windows 8 App Bar using HTML

by sunil ravulapalli /29. December 2011 22:08 /windows8 /Comments (0)

This code was tested on Windows 8 developer preview and may be outdated by the time future versions are released.

Once you create a Blank solution your default.html should look like the code below.
The new parts are the scripts tags and the control div as highlighted.
The scripts files are needed for the App Bar control to work. The actual control is the div with the attribute data-win-control="WinJS.UI.AppBar".

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>MyAppBar</title>
    <!-- WinJS references -->
    <link rel="stylesheet" href="/winjs/css/ui-dark.css" />
    <script src="/winjs/js/base.js"></script>
    <script src="/winjs/js/wwaapp.js"></script>
    <script src="winjs/js/ui.js"></script>
    <script src="winjs/js/binding.js"></script>
    <script src="winjs/js/controls.js"></script>
    <script src="winjs/js/animations.js"></script>
    <!-- MyAppBar references -->
    <link rel="stylesheet" href="/css/default.css" />
    <script src="/js/default.js"></script>
</head>
<body>
     <div id="mybar" data-win-control="WinJS.UI.AppBar" data-win-options="{position:'bottom', transient:true, autoHide:0, lightDismiss:true}">
       <div class="win-right">
            <button class="win-command" id="settingsButton">
                <span style="background-image: url('images/smalllogo.png')" class="win-commandicon"></span>
                <span class="win-label">Settings</span>
            </button>
        </div>
    </div>
</body>
</html>

The default.js file should like below. The highlighted(6 to 8) lines are required for WinJS controls to work.

Lines 13 to 16 are used to wire up the button in the App Bar button with a function.

(function () {
    'use strict';
    // Uncomment the following line to enable first chance exceptions.
    // Debug.enableFirstChanceException(true);
 
    document.addEventListener("DOMContentLoaded", function () {
        WinJS.UI.processAll();
    }, false);
 
    WinJS.Application.onmainwindowactivated = function (e) {
        if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            // TODO: startup code here
            var settingsButton = document.getElementById('settingsButton');
             settingsButton.addEventListener('click', function () {
              WinJS.Navigation.navigate('settings.html');
             });
        }
    }
 
    WinJS.Application.start();
})();